:root {
  color-scheme: light;
  --bg: #f0f9ff;
  --bg-strong: #e0f2fe;
  --surface: #ffffff;
  --surface-soft: #f7fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #dcebf4;
  --accent: #0284c7;
  --accent-dark: #0369a1;
  --accent-soft: #e0f2fe;
  --blue: #3478f6;
  --blue-soft: #eaf2ff;
  --purple: #7c3cff;
  --purple-soft: #f0e9ff;
  --yellow: #f59e0b;
  --yellow-soft: #fff4d8;
  --danger: #ff3b68;
  --danger-soft: #ffe8ee;
  --ok: #00a85a;
  --ok-soft: #dcfce7;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.075);
  --motion: 180ms ease;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  line-height: 1.4;
}

button,
input,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 100;
  transform: translateY(-150%);
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  padding: 10px 14px;
  font-weight: 800;
  text-decoration: none;
  transition: transform var(--motion);
}

.skip-link:focus {
  transform: translateY(0);
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

h1 {
  margin: 0 0 4px;
  font-size: 20px;
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.15;
  letter-spacing: 0;
}

h3 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0;
}

h4 {
  margin-bottom: 4px;
  font-size: 16px;
}

.app-shell {
  display: grid;
  grid-template-columns: 258px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  height: 100vh;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  padding: 18px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 0 14px 12px;
  border-bottom: 1px solid #eef2f6;
}

.brand-mark {
  display: inline-flex;
  width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #fff;
  color: var(--accent);
  font-weight: 900;
  box-shadow: 0 2px 12px rgba(2, 132, 199, 0.14);
}

.version-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 8px;
  background: #fff1c8;
  color: #b45309;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
}

.side-nav {
  display: grid;
  align-content: start;
  gap: 4px;
  overflow: auto;
  padding: 0 2px;
}

.nav-item,
.nav-link {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #223047;
  padding: 9px 15px;
  text-align: left;
  cursor: pointer;
  transition: background var(--motion), color var(--motion), border-color var(--motion), box-shadow var(--motion);
}

.nav-link {
  cursor: default;
}

.nav-item:hover,
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.nav-link:hover {
  background: #f8fafc;
}

.nav-icon {
  width: 20px;
  height: 20px;
}

.sidebar-footer {
  display: grid;
  gap: 8px;
  align-content: end;
  padding-top: 12px;
  border-top: 1px solid #eef2f6;
}

.side-section-title {
  padding: 0 14px;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 800;
}

.nav-link.compact {
  min-height: 44px;
}

.content {
  min-width: 0;
  padding: 0 24px 26px 30px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 18px;
  height: 65px;
  margin: 0 -24px 0 -30px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  padding: 0 22px 0 24px;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: grid;
  gap: 24px;
  padding-top: 32px;
}

.tab-panel.active > *,
.dashboard-grid > *,
.panel,
.table-wrap {
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: none;
}

.header-actions,
.actions,
.test-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.header-actions {
  justify-content: flex-end;
}

.decision-banner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px;
  gap: 18px;
  align-items: center;
  min-height: 128px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}

.decision-banner.safe {
  border-color: #c8f1df;
}

.decision-banner.medium {
  border-color: #fde68a;
}

.decision-banner.high {
  border-color: #fecdd3;
}

#decisionText {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
}

.decision-meter {
  display: grid;
  justify-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 14px;
  text-align: center;
}

.decision-meter strong {
  font-size: 36px;
  line-height: 1;
}

.decision-meter span:last-child {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 16px;
}

.stat-card {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 94px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px 16px;
}

.stat-card span:not(.stat-icon) {
  display: block;
  color: #52647d;
  font-size: 13px;
  font-weight: 700;
}

.stat-card strong {
  display: block;
  margin-top: 2px;
  font-size: 22px;
  line-height: 1.05;
}

.stat-card small {
  display: block;
  margin-top: 4px;
  color: var(--ok);
  font-size: 12px;
  font-weight: 750;
}

.stat-icon {
  display: inline-flex;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
}

.stat-icon .icon {
  width: 20px;
  height: 20px;
}

.stat-icon.blue {
  background: var(--blue-soft);
  color: var(--blue);
}

.stat-icon.purple {
  background: var(--purple-soft);
  color: var(--purple);
}

.stat-icon.green {
  background: var(--ok-soft);
  color: var(--ok);
}

.stat-icon.red {
  background: var(--danger-soft);
  color: var(--danger);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel-heading.compact {
  margin-bottom: 14px;
}

.quick-action-panel {
  padding: 16px;
}

.action-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 22px;
  align-items: center;
  gap: 12px;
  width: min(742px, 100%);
  min-height: 64px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--text);
  padding: 10px 14px;
  text-align: left;
  cursor: pointer;
  transition: background var(--motion), border-color var(--motion);
}

.action-row:hover {
  border-color: #c8f1ea;
  background: #f3fffc;
}

.action-row strong,
.action-row small {
  display: block;
}

.action-row small {
  color: var(--muted);
  font-size: 12px;
}

.action-chevron {
  justify-self: end;
  color: #94a3b8;
}

.chart-panel canvas {
  display: block;
  width: 100%;
  height: 320px;
  border: 0;
  border-radius: 0;
  background: #fff;
}

.api-test-panel {
  display: grid;
  gap: 10px;
}

.api-test-panel .panel-heading {
  margin-bottom: 0;
}

.api-test-panel .toast:empty {
  display: none;
}

.api-test-panel .advice-card {
  margin-top: 0;
}

