:root {
  /* 收敛后的配色：只保留一个主色 + 三个语义色，避免界面花 */
  --bg: #0b0f14;
  --surface: #121821;
  --surface-2: #18202b;
  --border: #232c39;
  --border-strong: #2e3948;
  --text: #e9eff6;
  --muted: #8a97a7;
  --accent: #4c8dff;
  --accent-soft: #16263d;
  --teal: #3ecf9a;
  --amber: #e2a94a;
  --danger: #f0736f;
  --radius: 12px;
}
* { box-sizing: border-box; }
/* 作者样式里的 display（如 .login-view{display:grid}）会覆盖浏览器默认的 [hidden]，
   导致 hidden=true 的元素仍然可见；此处强制统一，保证视图切换真正生效。 */
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 system-ui, -apple-system, "Microsoft YaHei", "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
h1, h2, h3, h4 { font-weight: 500; margin: 0 0 12px; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); font-size: 13px; }
.error-text { color: var(--danger); font-size: 13px; min-height: 20px; }
a { color: var(--accent); }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px;
}
.login-card h1 { margin: 16px 0 6px; }
.login-hint { color: var(--muted); font-size: 12px; margin-top: 14px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 20px; font-weight: 500;
}
.brand-mark.small { width: 28px; height: 28px; font-size: 14px; border-radius: 8px; }

