/* ============================================================
   小掌柜进销存 · 竹青账房 设计系统
   暖纸米底 / 白卡片 / 深竹青侧边栏 / 竹绿主色 + 赭金点缀
   ============================================================ */

:root {
  --bg: #f3f4ef;
  --card: #ffffff;
  --border: #e2e6dc;
  --border-strong: #d1d7c8;
  --text: #232c22;
  --muted: #5a6753;
  --faint: #939f89;
  --primary: #2e6b4f;
  --primary-soft: #e7f0e9;
  --primary-h: #21543c;
  --gold: #bd8c33;
  --green: #2e7d5b;
  --green-soft: #e5f1ea;
  --red: #c14d3e;
  --red-soft: #f9eae7;
  --orange: #bd8c33;
  --orange-soft: #f8efdb;
  --taupe: #7d8a74;
  --plum: #7d6b9e;
  --sidebar: #22372b;
  --sidebar-text: #a8bba8;
  --sidebar-active: rgba(255, 255, 255, .12);
  --shadow: 0 1px 2px rgba(35, 55, 43, .05), 0 4px 16px rgba(35, 55, 43, .06);
  --shadow-lg: 0 8px 20px rgba(35, 55, 43, .16), 0 24px 60px rgba(35, 55, 43, .20);
  --radius: 12px;
  --serif: "Microsoft YaHei UI", "PingFang SC", "Segoe UI", sans-serif;
  --sans: "Segoe UI", -apple-system, "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
}

[data-theme="dark"] {
  --bg: #10150f;
  --card: #171e16;
  --border: #253124;
  --border-strong: #344334;
  --text: #e9f0e6;
  --muted: #b6c4af;
  --faint: #8d9c84;
  --primary: #6fb392;
  --primary-soft: #1e2f22;
  --primary-h: #8cc7a6;
  --gold: #d6ab56;
  --green: #6cc49d;
  --green-soft: #1a2a1f;
  --red: #e28a79;
  --red-soft: #33201d;
  --orange: #d6ab56;
  --orange-soft: #332a18;
  --taupe: #8b9681;
  --plum: #a28fb9;
  --sidebar: #0c130e;
  --sidebar-text: #8fa38d;
  --sidebar-active: rgba(255, 255, 255, .14);
  --shadow: 0 1px 2px rgba(0, 0, 0, .30), 0 4px 16px rgba(0, 0, 0, .25);
  --shadow-lg: 0 8px 20px rgba(0, 0, 0, .45), 0 24px 60px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  letter-spacing: .01em;
}

button, input, select, textarea {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--text);
}

button { cursor: pointer; border: none; background: none; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(105, 125, 100, .32); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

.app { display: flex; height: 100vh; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 224px;
  flex: 0 0 224px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 26px 16px 18px;
  user-select: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px 28px;
}

.brand-logo {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, #4f8f6f, #24533c);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 19px;
  box-shadow: 0 3px 10px rgba(36, 83, 60, .35);
}

.brand-name {
  font-family: var(--serif);
  color: #eef2fa;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 2px;
}
.brand-sub { color: rgba(238, 242, 250, .55); font-size: 11px; margin-top: 2px; letter-spacing: .04em; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--sidebar-text);
  font-size: 14px;
  transition: background .16s, color .16s;
  text-align: left;
  width: 100%;
}

.nav-item:hover { background: rgba(255, 255, 255, .07); color: #f2f5fb; }

.nav-item.active {
  background: var(--sidebar-active);
  color: #ffffff;
  font-weight: 600;
}

.nav-item.active .nav-dot { opacity: 1; }

.nav-dot {
  width: 3px; height: 16px;
  border-radius: 2px;
  background: var(--gold);
  opacity: 0;
  margin-left: -4px;
  transition: opacity .16s;
}

.nav-item svg { width: 18px; height: 18px; flex: 0 0 18px; opacity: .85; }

.sidebar-foot {
  color: rgba(238, 242, 250, .52);
  font-size: 11px;
  padding: 12px 14px 4px;
  line-height: 1.7;
  border-top: 1px solid rgba(255, 255, 255, .09);
}

/* ---------- 主区域 ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 72px;
  flex: 0 0 72px;
  display: flex;
  align-items: center;
  padding: 0 30px;
  gap: 14px;
}

.page-title {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .05em;
}
.page-sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; }

.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.content { flex: 1; overflow-y: auto; padding: 10px 30px 36px; }

/* ---------- 通用 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13.5px;
  transition: all .16s;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn svg { width: 15px; height: 15px; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(36, 83, 60, .30);
}
.btn-primary:hover { background: var(--primary-h); box-shadow: 0 4px 12px rgba(36, 83, 60, .38); }

.btn-ghost {
  background: var(--card);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary-h); background: var(--primary-soft); }

.btn-danger-ghost { background: transparent; color: var(--red); border-color: transparent; }
.btn-danger-ghost:hover { background: var(--red-soft); }

.btn-sm { padding: 5px 12px; font-size: 12.5px; border-radius: 9px; }
.btn-icon { padding: 8px; border-radius: 10px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 24px 14px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .01em;
}
.card-head .spacer { flex: 1; }
.card-body { padding: 6px 24px 24px; }

/* 统计卡片 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 18px;
}

.stat {
  padding: 22px 24px 20px;
  position: relative;
  overflow: hidden;
}

.stat::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--primary);
  opacity: .9;
}

.stat.good::before { background: var(--green); }
.stat.warn::before { background: var(--orange); }
.stat.blue::before { background: var(--taupe); }
.stat.purple::before { background: var(--plum); }

.stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  margin-bottom: 10px;
}
.stat-value { font-size: 27px; font-weight: 700; letter-spacing: .2px; font-variant-numeric: tabular-nums; }
.stat-unit { font-size: 13px; font-weight: 600; color: var(--faint); margin-left: 3px; }
.stat-foot { color: var(--muted); font-size: 12px; margin-top: 7px; }
.stat-foot b { color: var(--green); }
.stat-foot b.down { color: var(--red); }

/* 图表行 */
.charts-row { display: grid; grid-template-columns: 1.7fr 1fr; gap: 16px; margin-bottom: 18px; }
.chart-wrap { width: 100%; height: 258px; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; }

/* 表格 */
.table-card { overflow: hidden; }

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 20px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}

