/* Wisp 表格工具箱 — 样式 */

:root {
  --bg: #f4f6f9;
  --bg-soft: #eef1f6;
  --panel: #ffffff;
  --panel-2: #fafbfd;
  --text: #1b1f26;
  --text-2: #4b5563;
  --muted: #8b93a1;
  --line: #e2e6ec;
  --line-2: #edf0f5;
  --brand: #2563eb;
  --brand-soft: #eaf1ff;
  --brand-deep: #1d4ed8;
  --ok: #0f9d58;
  --ok-soft: #e7f6ee;
  --warn: #c2410c;
  --warn-soft: #fff3e8;
  --err: #dc2626;
  --err-soft: #fdecec;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(18, 25, 40, .05), 0 8px 24px -16px rgba(18, 25, 40, .28);
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Code", Consolas, "Liberation Mono", monospace;
}

[data-theme="dark"] {
  --bg: #14171c;
  --bg-soft: #1a1e25;
  --panel: #1d222a;
  --panel-2: #21262f;
  --text: #e8ecf2;
  --text-2: #b6bec9;
  --muted: #8b93a1;
  --line: #2b323c;
  --line-2: #262c35;
  --brand: #4d86ff;
  --brand-soft: #1e2a44;
  --brand-deep: #6d9cff;
  --ok: #45c98a;
  --ok-soft: #16301f;
  --warn: #f0a06a;
  --warn-soft: #33251a;
  --err: #f27272;
  --err-soft: #351c1c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 28px -18px rgba(0, 0, 0, .8);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 12px; }

.logo {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--brand), #7c5cff);
  color: #fff;
  font-weight: 700;
  font-size: 19px;
  box-shadow: 0 6px 16px -8px var(--brand);
}

.brand-text h1 { margin: 0; font-size: 16px; letter-spacing: .2px; }
.brand-text p { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--ok-soft);
  color: var(--ok);
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-warn { background: var(--warn-soft); color: var(--warn); }

.icon-btn {
  width: 34px; height: 34px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text-2);
  cursor: pointer;
  font-size: 15px;
}
.icon-btn:hover { border-color: var(--brand); color: var(--brand); }

/* ---------- 标签页 ---------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 24px 0;
  max-width: 1220px;
  margin: 0 auto;
}

.tab {
  appearance: none;
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  color: var(--text-2);
  padding: 9px 16px;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.active {
  background: var(--panel);
  color: var(--brand);
  border-color: var(--line);
  box-shadow: inset 0 -2px 0 var(--brand);
}

/* ---------- 主体 ---------- */

#view { max-width: 1220px; margin: 0 auto; padding: 14px 24px 40px; }

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

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px 20px;
  margin-bottom: 16px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-head h2 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-actions { display: flex; gap: 8px; }

.step {
  width: 20px; height: 20px;
  border-radius: 6px;
  background: var(--brand-soft);
  color: var(--brand);
  display: grid; place-items: center;
  font-size: 12px;
  font-weight: 700;
}

/* ---------- 拖拽区 ---------- */

.dropzone {
  border: 1.5px dashed var(--line);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 26px 18px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover { border-color: var(--brand); background: var(--brand-soft); }
.dz-icon {
  width: 40px; height: 40px;
  margin: 0 auto 8px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--brand);
  display: grid; place-items: center;
  font-size: 20px;
}
.dz-main { font-size: 14px; }
.dz-sub { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.link { color: var(--brand); text-decoration: underline; text-underline-offset: 3px; }

.page.dragging .dropzone {
  border-color: var(--brand);
  background: var(--brand-soft);
  box-shadow: 0 0 0 4px var(--brand-soft);
}

/* ---------- 文件列表 ---------- */

.filelist { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }

.frow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  flex-wrap: wrap;
}
.frow-error { border-color: var(--err); background: var(--err-soft); }
.f-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.f-name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.f-meta { font-size: 12.5px; color: var(--muted); }
.f-actions { display: flex; gap: 6px; }

.warn { font-size: 12px; color: var(--warn); }

.fpreview {
  flex-basis: 100%;
  margin-top: 4px;
  border-top: 1px dashed var(--line);
  padding-top: 10px;
}
.pv-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.pv-tab {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text-2);
  border-radius: 7px;
  padding: 4px 10px;
  font-size: 12.5px;
  cursor: pointer;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pv-tab.active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }
.pv-tab-single { font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.pv-note { font-size: 12px; color: var(--muted); margin: 4px 0 8px; }
.pv-note code { font-family: var(--mono); font-size: 11.5px; background: var(--bg-soft); padding: 1px 4px; border-radius: 4px; }

.parse-extra {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: center;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line-2);
}

/* ---------- 预览表 ---------- */

