:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e5ea;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --danger: #c4372f;
  --ok-bg: #e5f4ea; --ok-fg: #1d6b3a;
  --warn-bg: #fdf1dc; --warn-fg: #8a5a00;
  --grace-bg: #fde7d6; --grace-fg: #9a4a0b;
  --bad-bg: #fbe4e2; --bad-fg: #a3271f;
  --off-bg: #eceef1; --off-fg: #4b5563;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1e232b;
    --border: #2b313a;
    --text: #e6e9ee;
    --muted: #98a2b3;
    --accent: #6d8ff0;
    --accent-text: #0b1020;
    --danger: #f0716a;
    --ok-bg: #12301f; --ok-fg: #7fd6a0;
    --warn-bg: #3a2c0d; --warn-fg: #f2c46b;
    --grace-bg: #3d2410; --grace-fg: #f5a66a;
    --bad-bg: #3c1715; --bad-fg: #f59a93;
    --off-bg: #262b33; --off-fg: #aeb6c2;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
[hidden] { display: none !important; }

/* Shell */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 0 20px; height: 52px;
  background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 650; letter-spacing: .2px; white-space: nowrap; }
.brand small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--surface-2); font-weight: 600; }
.topbar .right { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.who { color: var(--muted); }
main { max-width: 1200px; margin: 0 auto; padding: 20px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-body { padding: 16px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: end; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.json { font-family: var(--mono); font-size: 12px; color: var(--muted); word-break: break-all; max-width: 360px; }

/* Pills */
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.Active { background: var(--ok-bg); color: var(--ok-fg); }
.pill.Expiring { background: var(--warn-bg); color: var(--warn-fg); }
.pill.Grace { background: var(--grace-bg); color: var(--grace-fg); }
.pill.Expired, .pill.Revoked, .pill.alarm { background: var(--bad-bg); color: var(--bad-fg); }
.pill.none, .pill.kind { background: var(--off-bg); color: var(--off-fg); }

/* Forms and buttons */
button, .btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 6px 12px;
  border-radius: 6px; cursor: pointer; white-space: nowrap; }
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover { filter: brightness(1.05); }
button.danger { color: var(--danger); }
button.primary.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
button.small { padding: 3px 8px; font-size: 12.5px; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
button:disabled { opacity: .55; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 10px; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox] { width: auto; }
textarea { min-height: 70px; resize: vertical; }
.search { max-width: 280px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 4px; color: var(--muted); }
.field .err { color: var(--danger); font-size: 12.5px; margin-top: 3px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; color: var(--text); font-size: 14px; }
.inline-check { display: inline-flex; align-items: center; gap: 8px; }
.hint { color: var(--muted); font-size: 12.5px; }
.form-error { color: var(--danger); margin-top: 10px; }

/* AI quota meter (a <progress>: no inline styles under the CSP) */
progress.quota { display: block; width: 100%; max-width: 420px; height: 8px; margin: 6px 0 4px; border: 0; border-radius: 4px;
  background: var(--surface-2); accent-color: var(--accent); appearance: none; overflow: hidden; }
progress.quota::-webkit-progress-bar { background: var(--surface-2); }
progress.quota::-webkit-progress-value { background: var(--accent); }
progress.quota::-moz-progress-bar { background: var(--accent); }
progress.quota.high::-webkit-progress-value { background: var(--warn-fg); }
progress.quota.high::-moz-progress-bar { background: var(--warn-fg); }
progress.quota.over::-webkit-progress-value { background: var(--danger); }
progress.quota.over::-moz-progress-bar { background: var(--danger); }

/* Definition list */
.dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 20px; }
.dl div > span { display: block; font-size: 12px; color: var(--muted); }
.dl .full { grid-column: 1 / -1; }
.dl.stats { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }

/* Dialog */
dialog { border: 1px solid var(--border); border-radius: 10px; padding: 0; background: var(--surface); color: var(--text);
  width: min(560px, calc(100vw - 32px)); box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(10, 14, 20, .45); }
.dlg-head { padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dlg-body { padding: 16px 18px; max-height: 70vh; overflow-y: auto; }
.dlg-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.secret { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 10px; }
.secret code { flex: 1; word-break: break-all; }
.warn-box { background: var(--warn-bg); color: var(--warn-fg); border-radius: 6px; padding: 10px 12px; margin-bottom: 12px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); }
.login .card-body { display: grid; gap: 14px; }
.login h1 { margin-bottom: 2px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 50; max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 16px; gap: 8px; }
  .nav { order: 3; flex-basis: 100%; }
  main { padding: 16px; }
  .form { grid-template-columns: 1fr; }
  .search { max-width: none; }
  .who { display: none; }
  th, td { padding: 8px 10px; }
}

/* Organization platform: self-service / trial pills, Google button, "or" divider. */
.pill.self { background: var(--accent); color: var(--accent-text); }
.pill.trial { background: var(--warn-bg); color: var(--warn-fg); }
.login .or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.login .or::before, .login .or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.google-wrap { display: grid; gap: 14px; }
.google-wrap:empty { display: none; }
.google-btn { display: flex; justify-content: center; }
.dl .pill { justify-self: start; width: fit-content; }
