:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1b1f24;
  --muted: #5d6673;
  --accent: #2459d6;
  --accent-contrast: #ffffff;
  --danger: #c0342b;
  --success: #1c7c46;
  --warning: #9a6200;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #191d23;
    --surface-2: #20252c;
    --border: #2e353e;
    --text: #e7eaee;
    --muted: #9aa4b1;
    --accent: #6c9bff;
    --accent-contrast: #0b1020;
    --danger: #ff7b72;
    --success: #4cc38a;
    --warning: #e3b341;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: .25rem 0 .75rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* layout */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner, main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 16px;
}
.topbar-inner { display: flex; align-items: center; gap: 1.25rem; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: .5rem; }
.brand svg { width: 22px; height: 22px; }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav a { color: var(--muted); padding: .35rem .6rem; border-radius: 6px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--surface-2); font-weight: 600; }
.whoami { display: flex; align-items: center; gap: .75rem; color: var(--muted); }
main { padding-top: 1.5rem; padding-bottom: 3rem; }
.narrow { max-width: 440px; margin: 3rem auto; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card.flush { padding: 0; overflow: hidden; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* forms */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.field { margin-bottom: .9rem; }
.hint { font-weight: 400; color: var(--muted); font-size: .85rem; }
input[type=text], input[type=tel], input[type=search], input[type=datetime-local], input[type=number],
select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .5rem .65rem;
}
textarea { min-height: 6rem; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input[type=file] { font: inherit; max-width: 100%; }
input[type=checkbox] { width: 1rem; height: 1rem; }

.btn, button {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font: inherit;
  font-weight: 600;
  padding: .5rem .9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover, button:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover, button.primary:hover { filter: brightness(1.08); }
.btn.danger, button.danger { color: var(--danger); }
.btn.small, button.small { padding: .25rem .55rem; font-size: .85rem; }
.btn.link, button.link { border: none; background: none; padding: 0; color: var(--accent); font-weight: 500; }
button:disabled { opacity: .55; cursor: not-allowed; }
.big { width: 100%; justify-content: center; padding: .75rem 1rem; font-size: 1.05rem; }
form.inline { display: inline; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .65rem .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
tr.clickable:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }

/* badges */
.badge {
  display: inline-block;
  padding: .1rem .55rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge.draft { color: var(--muted); }
.badge.queued, .badge.rendering, .badge.submitted, .badge.sending { color: var(--accent); border-color: currentColor; }
.badge.delivered { color: var(--success); border-color: currentColor; }
.badge.failed { color: var(--danger); border-color: currentColor; }
.badge.canceled { color: var(--warning); border-color: currentColor; }
.pulse::before { content: "● "; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

.filters { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters a { padding: .25rem .7rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); background: var(--surface); }
.filters a.active { color: var(--accent-contrast); background: var(--accent); border-color: var(--accent); }

/* flash messages */
.messages { margin-bottom: 1rem; }
.msg { padding: .65rem .9rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); margin-bottom: .5rem; border-left-width: 4px; }
.msg.success { border-left-color: var(--success); }
.msg.error { border-left-color: var(--danger); }
.msg.warning { border-left-color: var(--warning); }
.msg.info { border-left-color: var(--accent); }
.alert { padding: .65rem .9rem; border-radius: 8px; margin: .5rem 0; border: 1px solid var(--danger); color: var(--danger); }

/* documents in job editor */
.doclist { list-style: none; margin: 0 0 .75rem; padding: 0; border: 1px solid var(--border); border-radius: 8px; }
.doclist li { display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem; border-bottom: 1px solid var(--border); }
.doclist li:last-child { border-bottom: none; }
.doclist .num { width: 1.5rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.doclist .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doclist .empty { padding: 1rem; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 11rem 1fr; gap: .75rem; padding: .5rem 0; border-bottom: 1px dashed var(--border); }
.timeline li:last-child { border-bottom: none; }
@media (max-width: 560px) { .timeline li { grid-template-columns: 1fr; gap: 0; } }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.25rem; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }

/* passkeys */
.passkeys { list-style: none; margin: 0; padding: 0; }
.passkey { display: flex; gap: 1rem; align-items: flex-start; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.passkey:last-child { border-bottom: none; }
.passkey.new { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.passkey-logo { flex: 0 0 40px; width: 40px; height: 40px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.passkey-logo img { width: 28px; height: 28px; object-fit: contain; }
.passkey-logo svg { width: 22px; height: 22px; color: var(--muted); }
.passkey-body { flex: 1; min-width: 0; }
.passkey-label { font-weight: 700; }
.passkey-default { color: var(--muted); font-size: .88rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.passkey-meta { color: var(--muted); font-size: .82rem; margin-top: .15rem; }
.passkey-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.rename-form { margin-top: .6rem; display: flex; gap: .5rem; flex-wrap: wrap; }
.rename-form input { flex: 1; min-width: 12rem; }

.code-box { font-size: 1.6rem; letter-spacing: .12em; font-weight: 700; text-align: center; padding: 1rem; border: 2px dashed var(--border); border-radius: var(--radius); margin: 1rem 0; user-select: all; }
.center { text-align: center; }
.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); margin: 1.25rem 0; font-size: .85rem; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.m-0 { margin: 0; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 1rem; }
.card > h2:first-child, .card > h1:first-child { margin-top: 0; }
