:root {
  color: #172033;
  background: #f4f6f8;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  --ink: #172033;
  --muted: #667085;
  --line: #dfe3e8;
  --line-strong: #c9d0d8;
  --surface: #ffffff;
  --surface-alt: #f7f8fa;
  --surface-strong: #edf0f3;
  --teal: #087f71;
  --teal-soft: #e9f8f4;
  --blue: #2764c4;
  --blue-soft: #edf4ff;
  --amber: #b85f08;
  --amber-soft: #fff5e6;
  --red: #c73636;
  --red-soft: #fff0f0;
  --shadow: 0 1px 3px rgba(23, 32, 51, 0.08);
  --radius: 7px;
}

html.dark {
  color: #e6e9ee;
  background: #12161e;
  --ink: #e6e9ee;
  --muted: #9aa4b2;
  --line: #2c3440;
  --line-strong: #3b4654;
  --surface: #1a202a;
  --surface-alt: #151b24;
  --surface-strong: #232b37;
  --teal: #55cdb6;
  --teal-soft: #17362f;
  --blue: #7eacfa;
  --blue-soft: #1c2d49;
  --amber: #f0a452;
  --amber-soft: #3b2b19;
  --red: #f18b8b;
  --red-soft: #3c2225;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body { min-width: 320px; min-height: 100vh; margin: 0; color: var(--ink); background: #f4f6f8; }
html.dark body { background: #12161e; }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
svg { width: 18px; height: 18px; display: block; }
.is-hidden { display: none !important; }
.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; }
.skip-link { position: fixed; z-index: 50; top: 8px; left: 8px; padding: 8px 11px; color: #fff; background: var(--teal); border-radius: var(--radius); transform: translateY(-150%); }
.skip-link:focus { transform: none; }

.button, .icon-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--surface);
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.button { min-height: 38px; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 13px; font-weight: 650; white-space: nowrap; }
.button:hover:not(:disabled), .icon-button:hover:not(:disabled) { border-color: var(--line-strong); background: var(--surface-strong); }
.button-primary { color: #fff; border-color: #087f71; background: #087f71; }
.button-primary:hover:not(:disabled) { border-color: #086d62; background: #086d62; }
.button-danger { color: #fff; border-color: #b72f2f; background: #b72f2f; }
.button-secondary { color: var(--muted); }
.button-full { width: 100%; }
.icon-button { width: 38px; height: 38px; padding: 0; display: inline-grid; place-items: center; flex: none; }

.app-header { position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(12px); }
.header-inner { width: min(1440px, 100%); min-height: 58px; margin: 0 auto; padding: 0 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 32px; height: 32px; border-radius: 6px; }
.brand div { display: grid; line-height: 1.12; }
.brand strong { font-size: 14px; }
.brand span { color: var(--muted); font-size: 11px; }
.header-actions { display: flex; align-items: center; gap: 8px; }

.health-badge { min-height: 28px; padding: 0 10px; border-radius: 999px; display: inline-flex; align-items: center; gap: 7px; color: var(--muted); background: var(--surface-alt); font-size: 12px; font-weight: 650; white-space: nowrap; }
.health-badge > span { width: 7px; height: 7px; border-radius: 50%; background: #98a2b3; }
.health-good { color: var(--teal); background: var(--teal-soft); }
.health-good > span { background: var(--teal); }
.health-bad { color: var(--red); background: var(--red-soft); }
.health-bad > span { background: var(--red); }

.content { width: min(1440px, 100%); margin: 0 auto; padding: 22px 24px 48px; }
.current-band { min-height: 92px; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line); }
.current-node { min-width: 0; display: grid; gap: 3px; }
.current-node > span:first-child { color: var(--muted); font-size: 12px; font-weight: 650; }
.current-node strong { max-width: min(760px, 70vw); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 22px; line-height: 1.3; letter-spacing: 0; }
.current-node > span:last-child { color: var(--muted); font-size: 11px; }
.mode-control { display: flex; align-items: center; gap: 14px; padding-left: 24px; border-left: 1px solid var(--line); }
.mode-control > div { display: grid; gap: 2px; text-align: right; }
.mode-control span { color: var(--muted); font-size: 11px; }
.mode-control strong { font-size: 13px; }

.switch { position: relative; display: inline-flex; flex: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch > span { width: 42px; height: 24px; padding: 3px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface-strong); transition: background-color 140ms ease, border-color 140ms ease; }
.switch > span::after { content: ""; display: block; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform 140ms ease; }
.switch input:checked + span { border-color: var(--teal); background: var(--teal); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--teal); outline-offset: 2px; }

.status-strip { min-height: 76px; display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); border-bottom: 1px solid var(--line); }
.status-item { min-width: 0; padding: 16px 20px; display: flex; align-items: center; gap: 11px; border-right: 1px solid var(--line); }
.status-item:first-child { padding-left: 0; }
.status-item:last-child { border-right: 0; }
.status-item > div { min-width: 0; display: grid; gap: 2px; }
.status-item span:not(.status-icon) { color: var(--muted); font-size: 11px; }
.status-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.status-icon { width: 32px; height: 32px; display: grid; place-items: center; flex: none; border-radius: 6px; color: var(--amber); background: var(--amber-soft); }
.status-green { color: var(--teal); background: var(--teal-soft); }
.status-blue { color: var(--blue); background: var(--blue-soft); }
.status-amber { color: var(--amber); background: var(--amber-soft); }

.workspace-tabs { height: 54px; display: flex; align-items: end; gap: 22px; border-bottom: 1px solid var(--line); }
.workspace-tab { position: relative; height: 54px; padding: 0 2px; display: inline-flex; align-items: center; gap: 7px; border: 0; color: var(--muted); background: none; font-size: 13px; font-weight: 650; }
.workspace-tab::after { content: ""; position: absolute; right: 0; bottom: -1px; left: 0; height: 2px; background: transparent; }
.workspace-tab.is-active { color: var(--ink); }
.workspace-tab.is-active::after { background: var(--teal); }
.workspace-tab strong { min-width: 20px; padding: 1px 6px; border-radius: 999px; color: var(--muted); background: var(--surface-strong); font-size: 10px; text-align: center; }

.workspace-panel { padding-top: 18px; }
.panel-toolbar { min-height: 46px; display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.toolbar-spacer { flex: 1; }
.search-field { width: min(320px, 32vw); height: 38px; padding: 0 10px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--muted); background: var(--surface); }
.search-field input { width: 100%; min-width: 0; border: 0; outline: 0; color: var(--ink); background: transparent; }
select { height: 38px; min-width: 126px; padding: 0 30px 0 10px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); background: var(--surface); }

.node-table-wrap, .event-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th { height: 42px; padding: 0 14px; color: var(--muted); background: var(--surface-alt); font-size: 11px; font-weight: 700; text-align: left; }
td { height: 58px; padding: 8px 14px; border-top: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
.node-table th:nth-child(2) { width: 40%; }
.node-table th:nth-child(3) { width: 130px; }
.node-table th:nth-child(4) { width: 120px; }
.node-table th:nth-child(5) { width: 160px; }
.check-cell { width: 50px; text-align: center; }
.action-cell { width: 86px; text-align: right; }
.node-name { min-width: 0; display: flex; align-items: center; gap: 8px; }
.node-name-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.current-label { padding: 2px 6px; border-radius: 999px; color: var(--blue); background: var(--blue-soft); font-size: 10px; font-weight: 700; }
.row-current { background: color-mix(in srgb, var(--blue-soft) 45%, var(--surface)); }
.candidate-check { width: 16px; height: 16px; accent-color: var(--teal); }
.node-health { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.node-health::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #98a2b3; }
.node-health.good { color: var(--teal); }
.node-health.good::before { background: var(--teal); }
.node-health.warn { color: var(--amber); }
.node-health.warn::before { background: var(--amber); }
.node-health.bad { color: var(--red); }
.node-health.bad::before { background: var(--red); }
.latency { font-variant-numeric: tabular-nums; font-weight: 650; }
.latency small { color: var(--muted); font-weight: 500; }
.row-action { display: inline-flex; justify-content: end; width: 100%; }
.row-action .icon-button { width: 34px; height: 34px; box-shadow: none; }
.empty-state { padding: 42px 20px; color: var(--muted); text-align: center; font-size: 13px; }

.policy-layout { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0 28px; }
.policy-section { padding: 8px 0 18px; border-bottom: 1px solid var(--line); }
.policy-section:nth-child(3) { grid-column: 1 / -1; }
.section-heading { min-height: 46px; display: flex; align-items: start; justify-content: space-between; }
.section-heading h2 { margin: 0; font-size: 15px; letter-spacing: 0; }
.section-heading span { color: var(--muted); font-size: 11px; }
.setting-row { min-height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-top: 1px solid var(--line); cursor: pointer; }
.setting-row > div { min-width: 0; display: grid; gap: 2px; }
.setting-row strong { font-size: 13px; }
.setting-row div span { color: var(--muted); font-size: 11px; }
.field-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
.field-grid.two-columns { grid-template-columns: repeat(2, minmax(0,1fr)); }
.field-grid label, .url-field { display: grid; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 650; }
.number-field { position: relative; }
.number-field input, .url-field input { width: 100%; height: 40px; border: 1px solid var(--line); border-radius: var(--radius); padding: 0 46px 0 11px; color: var(--ink); background: var(--surface); }
.number-field em { position: absolute; top: 12px; right: 11px; color: var(--muted); font-size: 11px; font-style: normal; }
.url-field { margin-top: 14px; }
.url-field input { padding-right: 11px; }
.policy-actions { grid-column: 1 / -1; min-height: 72px; display: flex; align-items: center; justify-content: end; gap: 18px; }
.policy-actions > span { color: var(--muted); font-size: 12px; }

.event-table th:nth-child(1) { width: 180px; }
.event-table th:nth-child(2) { width: 130px; }
.event-table th:nth-child(3) { width: 34%; }
.event-kind { display: inline-flex; padding: 3px 7px; border-radius: 999px; color: var(--muted); background: var(--surface-strong); font-size: 10px; font-weight: 700; }
.event-kind.switch, .event-kind.manual_switch { color: var(--blue); background: var(--blue-soft); }
.event-kind.rollback, .event-kind.error { color: var(--red); background: var(--red-soft); }
.event-kind.recovery { color: var(--teal); background: var(--teal-soft); }
.event-route { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-reason { color: var(--muted); }

.login-shell { min-height: 100vh; padding: 24px; display: grid; place-items: center; position: relative; }
.login-theme { position: fixed; top: 20px; right: 20px; }
.login-panel { width: min(400px, 100%); padding: 30px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 16px 48px rgba(23,32,51,.11); }
.login-logo { width: 52px; height: 52px; display: block; margin: 0 auto 18px; border-radius: 8px; }
.eyebrow { margin: 0; color: var(--teal); font-size: 10px; font-weight: 750; letter-spacing: 0; text-align: center; }
.login-panel h1 { margin: 5px 0 24px; font-size: 23px; letter-spacing: 0; text-align: center; }
.login-form { display: grid; gap: 9px; }
.login-form label { color: var(--muted); font-size: 12px; font-weight: 650; }
.login-form input { width: 100%; height: 42px; padding: 0 11px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); background: var(--surface); }
.password-field { position: relative; }
.password-field input { padding-right: 44px; }
.input-action { position: absolute; top: 2px; right: 2px; box-shadow: none; }
.form-error { min-height: 17px; margin: 0; color: var(--red); font-size: 11px; }

.confirm-dialog { width: min(430px, calc(100% - 32px)); padding: 0; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); background: var(--surface); box-shadow: 0 24px 80px rgba(0,0,0,.25); }
.confirm-dialog::backdrop { background: rgba(17,24,39,.48); }
.confirm-dialog form { padding: 24px; }
.confirm-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 7px; color: var(--amber); background: var(--amber-soft); }
.confirm-dialog h2 { margin: 16px 0 7px; font-size: 17px; letter-spacing: 0; }
.confirm-dialog p { min-height: 40px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.dialog-actions { margin-top: 22px; display: flex; justify-content: end; gap: 9px; }
.toast-region { position: fixed; z-index: 80; right: 18px; bottom: 18px; display: grid; gap: 8px; }
.toast { max-width: 360px; padding: 11px 13px; border: 1px solid var(--line); border-left: 3px solid var(--teal); border-radius: var(--radius); color: var(--ink); background: var(--surface); box-shadow: 0 10px 30px rgba(0,0,0,.16); font-size: 12px; }
.toast.error { border-left-color: var(--red); }
.is-spinning svg { animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .status-strip { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .status-item:nth-child(2) { border-right: 0; }
  .status-item:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .status-item:nth-child(3) { padding-left: 0; }
  .policy-layout { grid-template-columns: 1fr; }
  .policy-section:nth-child(3), .policy-actions { grid-column: 1; }
  .panel-toolbar { flex-wrap: wrap; }
  .toolbar-spacer { display: none; }
  .search-field { width: calc(100% - 136px); }
  .panel-toolbar .button { flex: 1; }
}

@media (max-width: 680px) {
  .header-inner { padding: 0 14px; }
  .header-actions .health-badge { display: none; }
  .content { padding: 14px 14px 36px; }
  .current-band { align-items: start; padding: 10px 0 16px; }
  .current-node strong { max-width: calc(100vw - 120px); font-size: 18px; }
  .mode-control { padding-left: 12px; }
  .mode-control > div { display: none; }
  .status-strip { min-height: 0; }
  .status-item { padding: 12px 10px; }
  .status-item:first-child, .status-item:nth-child(3) { padding-left: 0; }
  .status-icon { width: 28px; height: 28px; }
  .workspace-tabs { gap: 18px; overflow-x: auto; }
  .panel-toolbar { align-items: stretch; }
  .search-field { order: 0; width: 100%; }
  #node-filter { flex: 1; }
  #save-candidates, #probe-button { width: calc(50% - 5px); flex: none; }
  .node-table { min-width: 590px; }
  .optional-column, .node-table td:nth-child(5) { display: none; }
  .field-grid, .field-grid.two-columns { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .policy-actions { justify-content: space-between; }
  .event-table { min-width: 660px; }
  .toast-region { right: 12px; bottom: 12px; left: 12px; }
  .toast { max-width: none; }
}

@media (max-width: 410px) {
  .brand div { display: none; }
  .field-grid, .field-grid.two-columns { grid-template-columns: 1fr; }
  .status-item strong { font-size: 12px; }
}
