/* NotifyDesk admin UI. Follows the ui-standard skill (see /CLAUDE.md): page
   shell + max-width, table spacer-gap engine (see table-engine.js for the
   measuring half of it), sticky-tabs navigation, typography, tokens. */

/* --- Fonts: self-hosted, no runtime call to any font CDN. Inter and
   JetBrains Mono below are each a single variable-font file covering the
   weights this app actually uses (see app/static/fonts/); Fraunces ships
   only weight 600, the one headings need. --- */
@font-face {
  font-family: "Inter";
  src: url("fonts/inter-latin-variable.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("fonts/fraunces-latin-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/jetbrains-mono-latin-variable.woff2") format("woff2");
  font-weight: 400 500;
  font-style: normal;
  font-display: swap;
}

:root {
  --background: #f7f7f8;
  --card: #ffffff;
  --foreground: #1b1d21;
  --muted-foreground: #6b7280;
  --border: #e2e4e8;
  --primary: #2563eb;
  --primary-foreground: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #b45309;
  --table-header: #eef1f6;
  --table-header-foreground: #3a3f4b;

  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-heading: "Fraunces", Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Spacing scale used everywhere: no ad hoc pixel values outside this. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --background: #16181d;
    --card: #1e2128;
    --foreground: #e7e9ee;
    --muted-foreground: #9aa1ad;
    --border: #2c303a;
    --primary: #5b8def;
    --primary-foreground: #0d1117;
    --danger: #f87171;
    --success: #4ade80;
    --warning: #fbbf24;
    --table-header: #23262e;
    --table-header-foreground: #c7cbd4;
  }
}

:root[data-theme="dark"] {
  --background: #16181d;
  --card: #1e2128;
  --foreground: #e7e9ee;
  --muted-foreground: #9aa1ad;
  --border: #2c303a;
  --primary: #5b8def;
  --primary-foreground: #0d1117;
  --danger: #f87171;
  --success: #4ade80;
  --warning: #fbbf24;
  --table-header: #23262e;
  --table-header-foreground: #c7cbd4;
}

* { box-sizing: border-box; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

h1, h2, h3 { font-family: var(--font-heading); font-weight: 600; margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 18px; }

/* --- Top nav: one flat row of section links, zero dropdowns. --- */
.topnav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0 var(--space-4);
  height: 52px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

@media (min-width: 768px) {
  .topnav { padding: 0 var(--space-8); }
}

.topnav .brand {
  font-family: var(--font-heading);
  font-weight: 600;
  margin-right: var(--space-4);
  white-space: nowrap;
}

.topnav a {
  padding: var(--space-2) var(--space-3);
  border-radius: 6px;
  color: var(--muted-foreground);
  font-weight: 500;
  white-space: nowrap;
}

.topnav a:hover { color: var(--foreground); text-decoration: none; background: var(--background); }
.topnav a.active { color: var(--primary); background: var(--background); }

.topnav .spacer { flex: 1; }
.topnav .logout { color: var(--muted-foreground); font-size: 13px; }

/* --- Page shell: 1600px ceiling, centered, fluid below it. --- */
.container {
  max-width: 1600px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) 40px;
}

@media (min-width: 768px) {
  .container { padding: var(--space-6) var(--space-8) 40px; }
}

/* Detail / drill-down pages (a single message, a single number's QR page):
   narrower, per the standard's "larger detail page" guidance, so long
   fields and key/value rows don't stretch edge to edge. */
.container.detail { max-width: 1152px; }

.section-header { margin-bottom: var(--space-4); }

.section-icon {
  display: inline-flex;
  color: var(--primary);
  margin-right: var(--space-2);
  vertical-align: -4px;
}
.section-icon svg { display: block; }

.page-description {
  color: var(--muted-foreground);
  font-size: 13px;
  margin: var(--space-1) 0 var(--space-4);
}

/* --- Sticky tab strip: tabs left, actions right, both on one baseline. --- */
.tab-strip {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-4);
}

