/* DayZero control panel. Design tokens and shared components are used by app.js and analytics.js/analytics.css. */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light dark;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-2: #f2f4f5;
  --surface-raised: #ffffff;
  --border: #e3e6e9;
  --border-strong: #c3c9cf;
  --text: #15191e;
  --text-muted: #555e69;
  --text-subtle: #677080;
  --accent: #1f5f45;
  --accent-hover: #184d38;
  --accent-contrast: #ffffff;
  --accent-soft: #e6f1eb;
  --positive: #17673f;
  --positive-soft: #e3f3ea;
  --negative: #b42318;
  --negative-soft: #fdecea;
  --warning: #8a4b00;
  --warning-soft: #fdf1dc;
  --in-development: #c9a227;
  --info: #1d4fa8;
  --info-soft: #e7effc;
  --focus: #2e7d5b;
  --focus-ring: rgba(46, 125, 91, .22);
  --overlay: rgba(15, 20, 25, .42);
  --chart-1: #2e7d5b;
  --chart-2: #3866c8;
  --chart-3: #b8690a;
  --chart-4: #8a4fd6;
  --brand: #183d31;
  --brand-ink: #e5f0d1;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --font-mono: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;
  --fs-2xl: 24px;
  --fs-3xl: 30px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, .10), 0 2px 6px rgba(16, 24, 40, .06);
  --sidebar-width: 240px;
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23555e69' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1012;
    --surface: #16191c;
    --surface-2: #1e2226;
    --surface-raised: #2a2f35;
    --border: #2a2f34;
    --border-strong: #464d55;
    --text: #eceef0;
    --text-muted: #a7aeb6;
    --text-subtle: #8e96a0;
    --accent: #5ec795;
    --accent-hover: #7dd6ab;
    --accent-contrast: #07170f;
    --accent-soft: #15291f;
    --positive: #5ec795;
    --positive-soft: #132a1e;
    --negative: #f28b82;
    --negative-soft: #3a1916;
    --warning: #f0b55a;
    --warning-soft: #33250f;
    --in-development: #e0bd45;
    --info: #7fb0ff;
    --info-soft: #14233d;
    --focus: #7dd6ab;
    --focus-ring: rgba(125, 214, 171, .25);
    --overlay: rgba(0, 0, 0, .6);
    --chart-1: #5ec795;
    --chart-2: #7fa8ff;
    --chart-3: #f0b55a;
    --chart-4: #c49bff;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 12px 32px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .35);
    --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a7aeb6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--fs-md)/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; color: var(--text); line-height: 1.3; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.icon { flex-shrink: 0; display: inline-block; vertical-align: middle; }
[data-icon] { display: inline-flex; flex-shrink: 0; }
code, kbd { font-family: var(--font-mono); font-size: .92em; }
::selection { background: var(--accent-soft); color: var(--text); }

/* ---------- Utilities ---------- */
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.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;
}
.num { font-variant-numeric: tabular-nums; }
.text-warning { color: var(--warning); }
.text-negative { color: var(--negative); }
.text-positive { color: var(--positive); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
}
.card-header > div:first-child { min-width: 0; }
.card-title { font-size: var(--fs-lg); font-weight: 600; line-height: 1.4; margin: 0; display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.card-subtitle { font-size: var(--fs-sm); color: var(--text-muted); margin: 2px 0 0; }
.card-body { padding: var(--space-5); }
.card-header + .card-body { padding-top: var(--space-1); }
.card-header.bordered { border-bottom: 1px solid var(--border); }
.card-header.bordered + .card-body { padding-top: var(--space-5); }
.card-footer {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap;
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: background-color .12s ease, border-color .12s ease, color .12s ease, box-shadow .12s ease;
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); box-shadow: var(--shadow-sm); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger { background: transparent; color: var(--negative); }
.btn-danger:hover:not(:disabled) { background: var(--negative-soft); }
.btn-sm { height: 30px; padding: 0 10px; font-size: var(--fs-sm); gap: 5px; }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; padding: 0; }
.btn .spin, .spin { display: inline-flex; animation: dz-spin 1s linear infinite; }
@keyframes dz-spin { to { transform: rotate(360deg); } }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}
.badge .icon { width: 12px; height: 12px; }
.badge-neutral { background: var(--surface-2); border-color: var(--border); color: var(--text-muted); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-success { background: var(--positive-soft); color: var(--positive); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--negative-soft); color: var(--negative); }
.badge-info { background: var(--info-soft); color: var(--info); }

