:root {
  --bg: #f6f9fc;
  --surface: #ffffff;
  --surface-muted: #f7fafc;
  --text: #1a1f36;
  --text-secondary: #3c4257;
  --muted: #697386;
  --border: #e3e8ee;
  --border-strong: #c1c9d2;
  --accent: #635bff;
  --accent-hover: #5851ea;
  --accent-soft: #eeedff;
  --accent-text: #ffffff;
  --ok: #0e6245;
  --ok-bg: #d7f7c2;
  --bad: #c0123c;
  --bad-bg: #ffe7f2;
  --warn: #983705;
  --warn-bg: #fcedb9;
  --neutral-bg: #ebeef1;
  --shadow: 0 0 0 1px rgb(50 50 93 / 0.05), 0 2px 5px 0 rgb(50 50 93 / 0.08), 0 1px 1px 0 rgb(0 0 0 / 0.05);
  --shadow-button: 0 1px 1px rgb(0 0 0 / 0.08), 0 2px 5px rgb(60 66 87 / 0.08);
  --focus: 0 0 0 4px rgb(99 91 255 / 0.25);
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1117;
    --surface: #171b24;
    --surface-muted: #1d2230;
    --text: #e6e9ef;
    --text-secondary: #c3c8d4;
    --muted: #8e96a8;
    --border: #2a3040;
    --border-strong: #3a4256;
    --accent: #7a73ff;
    --accent-hover: #8a84ff;
    --accent-soft: #25234a;
    --ok: #7fe0a8;
    --ok-bg: #12301f;
    --bad: #ff8fab;
    --bad-bg: #3a1424;
    --warn: #f5c46b;
    --warn-bg: #362812;
    --neutral-bg: #262c3a;
    --shadow: 0 0 0 1px var(--border);
    --shadow-button: 0 0 #0000;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Ubuntu, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; color: var(--text); }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* Layout */

.topbar { position: sticky; top: 0; z-index: 2; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, #635bff, #00d4ff); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

main { max-width: 1200px; margin: 0 auto; padding: 28px 24px 64px; }
main.narrow { max-width: 440px; padding-top: 64px; }
main.narrow h1 { margin-bottom: 4px; }
main.narrow p { margin-bottom: 20px; }

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

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.span-2 { grid-column: 1 / -1; }

/* Cards */

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 20px 24px 16px; flex-wrap: wrap; }
.card-header > div:first-child { flex: 1 1 240px; min-width: 0; }
.card-header h2 { margin-bottom: 2px; }
.card-header .muted { font-size: 13px; }
.card-section { padding: 16px 24px 20px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.card-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
  border-radius: 0 0 var(--radius) var(--radius);
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.card-footer .hint { flex: 1 1 220px; }

.empty-state { max-width: 560px; margin: 48px auto; padding: 40px; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }

/* Fields */

.fields { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; border: 0; padding: 0; margin: 0; }
.field-label { font-size: 13px; font-weight: 500; color: var(--text-secondary); padding: 0; }
.value {
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 6px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  overflow-wrap: anywhere;
  color: var(--text-secondary);
}
.value.empty { color: var(--muted); }
.copyable { display: flex; gap: 8px; align-items: center; justify-content: space-between; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 7px 10px;
  min-width: 0;
  box-shadow: 0 1px 1px rgb(0 0 0 / 0.03);
}
textarea { resize: vertical; min-height: 36px; }
select.compact { padding: 4px 8px; font-size: 13px; max-width: 180px; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: none; box-shadow: var(--focus); border-color: var(--accent); }
::placeholder { color: var(--muted); }

.input-with-button { display: flex; }
.input-with-button input { flex: 1; border-radius: 6px 0 0 6px; }
.input-with-button .copy { border: 1px solid var(--border-strong); border-left: 0; border-radius: 0 6px 6px 0; padding: 0 12px; background: var(--surface-muted); }

.email-input { display: inline-flex; align-items: stretch; min-width: 0; }
.email-input input { flex: 1; min-width: 0; border-radius: 6px 0 0 6px; }
.email-input .suffix {
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-left: 0;
  border-radius: 0 6px 6px 0;
  background: var(--surface-muted);
  color: var(--muted);
  white-space: nowrap;
}

.inline-form { display: flex; gap: 8px; align-items: flex-start; }
.inline-form textarea { flex: 1; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 24px 16px; }
.toolbar > input { flex: 1 1 140px; }
.toolbar > .email-input { flex: 2 1 240px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.form-error { color: var(--bad); font-size: 13px; }
.callout { font-size: 13px; padding: 8px 12px; border-radius: 6px; background: var(--warn-bg); color: var(--warn); }

/* Buttons */

.button {
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: var(--shadow-button);
  white-space: nowrap;
  text-decoration: none;
}
.button:hover { background: var(--accent-hover); text-decoration: none; }
.button.secondary { background: var(--surface); color: var(--text-secondary); box-shadow: 0 0 0 1px var(--border-strong), var(--shadow-button); }
.button.secondary:hover { color: var(--text); background: var(--surface-muted); }
.button.ghost { background: none; box-shadow: none; color: var(--text-secondary); }
.button.ghost:hover { background: var(--neutral-bg); }
.button.danger { color: var(--bad); }
.button.small { height: 28px; padding: 0 10px; font-size: 13px; }
.button:disabled { opacity: 0.6; cursor: progress; }

.copy, .link {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  background: none;
  border: 0;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
.copy:hover, .link:hover { background: var(--accent-soft); }
.link.danger { color: var(--bad); }
.link.danger:hover { background: var(--bad-bg); }

/* Segmented control */

.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 8px; background: var(--neutral-bg); align-self: flex-start; max-width: 100%; }
.segmented button {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  border: 0;
  background: none;
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-button), 0 0 0 1px var(--border); }
.count { color: var(--muted); font-weight: 400; }

/* Pills */

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--ok); background: var(--ok-bg); }
.pill.bad { color: var(--bad); background: var(--bad-bg); }
.pill.warn { color: var(--warn); background: var(--warn-bg); }
.pill.neutral { color: var(--text-secondary); background: var(--neutral-bg); }
.pill.neutral::before { display: none; }

