:root {
  color-scheme: dark;
  --bg: #0b0e13;
  --surface: #12171f;
  --surface-2: #191f29;
  --surface-3: #202735;
  --text: #f1f4f8;
  --muted: #98a4b5;
  --line: #293241;
  --line-strong: #3a4659;
  --accent: #37c7a3;
  --accent-strong: #19a987;
  --accent-soft: rgba(55, 199, 163, 0.12);
  --info: #6f9eff;
  --warning: #f4bb55;
  --danger: #f47777;
  --shadow: rgba(0, 0, 0, 0.28);
  --sidebar: #0e131a;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f5f7fa;
  --surface-3: #eaf0f5;
  --text: #151a23;
  --muted: #667287;
  --line: #dce2ea;
  --line-strong: #c5ced9;
  --accent: #087c65;
  --accent-strong: #066451;
  --accent-soft: rgba(8, 124, 101, 0.09);
  --info: #3568d4;
  --warning: #a76400;
  --danger: #c23b3b;
  --shadow: rgba(31, 45, 61, 0.08);
  --sidebar: #ffffff;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 24px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button,
input { font: inherit; }

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 15px;
  background: var(--accent);
  color: #04130f;
  cursor: pointer;
  font-weight: 750;
  transition: background 150ms ease, border-color 150ms ease, transform 150ms ease;
}

button:hover { background: var(--accent-strong); }
button:active { transform: translateY(1px); }
button:disabled { cursor: not-allowed; opacity: 0.55; }

button.ghost,
button.secondary-action {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--text);
}

button.ghost:hover,
button.secondary-action:hover {
  border-color: var(--line-strong);
  background: var(--surface-3);
}

button.danger {
  border-color: rgba(244, 119, 119, 0.24);
  color: var(--danger);
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 11px;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input:hover { border-color: var(--line-strong); }

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

a { color: var(--info); }
.hidden { display: none !important; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(90deg, transparent 49.8%, rgba(255,255,255,0.025) 50%, transparent 50.2%),
    linear-gradient(0deg, transparent 49.8%, rgba(255,255,255,0.025) 50%, transparent 50.2%),
    var(--bg);
  background-size: 64px 64px;
}

.login-panel {
  width: min(430px, 100%);
  display: grid;
  gap: 18px;
  padding: 32px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px var(--shadow);
}

.login-panel label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-panel h1,
.topbar h1 {
  margin: 0;
  letter-spacing: 0;
}

.login-panel h1 { font-size: 36px; }
.topbar h1 { font-size: 30px; }

.eyebrow,
.section-kicker {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.page-description,
.panel-description {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
}

.dashboard-view {
  min-height: 100vh;
  min-width: 0;
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
}

.dashboard-page {
  min-width: 0;
  animation: page-enter 160ms ease-out;
}

.dashboard-page[hidden] {
  display: none !important;
}

@keyframes page-enter {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.sidebar {
  min-width: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 16px 18px;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 7px 25px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 7px;
  background: var(--accent);
  color: #04130f;
  font-weight: 900;
}

.brand strong,
.brand span { display: block; }
.brand strong { font-size: 14px; }
.brand span { margin-top: 2px; color: var(--muted); font-size: 11px; }

.live-dot {
  width: 6px;
  height: 6px;
  display: inline-block;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.primary-nav {
  min-width: 0;
  display: grid;
  gap: 3px;
  overflow-y: auto;
}

.nav-label {
  margin: 18px 10px 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.nav-label:first-child { margin-top: 0; }

.primary-nav a {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
  transition: background 150ms ease, color 150ms ease;
}

.primary-nav a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.primary-nav a.active {
  border-color: rgba(55, 199, 163, 0.2);
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: inherit;
  font-size: 10px;
  font-weight: 900;
}

.sidebar-footer {
  display: grid;
  gap: 3px;
  margin-top: auto;
  padding: 16px 8px 2px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
}

.sidebar-footer strong { color: var(--text); font-size: 11px; }

.mobile-nav-open,
.mobile-nav-close,
.mobile-nav-backdrop,
.mobile-tabbar {
  display: none;
}

.topbar-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.workspace {
  width: min(1540px, 100%);
  min-width: 0;
  display: grid;
  gap: 18px;
  padding: 28px 30px 50px;
}

.topbar,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  min-height: 72px;
  padding-bottom: 4px;
}

.actions,
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

.metric,
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 28px var(--shadow);
}

.metric {
  position: relative;
  min-height: 126px;
  padding: 18px;
  overflow: hidden;
}

.metric::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--accent);
}

.metric strong {
  display: block;
  margin: 9px 0 5px;
  font-size: 30px;
  line-height: 1.05;
}

.metric span:first-child {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric span:last-child { color: var(--muted); font-size: 12px; }

.panel { padding: 20px; }
.panel h2 { margin: 0; font-size: 17px; }
.panel-head > span { color: var(--muted); font-size: 12px; }

.grid {
  display: grid;
  gap: 18px;
}

.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.table-wrap {
  margin: 16px -20px -20px;
  overflow-x: auto;
  border-top: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--accent-soft); }
td a { color: var(--text); font-weight: 700; text-decoration: none; }
td a:hover { color: var(--accent); }

.keyword-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 13px;
  align-items: end;
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
}

