:root {
  --canvas: #f6f7f8;
  --surface: #ffffff;
  --ink: #111827;
  --muted: #5f6672;
  --border: #d9dde3;
  --primary: #0b47b7;
  --primary-soft: color-mix(in srgb, var(--primary) 8%, var(--surface));
  --success: #0f9d52;
  --success-soft: color-mix(in srgb, var(--success) 10%, var(--surface));
  --warning: #c47a00;
  --warning-soft: color-mix(in srgb, var(--warning) 10%, var(--surface));
  --error: #c73737;
  --error-soft: color-mix(in srgb, var(--error) 10%, var(--surface));
  --radius: 6px;
  --nav-width: 140px;
  --rail-width: 320px;
}

* { box-sizing: border-box; }
html { min-width: 360px; background: var(--canvas); }
body { margin: 0; color: var(--ink); background: var(--canvas); font: 14px/1.45 Inter, ui-sans-serif, system-ui, sans-serif; }
button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(11, 71, 183, .22); outline-offset: 2px; }
.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; }
.is-hidden { display: none !important; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--nav-width) minmax(0, 1fr) var(--rail-width);
  grid-template-rows: 72px minmax(0, 1fr) 46px;
  grid-template-areas: "nav top top" "nav main rail" "nav status status";
}
.nav-rail { grid-area: nav; position: sticky; top: 0; height: 100vh; background: var(--surface); border-right: 1px solid var(--border); z-index: 20; }
.wordmark { height: 72px; display: flex; flex-direction: column; justify-content: center; padding: 0 24px; color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--border); letter-spacing: -.03em; }
.wordmark span { font-size: 18px; line-height: 1; font-weight: 700; }
.wordmark small { margin-top: 4px; color: var(--muted); font-size: 10px; letter-spacing: .09em; text-transform: uppercase; }
.nav-rail nav { padding-top: 8px; }
.nav-item { position: relative; height: 64px; display: flex; align-items: center; gap: 12px; padding: 0 16px; color: var(--ink); text-decoration: none; font-weight: 500; }
.nav-item::after { content: ""; position: absolute; right: -1px; top: 12px; bottom: 12px; width: 3px; background: transparent; }
.nav-item svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-item:hover { background: var(--canvas); color: var(--primary); }
.nav-item.is-active { color: var(--primary); background: var(--primary-soft); }
.nav-item.is-active::after { background: var(--primary); }

