/* LiBE Admin. Tokens first; light and dark are each chosen, not flipped. */

:root {
  color-scheme: light;
  --surface-0: #f4f4f2;      /* page */
  --surface-1: #fcfcfb;      /* cards, chart surface */
  --surface-2: #efeeeb;      /* hover, inputs */
  --border: #e2e1dc;
  --grid: #e9e8e4;           /* hairline gridlines */
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0fc;
  --danger: #c4332f;
  --focus: #2a78d6;
  --series-email: #2a78d6;      /* categorical slot 1 */
  --series-microsoft: #eb6834;  /* categorical slot 2 */
  --series-new: #6250d6;        /* categorical slot 7: its own hue, never blue */
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 2px 8px rgb(0 0 0 / 0.04);
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #242422;
    --border: #2f2f2c;
    --grid: #2a2a28;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --accent-soft: #1b2c42;
    --danger: #e66767;
    --focus: #6da7ec;
    --series-email: #3987e5;
    --series-microsoft: #d95926;
    --series-new: #9085e9;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #242422;
  --border: #2f2f2c;
  --grid: #2a2a28;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --accent-soft: #1b2c42;
  --danger: #e66767;
  --focus: #6da7ec;
  --series-email: #3987e5;
  --series-microsoft: #d95926;
  --series-new: #9085e9;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 14px/1.5 var(--font);
}
[hidden] { display: none !important; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.nowrap { white-space: nowrap; }

/* ---- Top bar ---------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px; min-height: 56px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 7px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 13px;
}
.brand-name { font-weight: 700; font-size: 16px; }
.brand-chip, .env-badge {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 2px 7px; border-radius: 999px;
}
.brand-chip { background: var(--surface-2); color: var(--text-secondary); }
.env-badge { background: #8a5a00; color: #fff; }
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; padding: 17px 12px; white-space: nowrap;
  color: var(--text-secondary); text-decoration: none; font-weight: 500;
}
.tab:hover { color: var(--text-primary); }
.tab[aria-current="page"] { color: var(--text-primary); }
.tab[aria-current="page"]::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px;
  border-radius: 2px; background: var(--accent);
}
.tab[aria-disabled="true"] { color: var(--text-muted); cursor: default; }
.tab .soon { font-size: 10px; margin-left: 4px; color: var(--text-muted); }
.account { display: flex; align-items: center; gap: 10px; }
.account-email { color: var(--text-secondary); font-size: 13px; }

/* ---- Layout ------------------------------------------------------------ */
.main { max-width: 1200px; margin: 0 auto; padding: 24px; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; color: var(--text-secondary); }
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; min-width: 0;
}
.card + .card, .grid + .card, .card + .grid, .tiles + .grid { margin-top: 16px; }
.tiles > .card, .grid > .card { margin-top: 0; }  /* grid gap does the spacing there */
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head p { margin: 2px 0 0; color: var(--text-muted); font-size: 13px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.loading, .empty { color: var(--text-muted); padding: 24px 0; text-align: center; }
.empty strong { display: block; color: var(--text-secondary); font-size: 15px; margin-bottom: 4px; }

/* ---- Tiles ------------------------------------------------------------- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.tile { padding: 16px 18px; }
.tile-label { color: var(--text-secondary); font-size: 13px; }
.tile-value { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile-note { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }

/* ---- Controls ---------------------------------------------------------- */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
  font: inherit; font-weight: 500; padding: 7px 14px; border-radius: 8px; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.07); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--text-secondary); }
.btn-quiet:hover { background: var(--surface-2); color: var(--text-primary); }
.btn-block { width: 100%; }
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 9px; }
.segmented button {
  appearance: none; border: 0; background: transparent; color: var(--text-secondary);
  font: inherit; font-weight: 500; padding: 5px 12px; border-radius: 7px; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
input[type="text"], input[type="email"], input[type="search"], select {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
label.field { display: grid; gap: 5px; font-weight: 500; font-size: 13px; color: var(--text-secondary); }
label.field input { font-size: 15px; padding: 9px 12px; }

/* ---- Tables ------------------------------------------------------------ */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { color: var(--text-muted); font-weight: 500; font-size: 12.5px; white-space: nowrap; }
td.num, th.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.cell-message { max-width: 520px; overflow-wrap: anywhere; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); font-size: 12px; white-space: nowrap; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; color: var(--text-muted); font-size: 13px; }

/* ---- Charts ------------------------------------------------------------ */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--border); stroke-width: 1; }
.chart .tick { fill: var(--text-muted); font-size: 11px; font-family: var(--font); }
.chart .hit { fill: transparent; }
.chart .hit:hover + .col-hover, .chart .col-hover.on { fill: var(--surface-2); }
.chart .col-hover { fill: transparent; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; color: var(--text-secondary); font-size: 13px; }
.legend span { display: inline-flex; align-items: center; }
.tooltip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 140px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.12); padding: 8px 10px; font-size: 12.5px;
}
.tooltip .tt-title { color: var(--text-secondary); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 16px; }
.tooltip .tt-row b { font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-table { margin-top: 12px; max-height: 280px; overflow: auto; }

/* ---- Detail dialog ----------------------------------------------------- */
dialog.detail {
  width: min(820px, calc(100vw - 32px)); max-height: calc(100vh - 64px);
  border: 1px solid var(--border); border-radius: 12px; padding: 0;
  background: var(--surface-1); color: var(--text-primary); box-shadow: 0 12px 40px rgb(0 0 0 / 0.25);
}
dialog.detail::backdrop { background: rgb(0 0 0 / 0.35); }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 20px 12px; border-bottom: 1px solid var(--border); }
.detail-body { padding: 16px 20px 20px; overflow: auto; max-height: calc(100vh - 160px); }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 16px; }
.meta dt { color: var(--text-muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
pre.block {
  margin: 6px 0 16px; padding: 12px 14px; background: var(--surface-2); border-radius: 8px;
  font: 12.5px/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
}

/* ---- Sign-in ----------------------------------------------------------- */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.signin-card { width: min(400px, 100%); padding: 28px; }
.signin-card .brand { margin-bottom: 18px; }
.signin-card h1 { margin-bottom: 6px; }
.signin-card > p { color: var(--text-secondary); margin: 0 0 20px; }
.signin-card form { display: grid; gap: 12px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: 12px; margin: 16px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.form-error { color: var(--danger); font-size: 13px; min-height: 1em; margin: 0; }

/* ---- Toast ------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--text-primary); color: var(--surface-1); padding: 10px 16px; border-radius: 10px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.2); max-width: calc(100vw - 32px);
}

/* ---- Small screens ----------------------------------------------------- */
@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .account-email { display: none; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 8px 16px 0; gap: 8px; }
  .brand { flex: 1; }
  .tabs { order: 3; flex-basis: 100%; }
  .tab { padding: 10px 10px 12px; }
  .main { padding: 16px; }
  .card { padding: 16px; }
  .tile-value { font-size: 24px; }
  .table-wrap { margin: 0; padding: 0; overflow: visible; }
  table.cards thead { display: none; }
  table.cards tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--grid); }
  table.cards td { display: flex; gap: 12px; justify-content: space-between; border: 0; padding: 3px 0; text-align: right; }
  table.cards td::before { content: attr(data-label); color: var(--text-muted); text-align: left; flex: none; }
  table.cards td.cell-message { text-align: left; display: block; max-width: none; }
  table.cards td.cell-message::before { display: block; }
}
