/* RoomReceipts admin console. System fonts only: the CSP allows nothing
   off-origin but the API and the sign-in host. */

:root {
  color-scheme: light;
  --surface-0: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77756f;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --series-1: #2a78d6;
  --good-bg: #e3f4e3;
  --good-ink: #0b6b0b;
  --warn-bg: #fdf0d2;
  --warn-ink: #7a5300;
  --off-bg: #ecebe7;
  --off-ink: #52514e;
  --error-ink: #b42323;
  --notice-bg: #fdf0d2;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #242422;
    --border: #33332f;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #96958c;
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --series-1: #3987e5;
    --good-bg: #173117;
    --good-ink: #8fdc8f;
    --warn-bg: #3a2e10;
    --warn-ink: #f5cf6e;
    --off-bg: #2c2c29;
    --off-ink: #c3c2b7;
    --error-ink: #f08a8a;
    --notice-bg: #3a2e10;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #242422;
  --border: #33332f;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #96958c;
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --series-1: #3987e5;
  --good-bg: #173117;
  --good-ink: #8fdc8f;
  --warn-bg: #3a2e10;
  --warn-ink: #f5cf6e;
  --off-bg: #2c2c29;
  --off-ink: #c3c2b7;
  --error-ink: #f08a8a;
  --notice-bg: #3a2e10;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-secondary); }

code { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text-secondary); }
.muted { color: var(--text-muted); }

/* ---- top bar ---------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 700; font-size: 15px; }
.brand span { font-weight: 500; color: var(--text-muted); }
.who { margin-left: auto; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.actions { display: flex; gap: 8px; }

.btn {
  display: inline-block;
  font: inherit;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
}
.btn-quiet { background: transparent; color: var(--text-primary); border-color: var(--border); }
.btn:focus-visible, .chip:focus-visible, .link:focus-visible, .sort:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.status { color: var(--text-secondary); padding: 32px 0; }
.status.error { color: var(--error-ink); }
.notice {
  background: var(--notice-bg);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
}
.notice p { margin: 4px 0; }
.footnote { color: var(--text-muted); font-size: 12px; margin: 10px 2px 0; }

/* ---- tiles ------------------------------------------------------------------ */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.tile, .panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.tile { padding: 14px 16px; }
.tile-label { color: var(--text-secondary); font-size: 13px; }
.tile-value { font-size: 28px; font-weight: 600; margin-top: 2px; }
.tile-note { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

.panel { padding: 16px; margin-bottom: 16px; }
.panel > h2 { margin-bottom: 10px; }
.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.signed-out { max-width: 520px; margin: 48px auto; }
.signed-out p { color: var(--text-secondary); }

/* ---- chart ------------------------------------------------------------------ */
.chart-holder { width: 100%; min-height: 180px; }
.chart { display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--text-muted); font-size: 11px; }
.chart .bar { fill: var(--series-1); }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: var(--surface-2); fill-opacity: 0.6; }
.tooltip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  white-space: nowrap;
}

/* ---- filters ---------------------------------------------------------------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
input[type="search"] {
  font: inherit;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-0);
  color: var(--text-primary);
  width: 240px;
  max-width: 100%;
}

/* ---- tables ----------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--text-secondary); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--surface-2); }
tr.row-idle td { color: var(--text-muted); }
table.compact th, table.compact td { padding: 6px 8px; font-size: 13px; }
.sort { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.link {
  font: inherit;
  color: var(--accent-ink);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-align: left;
  overflow-wrap: break-word; /* only past the column: emails stay whole, the table scrolls */
}
.link:hover { text-decoration: underline; }

.badges { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--off-bg);
  color: var(--off-ink);
  white-space: nowrap;
}
.badges .badge, td > .badge:first-child { margin-left: 0; }
.badge-good { background: var(--good-bg); color: var(--good-ink); }
.badge-warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge-off { background: var(--off-bg); color: var(--off-ink); }

/* ---- drawer ----------------------------------------------------------------- */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(760px, 100vw);
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 10;
  display: flex;
  flex-direction: column;
}
.drawer[hidden] { display: none; }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.drawer-head h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { overflow-y: auto; padding: 4px 16px 32px; }
.drawer-section { padding: 14px 0; border-bottom: 1px solid var(--border); }
.drawer-section h3 { margin-bottom: 8px; }
.facts { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--text-secondary); }
.facts dd { margin: 0; word-break: break-word; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; }
  .who { order: 3; width: 100%; margin-left: 0; }
  .actions { margin-left: auto; }
  input[type="search"] { width: 100%; }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 8px; }
}
