/*
 * StagePilot Licenses — admin UI and the public offline page. Brand: apps/web/DESIGN.md (dark neutral surfaces,
 * 1 px borders, Inter / JetBrains Mono bundled, status as icon + text, 4 px grid, radius ≤ 6 px, no gradients or
 * shadows). Served as /assets/app.css under CSP default-src 'self' (fonts come from /assets/fonts).
 */

@font-face {
  font-family: 'Inter Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(/assets/fonts/inter-latin-ext.woff2) format('woff2-variations');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Inter Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(/assets/fonts/inter-latin.woff2) format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'JetBrains Mono Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 100 800;
  src: url(/assets/fonts/jetbrains-mono-latin.woff2) format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg-app: #0a0c0f;
  --bg-panel: #111419;
  --bg-raised: #171b21;
  --bg-hover: #1d222a;
  --bg-inset: #0d1014;
  --line: #232830;
  --line-strong: #2e3440;
  --fg: #e9ecf1;
  --fg-2: #a1a9b6;
  --fg-muted: #6b7482;
  --live: #22c55e;
  --live-dim: rgba(34, 197, 94, 0.12);
  --live-line: rgba(34, 197, 94, 0.35);
  --warning: #eab308;
  --warning-dim: rgba(234, 179, 8, 0.12);
  --warning-line: rgba(234, 179, 8, 0.35);
  --critical: #ef4444;
  --critical-dim: rgba(239, 68, 68, 0.12);
  --critical-line: rgba(239, 68, 68, 0.4);
  --active: #3b82f6;
  --active-dim: rgba(59, 130, 246, 0.14);
  --active-line: rgba(59, 130, 246, 0.45);
  --inactive: #6b7280;
  --inactive-dim: rgba(107, 114, 128, 0.14);
  --inactive-line: rgba(107, 114, 128, 0.4);
  --font: 'Inter Variable', Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono Variable', 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

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

* {
  outline-color: var(--active);
}

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

:focus-visible {
  outline: 2px solid var(--active);
  outline-offset: 2px;
}

a {
  color: #7fb0ff;
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

h1,
h2,
p {
  margin: 0;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.mono,
code {
  font-family: var(--mono);
  font-size: 12px;
}
.tnum {
  font-variant-numeric: tabular-nums;
}
.muted {
  color: var(--fg-muted);
}
.sub {
  color: var(--fg-muted);
  font-size: 11px;
  line-height: 16px;
}
.sub.tone-warning-text {
  color: var(--warning);
}
.extend-result {
  font-weight: 600;
}
.caps {
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.pre {
  white-space: pre-wrap;
}
.nowrap {
  white-space: nowrap;
}
.truncate {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon {
  width: 16px;
  height: 16px;
  flex: none;
}

/* ───────────── Shell ───────────── */

.shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  grid-template-rows: 48px minmax(0, 1fr);
  grid-template-areas: 'top top' 'side page';
  min-height: 100vh;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -40px;
  z-index: 10;
  padding: 6px 10px;
  background: var(--active);
  color: #fff;
  border-radius: 4px;
}
.skip-link:focus {
  top: 8px;
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
}
.topbar-spacer {
  flex: 1;
}
.topbar-user {
  color: var(--fg-2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--fg);
  font-weight: 700;
  font-size: 14px;
}
.brand:hover {
  text-decoration: none;
}
.brand-mark {
  width: 20px;
  height: 20px;
  color: var(--active);
}
.brand-sub {
  color: var(--fg-2);
  font-weight: 500;
  padding-left: 8px;
  border-left: 1px solid var(--line-strong);
}

.sidebar {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 8px;
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
}
.nav-link {
  white-space: nowrap;
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 4px;
  color: var(--fg-2);
  border: 1px solid transparent;
}
.nav-link:hover {
  background: var(--bg-hover);
  color: var(--fg);
  text-decoration: none;
}
.nav-link[aria-current='page'] {
  background: var(--active-dim);
  border-color: var(--active-line);
  color: var(--fg);
}
.nav-link[aria-current='page'] .icon {
  color: var(--active);
}
.sidebar-foot {
  margin-top: auto;
  padding: 8px 10px;
  color: var(--fg-muted);
  font-size: 11px;
}

.page {
  grid-area: page;
  padding: 20px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.page:focus {
  outline: none;
}
.page > div {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.page-header h1 {
  font-size: 16px;
  line-height: 22px;
  font-weight: 600;
}
.page-desc {
  color: var(--fg-2);
  margin-top: 2px;
  max-width: 720px;
}
.page-actions,
.action-bar,
.form-actions,
.preset-row,
.cell-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.cell-actions {
  justify-content: flex-end;
  flex-wrap: nowrap;
}
.form-actions {
  margin-top: 4px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--fg-2);
  width: fit-content;
}

.loading {
  color: var(--fg-muted);
}

/* ───────────── Panels, facts, tables ───────────── */

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.panel-title {
  font-size: 10px;
  line-height: 14px;
  font-weight: 700;
  color: var(--fg-muted);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.facts {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 8px 12px;
  margin: 0;
}
.facts dt {
  color: var(--fg-muted);
}
.facts dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.chips {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}
.chip {
  padding: 1px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--bg-raised);
  font-size: 11px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
}
.table {
  width: 100%;
  border-collapse: collapse;
}
.table th {
  text-align: left;
  font-size: 10px;
  line-height: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
  padding: 8px 10px;
  background: var(--bg-inset);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.table tr:last-child td {
  border-bottom: 0;
}
.table tbody tr:hover {
  background: var(--bg-raised);
}
.row-muted td {
  color: var(--fg-muted);
}
.row-link {
  font-weight: 600;
}
.with-icon {
  display: flex;
  align-items: center;
  gap: 6px;
}
.empty {
  color: var(--fg-muted);
  padding: 12px 0;
}

/* ───────────── Status ───────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 7px 1px 5px;
  border: 1px solid;
  border-radius: 4px;
  font-size: 11px;
  line-height: 18px;
  font-weight: 600;
  white-space: nowrap;
}
.badge .icon {
  width: 13px;
  height: 13px;
}
.tone-live {
  color: var(--live);
  background: var(--live-dim);
  border-color: var(--live-line);
}
.tone-warning {
  color: var(--warning);
  background: var(--warning-dim);
  border-color: var(--warning-line);
}
.tone-critical {
  color: var(--critical);
  background: var(--critical-dim);
  border-color: var(--critical-line);
}
.tone-active {
  color: #7fb0ff;
  background: var(--active-dim);
  border-color: var(--active-line);
}
.tone-inactive {
  color: var(--fg-2);
  background: var(--inactive-dim);
  border-color: var(--inactive-line);
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid;
  border-radius: 6px;
}
.notice p,
.notice div {
  color: var(--fg);
}
.notice div {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}
.notice .icon {
  margin-top: 1px;
}

/* ───────────── Controls ───────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--bg-raised);
  color: var(--fg);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 120ms, border-color 120ms;
}
.btn:hover {
  background: var(--bg-hover);
  text-decoration: none;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--active);
  border-color: var(--active);
  color: #fff;
}
.btn-primary:hover {
  background: #2f74e6;
}
.btn-danger {
  background: var(--critical-dim);
  border-color: var(--critical-line);
  color: #ff8a8a;
}
.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--fg-2);
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--fg);
}
.btn-sm {
  min-height: 28px;
  padding: 0 8px;
}
.btn[aria-pressed='true'] {
  background: var(--active-dim);
  border-color: var(--active-line);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.field label,
.radios legend {
  font-weight: 500;
  color: var(--fg-2);
}
.hint {
  color: var(--fg-muted);
  font-size: 12px;
  line-height: 16px;
}

.input {
  width: 100%;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--bg-inset);
  color: var(--fg);
  font: inherit;
}
.input.mono {
  font-family: var(--mono);
  font-size: 12px;
}
textarea.input {
  resize: vertical;
  line-height: 18px;
}
select.input {
  appearance: auto;
}
.input:hover {
  border-color: #3a4150;
}
.input:focus-visible {
  outline-offset: 0;
}

.radios {
  border: 0;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.radio {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.radio input {
  accent-color: var(--active);
  width: 16px;
  height: 16px;
  margin: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.filters {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) repeat(2, minmax(160px, 1fr)) auto;
  gap: 12px;
  align-items: end;
}
.filters-count {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 32px;
}

.form-error {
  padding: 8px 10px;
  border: 1px solid var(--critical-line);
  background: var(--critical-dim);
  color: #ffb4b4;
  border-radius: 4px;
}

.copyable {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.copy-value {
  padding: 8px 12px;
  border: 1px solid var(--active-line);
  background: var(--bg-inset);
  border-radius: 4px;
  font-size: 16px;
  line-height: 22px;
  letter-spacing: 0.04em;
  user-select: all;
}
.copy-status {
  color: var(--live);
  font-size: 12px;
}

/* ───────────── Dialogs and toasts ───────────── */

.dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--bg-panel);
  color: var(--fg);
}
.dialog-wide {
  width: min(760px, calc(100vw - 32px));
}
.dialog::backdrop {
  background: rgba(5, 6, 8, 0.72);
}
.dialog-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.dialog-header h2 {
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
}
.dialog-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 32px));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid;
  border-radius: 6px;
  background: var(--bg-raised);
}
.toast span {
  color: var(--fg);
}

/* ───────────── Sign-in and public page ───────────── */

.center-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: min(380px, 100%);
  padding: 20px;
  gap: 16px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.login-brand .brand-mark {
  width: 28px;
  height: 28px;
}
.login-brand h1 {
  font-size: 16px;
  line-height: 22px;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-form .btn {
  width: 100%;
}

.public-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px 16px;
}
.public-header {
  width: min(640px, 100%);
}
.public-card {
  width: min(640px, 100%);
  padding: 20px;
  gap: 16px;
}
.public-card h1 {
  font-size: 20px;
  line-height: 26px;
  font-weight: 600;
}
.public-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.steps {
  margin: 0;
  padding-left: 20px;
  color: var(--fg-2);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ───────────── Narrow screens ───────────── */

@media (max-width: 900px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 48px auto minmax(0, 1fr);
    grid-template-areas: 'top' 'side' 'page';
  }
  .sidebar {
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 8px;
  }
  .sidebar-foot {
    display: none;
  }
  .page {
    padding: 16px;
  }
  .grid-2,
  .form-grid,
  .filters {
    grid-template-columns: minmax(0, 1fr);
  }
  .brand-sub,
  .topbar-user {
    display: none;
  }
  .facts {
    grid-template-columns: 110px minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
