/* HYBRID RC: black and "go" green (from the HYBRID RC Round Timer). Desktop first, with a phone layout
   (bottom tab bar, card lists, big touch targets) under 760px. */
:root {
  --ink: #0e0f11;
  --ink-2: #2a2d33;
  --muted: #6b7179;
  --line: #e6e7ea;
  --bg: #f3f4f6;
  --card: #fff;
  --brand: #0d0d0f;
  --accent: #1fc35f;      /* timer "go" green: fills, bars, highlights */
  --on-accent: #04140a;   /* text on top of the green */
  --accent-ink: #0f7a39;  /* darker green for green text on white */
  --ok: #0f7a39;
  --ok-bg: #e3f5ea;
  --warn: #9a5800;
  --warn-bg: #fff2dc;
  --err: #b3261e;
  --err-bg: #fdeceb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 18, 22, 0.05), 0 4px 16px rgba(16, 18, 22, 0.05);
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: inherit; }
h1 { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; margin: 0.2em 0 0.7em; display: flex; align-items: center; gap: 0.5em; flex-wrap: wrap; }
h2 { font-size: 1.05rem; font-weight: 700; margin: 0 0 0.8em; }
h3 { font-size: 0.78rem; margin: 1.2em 0 0.5em; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }
code { background: #eef0f2; padding: 0.1em 0.35em; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
h1 .muted { font-weight: 600; }

/* ---------------------------------------------------------------- top bars */
.topbar, .pub-top {
  background: var(--brand); color: #fff; display: flex; align-items: center; gap: 1.2rem;
  padding: 0.55rem 1.4rem; padding-top: max(0.55rem, env(safe-area-inset-top));
  position: sticky; top: 0; z-index: 20; box-shadow: inset 0 -3px 0 var(--accent);
}
.brand { font-weight: 800; letter-spacing: 0.06em; text-decoration: none; color: #fff; }
.topbar nav, .pub-top nav { display: flex; gap: 0.15rem; flex-wrap: wrap; flex: 1; }
.pub-top nav { flex: none; flex-wrap: nowrap; margin-left: auto; }
.topbar nav a, .pub-top nav a { color: #b9bcc2; text-decoration: none; padding: 0.4rem 0.75rem; border-radius: 8px; font-weight: 600; font-size: 0.95rem; }
.topbar nav a:hover, .pub-top nav a:hover { color: #fff; background: #1d1e21; }
.topbar nav a.active { color: var(--accent); background: #26282c; box-shadow: inset 0 -2px 0 var(--accent); }
.logout button { color: #9a9ea6; font-size: 0.9rem; }
.logout button:hover { color: #fff; }

main { padding: 1.5rem 1.4rem 2.5rem; max-width: 1200px; margin: 0 auto; }
main.narrow { max-width: 640px; }

/* ---------------------------------------------------------------- phone tab bar */
.tabbar { display: none; }
.ico { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------------- cards & layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card.center { text-align: center; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1rem; align-items: start; }
.grid2 .card { margin: 0; }
.grid2 .wide { grid-column: 1 / -1; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.row-between h1 { margin: 0; }
.row-between > div { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-top: 0.6rem; }
td.actions { margin: 0; }
.hero { text-align: center; padding: 3rem 0; }
.hero h1 { justify-content: center; font-size: 2.4rem; }

/* ---------------------------------------------------------------- stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem; display: flex; flex-direction: column; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent); }
.stat .label { color: var(--muted); font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.stat .value { font-size: 2rem; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 0.8rem; color: var(--muted); }
.stat.warn { border-color: #f0c27a; background: var(--warn-bg); }
.stat.warn::before { background: var(--err); }

/* ---------------------------------------------------------------- check-in bars */
.bars { display: flex; gap: 0.5rem; align-items: flex-end; height: 140px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar-fill { width: 100%; max-width: 34px; background: var(--ink); border-radius: 6px 6px 2px 2px; min-height: 3px; }
.bar:last-child .bar-fill { background: var(--accent); }
.bar-n { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-d { font-size: 0.75rem; color: var(--muted); margin-top: 0.3rem; font-weight: 600; }
.h0 { height: 0; } .h1 { height: 10%; } .h2 { height: 20%; } .h3 { height: 30%; } .h4 { height: 40%; } .h5 { height: 50%; }
.h6 { height: 60%; } .h7 { height: 70%; } .h8 { height: 80%; } .h9 { height: 90%; } .h10 { height: 100%; }

/* ---------------------------------------------------------------- tables & lists */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.65rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th { font-size: 0.72rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; background: #fafafb; }
.table { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table tbody tr:hover { background: #fafafb; }
td a { font-weight: 600; text-decoration: none; }
td a:hover { text-decoration: underline; }
tr.failed td { color: var(--err); }
tr.refunded td { color: var(--muted); text-decoration: line-through; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 0.55rem 0; border-bottom: 1px solid var(--line); display: flex; gap: 0.6rem; justify-content: space-between; align-items: baseline; }
.list li:last-child { border-bottom: 0; }
.list li a { text-decoration: none; }
.list.small li { justify-content: flex-start; }
.ev-door_error, .ev-backup_error { color: var(--err); }
.ev-door_warning { color: var(--warn); }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1rem; margin: 0 0 1rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-weight: 500; }

/* ---------------------------------------------------------------- badges */
.badge { display: inline-flex; align-items: center; gap: 0.35em; font-size: 0.74rem; font-weight: 700; padding: 0.22em 0.65em; border-radius: 999px; background: #eceef0; color: var(--ink); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.badge-active, .badge-door-on { background: var(--ok-bg); color: var(--ok); }
.badge-past_due, .badge-error { background: var(--err-bg); color: var(--err); }
.badge-frozen, .badge-lead { background: var(--warn-bg); color: var(--warn); }
.badge-cancelled, .badge-door-off, .badge-expired { background: #eceef0; color: var(--muted); }

/* ---------------------------------------------------------------- forms */
label { display: block; font-size: 0.88rem; font-weight: 600; margin-bottom: 0.8rem; color: var(--ink-2); }
label.inline { display: flex; gap: 0.5rem; align-items: center; font-weight: 500; }
input, select, textarea { font: inherit; font-weight: 400; display: block; width: 100%; margin-top: 0.3rem; padding: 0.6rem 0.75rem; border: 1px solid #d3d6db; border-radius: 10px; background: #fff; color: var(--ink); }
select { appearance: none; -webkit-appearance: none; padding-right: 2rem; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%; background-size: 5px 5px; background-repeat: no-repeat; }
input[type="checkbox"], input[type="radio"] { width: auto; display: inline; margin: 0; accent-color: var(--accent-ink); }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(31, 195, 95, 0.28); outline-offset: 0; border-color: var(--accent-ink); }
fieldset { border: 1px solid var(--line); border-radius: 12px; margin: 0 0 1rem; padding: 0.7rem 1rem; }
legend { font-weight: 700; padding: 0 0.3rem; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 1rem; align-items: end; }
.inline-form { display: flex; gap: 0.5rem; margin-bottom: 0.6rem; align-items: center; }
.inline-form select, .inline-form input { margin: 0; width: auto; flex: 1; }
.filters { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filters input { flex: 2; min-width: 200px; margin: 0; }
.filters select { flex: 1; width: auto; margin: 0; }
.plan-choice { display: flex; gap: 0.75rem; align-items: flex-start; padding: 0.85rem; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; background: #fff; }
.plan-choice:has(input:checked) { border-color: var(--accent-ink); box-shadow: inset 0 0 0 1px var(--accent-ink); background: #f3fcf6; }
.plan-choice span { display: flex; flex-direction: column; }
input.copy { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 0.8rem; background: #f7f7f8; cursor: copy; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; font: inherit; font-weight: 700; padding: 0.55rem 1.05rem; border-radius: 10px; border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); cursor: pointer; text-decoration: none; transition: transform 0.08s ease, opacity 0.15s ease; }
.btn:hover { opacity: 0.88; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn:active { transform: scale(0.97); }
.btn.ghost { background: #fff; color: var(--ink); border-color: #d3d6db; }
.btn.danger, .link.danger { color: var(--err); }
.btn.big { padding: 0.85rem 1.5rem; font-size: 1.05rem; }
.btn.small { padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.link { background: none; border: 0; padding: 0; font: inherit; text-decoration: underline; cursor: pointer; color: inherit; }
td form, .actions form { display: inline; }

/* ---------------------------------------------------------------- flash messages */
.flash { padding: 0.8rem 1rem; border-radius: 12px; margin-bottom: 1rem; font-weight: 600; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--err-bg); color: var(--err); }
.flash.big { font-size: 1.3rem; }

/* ---------------------------------------------------------------- door */
.door-state { font-weight: 800; font-size: 1.15rem; margin: 0 0 0.3rem; }
.door-state.on { color: var(--ok); }
.door-state.off { color: var(--err); }
.qr-wrap { margin: 0.8rem 0; }
.qr { border: 1px solid var(--line); border-radius: 12px; image-rendering: pixelated; background: #fff; padding: 6px; }
.qr.big { width: min(280px, 80vw); height: auto; }

/* ---------------------------------------------------------------- check-in */
.checkin-form { display: flex; gap: 0.6rem; margin-bottom: 1rem; }
.checkin-form input { font-size: 1.4rem; padding: 0.85rem; margin: 0; border-radius: 12px; }
.checkin-form .btn { font-size: 1.2rem; padding: 0 1.6rem; }

/* ---------------------------------------------------------------- schedule */
.week { display: grid; grid-template-columns: repeat(7, minmax(120px, 1fr)); gap: 0.5rem; margin-bottom: 1rem; overflow-x: auto; }
.day { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.65rem; min-height: 120px; box-shadow: var(--shadow); }
.day.today { border-color: var(--accent-ink); box-shadow: inset 0 0 0 1px var(--accent-ink); }
.day h3 { margin: 0 0 0.5rem; }
.session { display: flex; flex-direction: column; font-size: 0.85rem; text-decoration: none; padding: 0.5rem 0.6rem; border-radius: 8px; background: #f2f3f5; margin-bottom: 0.4rem; border-left: 3px solid var(--ink); }
.session:hover { background: #e8eaed; }
.session.full { border-left-color: var(--err); }
.session.cancelled { opacity: 0.5; text-decoration: line-through; }
ul.classes { list-style: none; padding: 0; margin: 0; }
ul.classes li { display: flex; align-items: center; gap: 0.8rem; padding: 0.65rem 0; border-bottom: 1px solid var(--line); }
ul.classes li > span:first-child { flex: 1; }

/* ---------------------------------------------------------------- logo */
.brand-logo { display: flex; align-items: center; border: 0; padding: 0; }
.brand-logo img { height: 54px; width: auto; display: block; }
.hero-logo { width: min(520px, 90vw); height: auto; }

/* ---------------------------------------------------------------- month calendar */
.cal { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 1rem; box-shadow: var(--shadow); }
.cal-row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-head div { font-size: 0.72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; padding: 0.5rem; border-bottom: 1px solid var(--line); background: #fafafb; }
.cal-day { min-height: 104px; padding: 0.35rem; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-row .cal-day:last-child { border-right: 0; }
.cal-day.other { background: #fafafb; }
.cal-day.other .cal-date { color: #b5b9be; }
.cal-day.past .cal-ev { opacity: 0.55; }
.cal-day.today .cal-date { background: var(--accent); color: var(--on-accent); border-radius: 999px; width: 1.6rem; height: 1.6rem; display: grid; place-items: center; }
.cal-date { font-size: 0.8rem; font-weight: 700; }
.cal-ev { --prog: #111; display: block; font-size: 0.75rem; line-height: 1.25; padding: 3px 6px; border-radius: 5px; text-decoration: none; background: color-mix(in srgb, var(--prog) 12%, white); border-left: 3px solid var(--prog); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev:hover { background: color-mix(in srgb, var(--prog) 22%, white); }
.cal-ev.one-off { font-weight: 700; }
.cal-ev.cancelled { text-decoration: line-through; opacity: 0.5; }
.cal-time { font-variant-numeric: tabular-nums; }
.cal-extra { color: var(--muted); }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.85rem; margin-bottom: 0.7rem; }
.legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.legend span::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--prog, #111); }
.tabs { display: inline-flex; background: #e9eaed; border-radius: 10px; padding: 3px; gap: 2px; }
.tabs a { padding: 0.4rem 0.9rem; text-decoration: none; font-weight: 700; border-radius: 8px; color: var(--muted); }
.tabs a.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.plan-meta { font-size: 0.85rem; color: var(--muted); }

/* ================================================================ phones */
@media (max-width: 760px) {
  /* 16px text stops iPhones zooming in when a box is tapped. */
  input, select, textarea { font-size: 16px; padding: 0.75rem 0.85rem; }
  .btn { min-height: 46px; padding: 0.65rem 1.1rem; }
  .btn.small { min-height: 36px; }

  main { padding: 1rem 1rem calc(var(--tabbar-h) + var(--safe-b) + 1.5rem); }
  body.public main { padding-bottom: 2rem; }
  h1 { font-size: 1.55rem; margin-bottom: 0.6em; }
  .card { padding: 1rem; border-radius: 16px; }

  /* slim header: logo only, the rest lives in the tab bar */
  .topbar { justify-content: center; padding: 0.45rem 1rem; padding-top: max(0.45rem, env(safe-area-inset-top)); }
  .topbar .desk-nav, .topbar .logout { display: none; }
  .brand-logo img { height: 42px; }
  .pub-top { padding: 0.45rem 1rem; padding-top: max(0.45rem, env(safe-area-inset-top)); gap: 0.6rem; }
  .pub-top nav a { padding: 0.45rem 0.6rem; }

  /* bottom tab bar */
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    border-top: 1px solid #222;
  }
  /* The blur sits on a layer behind the tabs: a blur on .tabbar itself would
     trap the "More" sheet (position: fixed) inside the bar. */
  .tabbar::after {
    content: ""; position: absolute; inset: 0; z-index: -1;
    background: rgba(11, 11, 12, 0.94); backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  }
  .tabbar .more .ico { stroke-width: 3.6; }
  .tabbar > a, .tabbar summary {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: #8d9198; text-decoration: none; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.01em;
    list-style: none; cursor: pointer; position: relative; height: var(--tabbar-h);
  }
  .tabbar summary::-webkit-details-marker { display: none; }
  .tabbar > a.on, .tabbar .more.on summary, .tabbar .more[open] summary { color: var(--accent); }
  .tabbar > a.on::before, .tabbar .more.on summary::before {
    content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent);
  }
  .tabbar > a:active, .tabbar summary:active { transform: scale(0.94); }

  /* "More" opens a sheet above the tab bar */
  .tabbar .more { position: relative; }
  .tabbar .sheet {
    position: fixed; left: 0.75rem; right: 0.75rem; bottom: calc(var(--tabbar-h) + var(--safe-b) + 0.6rem);
    background: #fff; border-radius: 18px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3); overflow: hidden;
    animation: sheet-up 0.18s ease-out;
  }
  .tabbar .sheet a, .tabbar .sheet button {
    display: block; width: 100%; text-align: left; padding: 1rem 1.2rem; font: inherit; font-size: 1.05rem; font-weight: 600;
    color: var(--ink); text-decoration: none; background: none; border: 0; border-bottom: 1px solid var(--line); cursor: pointer;
  }
  .tabbar .sheet a.on { color: var(--accent-ink); }
  .tabbar .sheet form { margin: 0; }
  .tabbar .sheet .sheet-logout { color: var(--err); border-bottom: 0; }
  .tabbar .more[open]::before { content: ""; position: fixed; inset: 0; bottom: calc(var(--tabbar-h) + var(--safe-b)); background: rgba(0, 0, 0, 0.4); z-index: 1; }
  .tabbar .sheet { z-index: 2; }

  /* tables become stacked cards */
  table, thead, tbody, tr, th, td { display: block; }
  thead { display: none; }
  table tr { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.6rem; padding: 0.8rem 0.1rem; border-bottom: 1px solid var(--line); }
  table tr:last-child { border-bottom: 0; }
  table td { border: 0; padding: 0; }
  table td:first-child { flex-basis: 100%; font-size: 1rem; }
  table td:empty { display: none; }
  .table { padding: 0 1rem; }
  .table tbody tr:hover { background: none; }
  td.actions { flex-basis: 100%; }

  .stats { grid-template-columns: 1fr 1fr; gap: 0.7rem; }
  .stat { padding: 0.85rem 0.9rem; }
  .stat .value { font-size: 1.6rem; }
  .grid2 { grid-template-columns: 1fr; }
  .row-between > div { width: 100%; }
  .row-between > div .btn { flex: 1; }
  .filters input { min-width: 0; flex-basis: 100%; }
  .filters select, .filters .btn { flex: 1; }
  .inline-form { flex-wrap: wrap; }
  .inline-form select, .inline-form input { flex-basis: 100%; }
  .inline-form .btn { flex: 1; }
  .checkin-form { flex-direction: column; }
  .checkin-form .btn { padding: 0.8rem; }
  .week { grid-template-columns: 1fr; }
  .tabs { display: flex; }
  .tabs a { flex: 1; text-align: center; }
  /* Month view on a phone: each class is a coloured bar (tap it to open);
     the Week view lists them in full. */
  .cal-day { min-height: 62px; padding: 0.25rem; align-items: center; }
  .cal-ev { font-size: 0; line-height: 0; height: 7px; width: 100%; padding: 0; border: 0; border-radius: 4px; background: var(--prog); }
  .cal-ev:hover { background: var(--prog); }
  .cal-ev.cancelled { opacity: 0.25; }
  .cal-head div { padding: 0.4rem 0.2rem; text-align: center; }
  .bars { height: 120px; }
}

@keyframes sheet-up { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .tabbar .sheet { animation: none; } .btn { transition: none; } }
