/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

img, svg, iframe { max-width: 100%; display: block; }

h1, h2, h3, h4 { margin: 0; font-weight: 640; letter-spacing: -.015em; line-height: 1.2; }
h1 { font-size: clamp(1.75rem, 1.2rem + 1.8vw, 2.5rem); letter-spacing: -.025em; }
h2 { font-size: clamp(1.25rem, 1.05rem + .7vw, 1.6rem); }
h3 { font-size: 1.0625rem; }
p  { margin: 0; }

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }

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

::selection { background: var(--accent-soft); color: var(--ink); }

[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.shell { width: 100%; max-width: var(--shell); margin-inline: auto; padding-inline: 20px; }
@media (max-width: 767px) { .shell { padding-inline: 14px; } }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); }
.stack { display: grid; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-wrap { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1 1 auto; }
.nowrap { white-space: nowrap; }

/* ---------- icons ---------- */
/* Glyph paths vendored from Phosphor Icons (MIT). One icon family across the project. */
.i { width: 20px; height: 20px; flex: none; }
.i-sm { width: 16px; height: 16px; }

/* ---------- header ---------- */

.topbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  height: 64px;
  display: flex; align-items: center;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
}
@supports not (backdrop-filter: blur(4px)) { .topbar { background: var(--surface); } }

.topbar .shell { display: flex; align-items: center; gap: 18px; height: 100%; }

.brand {
  display: inline-flex; align-items: center; gap: 9px;
  font-weight: 660; letter-spacing: -.02em; font-size: 1.0625rem;
  color: var(--ink); text-decoration: none;
}
.brand:hover { color: var(--ink); }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700; letter-spacing: -.03em;
}

.nav { display: flex; align-items: center; gap: 2px; }
.nav a {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 11px; border-radius: var(--r-sm);
  color: var(--ink-2); text-decoration: none; font-size: .9375rem; font-weight: 500;
  white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
:root[data-theme="dark"] .nav a[aria-current="page"] { color: var(--accent-hover); }

@media (max-width: 900px) {
  .nav a .lbl { display: none; }
  .nav a { padding: 8px; }
}

.avatar {
  width: 30px; height: 30px; border-radius: var(--r-pill); flex: none;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  border: 1px solid var(--accent-line);
}

/* ---------- buttons ---------- */

.btn {
  appearance: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 15px;
  border-radius: var(--r); border: 1px solid var(--line-strong);
  background: var(--surface-raised); color: var(--ink);
  font: inherit; font-size: .9375rem; font-weight: 550; white-space: nowrap;
  text-decoration: none;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              transform var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); border-color: transparent; }

.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); background: transparent; }
.btn-danger:hover { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }

.btn-sm { height: 31px; padding: 0 11px; font-size: .875rem; gap: 6px; }
.btn-lg { height: 46px; padding: 0 22px; font-size: 1rem; }
.btn-icon { width: 38px; padding: 0; }
.btn-icon.btn-sm { width: 31px; }
.btn-block { width: 100%; }

/* ---------- forms ---------- */

.field { display: grid; gap: 6px; }
.field > label { font-size: .875rem; font-weight: 550; color: var(--ink); }
.field .help { font-size: .8125rem; color: var(--ink-2); }
.field .err { font-size: .8125rem; color: var(--bad); }

.input, .textarea, .select {
  width: 100%; font: inherit; color: var(--ink);
  background: var(--surface-raised);
  border: 1px solid var(--line-strong); border-radius: var(--r);
  padding: 9px 11px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--bad); }
.textarea { resize: vertical; min-height: 84px; line-height: 1.5; }
/* Chevron drawn with gradients so it inherits currentColor in both themes. */
.select {
  appearance: none; padding-right: 34px;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 1px), calc(100% - 13px) calc(50% - 1px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
.input-mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: .9375rem; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 38px; height: 22px; border-radius: var(--r-pill); flex: none;
  background: var(--surface-3); border: 1px solid var(--line-strong);
  position: relative; transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; bottom: 2px; left: 2px;
  width: 16px; border-radius: var(--r-pill); background: var(--surface-raised);
  box-shadow: var(--shadow-1);
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- surfaces ---------- */

.card {
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.card-pad { padding: 18px; }

.panel { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-raised); overflow: hidden; }
.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.panel-head h3 { font-size: .9375rem; font-weight: 600; }
.panel-body { padding: 16px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 10px; border-radius: var(--r-pill);
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: .75rem; font-weight: 600; color: var(--ink-2);
  letter-spacing: .01em; white-space: nowrap;
}
.chip-accent { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
:root[data-theme="dark"] .chip-accent { color: var(--accent-hover); }
.chip-ok   { background: var(--ok-soft);   border-color: color-mix(in srgb, var(--ok) 30%, transparent);   color: var(--ok); }
.chip-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); color: var(--warn); }
.chip-bad  { background: var(--bad-soft);  border-color: color-mix(in srgb, var(--bad) 30%, transparent);  color: var(--bad); }

hr.rule { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

/* ---------- page scaffolding ---------- */

.page { padding: 26px 0 72px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--ink-2); font-size: .9375rem; margin-top: 4px; }

/* ---------- states ---------- */

.empty {
  display: grid; gap: 12px; justify-items: center; text-align: center;
  padding: 56px 24px; border: 1px dashed var(--line-strong); border-radius: var(--r);
  color: var(--ink-2); background: var(--surface-2);
}
.empty h3 { color: var(--ink); }
.empty p { max-width: 46ch; }

.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 13px; border-radius: var(--r); font-size: .9375rem;
  border: 1px solid var(--line);
}
.alert-bad  { background: var(--bad-soft);  border-color: color-mix(in srgb, var(--bad) 30%, transparent);  color: var(--bad); }
.alert-ok   { background: var(--ok-soft);   border-color: color-mix(in srgb, var(--ok) 30%, transparent);   color: var(--ok); }
.alert-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); color: var(--warn); }

.skel {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  border-radius: var(--r-sm);
  animation: skel 1.4s linear infinite;
}
@keyframes skel { from { background-position: 100% 0; } to { background-position: 0 0; } }

.toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: var(--z-toast);
  display: grid; gap: 8px; justify-items: end; pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 9px;
  padding: 10px 14px; border-radius: var(--r);
  background: var(--ink); color: var(--surface);
  box-shadow: var(--shadow-2); font-size: .9375rem; font-weight: 500;
  max-width: 380px;
  animation: toast-in .2s var(--ease);
}
.toast-bad { background: var(--bad); color: #fff; }
.toast-ok  { background: var(--ok);  color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- modal ---------- */

.modal-back {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: color-mix(in srgb, var(--ink) 45%, transparent);
  display: grid; place-items: center; padding: 18px;
  animation: fade-in .15s var(--ease);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: min(560px, 100%); max-height: min(86dvh, 760px);
  display: flex; flex-direction: column;
  background: var(--surface-raised); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-2); overflow: hidden;
}
.modal-wide { width: min(880px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { flex: 1 1 auto; }
.modal-body { padding: 18px; overflow: auto; display: grid; gap: 14px; }
.modal-foot { display: flex; gap: 9px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--line); background: var(--surface-2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
