:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #eef2f5;
  --line: #d8e0e7;
  --text: #16202a;
  --muted: #667684;
  --accent: #167a72;
  --accent-strong: #0f5f59;
  --danger: #b42318;
  --warning: #a15c00;
  --good: #117044;
  --focus: #2563eb;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  padding: 0 12px;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  text-decoration: none;
}

button:hover {
  border-color: #9fb0bf;
}

.button-link:hover {
  border-color: #9fb0bf;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
}

input:focus,
select:focus,
button:focus {
  outline: 2px solid rgba(37, 99, 235, 0.18);
  border-color: var(--focus);
}

.app-shell {
  min-height: 100vh;
}

.loading {
  padding: 48px;
  color: var(--muted);
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-box {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-box h1 {
  margin: 0 0 20px;
  font-size: 24px;
}

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  min-width: 0;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #17212b;
  color: #f7fafc;
  padding: 20px 14px;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  padding: 0 8px 18px;
}

.nav-toggle,
.nav-close,
.nav-backdrop {
  display: none;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav button {
  justify-content: flex-start;
  width: 100%;
  border-color: transparent;
  background: transparent;
  color: #d8e2ec;
  text-align: left;
  padding: 0 12px;
}

.nav button.active {
  background: #253241;
  color: #ffffff;
}

.main {
  min-width: 0;
  padding: 24px;
}

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

.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.run-controls {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
}

.run-controls button {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

.run-controls .status {
  flex: 1 0 100%;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 18px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.panel h2,
.panel h3 {
  margin: 0 0 14px;
  font-size: 16px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-height: 36px;
  margin-bottom: 14px;
}

.panel-heading h2 {
  margin: 0;
  line-height: 36px;
}

.grid {
  display: grid;
  gap: 16px;
}

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

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

.metric {
  min-height: 92px;
  display: grid;
  align-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  font-size: 22px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.segmented button {
  min-width: 78px;
  border: 0;
  border-radius: 0;
  background: #fff;
}

.segmented button.active {
  background: var(--accent);
  color: #fff;
}

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

.primary:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.danger {
  border-color: #f1b8b2;
  background: #fff5f3;
  color: var(--danger);
}

.ghost {
  background: var(--surface-muted);
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 13px;
  background: var(--surface-muted);
  color: var(--muted);
  max-width: 100%;
  line-height: 1.35;
}

.status.good {
  background: #dcfce7;
  color: var(--good);
}

.status.warn {
  background: #fff4d6;
  color: var(--warning);
}

.status.bad {
  background: #fee4e2;
  color: var(--danger);
}

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

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  background: #fff;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  background: #f8fafc;
}

tr:last-child td {
  border-bottom: 0;
}

.row-actions {
  display: inline-flex;
  gap: 6px;
}

.icon-btn {
  width: 34px;
  min-width: 34px;
  padding: 0;
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  min-width: min(380px, calc(100vw - 36px));
  border-radius: 8px;
  padding: 12px 14px;
  background: #17212b;
  color: #fff;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.mono {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.positive {
  color: var(--good);
}

.negative {
  color: var(--danger);
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(300px, calc(100vw - 48px));
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom: 0;
    padding: 18px 14px;
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: 16px 0 36px rgba(15, 23, 42, 0.24);
  }

  .layout.nav-open .sidebar {
    transform: translateX(0);
  }

  .nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 25;
    display: none;
    border: 0;
    border-radius: 0;
    background: rgba(15, 23, 42, 0.42);
    padding: 0;
  }

  .layout.nav-open .nav-backdrop {
    display: block;
  }

  .brand {
    padding: 0;
  }

  .brand-row {
    min-height: 42px;
    margin-bottom: 18px;
    padding: 0 2px 0 8px;
  }

  .nav-toggle,
  .nav-close {
    display: inline-flex;
  }

  .nav-close {
    border-color: rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
  }

  .nav {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .nav button {
    justify-content: flex-start;
    min-height: 44px;
    text-align: left;
  }

  .main {
    padding: 16px;
  }

  .grid.two,
  .grid.three,
  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  button,
  .button-link,
  input,
  select {
    min-height: 42px;
  }

  .login-page {
    align-items: start;
    padding: 16px;
    padding-top: 48px;
  }

  .login-box {
    padding: 20px;
  }

  .sidebar {
    padding: 16px 12px;
  }

  .brand {
    font-size: 16px;
  }

  .nav {
    display: grid;
    gap: 6px;
  }

  .nav button {
    min-width: 0;
    padding: 0 10px;
  }

  .main {
    padding: 14px;
  }

  .topbar {
    display: grid;
    gap: 10px;
    margin-bottom: 14px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .topbar .toolbar {
    justify-content: flex-start;
  }

  .panel {
    padding: 14px;
  }

  .metric {
    min-height: 74px;
    padding: 12px;
  }

  .metric strong {
    font-size: 20px;
  }

  .toolbar button,
  .toolbar .button-link {
    flex: 0 1 auto;
    justify-content: center;
    text-align: center;
  }

  .run-controls button {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
  }

  .run-controls .status {
    flex: 1 0 100%;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions .status {
    flex: 0 1 auto;
  }

  .topbar-actions button,
  .panel-heading button,
  .row-actions button {
    flex: 0 0 auto;
  }

  .status {
    min-height: 30px;
    white-space: normal;
  }

  table {
    min-width: 560px;
  }

  th,
  td {
    height: 44px;
    padding: 8px;
  }

  table[data-strategy] {
    min-width: 420px;
  }

  table[data-strategy] th:first-child,
  table[data-strategy] td:first-child {
    width: 44px;
  }

  table[data-strategy] th:last-child,
  table[data-strategy] td:last-child {
    width: 58px;
  }

  table[data-strategy] select,
  table[data-strategy] input {
    min-width: 88px;
  }

  .toast {
    right: 12px;
    bottom: 12px;
    min-width: 0;
    width: calc(100vw - 24px);
  }
}

@media (max-width: 420px) {
  .main {
    padding: 10px;
  }

  .sidebar {
    padding: 12px 10px;
  }

  .panel {
    padding: 12px;
  }

  .grid {
    gap: 12px;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .toolbar {
    gap: 6px;
  }

  .toolbar button,
  .toolbar .button-link {
    width: 100%;
  }

  .run-controls button {
    width: auto;
  }

  .topbar-actions button,
  .topbar .status,
  .panel-heading button,
  .row-actions button {
    width: auto;
  }

  .metric {
    min-height: 68px;
  }

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