/* ============================================================
   下单管理 · 现代账本风格（简约）
   ============================================================ */

:root {
  --bg: #f4f4f0;
  --surface: #ffffff;
  --ink: #24241f;
  --ink-soft: #77776f;
  --ink-faint: #a6a69e;
  --line: #e8e8e2;
  --line-strong: #dcdcd4;
  --accent: #b02418;
  --accent-soft: #f9ecea;
  --button: #24241f;
  --mono: "SFMono-Regular", "JetBrains Mono", "Cascadia Code", "Consolas", "Courier New", monospace;
  --sans: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(36,36,31,.04), 0 10px 30px rgba(36,36,31,.06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(rgba(36,36,31,.02) 1px, transparent 1px);
  background-size: 22px 22px;
  -webkit-font-smoothing: antialiased;
}

.page { padding: 24px 28px 40px; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

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

.brand-mark {
  width: 10px; height: 10px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.brand h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: .5px; }
.brand p { margin: 3px 0 0; font-size: 12px; color: var(--ink-soft); letter-spacing: 1px; }

.topbar-actions { display: flex; gap: 10px; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform .08s ease, border-color .15s ease, background .15s ease;
}
.btn:hover { border-color: var(--ink-faint); }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--button); color: #fff; border-color: var(--button); }
.btn-primary:hover { background: #3a3a34; border-color: #3a3a34; }

/* ---------- 卡片 ---------- */
.matrix-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: cardIn .4s ease both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.table-wrap { max-height: calc(100vh - 190px); overflow: auto; }

table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
}

/* ---------- 表头 ---------- */
thead th {
  position: sticky; top: 0; z-index: 2;
  background: #fafaf8;
  border-bottom: 1px solid var(--line-strong);
  font-size: 12px; font-weight: 600; letter-spacing: .5px;
  color: var(--ink-soft);
  padding: 14px 16px;
  text-align: left;
  white-space: nowrap;
}

th.th-buyer {
  position: sticky; left: 0; z-index: 3;
  min-width: 210px;
  border-right: 1px solid var(--line-strong);
  background: #f6f6f2;
}

th.th-store { min-width: 200px; }

.store-del {
  border: none; background: none; color: var(--ink-faint);
  cursor: pointer; font-size: 16px; line-height: 1;
  margin-left: 8px; padding: 0 2px;
  opacity: 0; transition: opacity .15s ease, color .15s ease;
}
th.th-store:hover .store-del { opacity: 1; }
.store-del:hover { color: var(--accent); }

/* 表头重命名输入框 */
th.th-store input.eb-store-name {
  font-family: var(--sans);
  font-size: 12px; font-weight: 600;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 4px 8px;
  outline: none;
  width: 140px;
}

/* ---------- 单元格 ---------- */
tbody td {
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  vertical-align: top;
  transition: background .12s ease;
}
tbody tr:last-child td { border-bottom: none; }

td.td-buyer {
  position: sticky; left: 0; z-index: 1;
  background: var(--surface);
  border-right: 1px solid var(--line-strong);
  min-width: 210px;
  padding-right: 30px;
  cursor: pointer;
}
td.td-buyer:hover { background: #fbfbf9; }

.buyer-code { font-size: 17px; font-weight: 600; font-family: var(--mono); letter-spacing: .5px; }
.buyer-account { margin-top: 3px; font-size: 12px; color: var(--ink-soft); font-family: var(--mono); }

.buyer-del {
  position: absolute; top: 8px; right: 8px;
  border: none; background: none; color: var(--ink-faint);
  cursor: pointer; font-size: 15px; line-height: 1; padding: 0 2px;
  opacity: 0; transition: opacity .15s ease, color .15s ease;
}
td.td-buyer:hover .buyer-del { opacity: 1; }
.buyer-del:hover { color: var(--accent); }

.td-cell { cursor: pointer; }
.td-cell:hover { background: #fbfbf9; }

.cell-link { font-size: 13px; font-family: var(--mono); color: var(--ink); word-break: break-all; }
.cell-meta { margin-top: 6px; display: flex; align-items: center; gap: 10px; }
.cell-time { font-size: 12px; color: var(--ink-soft); font-family: var(--mono); }
.cell-count {
  font-size: 12px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 9px; border-radius: 999px;
}

.td-cell.is-empty .cell-link { color: var(--ink-faint); }
.td-cell.is-empty .cell-count { display: none; }

/* ---------- 内联编辑 ---------- */
.edit-box { display: flex; flex-direction: column; gap: 6px; min-width: 170px; }
.edit-box input {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 6px 8px;
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.edit-box input:focus { border-color: var(--button); box-shadow: 0 0 0 3px rgba(36,36,31,.08); }
.td-buyer .edit-box input:first-child { font-size: 15px; font-weight: 600; }

.edit-actions { display: flex; gap: 6px; margin-top: 2px; }
.mini-btn {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-family: var(--sans);
  font-size: 12px;
  padding: 4px 11px;
  border-radius: 6px;
  cursor: pointer;
}
.mini-btn.mini-save { background: var(--button); color: #fff; border-color: var(--button); }
.mini-btn.mini-cancel { color: var(--ink-soft); }

/* ---------- 弹窗 ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(30,30,26,.38);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  opacity: 0;
  transition: opacity .18s ease;
  backdrop-filter: blur(2px);
}
.modal-overlay.show { opacity: 1; }

.modal {
  width: 360px; max-width: calc(100vw - 40px);
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.18);
  transform: translateY(8px) scale(.98);
  transition: transform .18s ease;
}
.modal-overlay.show .modal { transform: none; }

.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 0; }
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-close { border: none; background: none; font-size: 22px; color: var(--ink-faint); cursor: pointer; line-height: 1; }

.modal-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--ink-soft); }
.field input {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: var(--sans);
  outline: none;
}
.field input:focus { border-color: var(--button); box-shadow: 0 0 0 3px rgba(36,36,31,.08); }

.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 0 20px 20px; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--accent); }

.foot { margin-top: 18px; text-align: center; font-size: 12px; color: var(--ink-faint); letter-spacing: .5px; }

.empty-tip { padding: 70px 20px; text-align: center; color: var(--ink-faint); font-size: 13px; }

/* ---------- 工具栏 ---------- */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.toolbar input[type="search"] {
  flex: 1; min-width: 200px; max-width: 340px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 9px 12px; font-size: 13px; font-family: var(--sans);
  background: var(--surface); outline: none;
}
.toolbar input[type="search"]:focus { border-color: var(--button); box-shadow: 0 0 0 3px rgba(36,36,31,.08); }
.toolbar select {
  border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 9px 10px; font-size: 13px; font-family: var(--sans);
  background: var(--surface); color: var(--ink); outline: none; cursor: pointer;
}
.toolbar-spacer { flex: 1; }

/* ---------- 合计列 / 合计行 ---------- */
th.th-total, td.td-total {
  border-left: 1px solid var(--line-strong);
  background: #fafaf8; text-align: center; min-width: 90px;
}
td.td-total-label {
  position: sticky; left: 0; z-index: 1;
  background: #f6f6f2; font-weight: 600; text-align: left;
  border-right: 1px solid var(--line-strong); border-top: 1px solid var(--line-strong);
}
td.td-grand { font-weight: 600; color: var(--accent); }
tfoot td { border-top: 1px solid var(--line-strong); }

/* ---------- 加载遮罩 ---------- */
.matrix-card { position: relative; }
.loading-mask {
  position: absolute; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.55); backdrop-filter: blur(1px);
}
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line-strong); border-top-color: var(--button);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 确认弹窗文本 ---------- */
.confirm-text { font-size: 14px; line-height: 1.6; color: var(--ink); }

/* ---------- 提示（可撤销） ---------- */
.toast.undo { display: flex; align-items: center; gap: 10px; pointer-events: auto; }
.toast-action {
  border: 1px solid rgba(255,255,255,.5); background: none; color: #fff;
  border-radius: 999px; padding: 2px 10px; font-size: 12px; cursor: pointer;
}
.toast-action:hover { background: rgba(255,255,255,.16); }

/* ---------- 导入 / 日志 ---------- */
.hint { font-size: 12px; color: var(--ink-soft); line-height: 1.5; }
.log-wrap { max-height: 50vh; overflow: auto; }
.log-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.log-table th, .log-table td {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.log-table th { color: var(--ink-soft); font-weight: 600; }
.log-detail { color: var(--ink-soft); max-width: 260px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- 店铺拖动排序 ---------- */
th.th-store { cursor: grab; }
th.th-store.dragging { opacity: .5; }
.drag-handle { color: var(--ink-faint); margin-right: 6px; cursor: grab; user-select: none; }

/* ---------- 多链接单元格 ---------- */
.cell-link-row { padding: 3px 0; display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.cell-link-row + .cell-link-row { border-top: 1px dashed var(--line); }
.cell-main { flex: 1; min-width: 0; }
.cell-link.is-empty-link { color: var(--ink-faint); }
.muted { color: var(--ink-faint); }
.quick-add {
  flex: none; border: 1px solid var(--line-strong); background: none;
  color: var(--accent); font-weight: 600; font-size: 12px; line-height: 1;
  padding: 4px 6px; border-radius: 6px; cursor: pointer; white-space: nowrap;
}
.quick-add:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.quick-add:active { transform: scale(.96); }

/* ---------- 多链接编辑 ---------- */
.cell-edit { min-width: 300px; }
.link-list { display: flex; flex-direction: column; gap: 6px; }
.link-edit-row { display: flex; gap: 6px; align-items: center; }
.link-edit-row .eb-link { flex: 1; min-width: 90px; }
.link-edit-row .eb-time { flex: 1; min-width: 150px; }
.link-edit-row .eb-count { width: 64px; }
.link-del {
  border: none; background: none; color: var(--ink-faint);
  font-size: 16px; line-height: 1; cursor: pointer; padding: 0 2px;
}
.link-del:hover { color: var(--accent); }
.link-add {
  align-self: flex-start; border: 1px dashed var(--line-strong);
  background: none; color: var(--ink-soft); padding: 4px 10px; border-radius: 6px;
  cursor: pointer; font-size: 12px;
}
.link-add:hover { border-color: var(--ink-faint); color: var(--ink); }
