:root,
[data-theme='light'] {
  --color-bg: #f7f6f2;
  --color-surface: #f9f8f5;
  --color-surface-2: #fbfbf9;
  --color-surface-offset: #f3f0ec;
  --color-border: #d4d1ca;
  --color-divider: #dcd9d5;
  --color-text: #28251d;
  --color-text-muted: #7a7974;
  --color-text-faint: #bab9b4;
  --color-text-inverse: #f9f8f4;
  --color-primary: #01696f;
  --color-primary-hover: #0c4e54;
  --color-primary-highlight: #cedcd8;
  --color-error: #a12c7b;
  --color-error-highlight: #e0ced7;
  --color-warning: #964219;
  --color-warning-highlight: #ddcfc6;
  --color-success: #437a22;
  --color-success-highlight: #d4dfcc;
  --shadow-sm: 0 1px 2px oklch(0.2 0.01 80 / 0.06);
  --shadow-md: 0 4px 12px oklch(0.2 0.01 80 / 0.08);
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --font-body: 'Noto Sans', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', Consolas, monospace;
  --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme='dark'] {
  --color-bg: #171614;
  --color-surface: #1c1b19;
  --color-surface-2: #201f1d;
  --color-surface-offset: #22211f;
  --color-border: #393836;
  --color-divider: #262523;
  --color-text: #cdccca;
  --color-text-muted: #979590;
  --color-text-faint: #6f6d68;
  --color-text-inverse: #2b2a28;
  --color-primary: #4f98a3;
  --color-primary-hover: #72b3bc;
  --color-primary-highlight: #313b3b;
  --color-error: #d163a7;
  --color-error-highlight: #4c3d46;
  --color-warning: #bb653b;
  --color-warning-highlight: #564942;
  --color-success: #6daa45;
  --color-success-highlight: #3a4435;
  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.2);
  --shadow-md: 0 4px 12px oklch(0 0 0 / 0.3);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -moz-text-size-adjust: none; -webkit-text-size-adjust: none; text-size-adjust: none; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }
