/* Algebra Nexus — shared theme
   Direction: premium fintech console (Stripe Dashboard school) — the
   device's own system font (SF Pro / Segoe UI, exactly what Stripe's own
   dashboard uses), cool blue-grey neutrals, one disciplined navy accent from
   the wordmark's tagline, soft layered shadows on white cards over a tinted
   page ground, tabular figures for every amount. */

:root {
  --ink: #0b0e14;
  --ink-soft: #565f6f;
  --ink-faint: #8892a0;

  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-1: #fafbfc;
  --surface-2: #f2f3f7;
  --surface-3: #e9ebf1;
  --border: #e4e6ed;
  --border-soft: #eef0f4;
  --border-strong: #d5d9e2;

  --accent: #1a2440;
  --accent-hover: #2f3d66;
  --accent-soft: #eef0f7;
  --accent-contrast: #ffffff;

  --success: #0f7a52;
  --success-soft: #e6f5ee;
  --danger: #b8342a;
  --danger-soft: #fbeae8;
  --warning: #a8630f;
  --warning-soft: #fbf0de;

  --radius: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 18, 28, 0.04);
  --shadow-md: 0 4px 16px rgba(15, 18, 28, 0.06), 0 1px 2px rgba(15, 18, 28, 0.04);
  --shadow-elevated: 0 20px 48px rgba(15, 18, 28, 0.16), 0 4px 12px rgba(15, 18, 28, 0.06);

  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Ubuntu, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #eef0f5;
    --ink-soft: #a7afc0;
    --ink-faint: #6d7688;

    --bg: #0e1016;
    --surface: #15171f;
    --surface-1: #181b24;
    --surface-2: #1d202b;
    --surface-3: #262a38;
    --border: #262a37;
    --border-soft: #1f2330;
    --border-strong: #333849;

    --accent: #9aa8e0;
    --accent-hover: #b4c0ec;
    --accent-soft: #212842;
    --accent-contrast: #0e1016;

    --success: #4fd8a4;
    --success-soft: #12291f;
    --danger: #f28b7f;
    --danger-soft: #2f1a19;
    --warning: #f0b35c;
    --warning-soft: #2d2314;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.35);
    --shadow-elevated: 0 20px 48px rgba(0, 0, 0, 0.55);

    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3 {
  font-family: var(--font-body);
  font-weight: 650;
  letter-spacing: -0.015em;
  margin: 0;
  color: var(--ink);
  text-wrap: balance;
}
h1 { font-size: 22px; }
h2 { font-size: 15px; margin-bottom: 12px; }

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

code {
  font-family: var(--font-mono);
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 0.86em;
}

.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

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

/* ---------- App shell (sidebar layout) ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Follows the theme like everything else. The wordmark (logo.png) is dark
   ink on transparent with no reversed variant, so in dark mode it's run
   through an invert + hue-rotate filter instead — that keeps the chrome/
   silver Σ reading as metal rather than turning into a flat silhouette. */
.sidebar {
  width: 236px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-logo {
  width: 100%;
  max-width: 168px;
  height: auto;
  margin: 4px 8px 18px;
}

.sidebar > a:first-child {
  display: block;
  border-bottom: 1px solid var(--border-soft);
  margin: 0 -2px 12px;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  padding: 8px 10px;
  border-radius: var(--radius);
  letter-spacing: -0.005em;
  transition: background 0.12s ease, color 0.12s ease;
}

.sidebar nav a svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  stroke: currentColor;
  opacity: 0.8;
}

.sidebar nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.sidebar nav a:hover svg { opacity: 1; }

.sidebar nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}
.sidebar nav a.active svg { opacity: 1; }

.sidebar-footer {
  border-top: 1px solid var(--border-soft);
  padding-top: 12px;
  margin-top: 12px;
}

.sidebar-footer .who {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  padding: 0 10px 10px;
  overflow-wrap: break-word;
}

.app-main {
  flex: 1;
  min-width: 0;
  padding: 32px 40px 60px;
  max-width: 1320px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header p.subtitle {
  color: var(--ink-faint);
  margin: 4px 0 0;
  font-size: 13.5px;
}

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
  }
  .sidebar > a:first-child { border-bottom: none; margin: 0; }
  .sidebar-logo { width: auto; height: 28px; margin: 0 12px 0 0; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-footer { border-top: none; margin: 0 0 0 auto; padding: 0; }
  .sidebar-footer .who { display: none; }
  .app-main { padding: 22px 16px 48px; }
}

