:root {
  color-scheme: light;
  --bg: #f5f5f3;
  --surface: #fcfcfb;
  --surface-2: #f0f0ed;
  --border: #e3e2de;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #75746f;
  --accent: #2a78d6;
  --accent-hover: #1f63b5;
  --accent-text: #ffffff;
  --accent-soft: #e6effb;
  --danger: #c93a3a;
  --danger-soft: #fbeaea;
  --ok: #1d7f4e;
  --ok-soft: #e3f3ea;
  --warn: #9a6200;
  --warn-soft: #fdf1d8;
  --series-1: #2a78d6;
  --grid: #e8e7e3;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --text-3: #9a998f;
    --accent: #3987e5;
    --accent-hover: #5a9ced;
    --accent-soft: #1d2b3d;
    --danger: #e66767;
    --danger-soft: #3a1f1f;
    --ok: #4cc287;
    --ok-soft: #173326;
    --warn: #e0a83a;
    --warn-soft: #3a2e14;
    --series-1: #3987e5;
    --grid: #2a2a28;
    --shadow: none;
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: #2f2f2c;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --text-3: #9a998f;
  --accent: #3987e5;
  --accent-hover: #5a9ced;
  --accent-soft: #1d2b3d;
  --danger: #e66767;
  --danger-soft: #3a1f1f;
  --ok: #4cc287;
  --ok-soft: #173326;
  --warn: #e0a83a;
  --warn-soft: #3a2e14;
  --series-1: #3987e5;
  --grid: #2a2a28;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12.5px; }
h1, h2 { margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mr-auto { margin-right: auto; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Shell ---- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; padding: 0 8px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  background: radial-gradient(circle at 35% 35%, #fff 0 3px, transparent 4px), var(--accent);
}
.brand-mark-admin { background: radial-gradient(circle at 35% 35%, #fff 0 3px, transparent 4px), #4a3aa7; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  color: var(--text-2); padding: 7px 10px; border-radius: 7px; font-weight: 500;
}
.sidebar nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 8px; font-size: 13px; }
.sidebar-user { display: flex; flex-direction: column; overflow: hidden; }
.sidebar-user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { padding: 28px 32px 64px; max-width: 1180px; width: 100%; display: flex; flex-direction: column; gap: 18px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center;
    padding: 10px 16px; gap: 10px; border-right: 0; border-bottom: 1px solid var(--border);
  }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-footer { margin: 0 0 0 auto; flex-direction: row; align-items: center; gap: 12px; padding: 0; }
  .sidebar-user { display: none; }
  .content { padding: 18px 16px 48px; }
}

/* ---- Page parts ---- */
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.page-header h1 { font-size: 22px; font-weight: 650; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-header p { margin: 4px 0 0; }
.crumb { color: var(--text-2); font-weight: 500; }
.crumb-sep { color: var(--text-3); font-weight: 400; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.actions.start { justify-content: flex-start; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs a {
  padding: 8px 12px; color: var(--text-2); font-weight: 500; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { font-size: 15px; font-weight: 600; }
.card-danger { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 960px) { .two-col { grid-template-columns: 1fr; } }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat-label { color: var(--text-2); font-size: 12.5px; font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; margin-top: 4px; }
.stat-hint { color: var(--text-3); font-size: 12.5px; margin-top: 2px; }
.stat-hero { grid-column: span 2; }
.stat-hero .stat-value { font-size: 48px; line-height: 1.1; }
@media (max-width: 560px) { .stat-hero { grid-column: auto; } .stat-hero .stat-value { font-size: 40px; } }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.project-card {
  display: flex; flex-direction: column; gap: 8px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow); transition: border-color 0.15s;
}
.project-card:hover { border-color: var(--accent); text-decoration: none; }
.project-card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.project-card-stats { display: flex; gap: 16px; color: var(--text-2); font-size: 13px; }
.project-card-stats strong { color: var(--text); }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--text-2); font-weight: 500; font-size: 12.5px; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Controls ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 13px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); padding: 5px 9px; }
.btn-ghost:hover { color: var(--text); }
.btn-block { width: 100%; padding: 9px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-align: left; }
.icon-btn { background: none; border: 0; font-size: 22px; line-height: 1; color: var(--text-2); cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.segmented button { background: var(--surface); border: 0; padding: 4px 11px; font: inherit; font-size: 12.5px; color: var(--text-2); cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.form { display: flex; flex-direction: column; gap: 14px; }
.form.narrow { max-width: 520px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.field-hint { font-size: 12px; color: var(--text-3); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 7px; padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.checks { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.checks legend { margin-bottom: 6px; padding: 0; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: auto; }
.filters input { max-width: 360px; }

.copy-field {
  display: flex; align-items: center; gap: 4px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 7px; padding: 4px 4px 4px 10px; min-width: 0;
}
.copy-field code { flex: 1; overflow-x: auto; white-space: nowrap; scrollbar-width: thin; padding: 4px 0; }

.code-block { position: relative; margin: 8px 0 4px; }
.code-block pre {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; margin: 0; overflow-x: auto; line-height: 1.55;
}
.code-copy { position: absolute; top: 6px; right: 6px; background: var(--surface); }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 14px; }

.badge {
  display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-off { background: var(--surface-2); color: var(--text-2); }
.badges { display: inline-flex; gap: 4px; flex-wrap: wrap; }

.error-note, .ok-note { border-radius: 7px; padding: 8px 12px; font-size: 13px; }
.error-note { background: var(--danger-soft); color: var(--danger); }
.ok-note { background: var(--ok-soft); color: var(--ok); }
.danger-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; padding-top: 4px; }
.empty { padding: 28px 12px; text-align: center; display: flex; flex-direction: column; gap: 6px; }
.loading { padding: 32px; text-align: center; color: var(--text-2); }
.live-note { display: flex; align-items: center; gap: 8px; margin: 0; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }

/* ---- Modal ---- */
.modal {
  border: 1px solid var(--border); border-radius: 12px; padding: 20px 22px; width: min(520px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.4); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { font-size: 17px; }
.modal p { margin: 0; }

/* ---- Toasts ---- */
.toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: 8px; font-size: 13.5px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2); }
.toast-error { background: var(--danger); color: #fff; }

/* ---- Auth ---- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow);
}
.auth-card .brand { padding: 0; margin-bottom: 6px; }
.auth-card h1 { font-size: 20px; }
.auth-card p { margin: 0; }

/* ---- Chart ---- */
.chart { position: relative; }
.chart-toolbar { display: flex; justify-content: flex-end; margin-bottom: 4px; font-size: 12.5px; }
.chart-plot { position: relative; width: 100%; }
.chart-plot svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--series-1); transition: opacity 0.12s; }
.chart .hover-band { fill: var(--surface-2); }
.chart-table { max-height: 260px; overflow-y: auto; }
.tooltip {
  position: absolute; transform: translate(-50%, -100%); pointer-events: none; z-index: 2;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15); font-size: 12.5px; white-space: nowrap;
}
.tooltip-title { color: var(--text-2); margin-bottom: 2px; }