.keyword-form + .table-wrap { margin-top: 18px; }

.keyword-form label:not(.check),
.inline-settings-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.inline-settings-form {
  display: grid;
  grid-template-columns: minmax(190px, 260px) auto;
  align-items: end;
  justify-content: start;
  gap: 12px;
  margin-top: 17px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
}

.check {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
  white-space: normal;
}

.check:hover { border-color: var(--line-strong); }

.check input {
  width: 32px;
  height: 18px;
  min-height: 18px;
  flex: 0 0 auto;
  appearance: none;
  border: 0;
  border-radius: 10px;
  background: var(--line-strong);
  cursor: pointer;
  position: relative;
}

.check input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  transition: transform 150ms ease;
}

.check input:checked { background: var(--accent); }
.check input:checked::after { transform: translateX(14px); }

.report-list,
.health-list,
.diagnostics-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.profile-item {
  min-width: 0;
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
}

.profile-item.active {
  border-color: var(--accent);
  box-shadow: inset 0 2px 0 var(--accent);
}

.profile-item h3 {
  margin: 12px 0 5px;
  font-size: 15px;
}

.profile-item p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.profile-item dl {
  display: grid;
  gap: 7px;
  margin: 0;
}

.profile-item dl div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 10px;
}

.profile-item dt { color: var(--muted); text-transform: capitalize; }
.profile-item dd { margin: 0; color: var(--text); }

.maintenance-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.explanation summary {
  color: var(--accent);
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

.explanation ul {
  min-width: 260px;
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
}

.health-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.report-item,
.health-item,
.diagnostic-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.health-item strong { font-size: 11px; text-transform: uppercase; }
.health-item .muted { font-size: 13px; }
.report-item h3 { margin: 0 0 6px; font-size: 14px; }
.report-item p:last-child { margin-bottom: 0; font-size: 13px; }
.muted { color: var(--muted); }

.diagnostic-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.status-pill,
#health-status,
#monitoring-status {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--text);
  font-size: 10px;
  font-style: normal;
  font-weight: 800;
  text-transform: uppercase;
}

.status-ok { background: var(--accent-soft); color: var(--accent); }
.status-warning,
.status-skipped { background: rgba(244, 187, 85, 0.12); color: var(--warning); }
.status-failed { background: rgba(244, 119, 119, 0.12); color: var(--danger); }

.diagnostic-item p { margin: 8px 0 0; color: var(--muted); font-size: 13px; }

.diagnostic-item dl {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 0;
}

