:root {
  --bg: #f4f5f7;
  --card: #fff;
  --line: #e8eaef;
  --text: #1a1d23;
  --muted: #858b98;
  --accent: #ff5a1f;
  --accent-weak: #fff1ea;
  --accent-deep: #e64a12;
  --danger: #d93025;
  --warn: #c27c0e;
  --ok: #12805c;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  overflow: hidden;
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 8px 14px;
  color: var(--text);
}
button:active { transform: translateY(1px); }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
button.primary:hover { background: var(--accent-deep); }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover { color: var(--accent); }
button:disabled { opacity: .55; cursor: not-allowed; }

input, select {
  font: inherit;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent-weak); border-color: var(--accent); }

/* ---------------- 布局 ---------------- */
.app { display: flex; height: 100%; }

.rail {
  width: 104px;
  flex: none;
  background: #1f232b;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 14px 10px;
  gap: 6px;
}
.rail-btn {
  background: transparent;
  border: none;
  color: #9aa1ad;
  padding: 14px 6px;
  border-radius: 12px;
  font-size: 13px;
  text-align: center;
}
.rail-btn:hover { background: rgba(255,255,255,.06); color: #fff; }
.rail-btn.on { background: var(--accent); color: #fff; font-weight: 600; }
.rail-spacer { flex: 1; }
.rail-btn.ask { background: rgba(255,90,31,.15); color: #ffb08c; }
.rail-btn.ask:hover { background: var(--accent); color: #fff; }

.workspace { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.spacer { flex: 1; }
.today { font-size: 13px; color: var(--muted); }
.today b { color: var(--text); font-size: 15px; }
.chip {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  border: none;
  background: var(--accent-weak);
  color: var(--accent);
}
.chip.warn { background: #fdf3e2; color: var(--warn); }
.chip.bad { background: #fdecea; color: var(--danger); }

.views { flex: 1; overflow: auto; padding: 18px 20px 40px; }
.view { display: none; }
.view.on { display: block; }

/* ---------------- 工作台 ---------------- */
.hero {
  background: linear-gradient(135deg, #ff6a2b, #ff4d0f);
  color: #fff;
  border-radius: 18px;
  padding: 22px 24px;
  display: flex;
  align-items: flex-end;
  gap: 28px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.hero .label { font-size: 13px; opacity: .85; }
.hero .amount { font-size: 40px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.hero .amount small { font-size: 18px; font-weight: 500; opacity: .9; }
.hero .stat { font-size: 13px; opacity: .92; }
.hero .stat b { font-size: 18px; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}
.tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 104px;
  transition: border-color .15s, box-shadow .15s;
}
.tile:hover { border-color: var(--accent); box-shadow: 0 6px 18px rgba(255,90,31,.08); }
.tile .t-name { font-weight: 600; font-size: 15px; }
.tile .t-desc { font-size: 12px; color: var(--muted); }
.tile .t-badge { margin-top: auto; font-size: 12px; color: var(--accent); }

/* ---------------- 收银 ---------------- */
.pos { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; min-height: calc(100vh - 150px); }
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.panel-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
.panel-body { padding: 14px 16px; overflow: auto; flex: 1; }
.panel-foot { padding: 14px 16px; border-top: 1px solid var(--line); }

.items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  align-content: start;
}
.item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 96px;
}
.item:hover { border-color: var(--accent); }
.item .nm { font-weight: 600; font-size: 14px; }
.item .meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.item .price { color: var(--accent); font-weight: 700; }

.cart-row {
  display: grid;
  grid-template-columns: 1fr 88px 92px 30px;
  gap: 8px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
}
.cart-row .nm { font-size: 14px; }
.cart-row .sub { font-size: 12px; color: var(--muted); }
.cart-row input { text-align: right; padding: 6px 8px; }
.cart-row .amt { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; font-size: 13px; }

.total-row { display: flex; justify-content: space-between; align-items: baseline; }
.total { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.total small { font-size: 13px; color: var(--muted); font-weight: 400; }
.pay-methods { display: flex; gap: 8px; margin: 12px 0; }
.pay-methods button { flex: 1; }
.pay-methods button.on { border-color: var(--accent); background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.cash-row { display: none; gap: 8px; align-items: center; margin-bottom: 10px; }
.cash-row.on { display: flex; }
.cash-row input { text-align: right; }

.member-bar { display: flex; gap: 8px; }
.member-card {
  display: none;
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--accent-weak);
  border-radius: 10px;
  font-size: 13px;
}
.member-card.on { display: block; }

.receipt {
  display: none;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfd;
  font-size: 13px;
  line-height: 1.7;
}
.receipt.on { display: block; }

.err { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------------- 进销存 ---------------- */
.tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* ---------------- 报表 ---------------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { font-size: 12px; color: var(--muted); }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: 13px; font-weight: 400; color: var(--muted); }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 13px; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
tr:last-child td { border-bottom: none; }
.ok { color: var(--ok); }
.bad { color: var(--danger); font-weight: 600; }

/* ---------------- AI 抽屉 ---------------- */
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(420px, 92vw);
  background: var(--card);
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 40px rgba(0,0,0,.08);
  transform: translateX(102%);
  transition: transform .22s ease;
  display: flex;
  flex-direction: column;
  z-index: 40;
}
.drawer.on { transform: translateX(0); }
.drawer-head { padding: 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.drawer-body { padding: 16px; overflow: auto; flex: 1; }
.drawer-foot { padding: 14px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.chip-btn {
  font-size: 12px; padding: 6px 11px; border-radius: 999px;
  background: var(--accent-weak); color: var(--accent); border: none;
}
.answer {
  margin-top: 14px; padding: 14px; background: #fbfcfd;
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 10px; line-height: 1.7; display: none;
}
.answer.on { display: block; }
.answer .meta { font-size: 12px; color: var(--muted); margin-top: 8px; }
.answer pre {
  background: #f2f4f7; padding: 10px; border-radius: 8px;
  font-size: 12px; overflow: auto; max-height: 240px;
}

/* ---------------- 弹窗与登录 ---------------- */
dialog { border: none; border-radius: var(--radius); padding: 22px; width: min(460px, 92vw); }
dialog::backdrop { background: rgba(15,20,28,.45); }
dialog h3 { margin: 0 0 12px; font-size: 16px; }
dialog label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }

.mask {
  position: fixed; inset: 0; background: rgba(15,20,28,.5);
  display: none; align-items: center; justify-content: center; z-index: 60;
}
.mask.on { display: flex; }
.login {
  background: #fff; border-radius: 18px; padding: 28px;
  width: min(380px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login h2 { margin: 0 0 4px; font-size: 20px; }
.login p { margin: 0 0 16px; font-size: 12px; color: var(--muted); }
.login label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
.login button { width: 100%; margin-top: 18px; padding: 12px; }

.alert-item {
  border: 1px solid var(--line);
  border-left: 4px solid var(--warn);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}
.alert-item.critical { border-left-color: var(--danger); }
.alert-item .explain { font-size: 13px; margin-top: 6px; line-height: 1.6; }
.alert-item .facts { font-size: 12px; color: var(--muted); margin-top: 4px; }

#print-area { display: none; }

@media print {
  @page { size: 58mm auto; margin: 3mm; }
  html, body { height: auto; overflow: visible; background: #fff; }
  body > *:not(#print-area) { display: none !important; }
  #print-area {
    display: block !important;
    width: 100%;
    font-family: "Courier New", Consolas, monospace;
    font-size: 11px;
    line-height: 1.45;
    color: #000;
  }
  #print-area .center { text-align: center; }
  #print-area .line { display: flex; justify-content: space-between; gap: 6px; }
  #print-area hr { border: none; border-top: 1px dashed #000; margin: 4px 0; }
  #print-area .big { font-size: 13px; font-weight: 700; }
}

@media (max-width: 1000px) {
  .pos { grid-template-columns: 1fr; }
  .rail { width: 78px; }
  .rail-btn { font-size: 12px; padding: 12px 4px; }
}