/* ---------- Stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-4); }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4) var(--space-5);
  min-width: 0;
}
.stat-label { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); font-weight: 500; color: var(--text-muted); }
.stat-label .icon { color: var(--text-subtle); }
.stat-value {
  margin-top: 6px;
  font-size: var(--fs-3xl);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.stat-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 6px; font-size: var(--fs-sm); color: var(--text-muted); }

/* ---------- Delta chips ---------- */
.delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  background: var(--surface-2);
  color: var(--text-muted);
}
.delta .icon { width: 12px; height: 12px; }
.delta-up { background: var(--positive-soft); color: var(--positive); }
.delta-down { background: var(--negative-soft); color: var(--negative); }
.delta-flat { background: var(--surface-2); color: var(--text-muted); }

/* ---------- Segmented control ---------- */
.segmented {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--surface-raised); color: var(--text); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }
.segmented button:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label, .field > label { font-size: var(--fs-sm); font-weight: 500; color: var(--text); }
.field-hint { font-size: var(--fs-xs); color: var(--text-muted); line-height: 1.45; margin: 0; }
.field-hint.is-warning { color: var(--warning); }
.field-hint.is-error { color: var(--negative); }
.field > input, .field > select, .field > textarea, .field .input-group { width: 100%; }

input:not([type]), input[type="text"], input[type="search"], input[type="url"], input[type="email"],
input[type="number"], input[type="password"], input[type="date"], input[type="month"], input[type="tel"],
select, textarea {
  height: 36px;
  max-width: 100%;
  min-width: 0;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  font-size: var(--fs-md);
  line-height: 1.4;
  transition: border-color .12s ease, box-shadow .12s ease;
}
textarea { height: auto; min-height: 84px; padding: 8px 10px; line-height: 1.5; resize: vertical; }
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 16px;
  cursor: pointer;
}
input::placeholder, textarea::placeholder { color: var(--text-subtle); opacity: 1; }
input:hover:not(:disabled):not(:focus), select:hover:not(:disabled):not(:focus), textarea:hover:not(:disabled):not(:focus) { border-color: var(--text-subtle); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--focus-ring); }
input:disabled, select:disabled, textarea:disabled { background-color: var(--surface-2); color: var(--text-muted); cursor: not-allowed; }
input[type="search"]::-webkit-search-cancel-button { cursor: pointer; }

.checkbox { display: inline-flex; align-items: flex-start; gap: 10px; font-size: var(--fs-md); color: var(--text); cursor: pointer; line-height: 1.45; }
.checkbox input[type="checkbox"], .checkbox input[type="radio"] { width: 16px; height: 16px; margin: 2px 0 0; flex-shrink: 0; accent-color: var(--accent); cursor: pointer; }
.checkbox .field-hint { display: block; margin-top: 2px; }

/* Switch: <label class="switch"><input type="checkbox" role="switch"> Label</label> */
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-sm); font-weight: 500; color: var(--text); cursor: pointer; white-space: nowrap; }
.switch input {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 34px;
  height: 20px;
  margin: 0;
  flex-shrink: 0;
  border-radius: 999px;
  background: var(--border-strong);
  cursor: pointer;
  transition: background-color .15s ease;
}
.switch input::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  transition: transform .15s ease;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::before { transform: translateX(14px); }
.switch input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch input:disabled { opacity: .55; cursor: not-allowed; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4) var(--space-5); }
.form-grid .span-2 { grid-column: 1 / -1; }
.input-group { position: relative; display: flex; align-items: center; }
.input-group > .icon, .input-group > .input-icon { position: absolute; left: 10px; color: var(--text-subtle); pointer-events: none; }
.input-group > input { padding-left: 34px; width: 100%; }

/* ---------- Notices ---------- */
.notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-sm);
  line-height: 1.5;
}
.notice > .icon { margin-top: 1px; color: var(--text-muted); }
.notice > div { min-width: 0; overflow-wrap: anywhere; }
.notice strong { font-weight: 600; }
.notice-info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 28%, transparent); }
.notice-info > .icon { color: var(--info); }
.notice-warning { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 30%, transparent); }
.notice-warning > .icon { color: var(--warning); }
.notice-danger { background: var(--negative-soft); border-color: color-mix(in srgb, var(--negative) 30%, transparent); }
.notice-danger > .icon { color: var(--negative); }