/* Activity log */

.activity { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; }
.activity li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.activity li:last-child { border-bottom: 0; }
.activity .call { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity .time { color: var(--muted); font-variant-numeric: tabular-nums; }
.activity .message { grid-column: 2 / -1; color: var(--bad); font-size: 12px; }
.activity li.empty { display: block; color: var(--muted); text-align: center; padding: 20px; }

/* Tables */

.table-wrap { overflow-x: auto; border-top: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th:first-child, td:first-child { padding-left: 24px; }
th:last-child, td:last-child { padding-right: 24px; }
th { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: var(--surface-muted); }
tbody tr:hover { background: var(--surface-muted); }
tbody tr:last-child td { border-bottom: 0; }
td.empty { color: var(--muted); text-align: center; padding: 32px; }
tr.inactive td:not(:last-child) { color: var(--muted); }
.actions { text-align: right; white-space: nowrap; }
.name-cell { font-weight: 500; }

/* Dialogs */

dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--border), 0 15px 35px rgb(50 50 93 / 0.2), 0 5px 15px rgb(0 0 0 / 0.12);
}
dialog.wide { width: min(600px, calc(100vw - 32px)); }
dialog .toolbar { padding-top: 16px; }
dialog .table-wrap { max-height: 50vh; overflow-y: auto; }
dialog::backdrop { background: rgb(26 31 54 / 0.45); }
.dialog-header { padding: 18px 24px 0; }
.dialog-body { padding: 16px 24px 20px; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 24px; border-top: 1px solid var(--border); background: var(--surface-muted); }

/* SSO user picker (server-rendered) */

.picker { display: flex; flex-direction: column; gap: 8px; }
.pick {
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 14px 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
}
.pick:hover { box-shadow: 0 0 0 2px var(--accent); }
.pick span { color: var(--muted); font-size: 13px; }

/* Toast */

#toast {
  position: fixed;
  inset: auto auto 20px 50%;
  transform: translateX(-50%);
  margin: 0;
  border: 0;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  background: #1a1f36;
  color: #fff;
  font-weight: 500;
  box-shadow: 0 15px 35px rgb(50 50 93 / 0.25), 0 5px 15px rgb(0 0 0 / 0.15);
}
#toast.error { background: var(--bad); }

@media (max-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 600px) {
  .topbar-inner, main { padding-left: 16px; padding-right: 16px; }
  .card-header, .card-section, .card-footer { padding-left: 16px; padding-right: 16px; }
  .toolbar { padding: 0 16px 16px; }
  th:first-child, td:first-child { padding-left: 16px; }
  th:last-child, td:last-child { padding-right: 16px; }
  .inline-form { flex-direction: column; align-items: stretch; }
  .topbar-actions { width: 100%; }
  .topbar-actions select { flex: 1; }
}
