/* AutoTune 手机端 · 深色工业风（与桌面端同一套品牌色） */

:root {
  --bg: #0b0f14;
  --bg-soft: #0f1620;
  --panel: #131c26;
  --panel-2: #16202b;
  --line: #223040;
  --text: #e8eef5;
  --muted: #8fa1b3;
  --accent: #22d3ee;
  --accent-dim: rgba(34, 211, 238, .14);
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
  --tap: 46px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC",
        "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: none;
}

body {
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}

/* -- 顶栏 ---------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: linear-gradient(180deg, #0d141c 0%, rgba(13, 20, 28, .94) 100%);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.mark {
  display: grid; place-items: center;
  width: 34px; height: 34px; flex: 0 0 34px;
  border-radius: 10px;
  background: var(--accent-dim);
  border: 1px solid rgba(34, 211, 238, .3);
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 15px; letter-spacing: .3px; }
.brand-text small { font-size: 11px; color: var(--muted); }

.badge {
  flex: 0 0 auto;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-idle { color: var(--muted); background: #1a2531; border-color: var(--line); }
.badge-ok { color: #06251d; background: var(--ok); }
.badge-busy { color: #06222b; background: var(--accent); }
.badge-warn { color: #2b1d02; background: var(--warn); }
.badge-err { color: #2b0b0b; background: var(--danger); }

/* -- 步骤条 -------------------------------------------------------------- */
.steps {
  position: sticky;
  top: calc(56px + env(safe-area-inset-top));
  z-index: 25;
  display: flex;
  gap: 8px;
  padding: 9px 14px;
  overflow-x: auto;
  background: rgba(11, 15, 20, .95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  scrollbar-width: none;
}
.steps::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
}
.chip.done { color: var(--ok); border-color: rgba(52, 211, 153, .45); }
.chip.live { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }

/* -- 卡片 ---------------------------------------------------------------- */
main { padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 12px; }

