/* Kilikood brand: saffron #FAC42B and ink #161616, taken from the logo.
   Mobile first: the base styles are for phones; wider screens build on them. */

/* ---------- Theme tokens ----------
   Light is the default. Dark applies when the device prefers it (unless the
   viewer picked light) or when the viewer picked dark (data-theme on <html>). */
:root {
  --brand: #fac42b;
  --brand-hover: #f2b814;
  --brand-soft: #fdf1cc;
  --ink: #161616;

  --bg: #f7f5ef;
  --surface: #ffffff;
  --text: #161616;
  --muted: #625c4f;
  --border: #e6e1d4;
  --row-hover: #fcf8ec;
  --track: #efe8d4;
  /* Saffron is too light for text or outlines on white; this darker amber
     keeps links, icons and focus rings readable. */
  --accent-text: #8a6100;
  --focus: #8a6100;
  --ok-bg: #e3f4e8;
  --ok-text: #1b6e36;
  --no-bg: #f0ede4;
  --no-text: #625c4f;
  --danger-bg: #fdecea;
  --danger-text: #a3201b;
  /* Sales chart: the line in a deeper saffron so it stands out on white
     (3:1); the fill under it fades out from brand saffron. */
  --trend-line: #b87e00;
  --trend-fill: #fac42b;
  --trend-fill-opacity: 0.5;
  /* Stacked "Sales by ticket type" columns: six hues in a fixed order,
     checked for colorblind separation and for contrast against the card.
     The legend names every type, so color is never the only cue. */
  --series-1: #eda100;
  --series-2: #1baf7a;
  --series-3: #2a78d6;
  --series-4: #e87ba4;
  --series-5: #008300;
  --series-6: #4a3aa7;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-soft: #3a3019;
    --bg: #121211;
    --surface: #1c1b19;
    --text: #f1eee6;
    --muted: #aba491;
    --border: #34312b;
    --row-hover: #25231f;
    --track: #34312b;
    --accent-text: #fac42b;
    --focus: #fac42b;
    --ok-bg: #15321e;
    --ok-text: #86d69e;
    --no-bg: #28261f;
    --no-text: #aba491;
    --danger-bg: #3a1b1a;
    --danger-text: #f2a8a4;
    --trend-line: #fac42b;
    --trend-fill: #fac42b;
    --trend-fill-opacity: 0.3;
    /* The same six hues stepped for the dark card, not an automatic flip. */
    --series-1: #c98500;
    --series-2: #199e70;
    --series-3: #3987e5;
    --series-4: #d55181;
    --series-5: #008300;
    --series-6: #9085e9;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --brand-soft: #3a3019;
  --bg: #121211;
  --surface: #1c1b19;
  --text: #f1eee6;
  --muted: #aba491;
  --border: #34312b;
  --row-hover: #25231f;
  --track: #34312b;
  --accent-text: #fac42b;
  --focus: #fac42b;
  --ok-bg: #15321e;
  --ok-text: #86d69e;
  --no-bg: #28261f;
  --no-text: #aba491;
  --danger-bg: #3a1b1a;
  --danger-text: #f2a8a4;
  --trend-line: #fac42b;
  --trend-fill: #fac42b;
  --trend-fill-opacity: 0.3;
  --series-1: #c98500;
  --series-2: #199e70;
  --series-3: #3987e5;
  --series-4: #d55181;
  --series-5: #008300;
  --series-6: #9085e9;
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent-text); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
pre { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow-x: auto; }
.muted { color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.icon { flex: none; display: block; width: 18px; height: 18px; }

.wrap {
  max-width: 1240px;
  margin: 0 auto;
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
}

/* ---------- Header: ink with a saffron rule in both themes, like the logo ---------- */
.topbar { background: var(--ink); border-bottom: 3px solid var(--brand); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 56px; }
.brand { display: inline-flex; align-items: center; gap: 10px; min-width: 0; color: #ffffff; text-decoration: none; font-weight: 700; letter-spacing: 0.01em; }
.brand img { flex: none; display: block; width: 30px; height: 30px; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.topbar form { margin: 0; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 40px;
  min-height: 40px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #e9e6dd;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.08); }
.topbar :focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.signout { color: var(--brand); }
.signout span { display: none; }

/* The theme button shows the current mode. */
.theme-toggle .icon { display: none; }
:root:not([data-theme]) .theme-toggle .i-auto,
:root[data-theme="light"] .theme-toggle .i-light,
:root[data-theme="dark"] .theme-toggle .i-dark { display: block; }

main.wrap { padding-top: 20px; padding-bottom: 48px; }
main.wrap.narrow { max-width: 440px; }

h1 { font-size: 22px; line-height: 1.25; margin: 0 0 4px; }
.meta { color: var(--muted); margin: 0 0 20px; }

/* ---------- Panels, alerts, forms ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.panel h1 { font-size: 22px; }
.empty { padding: 32px 20px; text-align: center; color: var(--muted); margin: 0; }
.empty .icon { width: 28px; height: 28px; margin: 0 auto 8px; }
.empty p { margin: 0; }

.alert { display: flex; align-items: flex-start; gap: 10px; background: var(--danger-bg); color: var(--danger-text); padding: 12px 14px; border-radius: 10px; margin: 0 0 16px; text-align: left; }
.alert .icon { margin-top: 2px; }

label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field { margin-bottom: 16px; }

input, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px stops iPhones zooming in on focus */
}

input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, tr:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.input-icon, .search { position: relative; }
.input-icon .icon, .search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon input, .search input { padding-left: 40px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--brand);
  border-radius: 10px;
  background: var(--brand);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); font-weight: 600; }
.btn.secondary:hover { border-color: var(--brand); }
.btn.full { width: 100%; }

/* ---------- Sign-in ---------- */
.login { margin-top: 8px; text-align: center; border-top: 4px solid var(--brand); }
.login form { text-align: left; }
.login-logo { display: block; margin: 0 auto 14px; }

/* "Fetching attendees…": the logo inside a turning saffron ring. */
.spinner { position: relative; display: grid; place-items: center; width: 96px; height: 96px; margin: 0 auto 16px; }
.spinner::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 4px solid var(--track);
  border-top-color: var(--brand);
  animation: spin 0.9s linear infinite;
}
.spinner img { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Event header ---------- */
.event-head { margin-bottom: 16px; }
.event-meta { display: flex; flex-direction: column; gap: 6px; list-style: none; margin: 8px 0 0; padding: 0; color: var(--muted); font-size: 14px; }
.event-meta li { display: flex; align-items: flex-start; gap: 8px; }
.event-meta .icon { color: var(--accent-text); margin-top: 1px; }

/* ---------- Tabs: Overview | Attendees ---------- */
.tabs { display: flex; gap: 2px; margin-bottom: 14px; padding: 3px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.tab {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 8px;
  white-space: nowrap;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tab .icon { width: 17px; height: 17px; }
.tab[aria-selected="true"] { background: var(--brand-soft); color: var(--text); }
.tab[aria-selected="true"] .icon { color: var(--accent-text); }
.tab-count { display: none; padding: 0 7px; border-radius: 999px; background: var(--no-bg); font-size: 12px; line-height: 1.6; font-variant-numeric: tabular-nums; }
.tab[aria-selected="true"] .tab-count { background: var(--surface); }
.event-tabs:not([data-tab="overview"]) #panel-overview,
.event-tabs:not([data-tab="checkin"]) #panel-checkin,
.event-tabs:not([data-tab="attendees"]) #panel-attendees { display: none; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 16px; }
.stat { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; min-width: 0; }
.stat-icon { display: grid; place-items: center; width: 32px; height: 32px; margin-bottom: 8px; border-radius: 9px; background: var(--no-bg); color: var(--no-text); }
.stat:first-child .stat-icon,
.stat.people .stat-icon { background: var(--brand-soft); color: var(--accent-text); }
.stat.ok .stat-icon { background: var(--ok-bg); color: var(--ok-text); }
.stat b { font-size: 22px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 12.5px; line-height: 1.3; }

progress.meter {
  display: block;
  width: 100%;
  height: 6px;
  margin-top: 8px;
  border: 0;
  border-radius: 3px;
  background: var(--track);
  overflow: hidden;
  -webkit-appearance: none;
  appearance: none;
}
progress.meter::-webkit-progress-bar { background: var(--track); border-radius: 3px; }
progress.meter::-webkit-progress-value { background: var(--brand); border-radius: 3px; }
progress.meter::-moz-progress-bar { background: var(--brand); border-radius: 3px; }

/* ---------- Ticket sales, last 7 days ----------
   A line with a fading fill, drawn by portal.js as SVG, over 7, 14 or 30
   days or since sales began. Numbers sit above the points (every day up to
   a week, then the busiest day and today), so there's no y-axis. */
.trend { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 12px 10px; margin-bottom: 16px; }
.trend-head { display: flex; align-items: center; gap: 10px; }
.trend .stat-icon { flex: none; margin: 0; background: var(--brand-soft); color: var(--accent-text); }
.trend-heading { flex: 1 1 auto; min-width: 0; }
.trend h2 { margin: 0; font-size: 15px; line-height: 1.3; }
/* Time frame dropdowns in the Overview cards' top right (16px so iPhones
   don't zoom in). */
.range-select { flex: none; align-self: flex-start; width: auto; min-height: 34px; margin: 0; padding: 4px 10px; border-radius: 8px; font-size: 16px; font-weight: 600; }
.trend-total { display: flex; align-items: baseline; gap: 5px; margin: 2px 0 0; }
.trend-total b { font-size: 22px; line-height: 1.15; }
.trend-total span { color: var(--muted); font-size: 13px; }
.trend-delta { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.trend-delta.up { color: var(--ok-text); }
.trend-delta:empty { display: none; }

.trend-chart { position: relative; margin-top: 6px; touch-action: pan-y; }
.trend-svg { display: block; width: 100%; height: 150px; overflow: visible; }
.trend-base { stroke: var(--border); stroke-width: 1; }
.trend-cross { stroke: var(--muted); stroke-width: 1; opacity: 0.6; }
.trend-fill-top { stop-color: var(--trend-fill); stop-opacity: var(--trend-fill-opacity); }
.trend-fill-bottom { stop-color: var(--trend-fill); stop-opacity: 0; }
.trend-line { fill: none; stroke: var(--trend-line); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* The surface-colored ring keeps each dot clear of the line. */
.trend-dot { fill: var(--trend-line); stroke: var(--surface); stroke-width: 2; }
/* The halo keeps numbers readable where the line passes behind them. */
.trend-value {
  fill: var(--text);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--surface);
  stroke-width: 4px;
  stroke-linejoin: round;
}
.trend-value.none { fill: var(--muted); font-weight: 400; }
/* One column per day (portal.js sets --days); names can spill into their
   unnamed neighbors. */
.trend-days, .mix-days { display: grid; grid-template-columns: repeat(var(--days, 7), minmax(0, 1fr)); min-height: 32px; margin: 4px 0 0; padding: 0; list-style: none; text-align: center; }
.trend-day { display: flex; flex-direction: column; align-items: center; white-space: nowrap; font-size: 12px; line-height: 1.3; color: var(--muted); font-variant-numeric: tabular-nums; }
.trend-days .today .trend-day { color: var(--text); font-weight: 600; }
.trend-days .active .trend-day { color: var(--text); }

/* Hover or tap a day: full date and count. */
.trend-tip, .chart-tip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 3;
  transform: translate(calc(var(--x, 0px) - 50%), calc(var(--y, 0px) - 100% - 6px));
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  font-size: 12.5px;
  line-height: 1.35;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}
.trend-tip b, .chart-tip b { display: block; font-size: 14px; }
.trend-tip span, .chart-tip > span { opacity: 0.8; }

/* ---------- Tickets by type ----------
   Best seller first; each bar is scaled to the best seller, and the share
   of all tickets is written beside the count. */
.types { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 12px 14px; margin-bottom: 16px; }
.types-head { display: flex; align-items: center; gap: 10px; }
.types-heading { flex: 1 1 auto; min-width: 0; }
.types .stat-icon { flex: none; margin: 0; background: var(--brand-soft); color: var(--accent-text); }
.types h2 { margin: 0; font-size: 15px; line-height: 1.3; }
.types-sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.3; }
.types-list { display: grid; gap: 14px; margin: 14px 0 0; padding: 0; list-style: none; }
.types-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: 6px 12px; }
.type-name { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.type-count { font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.type-count b { font-weight: 700; }
.type-share { display: inline-block; min-width: 3.2em; margin-left: 6px; color: var(--muted); font-size: 13px; text-align: right; }
.type-checked { grid-column: 1 / -1; color: var(--muted); font-size: 12.5px; }

/* ---------- By category (Overview) ---------- */
.cats { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 12px 14px; margin-bottom: 16px; }
.cats .stat-icon { flex: none; margin: 0; background: var(--brand-soft); color: var(--accent-text); }
.cats h2 { margin: 0; font-size: 15px; line-height: 1.3; }
.cat-table { width: 100%; margin-top: 10px; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.cat-table th, .cat-table td { padding: 9px 0 9px 12px; border-top: 1px solid var(--border); text-align: right; vertical-align: baseline; }
.cat-table th:first-child { padding-left: 0; text-align: left; }
.cat-table td { width: 6.5em; }
.cat-table thead th { padding-top: 4px; border-top: 0; color: var(--muted); font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.cat-table tbody th { font-weight: 600; }
.cat-table tfoot th, .cat-table tfoot td { border-top: 2px solid var(--border); font-weight: 700; }
.cat-table.cols-4 td { width: 4.2em; }
.cat-footnote { margin: 10px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.cat-note { display: block; margin-top: 2px; color: var(--muted); font-size: 12.5px; font-weight: 400; overflow-wrap: anywhere; }
progress.type-bar {
  grid-column: 1 / -1;
  display: block;
  width: 100%;
  height: 8px;
  border: 0;
  border-radius: 4px;
  background: var(--track);
  overflow: hidden;
  -webkit-appearance: none;
  appearance: none;
}
progress.type-bar::-webkit-progress-bar { background: var(--track); border-radius: 4px; }
progress.type-bar::-webkit-progress-value { background: var(--trend-line); border-radius: 4px; }
progress.type-bar::-moz-progress-bar { background: var(--trend-line); border-radius: 4px; }

/* ---------- Check-in: arrivals, and how they split by ticket type ----------
   Bars here are green and scaled to each tier's own sales, so a full bar
   means that tier is all in — not that it outsold the others. */
/* Refresh by hand, or every 30 seconds while this tab is on screen. */
.checkin-bar { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.checkin-actions { display: flex; gap: 8px; }
.checkin-actions .btn { flex: 1 1 0; min-width: 0; }
.checkin-actions .btn.is-on { background: var(--brand-soft); border-color: var(--brand); color: var(--text); }
.checkin-actions .btn.is-on .icon { color: var(--accent-text); }
.checkin-updated { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.checkin-updated.is-error { color: var(--danger-text); }

.checkin { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 14px 16px; margin-bottom: 16px; }
.checkin-head { display: flex; align-items: center; gap: 10px; }
.checkin .stat-icon { flex: none; margin: 0; background: var(--ok-bg); color: var(--ok-text); }
.checkin-heading { flex: 1 1 auto; min-width: 0; }
.checkin h2 { margin: 0; font-size: 15px; line-height: 1.3; }
.checkin-sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.3; }
.checkin-pct { flex: none; font-size: 28px; line-height: 1; font-variant-numeric: tabular-nums; }
progress.checkin-meter { height: 10px; border-radius: 5px; margin-top: 14px; }
progress.checkin-meter::-webkit-progress-bar { border-radius: 5px; }
progress.checkin-meter::-webkit-progress-value { background: var(--ok-text); border-radius: 5px; }
progress.checkin-meter::-moz-progress-bar { background: var(--ok-text); border-radius: 5px; }

.checkin-split { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 14px 0 0; padding: 0; list-style: none; }
.checkin-split li { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 10px; background: var(--no-bg); color: var(--no-text); }
.checkin-split li.arrived { background: var(--ok-bg); color: var(--ok-text); }
.checkin-split b { font-size: 22px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.checkin-split span { font-size: 12.5px; line-height: 1.3; }

/* Shown instead of the breakdown when the site's tickets carry no type. */
.checkin-note { display: flex; align-items: flex-start; gap: 10px; margin: 0; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--muted); font-size: 14px; }
.checkin-note .icon { flex: none; margin-top: 2px; }

.tiers { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 12px 14px; margin-bottom: 16px; }
.tiers .stat-icon { flex: none; margin: 0; background: var(--brand-soft); color: var(--accent-text); }
.tiers h2 { margin: 0; font-size: 15px; line-height: 1.3; }
.tier-list { display: grid; gap: 16px; margin: 14px 0 0; padding: 0; list-style: none; }
.tier-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: 6px 12px; }
.tier-name { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.tier-count { font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--muted); }
.tier-count b { font-weight: 700; font-size: 15px; color: var(--text); }
.tier-pct { display: inline-block; min-width: 3.2em; margin-left: 8px; text-align: right; }
.tier-left { grid-column: 1 / -1; color: var(--muted); font-size: 12.5px; }
.tier-list li.all-in .tier-left, .tier-list li.all-in .tier-pct { color: var(--ok-text); font-weight: 600; }
/* Group tiers' people count: after the ticket count on phones, below it on wide screens. */
.tier-people::before { content: ' · '; }
progress.tier-bar {
  grid-column: 1 / -1;
  display: block;
  width: 100%;
  height: 8px;
  border: 0;
  border-radius: 4px;
  background: var(--track);
  overflow: hidden;
  -webkit-appearance: none;
  appearance: none;
}
progress.tier-bar::-webkit-progress-bar { background: var(--track); border-radius: 4px; }
progress.tier-bar::-webkit-progress-value { background: var(--ok-text); border-radius: 4px; }
progress.tier-bar::-moz-progress-bar { background: var(--ok-text); border-radius: 4px; }

/* ---------- Sales by ticket type ----------
   A stacked column per day (per hour for Today and Yesterday). Segments are
   separated by a 2px gap in the card color and the top of each column is
   rounded; the legend names every type beside its color. */
.mix { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 12px 10px; margin-bottom: 16px; }
.mix-head { display: flex; align-items: center; gap: 10px; }
.mix .stat-icon { flex: none; margin: 0; background: var(--brand-soft); color: var(--accent-text); }
.mix-heading { flex: 1 1 auto; min-width: 0; }
.mix h2 { margin: 0; font-size: 15px; line-height: 1.3; }
.mix-sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.3; }

.mix-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 12px 0 0; padding: 0; list-style: none; font-size: 13px; }
.mix-key { display: flex; align-items: center; gap: 6px; min-width: 0; }
.mix-key-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mix-key-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.mix-swatch { flex: none; width: 10px; height: 10px; border-radius: 3px; }
.mix-swatch.s1, .mix-bar.s1 { background: var(--series-1); fill: var(--series-1); }
.mix-swatch.s2, .mix-bar.s2 { background: var(--series-2); fill: var(--series-2); }
.mix-swatch.s3, .mix-bar.s3 { background: var(--series-3); fill: var(--series-3); }
.mix-swatch.s4, .mix-bar.s4 { background: var(--series-4); fill: var(--series-4); }
.mix-swatch.s5, .mix-bar.s5 { background: var(--series-5); fill: var(--series-5); }
.mix-swatch.s6, .mix-bar.s6 { background: var(--series-6); fill: var(--series-6); }

.mix-chart { position: relative; margin-top: 10px; touch-action: pan-y; }
.mix-svg { display: block; width: 100%; height: 132px; }
.mix-chart.is-empty .mix-svg, .mix-chart.is-empty .mix-days { visibility: hidden; }
.mix-empty { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted); font-size: 13px; text-align: center; }
.mix-empty[hidden] { display: none; }
.mix-highlight { fill: var(--row-hover); }
.mix-tip-row { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.mix-tip-name { flex: 1 1 auto; opacity: 0.85; }
.mix-tip-count { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.toolbar-group { display: flex; gap: 8px; }
.toolbar-group > * { flex: 1 1 0; min-width: 0; }
/* Phones: the check-in and ticket-type filters side by side, the sort menu
   on its own row below them. */
.filters { flex-wrap: wrap; }
.filters > * { flex: 1 1 calc(50% - 4px); }

.count { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px 16px; color: var(--muted); font-size: 14px; margin: 0 0 10px; }
.updated { display: inline-flex; align-items: center; gap: 6px; }
.updated .icon { width: 15px; height: 15px; }

/* "Refreshing…": spinner in the button, current list dimmed until the
   fresh one arrives. */
.btn.is-loading { cursor: progress; }
.btn.is-loading .icon { display: none; }
.btn.is-loading::before {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--track);
  border-top-color: var(--brand);
  animation: spin 0.8s linear infinite;
}
.refreshing .stats,
.refreshing .trend,
.refreshing .types,
.refreshing .checkin,
.refreshing .tiers,
.refreshing .table-wrap { opacity: 0.5; transition: opacity 0.2s; pointer-events: none; }
.refreshing .updated { color: var(--text); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  .spinner::before, .btn.is-loading::before { animation-duration: 3s; }
}

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px 3px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 600; line-height: 1.4; }
.badge .icon { width: 14px; height: 14px; }
.badge.ok { background: var(--ok-bg); color: var(--ok-text); }
.badge.no { background: var(--no-bg); color: var(--no-text); }

/* ---------- Attendee list: cards on phones ---------- */
.table-wrap { position: relative; }
table.attendees { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
table.attendees thead { display: none; }
table.attendees tbody { display: block; }
/* A card is a wrapping row: name and chevron, the ticket type, then the
   check-in badge with the purchase time on the right (the time drops to its
   own line when a long check-in time leaves no room). */
table.attendees tbody tr {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin-bottom: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
table.attendees tbody tr[hidden] { display: none; }
table.attendees tbody tr.open { border-color: var(--brand); }
/* Chevron: points down when collapsed, up when open. */
table.attendees tbody tr::after {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  margin: 0 4px 4px 0;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s;
}
table.attendees tbody tr.open::after { transform: rotate(-135deg); margin: 4px 4px 0 0; }

table.attendees td { display: none; padding: 0; overflow-wrap: anywhere; }
table.attendees td.name { display: block; flex: 1 1 0; min-width: 0; font-size: 16px; font-weight: 650; line-height: 1.3; }
table.attendees td.summary { display: block; flex: 1 0 100%; order: 1; color: var(--muted); font-size: 14px; }
table.attendees td.checkin { display: block; flex: none; order: 2; margin-top: 4px; }
table.attendees tr.open td.checkin { flex: 1 0 100%; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
table.attendees tr.open td.detail {
  display: flex;
  flex: 1 0 100%;
  order: 3;
  justify-content: space-between;
  gap: 16px;
  padding-top: 6px;
  text-align: right;
}
table.attendees td.detail::before { content: attr(data-label); flex: none; max-width: 45%; color: var(--muted); text-align: left; }
table.attendees td.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

/* Purchase time: a cart icon and "4 hours ago" on a closed card, the exact
   time among the details once it's open. The table shows the exact time. */
table.attendees td.purchased .ago { display: none; }
table.attendees td.purchased .ago .icon { width: 14px; height: 14px; }
@media (max-width: 640px) {
  /* Closed card: check-in badge on the left, purchase time pushed right. */
  table.attendees tr:not(.open) td.purchased {
    display: block;
    flex: none;
    order: 2;
    margin: 4px 0 0 auto;
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
  }
  table.attendees tr:not(.open) td.purchased::before { content: none; }
  table.attendees tr:not(.open) td.purchased .exact { display: none; }
  table.attendees tr:not(.open) td.purchased .ago { display: inline-flex; align-items: center; gap: 6px; }
}

.sort-select { display: block; }

/* ---------- Tablets and desktops ---------- */
@media (min-width: 641px) {
  .wrap {
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
  }
  .topbar-inner { min-height: 60px; }
  .brand img { width: 34px; height: 34px; }
  .signout span { display: inline; }
  main.wrap { padding-top: 28px; padding-bottom: 56px; }
  h1 { font-size: 28px; }
  .login { margin-top: 24px; padding: 24px; }

  input, select { font-size: 15px; min-height: 42px; }
  .btn { min-height: 42px; }

  .event-head { margin-bottom: 20px; }
  .event-meta { flex-direction: row; flex-wrap: wrap; gap: 6px 20px; font-size: 15px; }

  /* The tab bar is sized to its labels instead of spanning the page. */
  .tabs { display: inline-flex; gap: 4px; padding: 4px; margin-bottom: 18px; }
  .tab { flex: none; min-width: 150px; gap: 7px; padding: 0 18px; font-size: 14px; }
  .tab-count { display: inline; }

  .stats { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 22px; }
  .stat { flex: none; min-width: 170px; padding: 14px 18px; }
  .stat b { font-size: 28px; }
  .stat-label { font-size: 13px; }

  .trend { padding: 16px 20px 12px; margin-bottom: 22px; }
  .trend h2 { font-size: 16px; }
  .trend-total b { font-size: 28px; }
  .range-select { min-height: 32px; font-size: 14px; }

  /* Name, bar and count on one line. */
  .mix { padding: 16px 20px 12px; margin-bottom: 22px; }
  .mix h2 { font-size: 16px; }
  .mix-svg { height: 160px; }
  .mix-legend { gap: 8px 20px; }

  .types, .cats { padding: 16px 20px; margin-bottom: 22px; }
  .cats h2 { font-size: 16px; }
  .cat-table td { width: 9em; }
  .cat-table.cols-4 td { width: 7em; }
  .types h2 { font-size: 16px; }
  .types-list { gap: 12px; }
  .types-list li { grid-template-columns: minmax(140px, 240px) minmax(0, 1fr) 120px; align-items: center; column-gap: 16px; }
  progress.type-bar { grid-column: 2; grid-row: 1; }
  .type-count { grid-column: 3; grid-row: 1; text-align: right; }
  .type-checked { grid-column: 2 / -1; }

  /* Name, bar, count and what's left on one line per tier. */
  .checkin-bar { flex-direction: row; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
  .checkin-actions { flex: none; gap: 10px; }
  .checkin-actions .btn { flex: none; }
  .checkin { padding: 18px 20px 20px; margin-bottom: 22px; }
  .checkin h2 { font-size: 16px; }
  .checkin-pct { font-size: 34px; }
  .checkin-split { grid-template-columns: repeat(3, minmax(0, 220px)); }
  .checkin-split b { font-size: 26px; }
  .tiers { padding: 16px 20px; margin-bottom: 22px; }
  .tiers h2 { font-size: 16px; }
  .tier-list { gap: 14px; }
  .tier-list li { grid-template-columns: minmax(140px, 240px) minmax(0, 1fr) 130px 150px; align-items: center; column-gap: 16px; }
  progress.tier-bar { grid-column: 2; grid-row: 1; }
  .tier-count { grid-column: 3; grid-row: 1; text-align: right; }
  .tier-left { grid-column: 4; grid-row: 1; text-align: right; }
  .tier-people { display: block; }
  .tier-people::before { content: none; }

  .toolbar { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; }
  .search { flex: 1 1 280px; }
  .toolbar-group { flex: none; gap: 10px; }
  .toolbar-group > * { flex: none; }
  .toolbar select { width: auto; }
  .sort-select { display: none; } /* column headers sort on wide screens */
  .phone-only { display: none; }

  /* A real table on wide screens. */
  .table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: auto;
    max-height: calc(100vh - 120px);
  }
  table.attendees thead { display: table-header-group; }
  table.attendees tbody { display: table-row-group; }
  table.attendees tbody tr { display: table-row; margin: 0; padding: 0; background: none; border: 0; border-radius: 0; cursor: default; }
  table.attendees tbody tr[hidden] { display: none; }
  table.attendees tbody tr::after { content: none; }
  table.attendees th,
  table.attendees td,
  table.attendees td.name,
  table.attendees td.summary,
  table.attendees td.checkin,
  table.attendees td.detail,
  table.attendees tr.open td.detail {
    display: table-cell;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    white-space: nowrap;
    text-align: left;
    overflow-wrap: normal;
    font-size: 14px;
    font-weight: 400;
    color: var(--text);
  }
  table.attendees td.detail::before { content: none; }
  table.attendees tr.open td.checkin { padding-bottom: 10px; }
  table.attendees tbody tr:last-child td { border-bottom: 0; }
  table.attendees tbody tr:hover td { background: var(--row-hover); }
  table.attendees th {
    position: sticky;
    top: 0;
    z-index: 1;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    box-shadow: inset 0 -2px 0 var(--brand);
  }
  table.attendees th:first-child, table.attendees td:first-child { position: sticky; left: 0; }
  table.attendees th:first-child { z-index: 2; }
  table.attendees th button { all: unset; cursor: pointer; }
  table.attendees th button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  table.attendees th[aria-sort] { color: var(--text); }
  table.attendees th[aria-sort="ascending"] button::after { content: " ↑"; }
  table.attendees th[aria-sort="descending"] button::after { content: " ↓"; }
  table.attendees td.name { font-weight: 600; }
  table.attendees td.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
}

/* ---------- Print: a plain table ---------- */
@media print {
  body { background: #fff; color: #000; }
  .topbar, .toolbar, .updated, progress.meter, .stat-icon, .trend, .types, .cats, .mix, .tabs, .checkin, .tiers, .checkin-note, .checkin-bar { display: none !important; }
  .table-wrap { border: 0; overflow: visible; max-height: none; }
  table.attendees thead { display: table-header-group; }
  table.attendees tbody { display: table-row-group; }
  table.attendees tbody tr { display: table-row; border: 0; padding: 0; margin: 0; }
  table.attendees tbody tr::after { content: none; }
  table.attendees th, table.attendees td { display: table-cell !important; position: static !important; padding: 4px 8px; border-bottom: 1px solid #ccc; background: #fff; box-shadow: none; }
  table.attendees td.detail::before { content: none; }
  tr[hidden] { display: none !important; }
  /* Print the attendee list whichever tab is open. */
  .tab-panel { display: block !important; }
}