.input, .select {
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--card);
  outline: none;
  transition: border-color .16s, box-shadow .16s;
}

.input:focus, .select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(46, 107, 79, .16);
}

.input::placeholder, textarea::placeholder { color: var(--faint); opacity: 1; }

.select { padding-right: 30px; }

.table-scroll { overflow: auto; max-height: calc(100vh - 340px); min-height: 140px; }

.table-sum {
  display: flex;
  gap: 22px;
  padding: 11px 20px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  flex-wrap: wrap;
}
.table-sum b { color: var(--text); font-variant-numeric: tabular-nums; }

table.grid { width: 100%; border-collapse: collapse; }

table.grid th {
  position: sticky;
  top: 0;
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: .05em;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  z-index: 1;
}

table.grid td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  white-space: nowrap;
}

table.grid tr:last-child td { border-bottom: none; }
table.grid tbody tr { transition: background .14s; cursor: default; }
table.grid tbody tr:hover { background: var(--primary-soft); }

td.num, th.num, table.grid th.num { text-align: center; font-variant-numeric: tabular-nums; }

.muted { color: var(--muted); }
.strong { font-weight: 700; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.chip-green { background: var(--green-soft); color: var(--green); }
.chip-red { background: var(--red-soft); color: var(--red); }
.chip-orange { background: var(--orange-soft); color: var(--orange); }
.chip-gray { background: var(--bg); color: var(--muted); }

td.num-neg, .num-neg { color: var(--red); }
td.num-pos, .num-pos { color: var(--green); }

.empty { text-align: center; color: var(--faint); padding: 48px 0; font-size: 13.5px; }
.empty .big { font-size: 15px; color: var(--muted); margin-bottom: 6px; }

/* 弹窗 */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn .16s ease;
}

.modal {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 660px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
  animation: popIn .18s cubic-bezier(.2, .9, .3, 1.2);
}

.modal.wide { width: 900px; }

.modal-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  row-gap: 6px;
  padding: 22px 26px 16px;
}

.modal-title {
  font-family: var(--serif);
  font-size: 17.5px;
  font-weight: 700;
  letter-spacing: .05em;
}

.modal-close {
  margin-left: auto;
  width: 32px; height: 32px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  font-size: 19px;
}

.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body { padding: 6px 26px 10px; overflow-y: auto; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px 26px 24px;
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.form-grid .full { grid-column: 1 / -1; }

.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 7px; letter-spacing: .02em; }
.field .input, .field .select { width: 100%; }

@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: scale(.97) translateY(8px); } }

/* 单据弹窗表格 */
.items-table { width: 100%; border-collapse: collapse; margin-top: 14px; min-width: 640px; }
.items-table th {
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.items-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); }
.items-table input {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--card);
  outline: none;
}
.items-table input:focus { border-color: var(--primary); }
.items-table td.num input { text-align: right; }
.items-table .blank-row td { padding-top: 4px; padding-bottom: 4px; }
.items-table .blank-row input { border-style: dashed; }
.items-table td { position: relative; }

.ac-list {
  position: absolute;
  left: 8px;
  top: calc(100% - 4px);
  z-index: 60;
  min-width: 240px;
  max-width: min(340px, calc(100vw - 56px));
  max-height: 264px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .16);
}
.ac-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.ac-item:last-child { border-bottom: none; }
.ac-item.on { background: rgba(46, 107, 79, .10); }
.ac-qty { margin-left: auto; font-size: 11.5px; color: var(--muted); }

.order-total {
  display: flex;
  align-items: baseline;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 2px 0;
}
.order-total .lbl { color: var(--muted); font-size: 13px; }
.order-total .val { font-size: 22px; font-weight: 700; color: var(--primary-h); }