.card {
  position: relative;
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.card.locked { opacity: .5; }
.card.locked::after {
  content: "请先完成上一步";
  position: absolute; inset: 0;
  display: grid; place-items: center;
  border-radius: var(--radius);
  background: rgba(11, 15, 20, .5);
  color: var(--muted);
  font-size: 12.5px;
  pointer-events: none;
}
.card h2 {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 8px;
  font-size: 15.5px;
  font-weight: 700;
}
.card .num {
  display: grid; place-items: center;
  width: 22px; height: 22px;
  border-radius: 7px;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 12px;
}
.hint { margin: 0 0 12px; color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.hint strong { color: var(--text); }

/* -- 能力提示 ------------------------------------------------------------ */
.caps { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.cap {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  border: 1px solid var(--line);
  background: #10192300;
  color: var(--muted);
}
.cap.yes { color: var(--ok); border-color: rgba(52, 211, 153, .35); }
.cap.no { color: var(--danger); border-color: rgba(248, 113, 113, .3); }

/* -- 链路选择 ------------------------------------------------------------ */
.link-grid { display: flex; flex-direction: column; gap: 9px; }
.link-opt {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  width: 100%;
  min-height: var(--tap);
  padding: 12px 13px;
  text-align: left;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font-family: inherit;
}
.link-opt:active { border-color: var(--accent); background: var(--accent-dim); }
.link-opt strong { font-size: 14px; }
.link-opt small { color: var(--muted); font-size: 11.5px; }
.link-opt .pill {
  position: absolute; top: 10px; right: 11px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--accent-dim); color: var(--accent);
  font-size: 10.5px; font-style: normal; font-weight: 600;
}
.link-opt-form input {
  width: 100%;
  margin: 8px 0 8px;
  padding: 0 11px;
  min-height: 40px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #0a1119;
  color: var(--text);
  font: 13px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.link-opt-form input:focus { outline: none; border-color: var(--accent); }

/* -- 按钮 ---------------------------------------------------------------- */
.btn {
  width: 100%;
  min-height: var(--tap);
  margin: 4px 0 0;
  padding: 0 16px;
  border-radius: 11px;
  border: none;
  background: var(--accent);
  color: #052a33;
  font: 600 14.5px inherit;
  font-family: inherit;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .38; }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
.btn-sm {
  width: auto;
  min-height: 40px;
  margin: 0;
  padding: 0 18px;
  font-size: 13.5px;
}

/* -- 表单 ---------------------------------------------------------------- */
.field { margin: 14px 0 10px; }
.field > label {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 9px;
  font-size: 12.5px; color: var(--muted);
}
.field output { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 26px; background: transparent;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 5px; border-radius: 3px; background: #22303f;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 24px; height: 24px; margin-top: -10px;
  border-radius: 50%; background: var(--accent);
  border: 3px solid #0b0f14;
}
input[type=range]::-moz-range-track { height: 5px; border-radius: 3px; background: #22303f; }
input[type=range]::-moz-range-thumb {
  width: 22px; height: 22px; border: 3px solid #0b0f14;
  border-radius: 50%; background: var(--accent);
}

.seg { display: flex; gap: 7px; }
.seg-item {
  flex: 1;
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--muted);
  font: 600 13.5px inherit;
  font-family: inherit;
}
.seg-item.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.check {
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 12.5px; line-height: 1.5; color: var(--muted);
}
.check input {
  flex: 0 0 20px; width: 20px; height: 20px; margin: 0;
  accent-color: var(--accent);
}
.check strong { color: var(--text); }

.safety {
  padding: 11px 12px;
  margin-bottom: 6px;
  border-radius: 11px;
  background: rgba(251, 191, 36, .08);
  border: 1px solid rgba(251, 191, 36, .28);
}

.warnbox {
  padding: 11px 12px;
  margin-bottom: 10px;
  border-radius: 11px;
  background: rgba(248, 113, 113, .09);
  border: 1px solid rgba(248, 113, 113, .32);
  font-size: 12.5px;
}
.warnbox > strong { display: block; color: var(--danger); margin-bottom: 4px; }
.warnbox > span { display: block; color: var(--muted); margin-bottom: 9px; word-break: break-all; }

/* -- 数据展示 ------------------------------------------------------------ */
.kv { margin-top: 12px; display: flex; flex-direction: column; gap: 1px; }
.kv:empty { display: none; }
.kv .row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 0;
  border-bottom: 1px dashed rgba(34, 48, 64, .8);
  font-size: 13px;
}
.kv .row:last-child { border-bottom: none; }
.kv .k { color: var(--muted); flex: 0 0 auto; }
.kv .v { text-align: right; font-variant-numeric: tabular-nums; word-break: break-all; }
.kv .v.ok { color: var(--ok); }
.kv .v.warn { color: var(--warn); }
.kv .v.err { color: var(--danger); }

.chart {
  display: block;
  width: 100%;
  margin-top: 12px;
  border-radius: 11px;
  background: #0a1119;
  border: 1px solid var(--line);
}

.axes { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.axis-row {
  display: grid;
  grid-template-columns: 34px repeat(3, 1fr);
  gap: 7px;
  align-items: center;
  padding: 9px 10px;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  font-size: 12.5px;
}
.axis-row .name { color: var(--muted); font-weight: 600; }
.axis-row .g { text-align: center; font-variant-numeric: tabular-nums; }
.axis-row .g b { display: block; color: var(--accent); font-size: 14px; }
.axis-row .g i { font-style: normal; color: var(--muted); font-size: 10.5px; }

.table-wrap { margin-top: 12px; overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.tbl th, .tbl td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tbl th { color: var(--muted); font-weight: 600; text-align: right; }
.tbl th:first-child, .tbl td:first-child { text-align: left; font-family: ui-monospace, Menlo, monospace; }
.tbl tr.hi td { color: var(--warn); }

.row-actions { display: flex; gap: 9px; margin-top: 12px; }
.row-actions .btn { margin: 0; }

/* -- 授权卡片 ------------------------------------------------------------ */
.lic-box {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.lic-box > summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  list-style: none;
  padding: 2px 0;
}
.lic-box > summary::-webkit-details-marker { display: none; }
.lic-box > summary::before { content: '▸ '; }
.lic-box[open] > summary::before { content: '▾ '; }
.lic-box textarea {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 10px 11px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
  box-sizing: border-box;
}
.lic-box textarea:focus { outline: none; border-color: var(--accent); }
.lic-box .btn { margin-top: 10px; }
#license-out .v { font-size: 12.5px; }

.bar {
  height: 5px;
  margin-top: 12px;
  border-radius: 3px;
  background: #1a2531;
  overflow: hidden;
}
.bar i {
  display: block; height: 100%; width: 0;
  border-radius: 3px;
  background: linear-gradient(90deg, #22d3ee, #34d399);
  transition: width .18s ease;
}

/* -- 日志 ---------------------------------------------------------------- */
.log-card summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  list-style: none;
}
.log-card summary::-webkit-details-marker { display: none; }
.log-card summary::before { content: "▸ "; }
.log-card[open] summary::before { content: "▾ "; }
.log-card pre {
  margin: 10px 0 0;
  max-height: 240px;
  overflow: auto;
  padding: 10px;
  border-radius: 9px;
  background: #0a1119;
  border: 1px solid var(--line);
  color: var(--muted);
  font: 11.5px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-all;
}

.foot {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 18px 12px calc(10px + env(safe-area-inset-bottom));
  color: #5f7183;
  font-size: 11.5px;
}
.foot .dot { opacity: .6; }

/* -- 浮层 ---------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 14px);
  max-width: min(92vw, 420px);
  padding: 11px 16px;
  border-radius: 11px;
  background: #1b2634;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: rgba(248, 113, 113, .5); }
.toast.ok { border-color: rgba(52, 211, 153, .5); }

/* -- 报告预览弹层 -------------------------------------------------------- */
body.modal-open { overflow: hidden; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(3, 7, 12, .8);
}
.modal[hidden] { display: none; }

.modal-sheet {
  display: flex;
  flex-direction: column;
  width: min(100%, 640px);
  max-height: 92vh;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.modal-head strong { font-size: 15px; }
.modal-serial {
  margin-left: 8px;
  font: 11.5px ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted);
}
.modal-x {
  flex: none;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

/* 报告本身是浅色纸张风，预览区给深底反而衬得清楚 → 用近黑底 */
.modal-body {
  flex: 1;
  min-height: 0;
  padding: 12px;
  overflow: auto;
  background: #0a1119;
  -webkit-overflow-scrolling: touch;
}
.modal-body img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  background: #fff;
}
/* 写参确认表用的浅底滚动区（表格是浅色内容，沿用深底会看不清） */
.modal-body.modal-scroll {
  background: var(--panel, #101822);
  max-height: 52vh;
}
.modal-body.modal-scroll .tbl { font-size: 12.5px; }

.modal-foot {
  display: flex;
  gap: 10px;
  padding: 12px 14px 6px;
}
.modal-foot .btn { flex: 1; }

.modal-hint {
  margin: 0 0 14px;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
}

@media (min-width: 620px) {
  main { max-width: 620px; margin: 0 auto; }
  .steps, .topbar { padding-left: max(14px, calc((100vw - 620px) / 2)); padding-right: max(14px, calc((100vw - 620px) / 2)); }
}

/* 参数快照列表 ---------------------------------------------------------- */
.snap-title {
  margin: 18px 0 8px;
  font-size: 13.5px;
  color: var(--text);
}
.snap-title small {
  display: block;
  margin-top: 2px;
  font-weight: 400;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.6;
}
.snap-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line, #22303f);
  border-radius: 9px;
  margin-bottom: 7px;
  background: rgba(255, 255, 255, 0.02);
}
.snap-item .info { flex: 1; min-width: 0; }
.snap-item .t { font-size: 13px; }
.snap-item .d { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.snap-item .badge-restored {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 6px;
  font-size: 10.5px;
  color: var(--ok);
  border: 1px solid var(--ok);
}
.snap-item .btn { margin: 0; padding: 7px 12px; font-size: 12.5px; flex: 0 0 auto; }

/* 整定历史 --------------------------------------------------------------- */
.hist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line, #22303f);
  border-radius: 9px;
  margin-bottom: 7px;
  cursor: pointer;
}
.hist-item input { flex: 0 0 auto; width: 17px; height: 17px; accent-color: #22d3ee; }
.hist-item .info { flex: 1; min-width: 0; }
.hist-item .t { font-size: 13px; }
.hist-item .d { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.hist-empty { color: var(--muted); font-size: 12.5px; padding: 6px 2px; }