/* ---------- Empty state ---------- */
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 48px 24px; }
.empty-state-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  color: var(--text-muted);
}
.empty-state h3 { font-size: var(--fs-lg); font-weight: 600; }
.empty-state p { max-width: 460px; color: var(--text-muted); font-size: var(--fs-md); }
.empty-state .btn { margin-top: 12px; }

/* ---------- Data table ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-md); }
.table th {
  padding: 9px 16px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background-color .1s ease; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.num { text-align: right; }

/* ---------- Skeleton ---------- */
.skeleton {
  display: block;
  min-height: 12px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 45%, var(--surface-2) 65%);
  background-size: 300% 100%;
  animation: dz-shimmer 1.4s ease-in-out infinite;
  color: transparent;
}
@keyframes dz-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.toolbar .spacer { flex: 1 1 auto; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: var(--space-5);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: none;
  color: var(--text-muted);
  font-size: var(--fs-md);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab[aria-selected="true"] { color: var(--text); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent); }
.tab:focus-visible { outline-offset: -2px; }

/* ---------- Drawer ---------- */
.drawer-backdrop { position: fixed; inset: 0; z-index: 40; background: var(--overlay); animation: dz-fade .15s ease; }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  display: flex;
  flex-direction: column;
  width: min(620px, 100vw);
  background: var(--bg);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  animation: dz-slide .18s ease;
}
.drawer:focus { outline: none; }
.drawer-header { padding: var(--space-5); background: var(--surface); border-bottom: 1px solid var(--border); }
.drawer-header-top { display: flex; align-items: flex-start; gap: var(--space-3); }
.drawer-header-top > div { flex: 1; min-width: 0; }
.drawer-title { font-size: var(--fs-xl); font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.drawer-meta { margin-top: 4px; color: var(--text-muted); font-size: var(--fs-md); overflow-wrap: anywhere; }
.drawer-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--space-3); }
.drawer-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4); overscroll-behavior: contain; }
.drawer-body .card-header { padding: var(--space-4) var(--space-5) 0; align-items: center; }
.drawer-body .card-title { font-size: var(--fs-md); }
.drawer-body .card-header + .card-body { padding-top: var(--space-3); }
body.drawer-open { overflow: hidden; }
@keyframes dz-fade { from { opacity: 0; } }
@keyframes dz-slide { from { transform: translateX(24px); opacity: 0; } }

