:root {
  color-scheme: dark;
  --canvas: #080d14;
  --sidebar-bg: #0d151f;
  --surface: #111b27;
  --surface-raised: #162230;
  --border: #263647;
  --border-soft: rgba(151, 174, 197, 0.14);
  --text: #edf3f8;
  --text-soft: #bdc9d5;
  --muted: #8496a8;
  --accent: #63b9dc;
  --accent-soft: rgba(99, 185, 220, 0.12);
  --success: #55c991;
  --warning: #e4b95f;
  --danger: #eb7777;
  --sidebar-width: 260px;
  --content-width: 1520px;
  --radius: 8px;
  --radius-small: 6px;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  --font-body: "Aptos", "Segoe UI Variable", "Segoe UI", sans-serif;
  --font-display: "Aptos Display", "Segoe UI Variable Display", "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.012) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.012) 1px, transparent 1px),
    var(--canvas);
  background-size: 32px 32px;
  color: var(--text);
  font: 15px/1.5 var(--font-body);
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea, summary { outline: none; }
:focus-visible { outline: 2px solid #8bd5f0; outline-offset: 2px; }
::selection { background: rgba(99, 185, 220, 0.3); }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 16px 12px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-soft);
  scrollbar-color: #34485c transparent;
  scrollbar-width: thin;
}

.sidebar-head, .topbar-title { display: flex; align-items: center; }
.sidebar-head { justify-content: space-between; }
.brand { display: flex; min-width: 0; align-items: center; gap: 11px; padding: 5px 8px 19px; }
.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border: 1px solid rgba(139, 213, 240, 0.22);
  border-radius: var(--radius);
  background: #203b50;
  color: #dff5ff;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.brand-text { min-width: 0; }
