/* TeamShared Router — console + auth styles. The public landing page loads
 * landing.css on top of this file.
 * Design system: dark-only, editorial, indigo. Tokens mirror teamshared console.css.
 * CSP: first-party only. No inline styles, no external fonts. Dynamic widths are
 * class-driven (see .bar[data-w]) so nothing needs an inline style attribute. */

:root {
  /* Surfaces */
  --bg: #07080d;
  --bg-soft: #0b0d15;
  --panel: #11131d;
  --panel-2: #171a29;
  --panel-hover: #1b1f30;
  /* Ink */
  --text: #e8eaf3;
  --muted: #9aa0b8;
  /* Lightened to clear WCAG AA (4.5:1) on every surface it lands on:
   * 5.55 on --bg, 5.13 on --panel, 4.79 on --panel-2, 5.38 on --bg-soft. */
  --faint: #7e86a3;
  /* Brand */
  --accent: #6366f1;
  --accent-bright: #8b90ff;
  /* Primary-button fills. White label needs 4.5:1, and --accent only reaches
   * 4.47, so buttons use a deeper indigo (5.55) and darken further on hover
   * (7.90) — the label gets more legible under the pointer, not less. */
  --accent-strong: #5457dd;
  --accent-strong-hover: #4338ca;
  --accent-soft: rgba(99, 102, 241, 0.14);
  /* Solid, not alpha: composited at 0.55 the ring measured 2.09:1 against
   * --bg, below the 3:1 that WCAG 1.4.11 wants for a focus indicator. */
  --accent-ring: #8b90ff;
  /* Semantic — success is never the accent */
  --success: #34d399;
  --danger: #f87171;
  --warn: #fbbf24;
  --pending: #a78bfa;
  --danger-soft: rgba(248, 113, 113, 0.13);
  /* Chrome */
  --border: #242838;
  --border-soft: #1a1d2b;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --topbar-h: 60px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.02), 0 12px 32px -18px rgba(0, 0, 0, 0.8);
  /* Type */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: var(--font-sans);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, legend {
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0 0 0.4rem;
}

h1 { font-size: 1.7rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }

p { margin: 0 0 0.75rem; }

a {
  color: var(--accent-bright);
  text-decoration: none;
  transition: color 0.15s var(--ease-out);
}
a:hover { color: var(--text); }

.eyebrow {
  margin: 0 0 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-bright);
}

.muted { color: var(--muted); }
.faint { color: var(--faint); }

code, .mono {
  font-family: var(--font-mono);
  font-size: 0.86em;
}

/* ---------- Focus + motion ---------- */

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

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ---------- Buttons ---------- */

button,
.btn,
.exports a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 550;
  line-height: 1;
  letter-spacing: 0.01em;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s var(--ease-out), border-color 0.15s var(--ease-out),
    transform 0.05s var(--ease-out);
}

button:hover,
.btn:hover,
.exports a:hover {
  background: var(--panel-hover);
  border-color: var(--accent);
  color: var(--text);
}

button:active,
.btn:active { transform: translateY(1px); }

/* Primary — exactly one per surface. `.btn-quiet` opts a submit out, for forms
 * whose submit is not the page's main action (e.g. the usage filter's Apply). */
button[type="submit"]:not(.btn-quiet):not(.text-btn),
.btn-primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}
button[type="submit"]:not(.btn-quiet):not(.text-btn):hover,
.btn-primary:hover {
  background: var(--accent-strong-hover);
  border-color: var(--accent-strong-hover);
  color: #fff;
}

/* Quiet text button — keep secondaries calm.
 * Uses `button.text-btn` so it outranks the `button[type="submit"]` primary rule
 * (equal specificity, wins on source order) for Sign out / Resend. */
button.text-btn,
.text-btn {
  display: inline;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}
button.text-btn:hover,
.text-btn:hover { color: var(--text); background: none; }

/* ---------- Forms ---------- */

label {
  display: block;
  margin: 0 0 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

input[type="email"],
input[type="text"],
input[type="number"],
input[type="search"] {
  width: 100%;
  margin: 0 0 1rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s var(--ease-out), box-shadow 0.15s var(--ease-out);
}

input::placeholder { color: var(--faint); }

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Drop the doubled ring for pointer focus only. Keyboard focus keeps the
 * outline, which is also the only indicator that survives forced-colors mode
 * (border-color and box-shadow are both discarded there). */
input:focus:not(:focus-visible) { outline: none; }

fieldset { border: 0; margin: 0; padding: 0; }

fieldset label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0.85rem 0.4rem 0;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 450;
  color: var(--text);
  font-size: 0.9rem;
}

legend {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.accent { color: var(--accent-bright); }

/* ---------- Notes / alerts ---------- */

.note {
  margin: 0 0 1rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--text);
  font-size: 0.9rem;
}

.note.err {
  border-color: var(--danger);
  border-left-color: var(--danger);
  background: var(--danger-soft);
  color: #fecaca;
}

/* ---------- Auth / login ---------- */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background:
    radial-gradient(1100px 600px at 50% -10%, rgba(99, 102, 241, 0.10), transparent 70%),
    var(--bg);
}