.tab-strip .tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
}

.tab-strip .tabs a {
  padding: var(--space-2) var(--space-3);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--muted-foreground);
}

.tab-strip .tabs a.active {
  border-bottom-color: var(--primary);
  color: var(--primary);
}

.tab-strip .actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-bottom: 6px;
  flex-shrink: 0;
}

/* Same-page filter toggle (not navigation): e.g. All / Groups / Contacts on
   one list. Per the sticky-tabs standard, this is a pill, not a tab strip. */
.pill-toggle {
  display: inline-flex;
  border-radius: 8px;
  padding: 2px;
  background: var(--background);
  border: 1px solid var(--border);
}

.pill-toggle a {
  padding: 5px var(--space-3);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted-foreground);
}

.pill-toggle a:hover { text-decoration: none; color: var(--foreground); }

.pill-toggle a.active {
  background: var(--card);
  color: var(--foreground);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: var(--space-4);
  overflow: hidden;
}

.card-header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
}

.card-body { padding: var(--space-4); }
.card-body.flush { padding: 0; }

/* ==========================================================================
   Tables: the spacer-gap column model.

   Column widths and inter-column gaps are computed by table-engine.js (one
   engine, mounted on every `table.data`, per the standard's "central, never
   per page" enforcement rule): it measures each column's widest unwrapped
   cell, then either distributes leftover container width as equal padding
   between columns, or leaves natural widths and lets the table scroll
   sideways inside `.table-wrap` when content doesn't fit. This stylesheet
   only supplies the parts that don't depend on measurement: the header
   look, edge insets, alignment, row density, sticky header, and the frozen
   first column / right-edge cue used once a table actually scrolls.
   ========================================================================== */

.table-wrap {
  overflow: auto;
  max-height: 70vh;
  position: relative;
}

/* Right-edge "more content" cue: only shows once the table engine marks the
   wrapper as actually overflowing (data-overflowing="1"). */
.table-wrap[data-overflowing="1"] {
  box-shadow: inset -12px 0 8px -8px rgba(0, 0, 0, 0.12);
}
:root[data-theme="dark"] .table-wrap[data-overflowing="1"] {
  box-shadow: inset -12px 0 8px -8px rgba(0, 0, 0, 0.4);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .table-wrap[data-overflowing="1"] {
    box-shadow: inset -12px 0 8px -8px rgba(0, 0, 0, 0.4);
  }
}

table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

table.data thead th {
  height: 40px;
  background: var(--table-header);
  color: var(--table-header-foreground);
  font-weight: 500;
  font-size: 13px;
  text-align: center;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}

/* Interactive column sorting: a clickable header (list-engine.js wires the
   click; this is just the affordance + the active-column highlight). */
table.data thead th.sortable {
  cursor: pointer;
  user-select: none;
}
table.data thead th.sortable:hover { color: var(--foreground); }
table.data thead th.sortable:focus-visible { outline-offset: -2px; }
table.data thead th.sort-active { color: var(--primary); }

table.data tbody td {
  padding: 10px var(--space-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--card);
}

/* One column may opt in to wrapping instead of forcing the table wider
   (a message body preview, an error message) — capped so it never runs
   away, per the engine's maxColWidth rule. */
table.data td.wrap, table.data th.wrap {
  white-space: normal;
  max-width: 600px;
}

table.data tbody tr:last-child td { border-bottom: none; }

/* Edge insets: 15px before the first column, 40px after the last. */
table.data th:first-child, table.data td:first-child { padding-left: 15px; }
table.data th:last-child, table.data td:last-child { padding-right: 40px; }

/* Frozen first column, only meaningful once the table actually scrolls
   sideways (table-engine.js adds data-overflowing="1" to the wrapper). */
.table-wrap[data-overflowing="1"] table.data th:first-child,
.table-wrap[data-overflowing="1"] table.data td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
}
.table-wrap[data-overflowing="1"] table.data thead th:first-child { z-index: 3; }

