:root {
  color-scheme: light;
  --ink-950: #101923;
  --ink-900: #17232f;
  --ink-800: #243442;
  --ink-700: #405364;
  --ink-600: #5d6e7c;
  --paper: #ffffff;
  --canvas: #f3f6f7;
  --panel: #f9fbfb;
  --line: #d7e0e3;
  --line-strong: #b9c7cb;
  --teal-800: #075951;
  --teal-700: #087067;
  --teal-600: #0c8277;
  --teal-100: #dff1ee;
  --teal-050: #eef8f6;
  --blue-700: #245f9d;
  --amber-700: #8a5900;
  --amber-100: #fff1cc;
  --red-700: #a23030;
  --red-100: #fbe7e7;
  --green-700: #256b45;
  --green-100: #e4f4ea;
  --shadow: 0 10px 30px rgba(16, 25, 35, .08);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --space-1: .25rem;
  --space-2: .5rem;
  --space-3: .75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-family: var(--font);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { color: var(--ink-900); background: var(--canvas); font: 14px/1.5 var(--font); }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid rgba(12, 130, 119, .32); outline-offset: 2px; }
a { color: var(--teal-800); }
h1, h2, h3, p { margin-top: 0; }
.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; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { min-height: 58px; display: flex; align-items: center; gap: var(--space-4); padding: 8px 16px; color: white; background: var(--ink-950); border-bottom: 1px solid #31404d; }
.topbar__brand { display: flex; align-items: center; gap: 10px; min-width: 220px; color: white; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: var(--ink-950); background: white; font-weight: 800; }
.brand-copy strong { display: block; line-height: 1.15; }
.brand-copy small { color: #b8c7d1; }
.topbar__commands { display: flex; align-items: center; gap: 6px; flex: 1; overflow-x: auto; padding: 3px; }
.topbar__meta { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.command, .button, .icon-button { min-height: 36px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 7px 11px; color: var(--ink-900); background: white; cursor: pointer; font-weight: 650; }
.topbar .command { color: #e8f1f4; background: #1c2a36; border-color: #3a4b59; }
.command:hover, .button:hover, .icon-button:hover { border-color: var(--teal-600); background: var(--teal-050); }
.topbar .command:hover { color: white; background: #273a48; }
.button--primary { color: white; background: var(--teal-700); border-color: var(--teal-700); }
.button--primary:hover { color: white; background: var(--teal-800); }
.button--danger { color: var(--red-700); border-color: #e4b7b7; }
button:disabled { opacity: .46; cursor: not-allowed; }

.status-badge { display: inline-flex; align-items: center; gap: 5px; min-height: 24px; padding: 2px 8px; border-radius: 999px; background: #e8eef0; color: var(--ink-800); font-size: 12px; font-weight: 750; }
.status-badge--ruo { color: #ffe39a; background: #49390c; }
.status-badge--ok { color: var(--green-700); background: var(--green-100); }
.status-badge--warn { color: var(--amber-700); background: var(--amber-100); }
.status-badge--error { color: var(--red-700); background: var(--red-100); }

.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: 0 2px 8px rgba(16,25,35,.04); }
.panel__header { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 42px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.panel__header h2, .panel__header h3 { margin: 0; font-size: 13px; letter-spacing: .02em; }
.panel__body { padding: 12px; }
.field { display: grid; gap: 5px; color: var(--ink-700); font-size: 12px; font-weight: 700; }
.field input, .field select, .field textarea, input.field-control, select.field-control { width: 100%; min-height: 36px; padding: 7px 9px; color: var(--ink-900); background: white; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); }
.field textarea { min-height: 84px; resize: vertical; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.help { color: var(--ink-600); font-size: 12px; }
.help-tooltip { border: 0; padding: 0; color: var(--teal-800); background: none; cursor: help; font-weight: 800; }
.divider { height: 1px; margin: 12px 0; background: var(--line); }

.tabs { display: flex; gap: 3px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tab { min-height: 40px; padding: 8px 12px; border: 0; border-bottom: 3px solid transparent; color: var(--ink-600); background: transparent; cursor: pointer; font-weight: 700; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--teal-800); border-bottom-color: var(--teal-700); }
.tab-panel[hidden] { display: none !important; }

.empty-state, .error-state { display: grid; place-items: center; gap: 8px; min-height: 140px; padding: 24px; color: var(--ink-600); text-align: center; }
.error-state { color: var(--red-700); background: var(--red-100); }
.toast-region { position: fixed; z-index: 100; right: 16px; bottom: 16px; display: grid; gap: 8px; width: min(360px, calc(100vw - 32px)); }
.toast { padding: 12px 14px; border: 1px solid var(--line-strong); border-left: 4px solid var(--teal-700); border-radius: var(--radius); background: white; box-shadow: var(--shadow); animation: toast-in .18s ease-out; }
.toast--error { border-left-color: var(--red-700); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.data-table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table th, .data-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.data-table th { position: sticky; top: 0; background: var(--panel); color: var(--ink-700); }
.data-table tr:last-child td { border-bottom: 0; }
.chart-container { position: relative; overflow: hidden; min-height: 250px; border: 1px solid var(--line); border-radius: var(--radius); background: white; }
.chart-container svg { display: block; width: 100%; height: auto; min-height: 250px; }

.dialog { width: min(560px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: 0 24px 70px rgba(16,25,35,.28); }
.dialog::backdrop { background: rgba(16,25,35,.48); }
.dialog__header, .dialog__footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.dialog__footer { justify-content: flex-end; border-top: 1px solid var(--line); border-bottom: 0; }
.dialog__body { padding: 16px; }
.dialog h2 { margin: 0; font-size: 18px; }

@media (max-width: 820px) {
  .topbar { flex-wrap: wrap; }
  .topbar__brand { min-width: auto; }
  .topbar__commands { order: 3; flex-basis: 100%; }
  .brand-copy small { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