.top-bar { grid-area: top; position: sticky; top: 0; z-index: 15; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 0 24px; background: rgba(255, 255, 255, .97); border-bottom: 1px solid var(--border); }
.top-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.top-title h1 { margin: 0; font-size: 20px; line-height: 1.2; letter-spacing: -.025em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-bar p { margin: 0; color: var(--muted); font-size: 12px; text-align: right; }
.version { color: var(--muted); font-size: 12px; white-space: nowrap; }
.status-badge { border-radius: 4px; padding: 4px 8px; color: var(--surface); font-size: 11px; font-weight: 700; letter-spacing: .04em; white-space: nowrap; }
.status-badge.ready { background: var(--success); }
.status-badge.running { background: var(--primary); }
.status-badge.warning { background: var(--warning); }
.status-badge.error { background: var(--error); }
.status-badge.ready, .status-badge.warning { color: var(--ink); }

.main-content { grid-area: main; min-width: 0; padding: 24px; }
.view { display: none; }
.view.is-active { display: block; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric { min-width: 0; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.metric span { display: block; color: var(--muted); font-size: 12px; font-weight: 600; }
.metric strong { display: block; margin-top: 4px; font-size: 24px; line-height: 1.15; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.metric small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }

.control-band { display: grid; grid-template-columns: minmax(260px, 1fr) 92px 110px 150px 150px; gap: 12px; align-items: end; margin-bottom: 16px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
label { display: grid; gap: 8px; color: var(--ink); font-size: 12px; font-weight: 600; }
input, select { width: 100%; height: 38px; padding: 0 12px; color: var(--ink); background: var(--surface); border: 1px solid var(--border); border-radius: 5px; }
input:hover, select:hover { border-color: var(--muted); }
input:focus, select:focus { border-color: var(--primary); }
.check-field { height: 38px; display: flex; flex-direction: row; align-items: center; gap: 8px; padding-bottom: 0; font-weight: 500; }
.check-field input { width: 16px; height: 16px; accent-color: var(--primary); }

.button { min-height: 38px; border: 1px solid transparent; border-radius: 5px; padding: 0 16px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.button:disabled { opacity: .55; cursor: not-allowed; }
.button.primary { color: var(--surface); background: var(--primary); border-color: var(--primary); }
.button.primary:hover:not(:disabled) { background: var(--primary); box-shadow: inset 0 0 0 999px rgba(17, 24, 39, .12); }
.button.secondary { color: var(--primary); background: var(--surface); border-color: var(--border); }
.button.secondary:hover:not(:disabled) { background: var(--primary-soft); border-color: var(--primary); }
.button.danger { color: var(--surface); background: var(--error); border-color: var(--error); }
.button.destructive-outline { color: var(--error); background: var(--surface); border-color: color-mix(in srgb, var(--error) 48%, var(--border)); }
.button.destructive-outline:hover:not(:disabled) { color: var(--surface); background: var(--error); border-color: var(--error); }
.button-group { display: flex; gap: 8px; }
.is-hidden { display: none !important; }

.panel { margin-bottom: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.panel-heading { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.panel-heading h2, .panel-heading h3 { margin: 0; font-size: 14px; letter-spacing: -.01em; }
.panel-heading p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.panel-meta { color: var(--muted); font-size: 11px; }
.chart-panel { min-height: 180px; }
.bar-chart { min-height: 126px; display: flex; align-items: flex-end; gap: 4px; padding: 24px 16px 12px; overflow-x: auto; }
.bar-column { min-width: 24px; flex: 1 0 24px; max-width: 54px; display: grid; align-content: end; gap: 8px; height: 92px; text-align: center; }
.bar-column span { width: 100%; min-height: 2px; background: var(--primary); border-radius: 2px 2px 0 0; }
.bar-column small { color: var(--muted); font-size: 9px; white-space: nowrap; }
.empty-inline { align-self: center; width: 100%; margin: 0; color: var(--muted); text-align: center; font-size: 12px; }

.table-panel { overflow: hidden; }
.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px; }
thead { position: sticky; top: 0; z-index: 2; }
th { height: 40px; padding: 0 12px; color: var(--ink); background: var(--canvas); border-bottom: 1px solid var(--border); text-align: left; font-weight: 600; white-space: nowrap; }
td { height: 42px; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--canvas); }
td:first-child { max-width: 360px; font-weight: 600; }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.empty-row td { height: 96px; color: var(--muted); text-align: center; font-weight: 400; }
.table-link { color: var(--primary); text-decoration: none; }
.table-link:hover { text-decoration: underline; }
.badge { display: inline-flex; align-items: center; min-height: 22px; padding: 4px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge.success { color: var(--ink); background: var(--success-soft); }
.badge.warning { color: var(--ink); background: var(--warning-soft); }
.badge.error { color: var(--ink); background: var(--error-soft); }
.badge.running { color: var(--primary); background: var(--primary-soft); }
.badge.neutral { color: var(--muted); background: var(--canvas); }

.page-heading { min-height: 64px; display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.page-heading h2 { margin: 0; font-size: 21px; letter-spacing: -.03em; }
.page-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.results-toolbar { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px; border-bottom: 1px solid var(--border); }
.search-field { width: min(420px, 70%); }
.results-toolbar span { color: var(--muted); font-size: 12px; }
.sort-button { border: 0; padding: 0; color: inherit; background: transparent; font-weight: inherit; cursor: pointer; }
.sort-button::after { content: " ↕"; color: var(--muted); font-size: 10px; }
.pagination { min-height: 50px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 12px; color: var(--muted); border-top: 1px solid var(--border); font-size: 12px; }
.pagination > div { display: flex; align-items: center; gap: 12px; }
.pagination label { display: flex; flex-direction: row; align-items: center; gap: 8px; color: var(--muted); font-weight: 500; }
.pagination select { width: 64px; height: 32px; }
.icon-button { min-width: 32px; height: 32px; color: var(--ink); background: var(--surface); border: 1px solid var(--border); border-radius: 4px; cursor: pointer; }
.icon-button:disabled { opacity: .4; cursor: not-allowed; }

.settings-panel { padding: 24px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; max-width: 800px; }
.settings-grid .wide { grid-column: 1 / -1; }
.settings-note { max-width: 800px; margin-top: 24px; padding: 12px 16px; color: var(--ink); background: var(--canvas); border-left: 3px solid var(--primary); }
.settings-note strong { font-size: 12px; }
.settings-note p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.form-actions { margin-top: 24px; }
code { color: var(--muted); background: var(--canvas); border-radius: 3px; padding: 4px; }

.health-rail { grid-area: rail; min-width: 0; padding: 24px 24px 24px 0; }
.rail-panel { margin-bottom: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.rail-panel .panel-heading { min-height: 54px; }
.health-list, .progress-details { margin: 0; padding: 0 16px; }
.health-list div, .progress-details div { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--border); }
.health-list div:last-child, .progress-details div:last-child { border-bottom: 0; }
.health-list dt, .progress-details dt { color: var(--ink); font-size: 12px; }
.health-list dd, .progress-details dd { margin: 0; color: var(--muted); font-size: 11px; text-align: right; overflow-wrap: anywhere; }
.health-list dd::before { content: "✓"; display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; margin-right: 8px; color: var(--success); border: 1px solid currentColor; border-radius: 50%; font-size: 10px; font-weight: 700; }
.health-list dd.is-error::before { content: "!"; color: var(--error); }
.text-status { font-size: 11px; font-weight: 700; }
.text-status.ok { color: var(--ink); }
.text-status.warning { color: var(--ink); }
.text-status.error { color: var(--error); }
.text-status.neutral { color: var(--muted); }
.progress-value { display: block; margin: 16px 16px 8px; color: var(--primary); font-size: 30px; letter-spacing: -.04em; }
.progress-track { height: 7px; margin: 0 16px 12px; overflow: hidden; background: var(--border); border-radius: 99px; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--primary); transition: width .25s ease; }
.text-link { display: block; padding: 12px 16px; color: var(--primary); border-top: 1px solid var(--border); font-size: 12px; font-weight: 600; }
.text-link.is-disabled { color: var(--muted); pointer-events: none; }

.status-strip { grid-area: status; position: sticky; bottom: 0; z-index: 14; display: flex; align-items: center; gap: 32px; padding: 0 24px; color: var(--ink); background: var(--surface); border-top: 1px solid var(--border); font-size: 11px; }
.status-strip span { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.status-dot { width: 7px; height: 7px; background: var(--success); border-radius: 50%; }
.strip-action { margin-left: auto; color: var(--primary); background: transparent; border: 0; font-weight: 600; cursor: pointer; }
.toast { position: fixed; right: 20px; bottom: 62px; z-index: 40; max-width: 400px; padding: 12px 16px; color: var(--surface); background: var(--ink); border-radius: 5px; box-shadow: 0 8px 24px rgba(17, 24, 39, .18); opacity: 0; transform: translateY(8px); pointer-events: none; transition: .18s ease; }
.toast.is-visible { opacity: 1; transform: none; }
.toast.is-error { background: var(--error); }

.confirm-dialog { width: min(460px, calc(100vw - 32px)); padding: 0; color: var(--ink); background: transparent; border: 0; }
.confirm-dialog::backdrop { background: rgba(17, 24, 39, .58); backdrop-filter: blur(2px); }
.confirm-card { padding: 24px; background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--error); border-radius: var(--radius); box-shadow: 0 24px 80px rgba(17, 24, 39, .28); }
.confirm-card h2 { margin: 8px 0; font-size: 20px; letter-spacing: -.02em; }
.confirm-card p { margin: 0 0 20px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.confirm-card label { color: var(--ink); font-size: 12px; }
.confirm-card input { margin-top: 8px; }
.danger-kicker { color: var(--error); font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

@media (max-width: 1279px) {
  .app-shell { grid-template-columns: var(--nav-width) minmax(0, 1fr); grid-template-rows: 72px auto auto 46px; grid-template-areas: "nav top" "nav main" "nav rail" "nav status"; }
  .nav-rail { grid-row: 1 / -1; }
  .health-rail { padding: 0 24px 24px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .health-rail .rail-panel { margin: 0; }
  .control-band { grid-template-columns: minmax(240px, 1fr) 90px 104px 146px; }
  .control-band .button { grid-column: 4; }
}

@media (max-width: 899px) {
  :root { --nav-width: 72px; }
  .wordmark { padding: 0; align-items: center; }
  .wordmark span { font-size: 15px; }
  .wordmark small { display: none; }
  .nav-item { justify-content: center; padding: 0; }
  .nav-item span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .top-bar { padding: 0 16px; }
  .top-title { gap: 8px; }
  .top-title h1 { font-size: 16px; }
  .top-bar p, .version { display: none; }
  .main-content { padding: 16px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .control-band { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .source-field { grid-column: 1 / -1; }
  .control-band .button { grid-column: 2; }
  .health-rail { padding: 0 16px 16px; grid-template-columns: 1fr; }
  .status-strip { gap: 16px; padding: 0 16px; overflow-x: auto; }
  .status-strip > span:nth-of-type(3) { display: none; }
  .strip-action { margin-left: auto; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-grid .wide { grid-column: auto; }
  .page-heading { min-height: 0; flex-direction: column; }
  .button-group { width: 100%; }
  .button-group .button { flex: 1; }
  .results-actions { flex-wrap: wrap; }
  .results-actions .button { flex: 1 1 calc(50% - 4px); }
  th, td { padding-left: 12px; padding-right: 12px; }
  table { min-width: 760px; }
}

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