/* ==========================================================================
   Waypoint Operator Console
   --------------------------------------------------------------------------
   The console takes on the accent of whichever product's production data is
   on screen. That is the one deliberate flourish here and it is load-bearing:
   an operator about to approve or reject a real person's account should never
   have to read a breadcrumb to know which system they are in.

   Typefaces follow the Waypoint system (Playfair Display / DM Sans / DM Mono)
   where they are installed locally, and degrade to system equivalents.
   Self-hosting later: drop woff2 into /fonts, add font-src 'self' to the CSP
   in server.js, and add @font-face here. No runtime third-party requests.
   ========================================================================== */

:root {
  --ink:        #14171f;
  --ink-soft:   #2a2f3a;
  --paper:      #f7f7f5;
  --card:       #ffffff;
  --line:       #e3e3df;
  --line-strong:#c9c9c3;
  --text:       #1c1f26;
  --text-dim:   #656b78;
  --text-faint: #8d93a0;

  --ok:    #1f7a4d;
  --warn:  #9a6b12;
  --danger:#a32b2b;
  --danger-soft:#fbeceb;

  --accent:      #4a5670;   /* admin / system default */
  --accent-ink:  #ffffff;
  --accent-wash: #eceef3;

  --display: "Playfair Display", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --body: "DM Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "DM Mono", ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --r: 6px;
  --shadow: 0 1px 2px rgba(20,23,31,.06), 0 4px 14px rgba(20,23,31,.05);
}

/* Product accents. Set via data-scope on the root element. */
[data-scope="ledger"]  { --accent:#8a6410; --accent-wash:#f8f1e2; }
[data-scope="balance"] { --accent:#136b6b; --accent-wash:#e4f1f0; }
[data-scope="pulse"]   { --accent:#a83c32; --accent-wash:#fbeae7; }
[data-scope="lumio"]   { --accent:#5a3d99; --accent-wash:#efeafa; }
[data-scope="mindset"] { --accent:#2f6b3c; --accent-wash:#e8f2ea; }
[data-scope="admin"]   { --accent:#4a5670; --accent-wash:#eceef3; }

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: -.01em; margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }

.mono, code, pre { font-family: var(--mono); font-variant-numeric: tabular-nums; }

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

/* ---------------------------------------------------------------- sign in */

.signin-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, #ffffff 0%, var(--paper) 60%);
}

.signin {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 32px;
}

.signin .brand {
  font-family: var(--display);
  font-size: 24px;
  margin-bottom: 4px;
}

.signin .brand-sub {
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 24px;
}

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }

.field input, .field select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  background: #fff;
}

.field input:focus, .field select:focus { border-color: var(--accent); }

.field-hint { font-size: 12px; color: var(--text-faint); margin-top: 5px; }

/* ------------------------------------------------------------------ shell */

.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100dvh; }

.rail {
  background: var(--ink);
  color: #d6d9e0;
  padding: 18px 0 12px;
  display: flex;
  flex-direction: column;
}

.rail-brand {
  font-family: var(--display);
  font-size: 17px;
  color: #fff;
  padding: 0 18px 16px;
  border-bottom: 1px solid #262b36;
  margin-bottom: 12px;
}

.rail-group { padding: 0 10px; margin-bottom: 6px; }

.rail-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: #6d7481;
  padding: 12px 8px 6px;
}

.rail-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: #c6cad3;
  padding: 8px 8px;
  border-radius: var(--r);
  cursor: pointer;
}