/* 提示 */
.toast {
  position: fixed;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--card);
  padding: 11px 22px;
  border-radius: 11px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: toastIn .22s ease;
}
.toast.err { background: var(--red); color: #fff; }

@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -8px); } }

/* 排行列表 */
.rank-list { padding: 4px 6px 8px; }
.rank-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
}
.rank-item:hover { background: var(--bg); }
.rank-no {
  width: 26px; height: 26px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary-h);
  font-weight: 700;
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 26px;
}
.rank-name { flex: 1; font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-bar-wrap { width: 110px; height: 7px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.rank-bar { height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--primary), #79b795); }
.rank-val { width: 78px; text-align: right; font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }

/* 分区标题 */
.section-gap { height: 16px; }

.seg {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}
.seg button {
  padding: 5px 14px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(28, 40, 66, .12); }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .app { flex-direction: column; }
  .sidebar {
    order: 2;
    width: 100%;
    flex: 0 0 60px;
    flex-direction: row;
    padding: 5px 4px;
    border-right: none;
    border-top: 1px solid var(--border);
  }
  .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; justify-content: space-around; gap: 0; }
  .nav-item { flex-direction: column; gap: 3px; padding: 4px 10px; border-radius: 8px; width: auto; }
  .nav-item svg { width: 20px; height: 20px; }
  .nav-dot { display: none; }
  .nav-label { display: inline; font-size: 10.5px; }
  .main { flex: 1; min-height: 0; }
  .topbar { height: 52px; flex: 0 0 52px; padding: 0 12px; }
  .page-title { font-size: 17px; }
  .page-sub { display: none; }
  .topbar-actions { gap: 4px; }
  .topbar-actions .btn-sm { display: none; }
  .content { padding: 8px 10px 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 14px 14px 12px; }
  .stat-label { font-size: 11px; margin-bottom: 6px; }
  .stat-value { font-size: 20px; }
  .stat-foot { display: none; }
  .charts-row { grid-template-columns: 1fr; gap: 8px; }
  .chart-wrap { height: 210px; }
  .table-scroll { max-height: calc(100vh - 240px); }
  .table-toolbar { padding: 10px; gap: 6px; }
  .modal { max-width: calc(100vw - 20px); width: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .card-head { padding: 14px 14px 10px; }
  .card-body { padding: 4px 14px 14px; }
}

/* ---------- v0.3 体验与审美优化 ---------- */
/* 全局过渡与行悬停反馈 */
.grid tbody tr, .items-table tbody tr { transition: background .12s ease; }
.grid tbody tr:hover { background: var(--hover-bg, rgba(46,107,79,.05)); }
.nav-item, .btn, .chip, .seg button { transition: all .15s ease; }

/* 可点击卡片 */
.stat { cursor: default; }
.stat.clickable { cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; }
.stat.clickable:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(28,40,66,.08); }

/* 开单合计更醒目 */
.order-total .val { font-size: 1.28em; letter-spacing: .01em; }

/* 欠款高亮 */
.num-debt { color: var(--red); font-weight: 600; }

/* 空状态动作按钮 */
.empty .btn { margin-top: 12px; }

/* 带动作的 Toast */
.toast { display: flex; align-items: center; gap: 10px; }
.toast .toast-btn {
  flex-shrink: 0;
  background: rgba(255,255,255,.22);
  border: 1px solid rgba(255,255,255,.5);
  color: #fff;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  cursor: pointer;
  font-weight: 600;
}
.toast .toast-btn:hover { background: rgba(255,255,255,.32); }

/* 密码可见切换 */
.pwd-wrap { position: relative; }
.pwd-wrap .input { padding-right: 40px; }
.pwd-eye {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 13px; padding: 6px;
}
.pwd-eye:hover { color: var(--primary); }

/* 登录页美化 */
.login-brand { text-align: center; margin-bottom: 16px; }
.login-brand .logo {
  width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 10px;
  background: linear-gradient(135deg, #4f8f6f, #24533c);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 26px; font-weight: 700; font-family: var(--serif);
  box-shadow: 0 6px 18px rgba(36, 83, 60, .35);
}
.login-brand .name { font-size: 17px; font-weight: 700; letter-spacing: .04em; }
.login-brand .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.login-feats { margin: 0 0 14px; padding: 12px 14px; background: var(--bg); border-radius: 10px; font-size: 12.5px; color: var(--muted); line-height: 1.9; }
.login-feats span { color: var(--primary); margin-right: 4px; }

/* 快捷日期按钮组 */
.date-quick { display: inline-flex; gap: 4px; }
.date-quick button {
  border: 1px solid var(--border); background: var(--card); color: var(--muted);
  border-radius: 7px; padding: 4px 9px; font-size: 12px; cursor: pointer;
}
.date-quick button:hover { border-color: var(--primary); color: var(--primary); }

/* 移动端底部安全区（PWA 全屏） */
.content { padding-bottom: 18px; }
@supports (padding: max(0px)) {
  .content { padding-bottom: max(18px, env(safe-area-inset-bottom)); }
}

