/* Platform design system — single external stylesheet (AGENTS.md §6: strict CSP, no inline styles).
 *
 * Served at /assets/app.css and used by BOTH surfaces:
 *   - the server-rendered pre-auth pages (login / 2FA / invite / recovery), and
 *   - the post-auth SPA (rendered in light DOM so this sheet styles it directly).
 *
 * No web fonts, no @import, no external assets — everything is same-origin and self-contained so the
 * `default-src 'self'` policy holds with zero exceptions. Theme: refined dark.
 */

:root {
  --bg: #0f1115;
  --panel: #161922;
  --panel-2: #1b1f2a;
  --line: #262b36;
  --line-strong: #323847;
  --fg: #e6e9ef;
  --muted: #9aa3b2;
  --faint: #6b7382;
  --accent: #4f8cff;
  --accent-hover: #6a9bff;
  --accent-quiet: rgba(79, 140, 255, 0.14);
  --danger: #ff6b6b;
  --danger-quiet: rgba(255, 107, 107, 0.14);
  --ok: #3ecf8e;
  --ok-quiet: rgba(62, 207, 142, 0.14);
  --warn: #f5b34a;
  --warn-quiet: rgba(245, 179, 74, 0.16);

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.25);

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

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

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: 0.2px; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
code { font-family: var(--mono); font-size: 0.92em; }

/* ---- Brand ---- */
.brand, .auth-brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 600; font-size: 16px; letter-spacing: 0.3px;
}
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-quiet);
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: #fff; border: 1px solid transparent;
  border-radius: var(--radius-sm); padding: 9px 16px;
  font: inherit; font-weight: 500; cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}
.btn:hover { background: var(--accent-hover); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--fg); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--panel-2); border-color: var(--faint); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-quiet); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---- Form fields ---- */
label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
input, select {
  width: 100%; background: var(--bg); color: var(--fg);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 9px 11px; font: inherit;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input::placeholder { color: var(--faint); }
input:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-quiet);
}
.field { margin-bottom: 14px; }

/* ---- Badges / pills ---- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 1.6;
  border: 1px solid var(--line-strong); color: var(--muted);
}
.badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: 0.9;
}
.badge-plain::before { display: none; }
.badge-accent { color: var(--accent); border-color: var(--accent); background: var(--accent-quiet); }
.badge-ok     { color: var(--ok);     border-color: var(--ok);     background: var(--ok-quiet); }
.badge-warn   { color: var(--warn);   border-color: var(--warn);   background: var(--warn-quiet); }
.badge-danger { color: var(--danger); border-color: var(--danger); background: var(--danger-quiet); }

/* ---- Alerts ---- */
.alert {
  border-radius: var(--radius-sm); padding: 11px 13px; margin: 0 0 16px;
  font-size: 13px; border: 1px solid var(--line-strong);
}
.alert-error { color: var(--danger); border-color: var(--danger); background: var(--danger-quiet); }
.alert-info  { color: var(--muted); background: var(--panel-2); }

/* ============================================================
   App shell (post-auth SPA, light DOM)
   ============================================================ */
app-shell { display: block; min-height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 60px; padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky; top: 0; z-index: 10;
}
.topbar-right { display: flex; align-items: center; gap: 14px; }
.identity { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.identity .email { color: var(--fg); }

.layout {
  display: grid; grid-template-columns: 220px 1fr;
  min-height: calc(100vh - 60px);
}
.sidebar {
  border-right: 1px solid var(--line);
  padding: 18px 12px; background: var(--panel);
  display: flex; flex-direction: column; gap: 2px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500; cursor: pointer;
  border: 1px solid transparent; user-select: none;
}
.nav-item:hover { background: var(--panel-2); color: var(--fg); }
.nav-item.active { background: var(--accent-quiet); color: var(--accent); }

.content { padding: 28px 32px; max-width: 1040px; }
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; gap: 16px;
}
.page-head h1 { font-size: 20px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ---- Cards ---- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 22px; overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line); gap: 12px;
}
.card-head h2 { font-size: 15px; }
.card-body { padding: 18px 20px; }
.card-body.flush { padding: 0; }