.diagnostic-item dl div { min-width: 0; }
.diagnostic-item dt { color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.diagnostic-item dd { margin: 4px 0 0; font-size: 12px; overflow-wrap: anywhere; }

.logs-output {
  min-height: 220px;
  max-height: 430px;
  margin: 16px -20px -20px;
  padding: 16px 20px;
  overflow: auto;
  border-top: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
  background: #070a0e;
  color: #cbd6e2;
  font: 12px/1.65 "Cascadia Code", Consolas, monospace;
  white-space: pre-wrap;
}

canvas {
  width: 100%;
  max-width: 100%;
  margin-top: 16px;
}

.video-cell {
  min-width: 220px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.video-thumbnail {
  width: 96px;
  aspect-ratio: 16 / 9;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 4px;
  object-fit: cover;
}

.thumbnail-comparisons {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.thumbnail-comparisons a {
  min-width: 0;
  color: var(--text);
  text-decoration: none;
}

.thumbnail-comparisons img {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: block;
  border-radius: 4px;
  object-fit: cover;
}

.thumbnail-comparisons span,
.thumbnail-comparisons small {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thumbnail-comparisons small { color: var(--muted); }

.pipeline-steps {
  min-width: 560px;
  display: flex;
  gap: 4px;
}

.pipeline-step {
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
}

.pipeline-step.complete {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

@media (max-width: 1100px) {
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .profile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  html { scroll-padding-top: 20px; }
  body.mobile-menu-open { overflow: hidden; }
  .dashboard-view { grid-template-columns: 1fr; }
  .sidebar {
    z-index: 40;
    width: min(86vw, 330px);
    max-width: 330px;
    height: 100dvh;
    position: fixed;
    inset: 0 auto 0 0;
    overflow: hidden;
    padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
    border-right: 1px solid var(--line);
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: 20px 0 50px rgba(0, 0, 0, 0.35);
  }
  body.mobile-menu-open .sidebar { transform: translateX(0); }
  .brand { padding: 0 4px 18px; }
  .brand > div { min-width: 0; flex: 1; }
  .mobile-nav-close {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    padding: 0 10px;
    font-size: 12px;
  }
  .primary-nav {
    display: grid;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 3px;
  }
  .primary-nav a { min-height: 44px; }
  .sidebar-footer { display: none; }
  .mobile-nav-open {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    padding: 0 12px;
  }
  .mobile-nav-backdrop {
    z-index: 30;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
    background: rgba(0, 0, 0, 0.58);
  }
  body.mobile-menu-open .mobile-nav-backdrop { display: block; }
  .mobile-tabbar {
    z-index: 25;
    position: fixed;
    inset: auto 0 0;
    min-height: 62px;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    padding: 6px 4px max(6px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--sidebar) 94%, transparent);
    backdrop-filter: blur(16px);
  }
  .mobile-tabbar a {
    min-width: 0;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 2px;
    border-radius: 6px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 750;
    text-decoration: none;
  }
  .mobile-tabbar a.active { color: var(--accent); }
  .mobile-tab-icon {
    font-size: 15px;
    font-weight: 900;
    line-height: 1;
  }
  .workspace { padding: 22px 18px calc(86px + env(safe-area-inset-bottom)); }
  .grid.two { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .workspace { padding: 18px 12px 36px; gap: 14px; }
  .topbar { align-items: stretch; flex-direction: column; }
  .panel-head { align-items: flex-start; flex-direction: column; }
  .topbar-title { align-items: flex-start; }
  .topbar h1 { font-size: 26px; }
  .actions { width: 100%; }
  .actions button { flex: 1; padding: 0 9px; font-size: 12px; }
  .metrics-grid,
  .keyword-form,
  .inline-settings-form,
  .diagnostic-item dl { grid-template-columns: 1fr; }
  .metric { min-height: 108px; }
  .panel { padding: 16px; }
  .table-wrap,
  .logs-output { margin-right: -16px; margin-left: -16px; }
  .health-list { grid-template-columns: 1fr; }
  .profile-grid { grid-template-columns: 1fr; }
  .keyword-form { padding: 12px; }
}