@media (prefers-color-scheme: dark) {
  .sidebar-logo,
  .auth-card .auth-logo {
    filter: invert(0.92) hue-rotate(180deg) brightness(1.1);
  }
  .checkout-card .auth-logo { filter: none; }
}

/* The customer checkout card stays light in every theme: Stripe's Payment
   Element inside it renders with Stripe's default light appearance, whose
   dark labels would be unreadable on a dark card. */
.checkout-card {
  --ink: #0b0e14;
  --ink-soft: #565f6f;
  --ink-faint: #8892a0;
  --surface: #ffffff;
  --surface-2: #f2f3f7;
  --border: #e4e6ed;
  --border-soft: #eef0f4;
  --border-strong: #d5d9e2;
  --accent: #1a2440;
  --accent-hover: #2f3d66;
  --accent-soft: #eef0f7;
  --accent-contrast: #ffffff;
  --danger: #b8342a;
  --success: #0f7a52;
  color-scheme: light;
}

/* ---------- Auth pages (centered card) ---------- */

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(640px circle at 12% 18%, rgba(47, 61, 102, 0.10), transparent 62%),
    radial-gradient(520px circle at 88% 88%, rgba(26, 36, 64, 0.08), transparent 62%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 392px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-elevated);
  padding: 40px 36px 34px;
}

.auth-card .auth-logo {
  display: block;
  height: 46px;
  margin: 0 auto 26px;
}

.auth-card h1 { text-align: center; font-size: 18px; margin-bottom: 4px; }

.auth-links {
  text-align: center;
  margin-top: 20px;
  font-size: 13px;
  color: var(--ink-soft);
}

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

label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-top: 14px;
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.12s, box-shadow 0.12s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

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

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

.btn, button {
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s, transform 0.06s;
}

.btn:hover, button:hover { background: var(--surface-2); border-color: var(--ink-faint); }
.btn:active, button:active { transform: translateY(1px); }

.btn-primary, button[type="submit"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  width: 100%;
  margin-top: 22px;
  padding: 10px 16px;
  box-shadow: 0 1px 2px rgba(15, 18, 28, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.btn-primary:hover, button[type="submit"]:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger {
  background: var(--danger-soft);
  border-color: var(--danger-soft);
  color: var(--danger);
  box-shadow: none;
}
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: white; }

button:disabled { opacity: 0.5; cursor: default; transform: none; }
/* `color` must be reset here too, not just background/border — .btn-primary
   (and any other variant whose own `color` equals --surface, e.g. dark text
   on a light button or vice versa in dark mode) would otherwise keep its
   own text color while the background resets to --surface, making the
   label invisible on hover (text color == background color). */
button:disabled:hover { background: var(--surface); border-color: var(--border-strong); color: var(--ink-faint); }

/* ---------- Key reveal banner (legacy, kept for anything not yet on the modal) ---------- */

.key-banner {
  margin: 0 0 20px;
  padding: 14px 16px;
  background: var(--success-soft);
  border: 1px solid var(--success);
  border-radius: var(--radius-md);
  font-size: 13.5px;
}
.key-banner .key-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.key-banner code { flex: 1; display: block; background: var(--surface); padding: 8px 10px; font-size: 13px; word-break: break-all; }

.copy-btn { flex-shrink: 0; padding: 8px 12px; }
.copy-btn.copied { background: var(--success); border-color: var(--success); color: white; }

/* ---------- Blocking key-reveal modal ----------
   Secrets (API keys) are hashed server-side the instant they're created —
   the plaintext is never stored anywhere, so this is the ONLY moment it can
   ever be copied. A dismissible banner is too easy to lose by accident
   (scroll, click away, tab close); a modal that requires an explicit
   confirmed action to close is not. */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 18, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  z-index: 100;
}

.modal-card {
  background: var(--surface);
  color: var(--ink);
  border-radius: 20px;
  box-shadow: var(--shadow-elevated);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}