.rail-item:hover { background: #1e222c; color: #fff; }
.rail-item[aria-current="true"] { background: #232833; color: #fff; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; background: currentColor; }
.dot-ledger  { background:#c08a1a; }
.dot-balance { background:#1c9494; }
.dot-pulse   { background:#d1584c; }
.dot-lumio   { background:#7d5cc6; }
.dot-mindset { background:#43915a; }
.dot-admin   { background:#7c88a3; }

.rail-foot {
  margin-top: auto;
  padding: 12px 18px 0;
  border-top: 1px solid #262b36;
  font-size: 13px;
}

.rail-who { color: #fff; word-break: break-all; }
.rail-role { color: #6d7481; font-size: 12px; margin-bottom: 10px; }

.linkish {
  background: none; border: 0; padding: 0;
  color: #9aa2b1; cursor: pointer; font-size: 13px;
  text-decoration: underline; text-underline-offset: 2px;
}
.linkish:hover { color: #fff; }

/* ------------------------------------------------------------------- main */

.main { min-width: 0; display: flex; flex-direction: column; }

.scope-band {
  height: 3px;
  background: var(--accent);
}

.head {
  padding: 20px 26px 0;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.head h1 { font-size: 22px; }

.head-sub { color: var(--text-dim); font-size: 13px; margin-top: 3px; }

.tabs { display: flex; gap: 2px; margin-top: 16px; flex-wrap: wrap; }

.tab {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text-dim);
  display: flex; align-items: center; gap: 7px;
}

.tab:hover { color: var(--text); }
.tab[aria-current="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }

.content { padding: 22px 26px 60px; min-width: 0; }

/* ------------------------------------------------------------------ chips */

.chip {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--accent-wash);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
}

.chip-plain { background: #f0f0ed; color: var(--text-dim); border-color: var(--line); }
.chip-ok    { background: #e7f2ec; color: var(--ok);     border-color:#bfe0cd; }
.chip-warn  { background: #fbf1dd; color: var(--warn);   border-color:#ecd7a8; }
.chip-off   { background: #f2f2f0; color: var(--text-faint); border-color: var(--line); }

/* ------------------------------------------------------------------ table */

.toolbar {
  display: flex; gap: 10px; align-items: center;
  margin-bottom: 12px; flex-wrap: wrap;
}

.toolbar input[type="search"] {
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  min-width: 220px;
  background: #fff;
}

.count { color: var(--text-dim); font-size: 13px; font-family: var(--mono); }

.table-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: auto;
  box-shadow: var(--shadow);
}

table { border-collapse: collapse; width: 100%; font-size: 14px; }

th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-dim);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfbfa;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

td { padding: 9px 12px; border-bottom: 1px solid #f0f0ed; vertical-align: top; }

tbody tr:hover { background: #fcfcfb; }

td.num, td.id { font-family: var(--mono); font-size: 13px; }
td.id { color: var(--text-dim); }

.cell-complex { color: var(--text-faint); font-family: var(--mono); font-size: 12px; }

.row-actions { display: flex; gap: 6px; white-space: nowrap; }

/* ----------------------------------------------------------------- button */

.btn {
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  padding: 6px 11px;
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { border-color: var(--text-dim); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-danger { color: var(--danger); border-color: #e3bdbd; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn-sm { padding: 3px 8px; font-size: 12px; }

/* ------------------------------------------------------------------ cards */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
  max-width: 720px;
}

.card h2 { font-size: 17px; margin-bottom: 4px; }
.card .card-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 16px; }

.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.check { display: flex; align-items: center; gap: 7px; }
.check input { width: auto; }

/* ------------------------------------------------------- empty / error */

.empty, .error-box, .notice {
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px;
  background: var(--card);
}

.empty { color: var(--text-dim); }
.empty strong { display: block; color: var(--text); font-weight: 500; margin-bottom: 4px; }

.error-box { border-color: #e3bdbd; background: var(--danger-soft); color: #7d2020; }
.error-box strong { display: block; margin-bottom: 3px; }

.notice { border-color: #ecd7a8; background: #fdf7e9; color: #6d4d0c; }

.loading { color: var(--text-faint); padding: 18px 0; }

/* ------------------------------------------------------------ modal/toast */

/* The modal layer defaults to display:none and only becomes a grid when the
   `hidden` attribute is absent.

   Writing `.modal-layer { display: grid }` and relying on the `hidden`
   attribute to suppress it does NOT work. The user-agent rule
   `[hidden] { display: none }` and a class selector have identical
   specificity, so the cascade is decided by origin — and author styles beat
   user-agent styles. The layer therefore stayed laid out as a fixed,
   full-viewport sheet at z-index 50 and silently swallowed every mouse click
   on the page, while keyboard focus still traversed the content underneath.
   The console looked keyboard-only. It was not: it was covered.

   Guarding on :not([hidden]) makes the visible state the exception rather
   than the default, so the failure mode is an invisible modal, not an
   invisible click-blocker. */
.modal-layer {
  display: none;
  position: fixed; inset: 0;
  background: rgba(20,23,31,.42);
  padding: 20px;
  z-index: 50;
}

.modal-layer:not([hidden]) {
  display: grid;
  place-items: center;
}

.modal {
  background: var(--card);
  border-radius: var(--r);
  box-shadow: 0 12px 40px rgba(20,23,31,.28);
  padding: 22px;
  width: 100%;
  max-width: 460px;
  max-height: 84vh;
  overflow: auto;
}

.modal.modal-wide { max-width: 720px; }
.modal h2 { font-size: 17px; margin-bottom: 6px; }
.modal-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

pre.detail {
  background: #fafaf8;
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 12px;
  font-size: 12.5px;
  overflow: auto;
  max-height: 52vh;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Never hidden, so it must not intercept pointer events for the corner of the
   screen it occupies — only the toasts themselves are interactive. */
.toast-layer {
  position: fixed; right: 18px; bottom: 18px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 60;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--r);
  font-size: 13.5px;
  box-shadow: 0 6px 20px rgba(20,23,31,.3);
  max-width: 380px;
}
.toast-bad { background: #7d2020; }

/* ------------------------------------------------------------ responsive */

@media (max-width: 780px) {
  .shell { grid-template-columns: 1fr; }
  .rail { flex-direction: column; }
  .rail-foot { margin-top: 12px; }
  .content, .head { padding-left: 16px; padding-right: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
