:root {
  color-scheme: dark;
  --bg: #0c0f12;
  --sidebar: #111519;
  --panel: #161b20;
  --panel-raised: #1a2026;
  --surface: #20272e;
  --line: #2b333b;
  --line-soft: #222a31;
  --text: #eef2f4;
  --muted: #98a3ad;
  --blue: #58a6ff;
  --green: #3fb983;
  --amber: #e3b341;
  --red: #f47067;
  --violet: #b7a1ff;
  --cyan: #57d4d0;
  --shadow: 0 16px 44px rgba(0, 0, 0, 0.24);
}

* { box-sizing: border-box; }

html { min-width: 320px; }

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

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 20px 14px 16px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 48px;
  padding: 0 8px;
  margin-bottom: 22px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 8px;
  background: #f2f5f7;
  color: #080a0c;
  font-size: 18px;
  font-weight: 850;
}

.brand strong { display: block; font-size: 15px; white-space: nowrap; }
.brand small { display: block; margin-top: 4px; color: #6f7b85; font-size: 9px; }

.side-nav { display: grid; gap: 4px; }

.nav-item {
  display: grid;
  grid-template-columns: 26px 1fr;
  align-items: center;
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-item > span:first-child { color: #7f8b95; font-size: 17px; text-align: center; }
.nav-item:hover { background: #191f24; color: var(--text); }
.nav-item.active { background: #20272d; border-color: #343d45; color: #fff; }
.nav-item.active > span:first-child { color: var(--green); }

.sidebar-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  margin-top: auto;
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #59636c; }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 3px rgba(63, 185, 131, 0.12); }
.status-dot.error { background: var(--red); }

.workspace { min-width: 0; padding: 24px 28px 42px; }

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

.eyebrow { margin: 0 0 5px; color: var(--green); font-size: 10px; font-weight: 750; }
.topbar h1 { margin: 0; font-size: 24px; line-height: 1.2; }
.topbar p:last-child { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.button, .icon-button, .text-button, .close-button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
}

.button { min-height: 38px; padding: 0 13px; font-size: 13px; font-weight: 650; }
.button.primary { background: #23815a; border-color: #32976e; color: #fff; }
.button.primary:hover { background: #299365; }
.button.subtle { background: transparent; }
.button.danger { border-color: rgba(244, 112, 103, 0.55); background: rgba(244, 112, 103, 0.09); color: #ff9b94; }
.button.small { min-height: 30px; padding: 0 9px; font-size: 11px; }
.environment-button { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.button:disabled { opacity: 0.45; cursor: not-allowed; }

.icon-button, .close-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 19px;
}

.text-button { padding: 5px 0; border: 0; background: transparent; color: var(--blue); font-size: 12px; }
.close-button { border: 0; background: transparent; color: var(--muted); font-size: 24px; }

.view { display: none; }
.view.active { display: block; }

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metrics.compact { grid-template-columns: repeat(3, minmax(160px, 1fr)); }

.metric {
  min-height: 92px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric-label { color: var(--muted); font-size: 11px; }
.metric-value { display: block; margin-top: 9px; font-size: 25px; font-weight: 780; line-height: 1; }
.metric-meta { margin-top: 8px; color: #7f8b95; font-size: 10px; }
.metric-value.good { color: var(--green); }
.metric-value.warn { color: var(--amber); }
.metric-value.bad { color: var(--red); }
.metric-value.blue { color: var(--blue); }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.panel {
  min-width: 0;
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

.panel-head h2, .section-intro h2 { margin: 0; font-size: 15px; }
.panel-head p, .section-intro p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.account-head-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

.route-lanes {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px minmax(0, 1fr);
  align-items: stretch;
  gap: 9px;
}

.route-lane {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 12px;
  align-items: start;
  min-height: 112px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #12171b;
}

.api-lane { border-left: 3px solid var(--blue); }
.browser-lane { border-left: 3px solid var(--violet); }
.route-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 7px; background: var(--surface); font-weight: 800; }
.api-lane .route-icon { color: var(--blue); }
.browser-lane .route-icon { color: var(--violet); }
.route-lane h3 { margin: 1px 0 7px; font-size: 14px; }
.route-lane p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.7; }
.route-divider { display: grid; place-items: center; color: #66727b; font-size: 20px; }

.notice {
  margin-top: 13px;
  padding: 10px 12px;
  border-left: 3px solid var(--amber);
  border-radius: 5px;
  background: rgba(227, 179, 65, 0.08);
  color: #d8c99e;
  font-size: 11px;
  line-height: 1.6;
}

.distribution { display: grid; gap: 15px; }
.distribution-item { display: grid; gap: 7px; }
.distribution-line { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; }
.distribution-line strong { color: var(--text); }
.progress { height: 7px; overflow: hidden; border-radius: 4px; background: #272e34; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--blue); }
.progress.browser > span { background: var(--violet); }
.progress.ready > span { background: var(--green); }

.chip, .badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: max-content;
  min-height: 23px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 10px;
  white-space: nowrap;
}

.chip.neutral, .badge.neutral { color: #b8c1c8; background: #232a30; }
.chip.warning, .badge.needs_review, .badge.awaiting_confirmation { color: #f2cf75; background: rgba(227, 179, 65, 0.1); border-color: rgba(227, 179, 65, 0.3); }
.badge.success, .badge.active, .badge.ready { color: #7ed7ab; background: rgba(63, 185, 131, 0.1); border-color: rgba(63, 185, 131, 0.3); }
.badge.failed, .badge.action_required, .badge.missing { color: #ff9b94; background: rgba(244, 112, 103, 0.1); border-color: rgba(244, 112, 103, 0.3); }
.badge.queued, .badge.running { color: #93c5ff; background: rgba(88, 166, 255, 0.1); border-color: rgba(88, 166, 255, 0.3); }
.badge.cancelled, .badge.disabled { color: #aab3bb; background: rgba(152, 163, 173, 0.09); }
.badge.api { color: #93c5ff; background: rgba(88, 166, 255, 0.1); border-color: rgba(88, 166, 255, 0.3); }
.badge.browser { color: #cabfff; background: rgba(183, 161, 255, 0.1); border-color: rgba(183, 161, 255, 0.3); }

.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line-soft); border-radius: 7px; }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 6px; min-height: 32px; margin-top: 12px; flex-wrap: wrap; }
.pagination .button { min-width: 34px; height: 32px; padding: 0 10px; }
.pagination .button:disabled { opacity: 0.4; cursor: not-allowed; }
table { width: 100%; min-width: 940px; border-collapse: collapse; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: middle; font-size: 12px; }
th { background: #13181d; color: #aeb8c0; font-size: 10px; font-weight: 680; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255, 255, 255, 0.018); }
.accounts-table { min-width: 990px; }
.x-cards-table { min-width: 930px; }
.selection-summary { color: var(--muted); }
.x-card-cell { display: grid; grid-template-columns: 54px minmax(180px, 1fr); align-items: center; gap: 10px; min-width: 300px; }
.x-card-thumb { width: 54px; height: 36px; border: 1px solid var(--line); border-radius: 5px; background: #0d1115; object-fit: cover; }
.x-card-title { display: block; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.x-card-meta { margin-top: 4px; color: var(--muted); font-size: 10px; }
.selection-cell { width: 42px; padding-inline: 12px; text-align: center; }
.selection-checkbox {
  width: 16px;
  min-width: 16px;
  height: 16px;
  min-height: 16px;
  padding: 0;
  border-radius: 4px;
  accent-color: var(--green);
  cursor: pointer;
}
.selected-row { background: rgba(63, 185, 131, 0.055); }
.button-spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  margin-right: 3px;
  border: 2px solid rgba(238, 242, 244, 0.35);
  border-top-color: var(--text);
  border-radius: 50%;
  vertical-align: -2px;
  animation: button-spin 0.8s linear infinite;
}
@keyframes button-spin { to { transform: rotate(360deg); } }
.task-copy { display: block; max-width: 310px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.id-text { color: #84909a; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; }
.muted { color: var(--muted); }
.actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) 170px 170px; gap: 8px; margin-bottom: 12px; }
input, select, textarea {
  width: 100%;
  min-height: 38px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: 0;
  background: #11161a;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { border-color: #4b8fcc; box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.1); }
textarea { min-height: 100px; resize: vertical; }
input[type="file"] { padding: 7px 9px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 11px; }
.field-inline { display: grid; grid-template-columns: minmax(0, 1fr) 38px; gap: 8px; }

.content-grid { display: grid; gap: 14px; }
.content-grid.two-column { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-stack { display: grid; gap: 12px; }
.span-all { grid-column: 1 / -1; }

.rule-list { display: grid; gap: 8px; }
.rule { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 68px; padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: #12171b; }
.rule strong { font-size: 12px; }
.rule p { margin: 5px 0 0; color: var(--muted); font-size: 10px; }
.switch { position: relative; width: 38px; height: 21px; flex: 0 0 38px; border-radius: 11px; background: #343c44; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: #dce2e7; }
.switch.on { background: #277b58; }
.switch.on::after { left: 20px; }
.result-box, .route-preview { margin-top: 12px; padding: 13px; border: 1px dashed #3b4852; border-radius: 7px; background: #11161a; color: var(--muted); font-size: 12px; line-height: 1.7; }
.result-box strong, .route-preview strong { color: var(--text); }
.route-preview { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 0; }
.x-card-preview { display: grid; grid-template-columns: 112px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: #11161a; }
.x-card-preview[hidden] { display: none; }
.x-card-preview img { width: 112px; height: 59px; border-radius: 5px; object-fit: cover; background: #0d1115; }
.x-card-preview strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.x-card-preview p { margin: 5px 0 0; color: var(--muted); font-size: 10px; }

.section-intro { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.node-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.node-card { min-height: 174px; padding: 15px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); box-shadow: var(--shadow); }
.node-card-head { display: flex; align-items: start; justify-content: space-between; gap: 10px; margin-bottom: 20px; }
.node-card h3 { margin: 0; font-size: 14px; }
.node-card p { margin: 6px 0 0; color: var(--muted); font-size: 11px; }
.node-stat { display: flex; justify-content: space-between; gap: 12px; margin-top: 9px; color: var(--muted); font-size: 11px; }

.cost-results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.cost-item { min-height: 90px; padding: 13px; border: 1px solid var(--line); border-radius: 7px; background: #12171b; }
.cost-item span { color: var(--muted); font-size: 11px; }
.cost-item strong { display: block; margin-top: 10px; font-size: 22px; }

.list-stack { display: grid; gap: 8px; }
.list-item { display: grid; grid-template-columns: minmax(180px, 0.7fr) minmax(240px, 1fr) auto; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: #12171b; }
.list-item strong { font-size: 12px; }
.list-item p { margin: 5px 0 0; color: var(--muted); font-size: 10px; }
.list-item time { color: #7e8992; font-size: 10px; white-space: nowrap; }
.empty-state { padding: 34px 16px; color: var(--muted); text-align: center; font-size: 12px; }

.modal { position: fixed; inset: 0; z-index: 30; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(0, 0, 0, 0.72); }
.modal.show { display: flex; }
.modal-box { width: min(620px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; padding: 18px; border: 1px solid #3a444d; border-radius: 8px; background: #161b20; box-shadow: 0 28px 80px rgba(0, 0, 0, 0.5); }
.wide-modal { width: min(760px, 100%); }
.compact-modal { width: min(440px, 100%); }
.modal-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-head p { margin: 6px 0 0; color: var(--muted); font-size: 11px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.check-group { display: grid; align-content: center; gap: 8px; }
.check { display: flex; grid-template-columns: none; align-items: center; gap: 8px; color: var(--text); }
.check input { width: 16px; min-height: 16px; height: 16px; accent-color: var(--green); }

.security-notice {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid rgba(63, 185, 131, 0.34);
  border-radius: 7px;
  background: rgba(63, 185, 131, 0.08);
  color: #b9d7c9;
  font-size: 11px;
  line-height: 1.55;
}
.security-notice strong { color: #7ed7ab; white-space: nowrap; }
.import-summary { min-height: 38px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 7px; background: #11161a; color: var(--muted); font-size: 11px; line-height: 1.55; }
.import-preview { display: grid; max-height: 240px; overflow-y: auto; border: 1px solid var(--line-soft); border-radius: 7px; }
.import-preview:empty { display: none; }
.import-preview-row { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr); gap: 12px; padding: 9px 11px; border-bottom: 1px solid var(--line-soft); font-size: 11px; }
.import-preview-row:last-child { border-bottom: 0; }
.import-preview-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.import-preview-row span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.import-preview-more { padding: 9px 11px; color: var(--muted); font-size: 11px; }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 60; display: none; max-width: min(420px, calc(100vw - 40px)); padding: 11px 13px; border: 1px solid #3a454e; border-radius: 7px; background: #1c2329; color: var(--text); box-shadow: var(--shadow); font-size: 12px; }
.toast.show { display: block; }
.toast.error { border-color: rgba(244, 112, 103, 0.55); }

.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; }

#tasksTable .actions { min-width: 88px; }
#tasksTable .actions .button { white-space: nowrap; }
#tasksTable td:nth-child(4) { min-width: 78px; white-space: nowrap; }

@media (max-width: 1180px) {
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .node-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 76px minmax(0, 1fr); }
  .sidebar { padding-inline: 9px; }
  .brand { justify-content: center; padding: 0; }
  .brand > span:last-child, .sidebar-foot span:last-child, .nav-item > span:last-child { display: none; }
  .nav-item { grid-template-columns: 1fr; padding: 0; text-align: center; }
  .workspace { padding: 20px; }
  .dashboard-grid, .content-grid.two-column { grid-template-columns: 1fr; }
  .route-summary { min-height: 220px; }
}

@media (max-width: 700px) {
  .app-shell { display: block; }
  .sidebar { position: sticky; z-index: 20; display: block; width: 100%; height: auto; padding: 8px 10px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand, .sidebar-foot { display: none; }
  .side-nav { display: flex; gap: 5px; overflow-x: auto; scrollbar-width: none; }
  .side-nav::-webkit-scrollbar { display: none; }
  .nav-item { display: flex; grid-template-columns: none; width: auto; min-width: max-content; min-height: 36px; padding: 0 10px; gap: 6px; font-size: 11px; }
  .nav-item > span:last-child { display: inline; }
  .workspace { padding: 16px 12px 34px; }
  .topbar { align-items: flex-start; margin-bottom: 16px; }
  .topbar h1 { font-size: 21px; }
  .top-actions .button.primary { display: none; }
  .metrics, .metrics.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .route-lanes { grid-template-columns: 1fr; }
  .route-divider { min-height: 24px; transform: rotate(90deg); }
  .toolbar { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .span-all { grid-column: 1; }
  .node-grid { grid-template-columns: 1fr; }
  .list-item { grid-template-columns: 1fr; }
  .x-card-preview { grid-template-columns: 82px minmax(0, 1fr); }
  .x-card-preview img { width: 82px; height: 44px; }
  .x-card-preview .button { grid-column: 1 / -1; }
}

@media (max-width: 430px) {
  .cost-results { grid-template-columns: 1fr; }
  .topbar { display: grid; }
  .top-actions { justify-content: flex-start; }
  .panel { padding: 13px; }
}

#view-tasks > .panel > .toolbar { grid-template-columns: minmax(0, 1fr); }
#view-tasks .panel-head { flex-wrap: wrap; }
#view-tasks .task-status-heading { min-width: 166px; padding-block: 7px; }
#taskFilter { min-height: 32px; font-size: 11px; padding: 6px 8px; }
#originalRetryFailedTasks, #randomRetryFailedTasks { min-width: 144px; white-space: nowrap; }
@media (max-width: 700px) {
  #view-tasks .panel-head > .account-head-actions { width: 100%; justify-content: flex-start; }
}