/* ---------- Toast ---------- */
.toast-region { position: fixed; right: var(--space-5); bottom: var(--space-5); z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--positive);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-md);
  font-size: var(--fs-md);
  line-height: 1.45;
  pointer-events: auto;
  animation: dz-toast .18s ease;
}
.toast > .icon { margin-top: 1px; color: var(--positive); }
.toast > span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast-error { border-left-color: var(--negative); }
.toast-error > .icon { color: var(--negative); }
.toast-info { border-left-color: var(--info); }
.toast-info > .icon { color: var(--info); }
.toast .btn { margin: -5px -6px -5px 0; }
@keyframes dz-toast { from { transform: translateY(8px); opacity: 0; } }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-3);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: var(--radius); color: var(--text); }
.brand:hover { text-decoration: none; background: var(--surface-2); }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--brand);
  color: var(--brand-ink);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -1px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08);
}
.brand-mark span { font-weight: 500; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.brand-name { font-size: var(--fs-md); font-weight: 600; }
.brand-sub { font-size: var(--fs-xs); color: var(--text-muted); }
.sidebar-nav { display: flex; flex-direction: column; flex: 1; gap: var(--space-4); min-height: 0; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-secondary { margin-top: auto; padding-top: var(--space-3); border-top: 1px solid var(--border); }
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: var(--fs-md);
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav-item .nav-trailing { margin-left: auto; color: var(--text-subtle); }
.nav-button { width: 100%; border: 0; background: transparent; font: inherit; text-align: left; cursor: pointer; }
.nav-count {
  margin-left: auto;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.nav-item[aria-current="page"] .nav-count { background: var(--surface); border-color: transparent; color: var(--accent); }

.main { min-width: 0; }
.content { max-width: 1280px; margin: 0 auto; padding: var(--space-6) 40px 48px; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-5); flex-wrap: wrap; }
.page-header > div:first-child { min-width: 0; flex: 1 1 320px; }
.page-title { font-size: var(--fs-2xl); font-weight: 600; letter-spacing: -.01em; line-height: 1.25; }
.page-subtitle { margin-top: 4px; color: var(--text-muted); font-size: var(--fs-md); }
.page-title:focus { outline: none; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.page-alert { margin-bottom: var(--space-4); }
.view { display: flex; flex-direction: column; gap: var(--space-5); }
#analytics-view { display: block; }

/* ---------- Opportunities ---------- */
.scan-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  padding: 6px 8px 6px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.scan-bar-text { flex: 1; min-width: 0; }
.scan-bar-text strong { color: var(--text); font-weight: 600; }
.scan-bar .sep { margin: 0 6px; color: var(--text-subtle); }
.status-dot { position: relative; width: 8px; height: 8px; flex-shrink: 0; border-radius: 50%; background: var(--text-subtle); }
.status-dot.is-ok { background: var(--positive); }
.status-dot.is-partial { background: var(--warning); }
.status-dot.is-failed { background: var(--negative); }
.status-dot.is-running { background: var(--info); }
.status-dot.is-running::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--info); opacity: 0; animation: dz-pulse 1.6s ease-out infinite; }
@keyframes dz-pulse { 0% { transform: scale(.5); opacity: .8; } 100% { transform: scale(1.4); opacity: 0; } }

.leads-card .toolbar { padding: var(--space-3) var(--space-4); }
.leads-card .toolbar .input-group { flex: 1 1 280px; }
.leads-card .toolbar select { flex: 0 1 220px; }
.result-count { margin-left: auto; padding-left: var(--space-2); font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; }
.leads-table th:first-child, .leads-table td:first-child { padding-left: var(--space-5); }
.leads-table th:last-child, .leads-table td:last-child { padding-right: var(--space-4); }
.leads-table .col-opportunity { width: 44%; }
.leads-table .col-open { width: 48px; text-align: right; }
.leads-table tbody tr[data-row-lead] { cursor: pointer; }
.lead-title {
  display: inline;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 600;
  line-height: 1.4;
  text-align: left;
  overflow-wrap: anywhere;
}
.lead-title:hover { color: var(--accent); text-decoration: underline; }
.lead-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 3px; font-size: var(--fs-sm); color: var(--text-muted); }
.lead-meta .sep { color: var(--text-subtle); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  white-space: nowrap;
}
.cell-location { font-size: var(--fs-sm); color: var(--text); max-width: 200px; }
.cell-location .loc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.cell-hint { display: block; margin-top: 2px; font-size: var(--fs-xs); color: var(--text-muted); }
.cell-hint.is-warning { color: var(--warning); }
.cell-hint.is-negative { color: var(--negative); }
.cell-note { display: flex; align-items: center; gap: 4px; margin-top: 4px; font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; }
.cell-note .icon { width: 12px; height: 12px; }
.cell-note.is-warning { color: var(--warning); }
.match { display: flex; flex-direction: column; gap: 5px; min-width: 56px; }
.match-score { font-size: var(--fs-md); font-weight: 600; font-variant-numeric: tabular-nums; }
.match-bar { display: block; width: 56px; height: 4px; border: 0; border-radius: 999px; background: var(--surface-2); overflow: hidden; appearance: none; -webkit-appearance: none; }
.match-bar::-webkit-progress-bar { background: var(--border); border-radius: 999px; }
.match-bar::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
.match-bar::-moz-progress-bar { background: var(--accent); border-radius: 999px; }
.match-bar.is-low::-webkit-progress-value { background: var(--text-subtle); }
.match-bar.is-low::-moz-progress-bar { background: var(--text-subtle); }
.table-note { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border); }
.skeleton-row td { padding-top: 16px; padding-bottom: 16px; }
.skeleton.w-40 { width: 40%; }
.skeleton.w-70 { width: 70%; }
.skeleton-row .skeleton + .skeleton { margin-top: 8px; }