body { min-height: 100dvh; font-family: var(--font-body); font-size: var(--text-base); color: var(--color-text); background: linear-gradient(135deg, color-mix(in oklab, var(--color-primary) 7%, transparent), transparent 38%), var(--color-bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 3px; border-radius: var(--radius-sm); }
.skip-link { position: absolute; left: var(--space-4); top: var(--space-4); z-index: 20; transform: translateY(-200%); padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); color: var(--color-text-inverse); background: var(--color-primary); }
.skip-link:focus { transform: translateY(0); }
.app-header { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--space-4) var(--space-6); border-bottom: 1px solid var(--color-border); background: color-mix(in oklab, var(--color-surface) 92%, transparent); backdrop-filter: blur(18px); }
.brand { display: flex; align-items: center; gap: var(--space-3); }
.brand-mark { width: 44px; color: var(--color-primary); }
.eyebrow { font-size: var(--text-xs); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; }
h1 { font-size: var(--text-lg); line-height: 1.15; }
.theme-button { min-width: 44px; min-height: 44px; border: 1px solid var(--color-border); border-radius: var(--radius-lg); background: var(--color-surface-2); color: var(--color-text); box-shadow: var(--shadow-sm); }
.app-shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: var(--space-6); width: min(1480px, 100%); margin: 0 auto; padding: var(--space-6); }
.sidebar { position: sticky; top: 92px; align-self: start; display: grid; gap: var(--space-2); padding: var(--space-3); border: 1px solid var(--color-border); border-radius: var(--radius-xl); background: var(--color-surface); box-shadow: var(--shadow-sm); }
.nav-item, .btn { min-height: 44px; border: 1px solid transparent; border-radius: var(--radius-md); transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition); }
.nav-item { padding: var(--space-3) var(--space-4); background: transparent; color: var(--color-text-muted); text-align: left; font-weight: 600; }
.nav-item:hover, .nav-item.active { color: var(--color-text); background: var(--color-primary-highlight); }
.sidebar-note { display: grid; gap: var(--space-2); margin-top: var(--space-4); padding: var(--space-4); border-radius: var(--radius-lg); background: var(--color-surface-offset); color: var(--color-text-muted); font-size: var(--text-xs); line-height: 1.45; }
.sidebar-note strong { color: var(--color-text); }
.workspace { display: grid; gap: var(--space-5); min-width: 0; }
.toolbar, .panel { border: 1px solid var(--color-border); border-radius: var(--radius-xl); background: var(--color-surface); box-shadow: var(--shadow-sm); }
.toolbar { display: flex; justify-content: space-between; gap: var(--space-4); align-items: center; padding: var(--space-5); }
.toolbar h2 { font-size: var(--text-xl); line-height: 1.15; }
.toolbar p, .panel-header p { margin-top: var(--space-1); color: var(--color-text-muted); font-size: var(--text-sm); }
.toolbar-actions, .inline-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); padding: 0 var(--space-4); font-size: var(--text-sm); font-weight: 700; }
.btn.primary { background: var(--color-primary); color: var(--color-text-inverse); }
.btn.primary:hover { background: var(--color-primary-hover); }
.btn.secondary, .btn.small { border-color: var(--color-border); background: var(--color-surface-2); color: var(--color-text); }
.btn.small { min-height: 36px; padding: 0 var(--space-3); font-size: var(--text-xs); }
.btn:hover { transform: translateY(-1px); }
.status { display: none; padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg); font-size: var(--text-sm); }
.status.visible { display: block; }
.status.ok { background: var(--color-success-highlight); color: var(--color-success); }
.status.warn { background: var(--color-warning-highlight); color: var(--color-warning); }
.status.error { background: var(--color-error-highlight); color: var(--color-error); }
.view { display: none; gap: var(--space-5); }
.view.active { display: grid; }
.panel { overflow: hidden; }
.panel-header { padding: var(--space-5); border-bottom: 1px solid var(--color-divider); }
.panel-header h3 { font-size: var(--text-lg); }
.panel-header.split { display: flex; justify-content: space-between; gap: var(--space-4); align-items: center; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); padding: var(--space-5); }
label { display: grid; gap: var(--space-2); color: var(--color-text-muted); font-size: var(--text-xs); font-weight: 700; }
input, select, textarea { width: 100%; min-height: 40px; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface-2); color: var(--color-text); padding: var(--space-2) var(--space-3); font-size: var(--text-sm); }
textarea { min-height: 68vh; padding: var(--space-4); resize: vertical; font-family: var(--font-mono); line-height: 1.55; }
.table-wrap { overflow: auto; scrollbar-gutter: stable; }
.data-table { width: 100%; border-collapse: collapse; table-layout: fixed; min-width: 100%; }
.data-table th, .data-table td { padding: var(--space-2) var(--space-1); border-bottom: 1px solid var(--color-divider); vertical-align: top; text-align: left; }
.data-table th { position: sticky; top: 0; z-index: 1; background: var(--color-surface-offset); color: var(--color-text-muted); font-size: var(--text-xs); font-weight: 800; }
.data-table td input, .data-table td select { min-width: 0; padding-inline: var(--space-2); font-size: 0.82rem; }
.data-table td .wide { min-width: 0; }
.nodes-table th:nth-child(1), .nodes-table td:nth-child(1) { width: 14%; }
.nodes-table th:nth-child(2), .nodes-table td:nth-child(2) { width: 14%; }
.nodes-table th:nth-child(3), .nodes-table td:nth-child(3) { width: 10%; }
.nodes-table th:nth-child(4), .nodes-table td:nth-child(4) { width: 13%; }
.nodes-table th:nth-child(5), .nodes-table td:nth-child(5), .nodes-table th:nth-child(6), .nodes-table td:nth-child(6) { width: 6%; }
.nodes-table th:nth-child(7), .nodes-table td:nth-child(7) { width: 9%; }
.nodes-table th:nth-child(8), .nodes-table td:nth-child(8), .nodes-table th:nth-child(9), .nodes-table td:nth-child(9) { width: 7%; }
.nodes-table th:nth-child(10), .nodes-table td:nth-child(10) { width: 8%; }
.nodes-table th:nth-child(11), .nodes-table td:nth-child(11) { width: 5%; }
.lines-table th:nth-child(1), .lines-table td:nth-child(1) { width: 10%; }
.lines-table th:nth-child(2), .lines-table td:nth-child(2) { width: 18%; }
.lines-table th:nth-child(3), .lines-table td:nth-child(3), .lines-table th:nth-child(4), .lines-table td:nth-child(4) { width: 14%; }
.lines-table th:nth-child(5), .lines-table td:nth-child(5), .lines-table th:nth-child(6), .lines-table td:nth-child(6) { width: 8%; }
.lines-table th:nth-child(7), .lines-table td:nth-child(7), .lines-table th:nth-child(8), .lines-table td:nth-child(8) { width: 12%; }
.lines-table th:nth-child(9), .lines-table td:nth-child(9) { width: 4%; }
.delete-row { min-width: 36px; min-height: 36px; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface-2); color: var(--color-text-muted); }
.delete-row:hover { color: var(--color-error); border-color: var(--color-error); }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-4); }
.kpi { display: grid; gap: var(--space-2); padding: var(--space-5); border: 1px solid var(--color-border); border-radius: var(--radius-xl); background: var(--color-surface); box-shadow: var(--shadow-sm); }
.kpi span { color: var(--color-text-muted); font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.kpi strong { font-family: var(--font-mono); font-size: var(--text-xl); line-height: 1; }
.badge { display: inline-flex; align-items: center; min-height: 28px; padding: 0 var(--space-2); border-radius: 999px; font-size: var(--text-xs); font-weight: 800; }
.badge.ok, .badge.info { background: var(--color-success-highlight); color: var(--color-success); }
.badge.warning { background: var(--color-warning-highlight); color: var(--color-warning); }
.badge.critical, .badge.error { background: var(--color-error-highlight); color: var(--color-error); }
.issues-list { display: grid; gap: var(--space-3); padding: var(--space-5); }
.issue-card { display: grid; grid-template-columns: auto 1fr; gap: var(--space-3); padding: var(--space-4); border: 1px solid var(--color-border); border-radius: var(--radius-lg); background: var(--color-surface-2); }
.issue-card h4 { font-size: var(--text-sm); }
.issue-card p { margin-top: var(--space-1); color: var(--color-text-muted); font-size: var(--text-sm); line-height: 1.45; }
.mono { font-family: var(--font-mono); font-size: var(--text-xs); }
.scheme-wrap { padding: var(--space-5); overflow: auto; background: linear-gradient(180deg, color-mix(in oklab, var(--color-primary) 4%, var(--color-surface-2)), var(--color-surface)); }
.scheme-canvas { width: 100%; min-width: 980px; min-height: 560px; display: block; }
.scheme-frame { fill: color-mix(in oklab, var(--color-surface-2) 88%, transparent); stroke: var(--color-border); stroke-width: 1.5; }
.scheme-title { fill: var(--color-text); font-size: 24px; font-weight: 700; }
.scheme-line { fill: none; stroke: var(--color-primary); stroke-width: 4; stroke-linecap: round; opacity: 0.9; }
.scheme-edge-label { fill: var(--color-text); font-size: 14px; font-weight: 700; }
.scheme-edge-sub { fill: var(--color-text-muted); font-size: 12px; }
.scheme-node-box { fill: var(--color-surface); stroke: var(--color-border); stroke-width: 1.5; filter: drop-shadow(0 4px 8px oklch(0.2 0.01 80 / 0.08)); }
.scheme-node.source .scheme-node-box { stroke: var(--color-primary); fill: color-mix(in oklab, var(--color-primary) 10%, var(--color-surface)); }
.scheme-node.switchboard .scheme-node-box { stroke: var(--color-warning); fill: color-mix(in oklab, var(--color-warning) 10%, var(--color-surface)); }
.scheme-node.load .scheme-node-box { stroke: var(--color-success); fill: color-mix(in oklab, var(--color-success) 10%, var(--color-surface)); }
.scheme-node-title { fill: var(--color-text); font-size: 14px; font-weight: 700; }
.scheme-node-sub { fill: var(--color-text-muted); font-size: 12px; }
.scheme-empty { fill: var(--color-text-muted); font-size: 18px; }
.scheme-meta { align-items: center; }
@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sidebar-note { grid-column: 1 / -1; }
  .form-grid, .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .app-header, .toolbar, .panel-header.split { align-items: stretch; flex-direction: column; }
  .app-shell { padding: var(--space-3); }
  .sidebar, .form-grid, .kpi-grid { grid-template-columns: 1fr; }
  .toolbar-actions, .inline-actions { width: 100%; }
  .btn { width: 100%; }
  .nodes-table { min-width: 920px; }
  .lines-table, .results-table { min-width: 820px; }
  .scheme-canvas { min-width: 900px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