.pv-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: 340px;
  background: var(--panel);
}
.pv-wrap.tall { max-height: 420px; }
.pv { border-collapse: collapse; font-size: 12.5px; white-space: nowrap; min-width: 100%; }
.pv th, .pv td {
  border-bottom: 1px solid var(--line-2);
  border-right: 1px solid var(--line-2);
  padding: 5px 9px;
  text-align: left;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pv th {
  position: sticky; top: 0;
  background: var(--bg-soft);
  font-weight: 600;
  z-index: 1;
}
.pv td.num, .pv th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pv td.fname { font-family: var(--mono); font-size: 12px; }
.pv-more { color: var(--muted); }
.pv tr:last-child td { border-bottom: none; }
.bad { color: var(--warn); }
.good { color: var(--ok); }

/* ---------- 选项 ---------- */

.mode-switch {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-soft);
  border-radius: 10px;
  margin-bottom: 16px;
}
.mode-btn {
  border: none;
  background: transparent;
  color: var(--text-2);
  padding: 7px 20px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
}
.mode-btn.active { background: var(--panel); color: var(--brand); box-shadow: var(--shadow); font-weight: 600; }

.opts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 18px;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.span2 { grid-column: 1 / -1; }
.field > label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.field .hint, .hint { font-size: 12px; color: var(--muted); font-style: normal; }
.hint-block {
  background: var(--panel-2);
  border: 1px dashed var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--text-2);
}

.inline-field { display: flex; align-items: center; gap: 8px; }
.inline-field label { font-size: 12.5px; color: var(--text-2); white-space: nowrap; }
.inline-field select { width: auto; min-width: 132px; }

select, input[type="number"], input[type="text"] {
  appearance: none;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
select:focus, input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }

.checks { display: flex; flex-wrap: wrap; gap: 10px 20px; }

.cb, .radio {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}
.cb.small { font-size: 12.5px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-2); }
.cb input, .radio input { accent-color: var(--brand); width: 15px; height: 15px; }
.cb .hint, .radio .hint { margin-left: 2px; }

.dedupe-cols { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 12px; }
.dedupe-cols .lbl { font-size: 12.5px; color: var(--text-2); }

.adv { margin-top: 16px; border: 1px solid var(--line); border-radius: 10px; padding: 0 14px; background: var(--panel-2); }
.adv > summary { cursor: pointer; padding: 11px 0; font-size: 13.5px; font-weight: 500; list-style: none; }
.adv > summary::-webkit-details-marker { display: none; }
.adv > summary::before { content: "▸ "; color: var(--muted); }
.adv[open] > summary::before { content: "▾ "; }
.adv-body { padding-bottom: 14px; display: flex; flex-direction: column; gap: 12px; }

.outbox {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
}

.runrow { display: flex; align-items: center; gap: 14px; margin-top: 18px; }
.run-hint { font-size: 12.5px; color: var(--muted); }

/* ---------- 按钮 ---------- */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 9px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  transition: background .14s, border-color .14s, color .14s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-deep); color: #fff; }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.ghost:hover { color: var(--err); border-color: var(--err); }
.btn.tiny { padding: 4px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.big { padding: 11px 34px; font-size: 14.5px; }

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

.stats { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.stat {
  flex: 1 1 120px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
}
.stat b { display: block; font-size: 19px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; color: var(--muted); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }

.empty-line { color: var(--muted); font-size: 13px; padding: 8px 0; }
.empty-line.big { padding: 26px 0; text-align: center; }

.align-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--panel-2);
}
.align-head { font-size: 13px; font-weight: 600; margin-bottom: 8px; }

/* ---------- 底部 / Toast / 遮罩 ---------- */

.foot {
  max-width: 1220px;
  margin: 0 auto;
  padding: 6px 24px 30px;
  color: var(--muted);
  font-size: 12.5px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.foot .dot { opacity: .5; }

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  max-width: 380px;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  border-radius: 9px;
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toastIn .18s ease-out;
}
.toast-ok { border-left-color: var(--ok); }
.toast-warn { border-left-color: var(--warn); }
.toast-error { border-left-color: var(--err); }
.toast-out { opacity: 0; transform: translateX(8px); transition: all .24s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(14, 18, 26, .45);
  display: grid;
  place-items: center;
  z-index: 80;
  backdrop-filter: blur(2px);
}
.overlay.hidden { display: none; }
.overlay-box {
  width: min(440px, calc(100vw - 40px));
  background: var(--panel);
  border-radius: 14px;
  padding: 22px 24px;
  box-shadow: 0 30px 70px -30px rgba(0, 0, 0, .6);
}
.ov-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.ov-label { font-size: 13px; color: var(--text-2); margin-bottom: 14px; min-height: 20px; word-break: break-all; }
.ov-track { height: 7px; background: var(--bg-soft); border-radius: 999px; overflow: hidden; }
.ov-bar { height: 100%; width: 2%; background: linear-gradient(90deg, var(--brand), #7c5cff); border-radius: 999px; transition: width .18s ease-out; }
.ov-foot { display: flex; justify-content: space-between; margin-top: 8px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- 响应式 ---------- */

@media (max-width: 860px) {
  .topbar { padding: 12px 14px; }
  #view, .tabs, .foot { padding-left: 14px; padding-right: 14px; }
  .opts-grid { grid-template-columns: 1fr; }
  .tabs { overflow-x: auto; }
  .tab { white-space: nowrap; }
  .brand-text p { display: none; }
}
