/* 网页版样式：与原生界面的两套配色一一对应。
   主题三态走 <html data-theme>：system 跟随系统，light/dark 强制。 */

:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --hover: #eef1f6;
  --pressed: #e2e7f0;
  --line: #d9dfea;
  --text: #2c313a;
  --muted: #5f6774;
  --accent: #2f80ed;
  --accent-fg: #ffffff;
  --danger: #d92d20;
  --warning: #b45309;
  --success: #15803d;
  --shadow: 0 18px 50px rgba(16, 24, 40, 0.18);
  --radius: 6px;
  --mono: 'Cascadia Mono', Consolas, 'Courier New', monospace;
}

html[data-theme='dark'] {
  --bg: #0d1017;
  --panel: #1a2030;
  --hover: #242c40;
  --pressed: #2d3750;
  --line: #37445c;
  --text: #eef1f7;
  --muted: #aab5c9;
  --accent: #d9b25e;
  --accent-fg: #161a23;
  --danger: #f87171;
  --warning: #fbbf24;
  --success: #4ade80;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
}

@media (prefers-color-scheme: dark) {
  html[data-theme='system'] {
    --bg: #0d1017;
    --panel: #1a2030;
    --hover: #242c40;
    --pressed: #2d3750;
    --line: #37445c;
    --text: #eef1f7;
    --muted: #aab5c9;
    --accent: #d9b25e;
    --accent-fg: #161a23;
    --danger: #f87171;
    --warning: #fbbf24;
    --success: #4ade80;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }

/* hidden 属性必须压过组件自己的 display（.card/.empty 都是 flex），
   否则"求解中…"和空态提示会一直显示在结果上面。 */
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei',
    'PingFang SC', 'Hiragino Sans GB', sans-serif;
  overflow: hidden;
}

.app { height: 100%; display: flex; flex-direction: column; }

/* ------------------------------------------------------------------ 顶栏 */

.topbar {
  flex: none;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.logo { font-weight: 700; font-size: 15px; color: var(--accent); }
.title { font-weight: 600; font-size: 15px; }
.actions { display: flex; align-items: center; gap: 8px; }

/* ------------------------------------------------------------------ 通用 */

.badge {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--hover);
  white-space: nowrap;
}
.badge.muted { color: var(--muted); }

.btn {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover { background: var(--hover); }
.btn:active { background: var(--pressed); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.ghost { background: transparent; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.input {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 9px;
  width: 100%;
  min-width: 0;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.row { display: flex; align-items: center; gap: 6px; }
.row.gap8 { gap: 8px; }
.row.gap12 { gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }

.hint { color: var(--muted); font-size: 12px; margin: 2px 0; }
.strong { font-weight: 600; }
.warn-text { color: var(--warning); font-size: 12px; }

.divider { height: 1px; background: var(--line); margin: 2px 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}
.card-head > span:first-child { flex: 1 1 auto; }

/* ------------------------------------------------------------------ 布局 */

.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 0;
}

.sidebar {
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
  border-right: 1px solid var(--line);
}

.main {
  min-height: 0;
  overflow: hidden;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ------------------------------------------------------------------ 表单 */

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: 12px; color: var(--muted); }

.target-group { display: flex; flex-direction: column; gap: 6px; }
.group-head { display: flex; align-items: center; gap: 8px; }
.group-head .field-label { flex: 1 1 auto; }

.chips { display: flex; flex-direction: column; gap: 6px; }

.chip {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--hover);
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.chip.locked { border-color: var(--warning); background: color-mix(in srgb, var(--warning) 12%, var(--panel)); }
.chip-text { font-size: 13px; word-break: break-word; }
.chip-row { display: flex; align-items: center; gap: 6px; }
.chip-row select { width: 116px; flex: none; }
.chip-row .spacer { flex: 1 1 auto; }

.check { display: flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--accent); }

.advanced > summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  padding: 4px 0;
}
.advanced-body { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; }

/* ------------------------------------------------------------------ 结果 */

.empty {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
}

.loading-card { flex: none; flex-direction: row; align-items: center; gap: 12px; }

.spinner {
  width: 18px; height: 18px; flex: none;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.alert {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  background: var(--hover);
}
.alert.danger { border-color: var(--danger); }
.alert-title { font-weight: 600; color: var(--danger); font-size: 13px; }
.alert-body {
  margin: 4px 0 0;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 160px;
  overflow: auto;
  font-family: var(--mono);
}

.result { flex: 1 1 auto; min-height: 0; gap: 8px; }

.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.result-base { font-weight: 600; font-size: 15px; }
.result-meta { color: var(--muted); font-size: 12px; }

.targets { display: flex; flex-wrap: wrap; gap: 6px; }
.target {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--hover);
  border: 1px solid var(--line);
}
.target.prefix { color: var(--accent); }
.target.suffix { color: var(--warning); }

.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0;
  flex: none;
}
.tab {
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 7px 12px;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.panes { flex: 1 1 auto; min-height: 0; display: flex; }
.pane { flex: 1 1 auto; min-height: 0; overflow: auto; padding-top: 8px; }
.pane[hidden] { display: none; }

/* ------------------------------------------------------------------ 表格 */

table { border-collapse: collapse; width: 100%; font-size: 13px; }
table.fixed { table-layout: fixed; }
th {
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding: 7px 8px;
  position: sticky;
  top: 0;
  background: var(--panel);
}
td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: var(--hover); cursor: pointer; }
tbody tr.selected { background: color-mix(in srgb, var(--accent) 18%, var(--panel)); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.muted, span.muted { color: var(--muted); }
.nowrap { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.table-wrap { min-height: 0; overflow: auto; flex: 1 1 auto; border: 1px solid var(--line); border-radius: var(--radius); }
.table-wrap table { min-width: 100%; }

/* ------------------------------------------------------------------ 步骤/前置/参考 */

.metrics {
  display: flex;
  gap: 28px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--hover);
  margin-bottom: 10px;
}
.metric-label { font-size: 12px; color: var(--muted); }
.metric-value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }

.steps { margin: 0; padding-left: 0; list-style: none; }
.steps li { display: flex; gap: 8px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.steps .idx { font-weight: 600; width: 20px; flex: none; }
.steps .step-text { flex: 1 1 auto; }
.steps .step-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }

.note {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--hover);
  padding: 9px 12px;
  font-size: 12.5px;
  color: var(--muted);
  margin: 10px 0;
  line-height: 1.7;
}