.login {
  width: min(27rem, 100%);
  padding: 2.1rem 1.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login .brand { margin-bottom: 1.35rem; }
.login h1 { font-size: 1.5rem; }
/* :not(.text-btn) matters — this rule's specificity (0,2,1) outranks
 * `button.text-btn` (0,1,1), so without it the quiet "Resend code" button
 * stretched to the full width of the card like a second primary. */
.login button[type="submit"]:not(.text-btn) { width: 100%; margin-top: 0.25rem; }

/* The OTP field is a fixed six digits: monospace and tracked so each digit
 * reads as its own slot, and so the placeholder lines up with typed input. */
.login input[name="code"] {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  letter-spacing: 0.35em;
  text-align: center;
}

.tagline { color: var(--muted); margin: 0 0 1.35rem; font-size: 0.95rem; }
.alt { margin: 1.15rem 0 0; color: var(--muted); font-size: 0.9rem; }

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

.app-page {
  max-width: 70rem;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 4rem;
}

.mast {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  padding: 0.5rem 0 1.25rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

/* Brand lockup */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand:hover { color: var(--text); }
/* The TeamShared mark — the same vector teamshared.com serves, so the router
 * reads as part of the suite rather than a separate product. It ships its own
 * near-black tile, which is why this has a radius but no fill of its own. */
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  /* The tile colour is the mark's own, repeated here so a failed or
   * blocked SVG leaves the lockup a dark tile rather than a hole. */
  background: #1c1c1e url("/assets/logo.svg") center / cover no-repeat;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
  flex: none;
}
.brand-sub { color: var(--faint); font-weight: 500; font-size: 0.85rem; }

.topnav {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}
.topnav a {
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}
.topnav a:hover { color: var(--text); background: var(--panel-2); }
.topnav a.is-active { color: var(--text); background: var(--accent-soft); }

.who {
  display: grid;
  justify-items: end;
  gap: 0.15rem;
  font-size: 0.9rem;
}
.who > span:first-child { font-weight: 550; }

.org-switch {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}
.org-switch select {
  max-width: 16rem;
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
}
.org-switch-err { color: var(--danger); font-size: 0.85rem; }
.org-switch select:focus { border-color: var(--accent); color: var(--text); outline: none; }

.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;
}

.page-lead { color: var(--muted); margin: -0.3rem 0 1.4rem; max-width: 60ch; }

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

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.35rem;
}

.stat {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  padding: 1.05rem 1.1rem 0.95rem;
}

.stat .label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat .value {
  font-size: 1.7rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0.4rem 0 0.1rem;
  font-variant-numeric: tabular-nums;
}
.stat .muted { font-size: 0.82rem; margin: 0; }

/* ---------- Panels ---------- */

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 1.25rem 1.25rem 1.35rem;
  margin-bottom: 1rem;
}
.panel > h2 { margin-bottom: 0.85rem; }

.credits, .filters form {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 1rem 1.5rem;
  align-items: end;
}
.filters .stack { margin: 0; }
.filters form { grid-template-columns: 1.4fr 1fr 0.7fr 0.7fr auto; }
.credits h2 { margin-bottom: 0.35rem; }
.credits .muted { font-size: 0.9rem; }

.exports {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
}
.exports a { font-size: 0.82rem; padding: 0.45rem 0.8rem; }

/* ---------- API keys ---------- */

.key-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0 0.75rem;
  align-items: start;
  max-width: 34rem;
  margin-top: 0.9rem;
}
.key-form label { grid-column: 1 / -1; }
.key-form input { margin-bottom: 0; }

.reveal { border-color: var(--accent); background: var(--accent-soft); }
.reveal-row {
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
  margin-top: 0.9rem;
}
.reveal-secret {
  flex: 1 1 auto;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  word-break: break-all;
  user-select: all;
}

.row-action { text-align: right; white-space: nowrap; }
button.text-btn.danger,
.text-btn.danger { color: var(--danger); }
button.text-btn.danger:hover,
.text-btn.danger:hover { color: #fecaca; }
button.text-btn:disabled { color: var(--faint); cursor: default; }

@media (max-width: 620px) {
  .key-form { grid-template-columns: 1fr; gap: 0.75rem; }
  .reveal-row { flex-direction: column; }
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

th, td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}

/* Not sticky: .table-wrap has no height constraint so it never scrolls
 * vertically, and an opaque sticky header squared off the wrapper's radius. */
thead th {
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(255, 255, 255, 0.015); }
td code { color: var(--accent-bright); }

/* ---------- Metric bars (class-driven widths — CSP-safe) ---------- */

.bar-row {
  display: grid;
  grid-template-columns: 8rem 1fr 3rem;
  gap: 0.6rem;
  align-items: center;
  margin: 0.4rem 0;
  font-size: 0.85rem;
}
.bar-label { color: var(--muted); }
.bar {
  display: block;
  height: 0.6rem;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
  min-width: 2px;
}
.bar[data-w="0"] { width: 0; }
.bar[data-w="1"] { width: 10%; }
.bar[data-w="2"] { width: 20%; }
.bar[data-w="3"] { width: 30%; }
.bar[data-w="4"] { width: 40%; }
.bar[data-w="5"] { width: 50%; }
.bar[data-w="6"] { width: 60%; }
.bar[data-w="7"] { width: 70%; }
.bar[data-w="8"] { width: 80%; }
.bar[data-w="9"] { width: 90%; }
.bar[data-w="10"] { width: 100%; }
.bar-n { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---------- Code blocks ---------- */

.code {
  margin: 0;
  padding: 1.15rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
  overflow-x: auto;
}
.code code {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text);
  white-space: pre;
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .credits, .filters form { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .app-page { padding: 1.25rem 1rem 3rem; }
  .stats { grid-template-columns: 1fr; }
  .mast { flex-wrap: wrap; gap: 1rem; }
  .who { justify-items: start; }
  .topnav { order: 3; width: 100%; }
}