label { display: block; color: var(--muted); font-size: 12px; margin: 14px 0 6px; }
input, select, textarea {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 120px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
input[type="checkbox"] { width: auto; margin-right: 6px; }

.btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 8px; padding: 8px 14px; cursor: pointer; transition: border-color .15s, opacity .15s;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #07121f; font-weight: 500; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.full { width: 100%; margin-top: 20px; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.topbar {
  height: 54px; border-bottom: 1px solid var(--border); background: var(--surface);
  display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 0 24px;
}
.topbar-brand { display: flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 500; letter-spacing: .2px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-actions .btn { padding: 5px 10px; }
#user-label { font-size: 12px; margin-left: 4px; }
.badge {
  font-size: 12px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted);
}
.badge.ok { color: var(--teal); border-color: #1c5c46; }
.badge.bad { color: var(--danger); border-color: #6b2b2b; }

.layout { display: flex; min-height: calc(100vh - 58px); }
.sidebar {
  width: 210px; flex: none; border-right: 1px solid var(--border);
  background: var(--surface); padding: 18px 12px;
}
.nav-item {
  width: 100%; text-align: left; border: 0; background: transparent; color: var(--muted);
  padding: 9px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 4px;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-note {
  margin-top: 28px; padding: 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 6px;
}
.sidebar-note strong { color: var(--text); font-weight: 500; }
.workspace { width: 100%; max-width: 1160px; margin: 0 auto; padding: 26px 24px 64px; min-width: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 22px; margin-bottom: 16px;
}
.card > h2, .card-head h2 { font-size: 15px; letter-spacing: .2px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.field { min-width: 0; }
.field label { margin-top: 0; }

.dropzone {
  border: 1px dashed var(--border); border-radius: var(--radius); padding: 26px;
  text-align: center; cursor: pointer; background: var(--surface-2);
}
.dropzone.hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone strong { display: block; margin-bottom: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; background: transparent; }
tbody tr:hover { background: rgba(74, 158, 255, .05); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }

/* 数据预览：固定约 10 行高度，更多数据在容器内下滑查看（表头吸顶） */
.preview-scroll { max-height: 430px; overflow-y: auto; }
.preview-scroll thead th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px;
  border: 1px solid var(--border); color: var(--muted);
}
.tag.ok { color: var(--teal); border-color: #1c5c46; }
.tag.warn { color: var(--amber); border-color: #6a4c18; }
.tag.info { color: var(--accent); border-color: #1d4a75; }

.metric-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.metric-card .label { color: var(--muted); font-size: 12px; }
.metric-card .value { font-size: 22px; margin: 4px 0; }
.metric-card .delta.up { color: var(--danger); }
.metric-card .delta.down { color: var(--teal); }
.metric-card .delta.flat { color: var(--muted); }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.chart-box { background: #fff; border-radius: 8px; padding: 10px; min-height: 180px; }
.chart-box img { width: 100%; display: block; }
.chart-box .chart-title { color: #1f2933; font-size: 13px; padding: 2px 4px 8px; }
.chart-placeholder { color: var(--muted); font-size: 12px; padding: 24px; text-align: center; }

.report-head { border-bottom: 1px solid var(--border); padding-bottom: 14px; margin-bottom: 18px; }
.report-head h2 { font-size: 20px; }
.bullets { margin: 0; padding-left: 20px; color: var(--text); }
.bullets li { margin-bottom: 6px; }
.notice { border-left: 3px solid var(--accent); padding: 8px 12px; background: var(--surface-2); border-radius: 0 8px 8px 0; margin-bottom: 10px; font-size: 13px; }
.notice.warn { border-left-color: var(--amber); }
.empty { color: var(--muted); text-align: center; padding: 32px 12px; }

.checkbox-list { display: flex; flex-wrap: wrap; gap: 8px; }
.checkbox-list label {
  margin: 0; display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 9px; font-size: 12px; color: var(--text);
}
/* 模板导入：结构预览 */
.import-hint, .import-result {
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 8px; padding: 14px; font-size: 13px;
}
.import-hint p { margin: 6px 0; }
.import-hint code, .import-result code {
  background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 5px; font-size: 12px; color: var(--accent);
}
.import-result .card-head { margin-bottom: 8px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.struct-list { max-height: 220px; overflow-y: auto; margin-top: 10px; }
.struct-row { display: flex; align-items: center; gap: 8px; padding: 5px 2px; border-bottom: 1px solid var(--border); font-size: 13px; }
.struct-sheet { display: flex; flex-direction: column; gap: 2px; padding: 8px 2px; border-bottom: 1px solid var(--border); }
.struct-headers { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toast {
  position: fixed; right: 24px; bottom: 24px; max-width: 380px; z-index: 20;
  background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 12px 16px; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }
.toast.error { border-left-color: var(--danger); }
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media print {
  body { background: #fff; color: #000; }
  .topbar, .sidebar, .no-print, .toast { display: none !important; }
  .layout { display: block; }
  .workspace { padding: 0; max-width: none; }
  .card { border: 0; background: #fff; color: #000; padding: 8px 0; }
  .chart-box { border: 1px solid #ddd; }
  th { background: #f2f2f2; color: #000; }
  .muted, .metric-card .label { color: #555; }
  .metric-card, .notice { background: #fff; color: #000; border-color: #ddd; }
}

/* 导入数据网格：查看原始格式与逐格手工修正 */
.grid-toolbar { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; margin: 12px 0; }
.grid-toolbar .field label { margin-top: 0; }
.grid-summary { margin-bottom: 10px; }
.format-panel { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; background: var(--surface-2); }
.format-panel summary { cursor: pointer; color: var(--text); font-size: 13px; }
.format-panel .table-wrap { margin-top: 10px; max-height: 260px; overflow: auto; }
.format-panel p { margin: 8px 0 0; }
.grid-scroll { overflow: auto; max-height: 520px; border: 1px solid var(--border); border-radius: 8px; }
.data-grid { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; }
.data-grid th, .data-grid td { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 4px 6px; white-space: nowrap; }
.data-grid thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); }
.data-grid thead tr.header-edit-row th { top: 42px; z-index: 1; }
.data-grid th.row-num, .data-grid td.row-num { position: sticky; left: 0; z-index: 3; background: var(--surface-2); min-width: 76px; }
.data-grid td.row-num div { font-size: 12px; color: var(--muted); }
.data-grid td.row-num .btn { padding: 2px 6px; font-size: 11px; margin-top: 2px; }
.data-grid .th-letter { font-size: 10px; color: var(--muted); font-weight: 400; }
.data-grid .cell-input { width: 132px; min-width: 110px; padding: 5px 7px; font-size: 12px; background: transparent; border: 1px solid transparent; border-radius: 4px; color: var(--text); }
.data-grid .cell-input:hover { border-color: var(--border); }
.data-grid .cell-input:focus { border-color: var(--accent); background: var(--bg); }
.data-grid .cell-input.cell-changed { background: rgba(224, 162, 60, .12); border-left: 2px solid var(--amber); }
.data-grid .cell-input.cell-dirty { background: rgba(74, 158, 255, .18); border-left: 2px solid var(--accent); }
.data-grid .cell-input:disabled { opacity: .85; cursor: default; }
.grid-pager { margin-top: 12px; }
@media print { .grid-scroll, .format-panel, .grid-toolbar, .grid-pager { display: none !important; } }

/* 一键导出：工作台入口与配置弹窗 */
.export-banner { display: flex; justify-content: space-between; align-items: center; gap: 18px; border-left: 3px solid var(--accent); }
.export-banner h2 { margin-bottom: 4px; }
.export-banner p { margin: 0; }
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal-mask { position: absolute; inset: 0; background: rgba(5, 9, 14, .74); }
.modal-panel {
  position: relative; width: min(880px, 100%); max-height: 88vh;
  display: flex; flex-direction: column; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .5);
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 18px 22px 14px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin-bottom: 4px; }
.modal-head p { margin: 0; }
.modal-close { font-size: 20px; line-height: 1; padding: 4px 11px; }
.modal-body { overflow: auto; padding: 18px 22px 22px; }
.export-section { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; background: var(--surface-2); }
.export-section h3 { color: var(--accent); margin-bottom: 12px; }
.export-section .field label { margin-top: 0; }
.range-preview { display: flex; flex-direction: column; gap: 2px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 7px 11px; min-height: 40px; }
.range-preview b { color: var(--text); font-size: 13px; }
.range-preview span { color: var(--muted); font-size: 12px; }
.export-footer { border-top: 1px solid var(--border); padding-top: 14px; }
.export-notes { margin-top: 8px; }
.export-footer .notice { margin-top: 12px; }
@media print { .modal, .export-banner { display: none !important; } }

/* ---------------- AI 配置与分析 ---------------- */
.tag.danger { color: var(--danger); border-color: #6b2b2b; }
.metric-card .value.small { font-size: 15px; line-height: 1.4; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; }
.ai-url { word-break: break-all; max-width: 220px; }
.ai-cell-note { font-size: 11px; }
.ai-run-overview { max-width: 320px; }
.ai-test-result { margin-top: 12px; }
.ai-result .ai-overview { font-size: 14px; line-height: 1.75; }
.ai-result h3 { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.ai-result .ai-conclusion {
  margin-top: 14px; padding: 10px 12px; border-left: 3px solid var(--accent);
  background: var(--surface-2); border-radius: 0 8px 8px 0; font-size: 13px;
}
.ai-result .ai-footnote { margin-top: 12px; font-size: 11px; }

/* 表格行内操作：多个按钮并排时留出间隔，避免"载入并查看"和"删除"黏在一起 */
td.row-actions { white-space: nowrap; }
td.row-actions .btn + .btn { margin-left: 6px; }

@media print {
  .ai-result .ai-footnote { color: #666; }
}

/* 应用内确认框（替代被内嵌 WebView 拦截的原生 confirm） */
.confirm-panel { width: min(460px, 100%); }
#confirm-text { white-space: pre-line; line-height: 1.7; }
.confirm-actions { justify-content: flex-end; margin-top: 4px; }

/* ================= 顶部流程导航 ================= */
.flowbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 18px;
  padding: 8px 24px; background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.flow-steps {
  display: flex; align-items: center; gap: 2px;
  margin: 0; padding: 0; list-style: none;
  overflow-x: auto; scrollbar-width: none;
}
.flow-steps::-webkit-scrollbar { display: none; }
.flow-steps li { display: flex; align-items: center; flex: none; }
.flow-steps li + li::before {
  content: ''; width: 16px; height: 1px; flex: none;
  background: var(--border-strong); margin: 0 2px;
}
.flow-step {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 10px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; background: transparent; color: var(--muted);
  text-align: left; transition: background .15s, color .15s, border-color .15s;
}
.flow-step:hover { background: var(--surface-2); color: var(--text); }
.flow-step .num {
  width: 22px; height: 22px; flex: none; border-radius: 50%;
  border: 1px solid var(--border-strong); color: var(--muted);
  display: grid; place-items: center; font-size: 11px;
}
.flow-step .copy { display: flex; flex-direction: column; line-height: 1.25; }
.flow-step .copy b { font-size: 13px; font-weight: 500; }
.flow-step .copy small { font-size: 11px; color: var(--muted); }
.flow-step.done .num { background: rgba(62, 207, 154, .14); border-color: rgba(62, 207, 154, .4); color: var(--teal); }
.flow-step.active { background: var(--accent-soft); border-color: rgba(76, 141, 255, .4); color: var(--text); }
.flow-step.active .num { background: var(--accent); border-color: transparent; color: #08111e; font-weight: 600; }
.flow-step.active .copy small { color: #a8c2e8; }
.flow-next { margin-left: auto; flex: none; }
.flow-next .muted { font-size: 12px; }

/* ================= 简洁化收尾 ================= */
.btn { border-radius: 8px; transition: border-color .15s, background .15s, opacity .15s; }
.btn.primary { color: #08111e; font-weight: 500; }
.btn.primary:hover { background: #6ba0ff; border-color: #6ba0ff; }
.btn.ghost:hover { background: var(--surface-2); }
.btn:focus-visible, .flow-step:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid rgba(76, 141, 255, .55); outline-offset: 1px;
}
.metric-card { background: var(--bg); border-color: var(--border); }
.metric-card .value { font-size: 20px; }
.notice { background: transparent; border: 1px solid var(--border); border-left: 3px solid var(--accent); }
.export-banner { border-left-width: 1px; }
.export-banner h2 { font-size: 16px; }
.dropzone { background: transparent; }
.dropzone:hover { background: var(--surface-2); }
.tag { border-radius: 6px; }
.badge { border-radius: 6px; }
.table-wrap { border-radius: 10px; }
tbody tr:last-child td { border-bottom: 0; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #253040; border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1080px) {
  .flow-step .copy small { display: none; }
}
@media (max-width: 820px) {
  .flowbar { padding: 8px 12px; gap: 10px; }
  .flow-steps li + li::before { width: 8px; }
  .topbar { padding: 0 12px; }
  .workspace { padding: 18px 12px 48px; }
}
@media print {
  .flowbar { display: none !important; }
}