.section-title { font-size: 13px; font-weight: 600; margin: 16px 0 6px; }
.section-title:first-child { margin-top: 0; }

.issue-list { margin: 4px 0 0; padding-left: 18px; font-size: 12.5px; }
.issue-list li { margin: 3px 0; }
.issue-item { font-weight: 600; }
.issue-facts { margin: 3px 0 0; padding: 0; list-style: none; font-size: 12px; color: var(--muted); }
.issue-facts .k { display: inline-block; min-width: 7em; }

.route-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.route-title { font-size: 15px; font-weight: 600; margin: 0; }

/* ------------------------------------------------------------------ 对话框 */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 20;
}
.backdrop[hidden] { display: none; }

.dialog {
  width: min(820px, 100%);
  max-height: min(700px, 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--shadow);
  padding: 14px;
  overflow: hidden;
}
.dialog.wide { width: min(960px, 100%); }
.dialog.narrow { width: min(680px, 100%); }

.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dialog-head h3 { margin: 0; font-size: 15px; }

.dialog-body { min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.dialog-body.scroll { overflow: auto; }
.dialog-body.two-col { flex-direction: row; gap: 0; flex: 1 1 auto; }
.dialog-body.two-col .col-list {
  width: 216px;
  flex: none;
  overflow: auto;
  border-right: 1px solid var(--line);
  padding-right: 10px;
}
.dialog-body.two-col .col-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-left: 12px;
}

.class-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 13px;
  cursor: pointer;
}
.class-item:hover { background: var(--hover); }
.class-item.active { background: color-mix(in srgb, var(--accent) 18%, var(--panel)); color: var(--accent); }
.class-item .count { margin-left: auto; font-size: 11px; color: var(--muted); }
.class-group-title { font-size: 12px; font-weight: 600; color: var(--muted); padding: 9px 8px 3px; }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.segmented button {
  font: inherit;
  font-size: 13px;
  padding: 5px 14px;
  border: none;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
}
.segmented button.active { background: var(--accent); color: var(--accent-fg); font-weight: 600; }

.dialog-foot { display: flex; align-items: center; gap: 8px; }

.about-row { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; }
.about-row .k { width: 72px; flex: none; color: var(--muted); font-size: 12px; }
.about-row .v { flex: 1 1 auto; word-break: break-all; }
.mono { font-family: var(--mono); font-size: 12px; }

/* ------------------------------------------------------------------ 提示条 */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 40;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: pop 0.16s ease-out;
  max-width: 70vw;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line); max-height: 46vh; }
}