.brand-text strong { display: block; font: 700 0.9rem var(--font-display); letter-spacing: 0.05em; }
.brand-text span {
  display: block;
  margin-top: 1px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.75rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-group { display: grid; gap: 5px; padding-bottom: 16px; }
.nav-section { border-radius: var(--radius); }
.nav-section-toggle {
  display: flex;
  min-height: 34px;
  list-style: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 9px;
  border-radius: var(--radius-small);
  cursor: pointer;
  user-select: none;
}
.nav-section-toggle::-webkit-details-marker { display: none; }
.nav-section-toggle:hover { background: rgba(255, 255, 255, 0.025); }
.nav-label { color: #71869a; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.13em; text-transform: uppercase; }
.nav-chevron {
  width: 7px;
  height: 7px;
  margin-right: 3px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 160ms ease;
}
.nav-section[open] .nav-chevron { transform: rotate(225deg); }
.nav-list { display: grid; gap: 2px; padding: 0 0 7px; }
.nav-link {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 39px;
  align-items: center;
  padding: 9px 11px 9px 13px;
  border: 1px solid transparent;
  border-radius: var(--radius-small);
  color: var(--text-soft);
  font-size: 0.86rem;
  transition: color 140ms ease, background-color 140ms ease, border-color 140ms ease;
}
.nav-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-link small { display: none; }
.nav-link:hover { background: rgba(255, 255, 255, 0.035); color: var(--text); }
.nav-link.active { border-color: rgba(99, 185, 220, 0.15); background: var(--accent-soft); color: #e8f8ff; font-weight: 650; }
.nav-link.active::before {
  position: absolute;
  inset: 8px auto 8px 0;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  content: "";
}
.sidebar-footer { display: grid; gap: 10px; margin-top: auto; padding-top: 12px; }
.nav-open, .nav-close, .nav-backdrop { display: none; }

.main { min-width: 0; min-height: 100vh; margin-left: var(--sidebar-width); padding: 28px clamp(22px, 3vw, 46px) 48px; }
.main-inner { display: grid; width: min(100%, var(--content-width)); margin: 0 auto; gap: 16px; }
.topbar { display: flex; min-height: 52px; align-items: flex-start; justify-content: space-between; gap: 24px; padding-bottom: 2px; }
.topbar-title { min-width: 0; gap: 12px; }
.page-title, .section-title, .metric-value, .hero-kicker { font-family: var(--font-display); }
.page-title { margin: 0; font-size: clamp(1.55rem, 2vw, 1.9rem); font-weight: 700; line-height: 1.2; }
.page-subtitle { max-width: 76ch; margin: 5px 0 0; color: var(--muted); font-size: 0.9rem; }
.topbar-actions, .form-actions, .table-actions, .hero-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.topbar-actions { flex: 0 0 auto; justify-content: flex-end; }

.button, .button-secondary, .button-ghost {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-small);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 650;
  line-height: 1.2;
  text-align: center;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}
.button { border-color: #74c7e7; background: #74c7e7; color: #07121a; }
.button:hover { border-color: #95daf1; background: #95daf1; }
.button-secondary { border-color: var(--border); background: var(--surface-raised); color: var(--text-soft); }
.button-secondary:hover { border-color: #3b5268; background: #1a2a3a; color: var(--text); }
.button-ghost { background: transparent; color: var(--muted); }
.button-ghost:hover { background: rgba(255, 255, 255, 0.04); color: var(--text); }

.status-card, .panel, .hero, .metric-card, .table-card, .stack-card, .form-card, .timeline-card, .activity-card {
  min-width: 0;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel, .table-card, .stack-card, .form-card, .timeline-card, .activity-card { padding: 18px; }
.status-card { padding: 14px; }
.status-card .label, .metric-label { color: var(--muted); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; }
.status-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }
.status-value { font-size: 1rem; font-weight: 700; }
.status-pill, .badge, .tag, .chip {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
}
.status-pill.online, .badge.success, .tag.success, .chip.success { border-color: rgba(85, 201, 145, 0.2); background: rgba(85, 201, 145, 0.11); color: #9ee0bf; }
.status-pill.warning, .badge.warning, .tag.warning, .chip.warning { border-color: rgba(228, 185, 95, 0.2); background: rgba(228, 185, 95, 0.11); color: #f1d28f; }
.status-pill.danger, .badge.danger, .tag.danger, .chip.danger { border-color: rgba(235, 119, 119, 0.2); background: rgba(235, 119, 119, 0.11); color: #f3aaaa; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric-card { padding: 15px 16px; }
.metric-value { margin: 8px 0 5px; font-size: clamp(1.55rem, 2.2vw, 2rem); font-weight: 650; line-height: 1.15; }
.metric-delta { color: var(--text-soft); font-size: 0.78rem; }
.content-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.85fr); gap: 12px; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

.section-head, .card-head, .table-head, .stack-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.section-title { margin: 0; font-size: 1rem; font-weight: 700; }
.section-copy, .card-copy { max-width: 80ch; margin: 4px 0 0; color: var(--muted); font-size: 0.86rem; }
.list, .table-list, .timeline, .activity-list, .stack-list { display: grid; gap: 8px; }
.row, .activity-item, .timeline-item, .stack-item {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 13px;
  border: 1px solid rgba(151, 174, 197, 0.09);
  border-radius: var(--radius-small);
  background: rgba(255, 255, 255, 0.018);
}
.row-main, .activity-main, .timeline-main, .stack-main { display: grid; min-width: 0; gap: 2px; }
.row-title, .activity-title, .timeline-title, .stack-title { font-size: 0.9rem; font-weight: 650; }
.row-sub, .activity-sub, .timeline-sub, .stack-sub, .meta, .muted { color: var(--muted); font-size: 0.82rem; overflow-wrap: anywhere; }

.table-card { overflow: hidden; }
.matrix { width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; scrollbar-color: #40566b transparent; scrollbar-width: thin; }
table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
th, td { padding: 11px 10px; border-bottom: 1px solid rgba(151, 174, 197, 0.11); text-align: left; vertical-align: middle; }
th { color: #91a5b8; font-size: 0.68rem; font-weight: 750; letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(99, 185, 220, 0.025); }
.matrix td { min-width: 100px; }
.matrix td:first-child, .matrix th:first-child { padding-left: 3px; }
.matrix td:last-child, .matrix th:last-child { padding-right: 3px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.form-field { display: grid; min-width: 0; align-content: start; gap: 6px; }
.form-field label { color: var(--text-soft); font-size: 0.8rem; font-weight: 600; }
.form-field label:has(input[type="checkbox"]) { display: flex; min-height: 38px; align-items: center; gap: 8px; }
.search-bar, .select, .input, .textarea {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: #0c151f;
  color: var(--text);
  font-size: 0.86rem;
  line-height: 1.3;
  transition: border-color 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}
.search-bar:hover, .select:hover, .input:hover, .textarea:hover { border-color: #3b5165; }
.search-bar:focus, .select:focus, .input:focus, .textarea:focus { border-color: var(--accent); background: #0e1924; box-shadow: 0 0 0 3px rgba(99, 185, 220, 0.1); }
.search-bar::placeholder, .input::placeholder, .textarea::placeholder { color: #60758a; }
select.input, select.select { color-scheme: dark; }
select.input option, select.select option { background: #101a26; color: var(--text); }
input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.textarea { min-height: 112px; resize: vertical; }
.form-actions { justify-content: flex-end; }
td .form-actions { min-width: max-content; }

.tab-list { display: flex; gap: 4px; margin: 0 0 14px; padding-bottom: 1px; overflow-x: auto; scrollbar-width: none; }
.tab-list::-webkit-scrollbar { display: none; }
.tab-button {
  min-height: 36px;
  flex: 0 0 auto;
  padding: 7px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-small);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 650;
}
.tab-button:hover { background: rgba(255, 255, 255, 0.035); color: var(--text-soft); }
.tab-button.active { border-color: rgba(99, 185, 220, 0.18); background: var(--accent-soft); color: #dff6ff; }

.panel-collapsible { padding: 0; overflow: hidden; }
.panel-collapsible-toggle { display: flex; min-height: 56px; list-style: none; align-items: center; justify-content: space-between; gap: 14px; padding: 15px 18px; cursor: pointer; }
.panel-collapsible-toggle::-webkit-details-marker { display: none; }
.panel-collapsible-toggle:hover { background: rgba(255, 255, 255, 0.02); }
.panel-collapsible-hint { color: var(--muted); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.panel-collapsible-body { padding: 0 18px 18px; border-top: 1px solid var(--border-soft); }
.panel-collapsible-body > :first-child { margin-top: 16px; }

.flash { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.flash.info { border-color: rgba(99, 185, 220, 0.28); background: rgba(99, 185, 220, 0.08); }
.flash.success { border-color: rgba(85, 201, 145, 0.28); background: rgba(85, 201, 145, 0.08); }
.flash.warning { border-color: rgba(228, 185, 95, 0.28); background: rgba(228, 185, 95, 0.08); }
.flash strong { display: block; margin-bottom: 2px; font-size: 0.84rem; }
.flash p { margin: 0; color: var(--text-soft); font-size: 0.84rem; }

.hero { padding: 22px; }
.hero-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(260px, 0.65fr); align-items: center; gap: 24px; }
.hero-kicker { display: inline-flex; margin-bottom: 10px; color: #8bd5f0; font-size: 0.74rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.hero h1 { margin: 0; font-size: clamp(1.8rem, 3.5vw, 3rem); font-weight: 700; line-height: 1.08; }
.hero p { max-width: 68ch; margin: 10px 0 0; color: var(--text-soft); }
.hero-actions { margin-top: 16px; }
.hero-stats { display: grid; gap: 8px; }
.stat-spot, .mini-card { padding: 13px; border: 1px solid var(--border-soft); border-radius: var(--radius-small); background: rgba(255, 255, 255, 0.02); }
.stat-spot h3, .mini-card h3 { margin: 0; font-size: 0.9rem; }
.stat-spot p, .mini-card p { margin: 4px 0 0; color: var(--muted); font-size: 0.82rem; }

.login-shell { display: grid; min-height: 100vh; place-items: center; padding: clamp(16px, 4vw, 40px); }
.login-card, .setup-card { width: 100%; }
.login-card { max-width: 440px; padding: 26px; }
.setup-card { max-width: 1040px; padding: 26px; }
.login-card h1, .setup-card h1 { margin: 18px 0 6px; font: 700 clamp(1.65rem, 4vw, 2rem) var(--font-display); }
.login-card > p, .setup-card > p { margin: 0; color: var(--muted); }
.login-card .form-grid { grid-template-columns: 1fr; margin-top: 20px; }
.login-card .form-actions { justify-content: stretch; }
.login-card .form-actions .button { width: 100%; }
.login-footer { margin-top: 16px; color: #667b90; font-size: 0.76rem; text-align: center; }

.setup-grid { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 18px; margin-top: 22px; }
.setup-steps, .setup-summary { display: grid; align-content: start; gap: 8px; }
.setup-step { display: flex; gap: 11px; padding: 12px; border: 1px solid var(--border-soft); border-radius: var(--radius); background: rgba(255, 255, 255, 0.015); }
.setup-step.active { border-color: rgba(99, 185, 220, 0.25); background: var(--accent-soft); }
.setup-step.complete { border-color: rgba(85, 201, 145, 0.22); }
.setup-step-index { display: grid; width: 28px; height: 28px; flex: 0 0 28px; place-items: center; border-radius: 50%; background: #1b2a39; font-size: 0.78rem; font-weight: 750; }
.setup-step.complete .setup-step-index { background: rgba(85, 201, 145, 0.14); color: #a9e6c8; }
.setup-step-copy strong { display: block; font-size: 0.84rem; }
.setup-step-copy span { display: block; margin-top: 2px; color: var(--muted); font-size: 0.76rem; }
.setup-panel { min-width: 0; padding: 18px; border: 1px solid var(--border-soft); border-radius: var(--radius); background: rgba(255, 255, 255, 0.018); }
.code-block { margin: 0; padding: 14px; overflow: auto; border: 1px solid var(--border-soft); border-radius: var(--radius-small); background: #090f17; color: #c7d6e3; font: 0.8rem/1.55 "Cascadia Mono", Consolas, monospace; white-space: pre; }
.hidden, [hidden] { display: none !important; }

@media (max-width: 1240px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-grid, .content-grid { grid-template-columns: 1fr; }
  .hero-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1023px) {
  .sidebar {
    width: min(280px, calc(100vw - 48px));
    transform: translateX(-101%);
    transition: transform 180ms ease;
    box-shadow: 20px 0 45px rgba(0, 0, 0, 0.35);
  }
  .main { margin-left: 0; padding: 22px clamp(18px, 3vw, 30px) 38px; }
  .nav-open, .nav-close {
    display: grid;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    place-items: center;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    background: var(--surface);
    color: var(--text-soft);
    cursor: pointer;
  }
  .nav-open:hover, .nav-close:hover { border-color: #41576c; color: var(--text); }
  .nav-open span, .nav-open span::before, .nav-open span::after { display: block; width: 16px; height: 2px; border-radius: 2px; background: currentColor; content: ""; }
  .nav-open span { position: relative; }
  .nav-open span::before, .nav-open span::after { position: absolute; left: 0; }
  .nav-open span::before { top: -5px; }
  .nav-open span::after { top: 5px; }
  .nav-close span, .nav-close span::after { display: block; width: 16px; height: 2px; border-radius: 2px; background: currentColor; content: ""; transform: rotate(45deg); }
  .nav-close span::after { transform: rotate(90deg); }
  .nav-backdrop { position: fixed; inset: 0; z-index: 30; width: 100%; height: 100%; padding: 0; border: 0; background: rgba(2, 6, 10, 0.7); }
  body.nav-open { overflow: hidden; }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .nav-backdrop { display: block; }
  .setup-grid { grid-template-columns: 1fr; }
  .setup-steps { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  body { font-size: 14px; }
  .main { padding: 16px 12px 28px; }
  .main-inner { gap: 12px; }
  .topbar { min-height: 44px; gap: 10px; }
  .topbar-title { gap: 9px; }
  .page-title { font-size: 1.35rem; }
  .page-subtitle, .dashboard-link { display: none; }
  .topbar-actions .button { min-height: 38px; padding-inline: 11px; }
  .metric-grid, .two-col, .form-grid, .hero-stats { grid-template-columns: 1fr; }
  .metric-card { padding: 13px 14px; }
  .metric-value { margin-block: 5px 3px; font-size: 1.55rem; }
  .panel, .table-card, .stack-card, .form-card, .timeline-card, .activity-card, .hero { padding: 14px; }
  .section-head, .card-head, .table-head, .stack-head { align-items: stretch; flex-direction: column; gap: 10px; margin-bottom: 12px; }
  .row, .activity-item, .timeline-item, .stack-item, .status-row { align-items: flex-start; flex-direction: column; }
  .form-actions { width: 100%; justify-content: stretch; }
  .form-actions > .button, .form-actions > .button-secondary, .form-actions > .button-ghost { flex: 1 1 auto; }
  td .form-actions { width: auto; flex-wrap: nowrap; }
  td .form-actions > .input { min-width: 150px; }
  .matrix { width: calc(100% + 28px); margin-inline: -14px; padding-inline: 14px; }
  .matrix table { min-width: 660px; }
  th, td { padding-block: 10px; }
  .setup-card, .login-card { padding: 18px; }
  .setup-steps { grid-template-columns: 1fr; }
  .setup-step-copy span { display: none; }
  .setup-panel { padding: 14px; }
  .panel-collapsible-toggle { padding: 14px; }
  .panel-collapsible-body { padding: 0 14px 14px; }
  .hero h1 { font-size: 1.7rem; }
  .flash { padding: 11px 12px; }
}

@media (max-width: 390px) {
  .page-title { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-actions { gap: 5px; }
  .button, .button-secondary, .button-ghost { padding-inline: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}