.modal-card h2 { font-size: 17px; margin-bottom: 8px; }
.modal-card p { color: var(--ink-soft); font-size: 13px; margin: 0 0 16px; line-height: 1.55; }

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13.5px;
}
.detail-row:last-child { border-bottom: none; }
.detail-row > span:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.detail-label { color: var(--ink-soft); flex-shrink: 0; }

.modal-card .key-display {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 16px;
}

.modal-card .key-display code {
  flex: 1;
  background: transparent;
  border: none;
  padding: 4px 6px;
  font-size: 12.5px;
  word-break: break-all;
}

.modal-card .confirm-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin-top: 4px;
}

.modal-card .confirm-row input[type="checkbox"] { width: auto; accent-color: var(--accent); box-shadow: none; }
.modal-card .confirm-row label { margin: 0; font-weight: 400; color: var(--ink); }

/* ---------- Cards & tables ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

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

/* Cramped columns used to force cell text to wrap onto 2-3 lines on narrow
   (mobile) screens instead of just scrolling sideways — nowrap plus the
   .card's own horizontal scroll above keeps every row a single readable
   line at any width. */
th, td { white-space: nowrap; }

th {
  text-align: left;
  padding: 11px 18px;
  color: var(--ink-faint);
  font-weight: 650;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
}

td {
  text-align: left;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--ink);
  vertical-align: middle;
}

th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s; }
tbody tr:hover { background: var(--surface-1); }

/* ---------- Status pills ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 650;
  line-height: 1.5;
}
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}
.pill-success { background: var(--success-soft); color: var(--success); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-warning { background: var(--warning-soft); color: var(--warning); }
.pill-neutral { background: var(--surface-3); color: var(--ink-soft); }

/* ---------- Messages / callouts ---------- */

#message, .form-message {
  margin-top: 14px;
  font-size: 13px;
}
.error, #message.error { color: var(--danger); }
.success, #message.success { color: var(--success); }

.callout {
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin: 16px 0;
  font-size: 13px;
  color: var(--ink);
}

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

/* ---------- Shared page components (list pages) ---------- */

.page-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-actions .btn-primary { width: auto; margin-top: 0; padding: 9px 16px; display: inline-flex; align-items: center; gap: 8px; }
.page-actions .btn-primary svg { width: 15px; height: 15px; }

.mini-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.mini-stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 14px 18px; box-shadow: var(--shadow-sm); }
.mini-stat .label { font-size: 12px; color: var(--ink-faint); font-weight: 600; }
.mini-stat .value { font-size: 20px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
@media (max-width: 640px) { .mini-stats { grid-template-columns: 1fr; } }

.banner { display: flex; align-items: flex-start; gap: 10px; border-radius: var(--radius-md); padding: 12px 16px; font-size: 13px; margin-bottom: 16px; }
.banner[hidden] { display: none; }
.banner.success { background: var(--success-soft); color: var(--success); }
.banner.error { background: var(--danger-soft); color: var(--danger); }
.banner.warning { background: var(--warning-soft); color: var(--warning); }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; color: var(--ink-soft);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 8px; font-variant-numeric: tabular-nums;
}

.kebab {
  width: 32px; height: 32px; padding: 0; display: inline-flex; align-items: center; justify-content: center;
  border-color: transparent; background: transparent; box-shadow: none; color: var(--ink-soft);
}
.kebab:hover { background: var(--surface-2); border-color: var(--border); color: var(--ink); }
.kebab svg { width: 16px; height: 16px; }

.row-menu {
  position: fixed; z-index: 90; min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-elevated); padding: 6px;
}
.row-menu[hidden] { display: none; }
.row-menu button {
  display: flex; width: 100%; align-items: center; gap: 10px; text-align: left;
  border: none; background: transparent; box-shadow: none; border-radius: 7px;
  padding: 8px 10px; font-size: 13px; font-weight: 550; color: var(--ink);
}
.row-menu button:hover { background: var(--surface-2); }
.row-menu button.danger { color: var(--danger); }
.row-menu button.danger:hover { background: var(--danger-soft); }
.row-menu hr { border: none; border-top: 1px solid var(--border-soft); margin: 5px 2px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.modal-actions button { width: auto; margin-top: 0; }
.field-hint { font-size: 12px; color: var(--ink-faint); margin: 5px 0 0; font-weight: 400; }