.quick-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.quick-card {
  display: grid;
  gap: 5px;
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 13px 15px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--motion), background var(--motion);
}

.quick-card:hover {
  border-color: #b2ebe3;
}

.quick-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.quick-card strong {
  font-size: 17px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px;
}

label {
  display: grid;
  gap: 7px;
  color: #52647d;
  font-size: 13px;
  font-weight: 750;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 11px;
}

select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 11px;
}

input:focus {
  border-color: var(--accent);
  outline: 3px solid var(--accent-soft);
}

select:focus {
  border-color: var(--accent);
  outline: 3px solid var(--accent-soft);
}

input[type="range"] {
  min-height: 34px;
  padding: 0;
  accent-color: var(--accent);
}

.range-shell,
.secret-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  gap: 10px;
  align-items: center;
}

.secret-field {
  grid-template-columns: minmax(0, 1fr) 44px;
}

.range-shell output {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 850;
}

.span-2 {
  grid-column: 1 / -1;
}

.windows-section {
  margin-top: 24px;
}

.windows-list {
  display: grid;
  gap: 10px;
}

.window-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 86px;
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 12px;
}

.window-summary {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--motion), border-color var(--motion), color var(--motion), box-shadow var(--motion), opacity var(--motion);
}

.button {
  min-height: 44px;
  padding: 8px 14px;
}

.icon-button {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.button.primary:hover {
  background: var(--accent-dark);
}

.button.secondary {
  border-color: #d9e3ea;
  color: #0f172a;
}

.button.ghost {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.button.danger {
  border-color: #ffd5df;
  color: var(--danger);
}

.button:disabled,
.icon-button:disabled {
  cursor: progress;
  opacity: 0.62;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(2, 132, 199, 0.28);
  outline-offset: 2px;
}

.actions {
  margin-top: 20px;
}

.actions .button,
.header-actions .button,
.test-actions .button {
  min-width: 108px;
}

.toast {
  min-height: 22px;
  color: var(--muted);
  font-size: 14px;
}

.toast.ok {
  color: var(--ok);
}

.toast.err {
  color: var(--danger);
}

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100% - 36px));
  pointer-events: none;
}

.toast-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  color: var(--text);
  font-size: 14px;
  font-weight: 750;
}

.toast-item.ok {
  border-color: #b7e4d7;
}

.toast-item.err {
  border-color: #fecaca;
}

.badge,
.risk-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border-radius: 8px;
  padding: 5px 10px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.badge-muted {
  background: #eef2f6;
  color: var(--muted);
}

.badge-warn,
.risk-pill.medium {
  background: var(--yellow-soft);
  color: #b7791f;
}

.risk-pill.high {
  background: var(--danger-soft);
  color: var(--danger);
}

.risk-pill.low {
  background: var(--ok-soft);
  color: var(--ok);
}

.hidden {
  display: none;
}

.small-note {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.status-list div,
.metric-grid div {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 12px;
}

.status-list dt {
  color: var(--muted);
  font-weight: 750;
}

.status-list dd {
  margin: 0;
  font-weight: 850;
}

.advice-card {
  display: grid;
  gap: 7px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 16px;
}

.advice-card p {
  margin-bottom: 0;
  color: var(--muted);
}

.advice-card.high {
  border-color: #fecaca;
  background: #fff5f5;
}

.advice-card.medium {
  border-color: #fedf89;
  background: #fffbeb;
}

.advice-card.low {
  border-color: #b7e4d7;
  background: #f0fdf9;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.metric-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.metric-grid strong {
  font-size: 18px;
}

.raw-json {
  margin-top: 14px;
  color: var(--muted);
  font-size: 14px;
}

.raw-json summary {
  cursor: pointer;
  font-weight: 800;
}

.raw-json pre {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f172a;
  color: #e6edf3;
  padding: 12px;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 12px;
}

.table-wrap {
  overflow-x: auto;
}

.history-table {
  width: 100%;
  min-width: 660px;
  border-collapse: collapse;
}

.history-table th,
.history-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  white-space: nowrap;
}

.history-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.history-table td {
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .side-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
  }

  .sidebar-footer {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .side-section-title {
    grid-column: 1 / -1;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .stat-grid,
  .quick-strip,
  .filter-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}

.filter-panel {
  padding: 16px;
}

.filter-controls {
  display: grid;
  grid-template-columns: minmax(160px, 0.8fr) minmax(160px, 1fr) minmax(200px, 1.2fr) auto;
  gap: 12px;
  align-items: end;
}

.filter-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

@media (max-width: 760px) {
  .content {
    padding: 0 12px 22px;
  }

  .topbar {
    align-items: flex-start;
    height: auto;
    margin: 0 -12px;
    padding: 14px 12px;
  }

  .tab-panel.active {
    gap: 16px;
    padding-top: 18px;
  }

  .page-header {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .header-actions,
  .actions,
  .test-actions {
    align-items: stretch;
  }

  .header-actions .button,
  .actions .button,
  .test-actions .button {
    flex: 1 1 0;
  }

  .api-test-panel .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .decision-banner,
  .form-grid,
  .window-row,
  .metric-grid,
  .quick-strip,
  .filter-controls,
  .stat-grid,
  .status-list,
  .side-nav,
  .sidebar-footer {
    grid-template-columns: 1fr;
  }

  .stat-card {
    min-height: 86px;
  }

  .panel,
  .decision-banner {
    padding: 14px;
  }

  .filter-actions,
  .filter-actions .button {
    width: 100%;
  }

  .filter-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

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