/* Numbers and dates: right-aligned, mono font so digits stack. Negatives
   (none in this app today, but kept for the shared convention) would use
   var(--danger) with a leading minus sign, never color alone. */
table.data td.num, table.data td.date {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
table.data td.mono { font-family: var(--font-mono); }

table.data tbody tr:hover td { background: color-mix(in srgb, var(--table-header) 40%, var(--card)); }

/* The virtualized list engine's top/bottom spacer rows: invisible, just
   reserve scroll height for the rows above/below the current render window. */
table.data tbody tr.list-spacer:hover td { background: transparent; }
table.data tbody tr.list-spacer td { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge.ok { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.badge.warn { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }
.badge.bad { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.badge.muted { background: color-mix(in srgb, var(--muted-foreground) 15%, transparent); color: var(--muted-foreground); }

/* WhatsApp read receipts in the message log: one tick sent, two grey ticks
   delivered, two coloured ticks read -- the shape people already read without
   a legend. Uses --primary rather than WhatsApp's own blue so it stays legible
   in dark mode, and colour is never the only signal: every tick carries a
   title spelling out which state it is. */
.ticks { color: var(--muted-foreground); letter-spacing: -2px; }
.ticks.read { color: var(--primary); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--foreground);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover { background: var(--background); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--background); }
.btn.small { padding: 4px 10px; font-size: 12px; }

form.inline { display: inline; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: var(--space-1); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: var(--space-2) 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--background);
  color: var(--foreground);
  font-size: 14px;
  font-family: inherit;
}
.field textarea { min-height: 80px; resize: vertical; }
.field .hint { color: var(--muted-foreground); font-size: 12px; margin-top: var(--space-1); }

/* Forms keep the page at its normal width but constrain their own fields, so
   inputs don't stretch the full card (ui-standard section 1). */
.form-narrow { max-width: 560px; }

/* Label/value readout for settings that are shown here but edited elsewhere. */
.settings-readout { border-collapse: collapse; font-size: 13px; }
.settings-readout td { padding: 4px 0; }
.settings-readout td:first-child { padding-right: var(--space-6); white-space: nowrap; }

.filter-bar { display: flex; gap: 10px; margin-bottom: var(--space-4); flex-wrap: wrap; align-items: flex-end; }
.filter-bar .field { margin-bottom: 0; min-width: 140px; }

.flash {
  padding: var(--space-2) var(--space-4);
  border-radius: 8px;
  margin-bottom: var(--space-4);
  font-size: 13px;
}
.flash.success { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.flash.error { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }

.key-reveal {
  font-family: var(--font-mono);
  background: var(--background);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: var(--space-3);
  word-break: break-all;
  margin: var(--space-3) 0;
}

.login-wrap {
  max-width: 360px;
  margin: 96px auto;
  padding: var(--space-8);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}
.stat-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: var(--space-3) var(--space-4);
}
.stat-tile .value { font-family: var(--font-mono); font-size: 22px; font-weight: 600; }
.stat-tile .label { color: var(--muted-foreground); font-size: 12px; margin-top: 2px; }

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-6);
}
.qr-box img { width: 220px; height: 220px; border: 1px solid var(--border); border-radius: 8px; }

.muted { color: var(--muted-foreground); }
.mono { font-family: var(--font-mono); }

/* --- Page-action dialogs: the tab-strip baseline button's <dialog>. --- */
dialog {
  padding: 0;
  border: none;
  border-radius: 10px;
  background: var(--card);
  color: var(--foreground);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  overflow: auto;
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}
dialog .card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
dialog .card-body { padding: var(--space-4); }
dialog form .field:last-of-type { margin-bottom: var(--space-3); }

/* --- List loading / error rows inside a card holding a virtualized table. --- */
.table-loading {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  color: var(--muted-foreground);
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.table-loading[hidden] { display: none; }

@media (max-width: 720px) {
  table.data th:last-child, table.data td:last-child { padding-right: 15px; }
}