/* ---- Stat tiles (dashboard) ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px;
}
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 600; margin-top: 6px; }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; padding: 11px 20px; color: var(--muted); font-weight: 500;
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px;
  border-bottom: 1px solid var(--line); background: var(--panel-2);
}
tbody td { padding: 12px 20px; border-bottom: 1px solid var(--line); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--panel-2); }
td.actions { text-align: right; white-space: nowrap; }
.cell-mono { font-family: var(--mono); color: var(--muted); }

/* ---- Empty state ---- */
.empty { padding: 40px 20px; text-align: center; color: var(--faint); }

/* ---- Inline form rows (e.g. create tenant) ---- */
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.form-row .field { margin-bottom: 0; flex: 1; min-width: 200px; }

/* ---- Copyable link box ---- */
.copybox { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
.copybox input { font-family: var(--mono); font-size: 12px; }

/* ============================================================
   Modal
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5, 7, 11, 0.6);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 80px 16px; z-index: 100;
}
.modal {
  width: 100%; max-width: 440px;
  background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--line);
}
.icon-btn {
  background: transparent; border: 0; color: var(--muted);
  font-size: 20px; line-height: 1; cursor: pointer; padding: 2px 6px;
}
.icon-btn:hover { color: var(--fg); }

.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 13px; margin-top: 10px; }

/* ============================================================
   Pre-auth pages (server-rendered, app/auth/pages.py)
   ============================================================ */
.auth-body {
  min-height: 100vh; display: grid; place-items: center; padding: 32px 16px;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(79, 140, 255, 0.10), transparent 70%),
    var(--bg);
}
.auth-wrap { width: 100%; max-width: 400px; }
.auth-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 28px 28px 24px;
}
.auth-card .auth-brand { margin-bottom: 22px; }
.auth-card h1 { font-size: 20px; margin-bottom: 6px; }
.auth-card h2 { font-size: 13px; color: var(--muted); font-weight: 500; margin: 0 0 12px; }
.auth-card section { margin-top: 22px; }
.auth-card section:first-of-type { margin-top: 18px; }
.auth-card p { margin: 0 0 14px; }
.auth-card label { margin-bottom: 6px; }
.auth-card input { margin-bottom: 14px; }
.auth-card button, .auth-card .btn { width: 100%; }
.auth-card small { color: var(--faint); }
.auth-card code {
  display: inline-block; background: var(--bg); border: 1px solid var(--line-strong);
  border-radius: 6px; padding: 3px 7px; word-break: break-all;
}

/* Server pages use bare <button>/<a> — give them the primary/ghost look without extra classes. */
.auth-card button[type="submit"] {
  background: var(--accent); color: #fff; border: 1px solid transparent;
  border-radius: var(--radius-sm); padding: 10px 16px; font: inherit; font-weight: 500;
  cursor: pointer; transition: background 0.12s ease;
}
.auth-card button[type="submit"]:hover { background: var(--accent-hover); }

/* Primary call-to-action rendered as a link (server pages have no JS). */
.auth-card a.button {
  display: block; text-align: center; background: var(--accent); color: #fff;
  border-radius: var(--radius-sm); padding: 10px 16px; font-weight: 500; margin-top: 8px;
}
.auth-card a.button:hover { background: var(--accent-hover); color: #fff; }

/* TOTP enrollment QR (inline SVG already carries a white quiet zone). */
.auth-card .qr { display: flex; justify-content: center; margin: 18px 0 6px; }
.auth-card .qr svg { border-radius: 8px; }
.auth-card .manual { text-align: center; color: var(--muted); }

.auth-divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--faint); font-size: 12px; margin: 22px 0 4px;
}
.auth-divider::before, .auth-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}
.sso-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.sso-list a {
  display: block; text-align: center; color: var(--fg);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 10px 16px; font-weight: 500;
}
.sso-list a:hover { background: var(--panel-2); border-color: var(--faint); color: var(--fg); }

.codes { list-style: none; margin: 16px 0; padding: 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.codes li {
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: 6px;
  padding: 8px 10px; text-align: center; font-family: var(--mono); letter-spacing: 1px;
}
.codes li code { background: none; border: 0; padding: 0; display: inline; } /* li is the box */

[role="alert"] {
  display: block; color: var(--danger);
  background: var(--danger-quiet); border: 1px solid var(--danger);
  border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 16px; font-size: 13px;
}