/* ---------- Lead drawer ---------- */
.check-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: var(--fs-md); }
.check-list li { display: flex; align-items: flex-start; gap: 8px; }
.check-list li > .icon { margin-top: 2px; color: var(--positive); }
.check-list.is-caution li > .icon { color: var(--warning); }
.check-list + .check-list { margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--border); }
.caption { font-size: var(--fs-xs); color: var(--text-muted); line-height: 1.5; }
.button-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--space-2); }
.divider { height: 1px; background: var(--border); border: 0; margin: 0; }
.draft-body { min-height: 260px; }
.detail-list { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px var(--space-4); margin: 0; font-size: var(--fs-md); }
.detail-list dt { color: var(--text-muted); }
.detail-list dd { margin: 0; overflow-wrap: anywhere; }
.description {
  max-height: 320px;
  overflow: auto;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-sm);
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.history-list { list-style: none; margin: 0; padding: 0; }
.history-list li { display: flex; justify-content: space-between; gap: var(--space-3); padding: 8px 0; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); }
.history-list li:last-child { border-bottom: 0; }
.history-list time { flex-shrink: 0; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.source-rows { display: flex; flex-direction: column; }
.source-row { padding: 12px 0; border-bottom: 1px solid var(--border); }
.source-row:first-child { padding-top: 0; }
.source-row:last-child { border-bottom: 0; padding-bottom: 0; }
.source-row-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.source-row-name { font-weight: 600; font-size: var(--fs-md); min-width: 0; overflow-wrap: anywhere; }
.source-row-meta { margin-top: 2px; font-size: var(--fs-sm); color: var(--text-muted); }
.source-row-message { margin-top: 4px; font-size: var(--fs-sm); color: var(--text-muted); overflow-wrap: anywhere; }
.source-row-message.is-error { color: var(--negative); }
.mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: var(--space-2); }
.mini-stat { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.mini-stat-label { font-size: var(--fs-xs); color: var(--text-muted); }
.mini-stat-value { font-size: var(--fs-lg); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Settings ---------- */
.settings-panel, .settings-form { display: flex; flex-direction: column; gap: var(--space-5); }
.settings-panel:focus { outline: none; }
.form-footer {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  margin: 0 -1px;
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.form-footer .dirty-note { margin-right: auto; font-size: var(--fs-sm); color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.form-footer .dirty-note.is-dirty { color: var(--warning); }
.source-head { display: flex; align-items: flex-start; gap: var(--space-3); }
.source-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
}
.source-head > div { flex: 1; min-width: 0; }
.source-head .card-subtitle { max-width: 720px; }
.source-status { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: var(--fs-xs); color: var(--text-muted); }
.key-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.key-row input { flex: 1 1 260px; }
.list-rows { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-row:first-child { padding-top: 0; }
.list-row:last-child { border-bottom: 0; }
.list-row-main { min-width: 0; }
.list-row-title { font-weight: 600; font-size: var(--fs-md); overflow-wrap: anywhere; }
.list-row-meta { font-size: var(--fs-sm); color: var(--text-muted); overflow-wrap: anywhere; }
.list-row-actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }
.board-add { display: grid; grid-template-columns: 150px minmax(0, 1.4fr) minmax(0, 1fr) auto; gap: var(--space-2); align-items: end; }
.portfolio-item { padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); }
.portfolio-item + .portfolio-item { margin-top: var(--space-3); }
.portfolio-item-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.portfolio-item-head h3 { font-size: var(--fs-md); font-weight: 600; min-width: 0; overflow-wrap: anywhere; display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
/* Release status: green for published games, yellow for games in development. */
.portfolio-item.is-published { border: 2px solid var(--positive); }
.portfolio-item.is-development { border: 2px solid var(--in-development); }
.portfolio-status-badge { display: inline-flex; }
.portfolio-item textarea { min-height: 64px; }
.run-list { display: flex; flex-direction: column; }
.run { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); }
.run:first-child { border-top: 0; }
.run-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.run-title { font-weight: 600; font-size: var(--fs-md); }
.run-time { font-size: var(--fs-sm); color: var(--text-muted); }
.run-counts { margin-top: 6px; font-size: var(--fs-sm); color: var(--text); font-variant-numeric: tabular-nums; }
.run-counts .sep { margin: 0 6px; color: var(--text-subtle); }
.run-sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.run-sources .badge { height: auto; min-height: 22px; padding: 3px 8px; border-radius: var(--radius-sm); line-height: 1.35; white-space: normal; overflow-wrap: anywhere; }
.run-errors { margin: 10px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-sm); color: var(--negative); }
.run-errors li { display: flex; gap: 6px; align-items: flex-start; overflow-wrap: anywhere; }
.run-errors .icon { margin-top: 2px; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .content { padding: var(--space-5) var(--space-5) 40px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .leads-table .col-location { display: none; }
}

@media (max-width: 899px) {
  .app { display: block; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: var(--space-2);
    padding: 8px var(--space-3);
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow: visible;
  }
  .brand { padding: 4px; }
  .brand-text { display: none; }
  .brand-mark { width: 30px; height: 30px; font-size: 16px; }
  .sidebar-nav { position: relative; flex-direction: row; align-items: center; gap: 2px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
  .sidebar-nav::-webkit-scrollbar { display: none; }
  .nav { flex-direction: row; gap: 2px; }
  .nav-secondary { margin-top: 0; padding-top: 0; border-top: 0; padding-left: var(--space-2); margin-left: var(--space-1); border-left: 1px solid var(--border); }
  .nav-item { height: 34px; padding: 0 10px; gap: 8px; font-size: var(--fs-sm); }
  .nav-count { margin-left: 2px; }
  .content { padding: var(--space-5) var(--space-4) 40px; }
  .page-title { font-size: var(--fs-xl); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .board-add { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .board-add .btn { grid-column: 1 / -1; justify-self: start; }
  .drawer-header, .drawer-body { padding: var(--space-4); }
  .card-header { padding: var(--space-4); }
  .card-body { padding: var(--space-4); }
  .card-footer { padding: var(--space-3) var(--space-4); }
  .run { padding: var(--space-4); }
  .toast-region { right: var(--space-4); left: var(--space-4); bottom: var(--space-4); max-width: none; }
}

@media (max-width: 720px) {
  .leads-table thead { display: none; }
  .leads-table, .leads-table tbody { display: block; }
  .leads-table tbody tr { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 14px var(--space-4); border-bottom: 1px solid var(--border); }
  .leads-table tbody tr:last-child { border-bottom: 0; }
  .leads-table td { display: block; padding: 0 !important; border: 0; }
  .leads-table td.col-opportunity { flex: 1 1 100%; width: auto; padding-right: 36px !important; }
  .leads-table td.col-location { display: block; flex: 1 1 100%; order: 1; }
  .leads-table td.col-type, .leads-table td.col-match, .leads-table td.col-status { order: 2; }
  .leads-table td.col-status { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; }
  .leads-table td.col-status .cell-note { margin-top: 0; }
  .leads-table .cell-location { max-width: none; }
  .leads-table td.col-open { position: absolute; top: 10px; right: 8px; width: auto; }
  .leads-table .match { flex-direction: row; align-items: center; gap: 8px; }
  .leads-table .skeleton-row td { flex: 1 1 100%; }
  .leads-card .toolbar select { flex: 1 1 140px; }
  .result-count { margin-left: 0; padding-left: 0; flex-basis: 100%; }
}

@media (max-width: 520px) {
  .stat-grid { gap: var(--space-3); }
  .stat { padding: var(--space-3) var(--space-4); }
  .stat-value { font-size: var(--fs-2xl); }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; }
  .scan-bar { flex-wrap: wrap; padding: 8px 12px; }
  .scan-bar .btn { margin-left: auto; }
  .list-row { flex-direction: column; align-items: flex-start; gap: var(--space-2); }
  .board-add { grid-template-columns: minmax(0, 1fr); }
  .detail-list { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .detail-list dd { margin-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .skeleton { animation: none; }
  .status-dot.is-running::after { display: none; }
}

/* ---------- Sign-in page (login.html) ---------- */
.login-page { min-height: 100vh; }
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-5); padding: var(--space-5) var(--space-4); }
.login-brand:hover { background: transparent; }
.login-card { width: 100%; max-width: 380px; padding: var(--space-6) var(--space-5); display: flex; flex-direction: column; gap: var(--space-4); }
.login-title { font-size: var(--fs-xl); font-weight: 600; margin: 0; }
.login-subtitle { font-size: var(--fs-sm); color: var(--text-muted); margin: -8px 0 0; }
.login-button { width: 100%; height: 40px; margin-top: var(--space-2); }
