/* Bookerbaby — mobile-first styles */
:root {
  --bg: #f7f8fa;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #6b7785;
  --line: #e3e8ee;
  --brand: #5b6ee1;
  --brand-dark: #4555c8;
  --yes: #34c759;
  --yes-bg: #e6f9ec;
  --maybe: #ffb020;
  --maybe-bg: #fff5e0;
  --no: #ff4d4f;
  --no-bg: #ffe9e9;
  --gray: #cbd2da;
  --control-bg: #ffffff;   /* inputs, controls */
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 30, 50, .08), 0 6px 24px rgba(20, 30, 50, .06);
}

/* ---- dark mode (follows the OS setting) ---- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --card: #1d2027;
    --ink: #e7eaee;
    --muted: #9aa4b2;
    --line: #2c313b;
    --brand: #818df2;
    --brand-dark: #6b78e8;
    --gray: #4b5563;
    --control-bg: #252a33;
    --yes-bg: rgba(52, 199, 89, .16);
    --maybe-bg: rgba(255, 176, 32, .16);
    --no-bg: rgba(255, 77, 79, .18);
    --shadow: 0 1px 3px rgba(0, 0, 0, .45), 0 6px 24px rgba(0, 0, 0, .4);
  }
  /* hardcoded light surfaces -> dark equivalents */
  .btn.secondary { background: #2a2f3a; color: var(--ink); }
  .btn.secondary:hover { background: #333a47; }
  .cal-nav { background: var(--control-bg); color: var(--ink); }
  .cal-nav:hover { background: #2c313b; }
  .cal-cell.tappable { background: #262b34; }
  .toggle-opt { background: var(--card); }
  .chip { background: #2a2f3a; }
  .chip button:hover { color: var(--no); }
  .linkbox input { background: var(--control-bg); }
  .stat { background: var(--control-bg); }
  .event-card { background: var(--card); }
  .tab { background: var(--card); }
  .navlink:hover { background: #2a2f3a; }
  .pill.gray { background: #2a2f3a; }
  .pill.green { color: #6fe39a; }
  .pill.amber { color: #ffce6b; }
  .sticky-save { background: rgba(20, 22, 27, .92); }
  .toast { background: #2c313b; }
  /* readable status text on dark */
  .cal-cell.s-yes, .slotchip.s-yes { color: #6fe39a; }
  .cal-cell.s-maybe, .slotchip.s-maybe { color: #ffce6b; }
  .cal-cell.s-no, .slotchip.s-no { color: #ff8e90; }
  table.grid td.cell-maybe { color: #ffce6b; }
  table.grid td.cell-yes, table.grid th.best, .bestlabel { color: #6fe39a; }
  .banner.final { color: #8fe7ad; }
  .banner.closed { color: #ff9a9c; }
  .warn { color: #e8c98a; }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;           /* never sideways-scroll the page itself */
}

/* No grey tap-flash on iOS; let only the calendar/results table scroll-x */
* { -webkit-tap-highlight-color: transparent; }
button, .btn, .toggle-opt, .cal-cell, .chip button { touch-action: manipulation; }

.wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 20px 16px calc(120px + env(safe-area-inset-bottom));
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -.02em;
  color: var(--brand);
  margin-bottom: 18px;
}
.brand .dot { font-size: 22px; }
.brand a { color: inherit; text-decoration: none; }
.brand .spacer { flex: 1; }
.authnav { display: inline-flex; align-items: center; gap: 4px; }
.navlink {
  font-size: 13px; font-weight: 600; color: var(--muted);
  text-decoration: none; padding: 6px 10px; border-radius: 8px;
}
.navlink:hover { background: #eef1f6; color: var(--ink); }
.navlink.as-btn { border: none; background: none; cursor: pointer; font-family: inherit; }

/* tables for dashboard / owner console */
table.list { border-collapse: collapse; width: 100%; font-size: 14px; }
table.list th, table.list td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; }
table.list th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat { background: #f4f6f9; border-radius: 10px; padding: 14px; text-align: center; }
.stat .v { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.stat .k { font-size: 12px; color: var(--muted); margin-top: 2px; }
.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.pill.green { background: var(--yes-bg); color: #137a36; }
.pill.gray { background: #eef1f6; color: var(--muted); }
.pill.amber { background: var(--maybe-bg); color: #9a6500; }
.event-card {
  display: block; border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 10px; text-decoration: none; color: inherit;
  background: #fff;
}
.event-card:hover { border-color: var(--brand); box-shadow: var(--shadow); }
.event-card .et { font-weight: 700; font-size: 16px; }
.event-card .em { font-size: 13px; color: var(--muted); margin-top: 3px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tab { padding: 9px 14px; border-radius: 9px; border: 1px solid var(--line); background: #fff; cursor: pointer; font: inherit; font-weight: 600; font-size: 14px; color: var(--muted); }
.tab.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* time-slot chips (datetime events) */
.slotchip {
  padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--control-bg); color: var(--ink); font: inherit; font-weight: 600;
  font-size: 14px; cursor: pointer;
}
.slotchip:hover { border-color: var(--brand); }
.slotchip.s-yes { background: var(--yes-bg); border-color: var(--yes); color: #137a36; }
.slotchip.s-maybe { background: var(--maybe-bg); border-color: var(--maybe); color: #9a6500; }
.slotchip.s-no { background: var(--no-bg); border-color: var(--no); color: #b21f22; }
.account-nudge {
  background: rgba(91,110,225,.06); border: 1px solid rgba(91,110,225,.25);
  border-radius: 10px; padding: 11px 13px; font-size: 13px; margin-top: 12px; color: var(--ink);
}
.account-nudge a { color: var(--brand); font-weight: 700; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.02em; }
h2 { font-size: 17px; margin: 0 0 12px; }
p.sub { color: var(--muted); margin: 0 0 16px; }
.muted { color: var(--muted); }

label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
input[type=text], input[type=password], input[type=email], input[type=date], input[type=time], textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: var(--control-bg);
  color: var(--ink);
}
input[type=date], input[type=time] { color-scheme: light dark; }
input[type=text]:focus, input[type=password]:focus, input[type=email]:focus, input[type=date]:focus, input[type=time]:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(91, 110, 225, .15);
}
textarea { resize: vertical; min-height: 64px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 18px;
  border: none;
  border-radius: 11px;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s, transform .04s;
}
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: #eef1f6; color: var(--ink); }
.btn.secondary:hover { background: #e3e8ef; }
.btn.danger { background: var(--no-bg); color: var(--no); }
.btn.block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---- calendar ---- */
.cal { user-select: none; -webkit-user-select: none; }
.cal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.cal-title { font-weight: 700; font-size: 16px; }
.cal-nav {
  width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; font-size: 18px; cursor: pointer; color: var(--ink);
}
.cal-nav:hover { background: #f1f4f9; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; padding-bottom: 2px; }
.cal-cell {
  aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  font-size: 15px;
  border: 1px solid transparent;
  position: relative;
}
.cal-cell.empty { visibility: hidden; }
.cal-cell.pad { color: var(--gray); }
.cal-cell.tappable { cursor: pointer; background: #f1f4f9; border-color: var(--line); }
.cal-cell.tappable:hover { border-color: var(--brand); }
.cal-cell.disabled { color: var(--gray); background: transparent; }
.cal-cell.selected { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 700; }
.cal-cell.anchor { box-shadow: 0 0 0 3px rgba(91,110,225,.3); }
.cal-cell.s-yes { background: var(--yes-bg); border-color: var(--yes); color: #137a36; font-weight: 700; }
.cal-cell.s-maybe { background: var(--maybe-bg); border-color: var(--maybe); color: #9a6500; font-weight: 700; }
.cal-cell.s-no { background: var(--no-bg); border-color: var(--no); color: #b21f22; font-weight: 700; }
.cal-cell .final-star { position: absolute; top: 2px; right: 4px; font-size: 10px; }
.cal-cell.final { box-shadow: 0 0 0 3px rgba(52,199,89,.45); }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; border: 1px solid rgba(0,0,0,.08); }
.swatch.yes { background: var(--yes); }
.swatch.maybe { background: var(--maybe); }
.swatch.no { background: var(--no); }

/* ---- toggle ---- */
.toggle-row { display: flex; gap: 8px; margin-top: 6px; }
.toggle-opt {
  flex: 1; padding: 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; cursor: pointer; text-align: left; font: inherit;
}
.toggle-opt .t-title { font-weight: 700; font-size: 14px; }
.toggle-opt .t-desc { font-size: 12px; color: var(--muted); }
.toggle-opt.active { border-color: var(--brand); background: rgba(91,110,225,.06); box-shadow: 0 0 0 2px rgba(91,110,225,.15); }

/* ---- chips / selected dates ---- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #eef1f6; border-radius: 999px; padding: 6px 10px 6px 12px; font-size: 13px;
}
.chip button { border: none; background: none; cursor: pointer; color: var(--muted); font-size: 15px; line-height: 1; padding: 0; }
.chip button:hover { color: var(--no); }

/* ---- results table ---- */
.results { overflow-x: auto; }
table.grid { border-collapse: collapse; width: 100%; font-size: 14px; }
table.grid th, table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; }
table.grid th.name, table.grid td.name { text-align: left; position: sticky; left: 0; background: var(--card); font-weight: 600; }
table.grid thead th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.grid td.cell-yes { color: var(--yes); font-weight: 700; }
table.grid td.cell-maybe { color: var(--maybe); font-weight: 700; }
table.grid td.cell-no { color: var(--no); }
table.grid td.cell-none { color: var(--gray); }
table.grid tr.totals td { font-weight: 700; border-top: 2px solid var(--line); }
table.grid th.best { color: var(--yes); }

.barlist { display: flex; flex-direction: column; gap: 10px; }
.barrow { display: grid; grid-template-columns: 110px 1fr auto; align-items: center; gap: 10px; }
.barrow .d { font-weight: 600; font-size: 14px; }
.bar { background: #eef1f6; border-radius: 8px; height: 22px; overflow: hidden; display: flex; }
.bar .seg-yes { background: var(--yes); }
.bar .seg-maybe { background: var(--maybe); }
.barrow .n { font-size: 13px; color: var(--muted); }
.barrow.best .d { color: var(--yes); }

/* ---- success / link box ---- */
.linkbox { display: flex; gap: 8px; align-items: stretch; margin-top: 6px; }
.linkbox input { flex: 1; font-size: 13px; background: #f4f6f9; }
.warn {
  background: var(--maybe-bg); border: 1px solid var(--maybe);
  border-radius: 10px; padding: 12px 14px; font-size: 14px; margin-top: 14px; color: #7a5200;
}
.banner {
  border-radius: 10px; padding: 12px 14px; font-size: 14px; margin-bottom: 14px;
}
.banner.closed { background: var(--no-bg); border: 1px solid var(--no); color: #b21f22; }
.banner.final { background: var(--yes-bg); border: 1px solid var(--yes); color: #137a36; }

/* ---- sticky save ---- */
.sticky-save {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex; justify-content: center;
}
.sticky-save .inner { width: 100%; max-width: 680px; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--no); }

/* ---- small phones ---- */
@media (max-width: 400px) {
  .wrap { padding-left: 13px; padding-right: 13px; }
  .card { padding: 15px; }
  h1 { font-size: 22px; }
  .cal-grid { gap: 4px; }
  /* visibility cards read better stacked when their text is long */
  .toggle-row.stack { flex-direction: column; }
}

.hidden { display: none !important; }
.spinner { text-align: center; color: var(--muted); padding: 40px 0; }
.error-state { text-align: center; padding: 50px 16px; color: var(--muted); }
.error-state h1 { color: var(--ink); }
.bestlabel { font-size: 12px; color: var(--yes); font-weight: 700; margin-top: 12px; }
