/* 蝦貨通 ShrimpFlow — 蝦紅 × 海洋藍主題, mobile-first PWA
   [claude code] 2026-08-10 建檔
   配色慣例:台灣紅賺綠賠 → .gain 紅 (賺 / 收入) / .loss 綠 (賠 / 負數), 成本用中性灰藍 */
:root {
  --shrimp: #ff6b35;
  --shrimp-d: #e2510f;
  --shrimp-l: #fff1e9;
  --ocean: #0891b2;
  --ocean-l: #ecfeff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg1: #fff7ed;
  --bg2: #ecfeff;
  --card: #ffffff;
  --gain: #dc2626;   /* 紅 = 賺 / 收入 (台灣慣例) */
  --gain-l: #fef2f2;
  --loss: #059669;   /* 綠 = 賠 / 負數 */
  --loss-l: #ecfdf5;
  --cost: #475569;
  --amber: #f59e0b;
  --shadow: 0 6px 20px rgba(15, 23, 42, .08);
  --radius: 16px;
  --nav-h: 62px;
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
  min-height: 100vh;
  overscroll-behavior-y: none;
}
#app { min-height: 100vh; }

.boot {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: var(--shrimp-d); font-weight: 700;
}

/* ───────── layout ───────── */
.screen {
  max-width: 560px; margin: 0 auto;
  padding: 0 16px calc(var(--nav-h) + 28px);
  min-height: 100vh;
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(135deg, var(--shrimp), #f97316 60%, #fb923c);
  color: #fff; margin: 0 -16px 16px;
  padding: calc(env(safe-area-inset-top) + 14px) 18px 16px;
  border-radius: 0 0 22px 22px; box-shadow: var(--shadow);
  display: flex; align-items: flex-end; gap: 10px;
}
.topbar .tb-main { flex: 1; min-width: 0; }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: .5px; }
.topbar .sub { margin-top: 3px; font-size: 13px; opacity: .95; }
.topbar .tb-act {
  flex: 0 0 auto; background: rgba(255,255,255,.22); border: 1.5px solid rgba(255,255,255,.45);
  color: #fff; border-radius: 12px; padding: 8px 12px; font-size: 13px; font-weight: 700;
  font-family: inherit; cursor: pointer;
}
.topbar .tb-act:active { transform: scale(.95); }

/* ───────── card ───────── */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 12px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.card h2 .ico { font-size: 19px; }
.card h2 .h2-right { margin-left: auto; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.section-title { font-size: 13px; color: var(--muted); font-weight: 700; margin: 18px 4px 8px; }

/* ───────── 今日結算 (主打卡) ───────── */
.net-card { text-align: center; background: linear-gradient(140deg, #fff, #fff7ed); border: 1.5px solid #fed7aa; }
.net-card .nc-lab { font-size: 13.5px; color: var(--muted); font-weight: 700; }
.net-card .nc-amt { font-size: 44px; font-weight: 900; line-height: 1.15; margin: 2px 0 4px; font-variant-numeric: tabular-nums; }
.net-card .nc-amt.gain { color: var(--gain); }
.net-card .nc-amt.loss { color: var(--loss); }
.net-card .nc-amt.zero { color: var(--muted); }
.net-card .nc-sub { font-size: 12.5px; color: var(--muted); }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 12px; }
.stat-grid.g2 { grid-template-columns: 1fr 1fr; }
.stat {
  background: #f8fafc; border: 1.5px solid var(--line); border-radius: 13px;
  padding: 11px 8px; text-align: center;
}
.stat .v { font-size: 19px; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 12px; font-weight: 700; color: var(--muted); }
.stat .l { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.stat.rev { background: var(--gain-l); border-color: #fecaca; }
.stat.rev .v { color: var(--gain); }
.stat.buy .v, .stat.exp .v { color: var(--cost); }
.v.gain { color: var(--gain); } .v.loss { color: var(--loss); }

/* ───────── 快速記帳 ───────── */
.quick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.quick {
  border-radius: var(--radius); padding: 16px 8px; color: #fff; cursor: pointer;
  box-shadow: var(--shadow); transition: transform .12s; text-align: center; border: none;
  font-family: inherit;
}
.quick:active { transform: scale(.96); }
.quick .qe { font-size: 27px; display: block; }
.quick .qt { font-weight: 800; font-size: 14.5px; margin-top: 4px; }
.q-sale { background: linear-gradient(140deg, #ef4444, #f97316); }
.q-buy  { background: linear-gradient(140deg, #0891b2, #0ea5e9); }
.q-exp  { background: linear-gradient(140deg, #64748b, #94a3b8); }

/* ───────── 未收帳款 ───────── */
.owe-row {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  border-radius: 13px; margin-bottom: 9px; background: #f8fafc;
  border: 1.5px solid var(--line); cursor: pointer;
}
.owe-row:active { transform: scale(.99); }
.owe-row.hot { background: var(--gain-l); border-color: #fecaca; }
.owe-row .oe { font-size: 24px; width: 40px; text-align: center; }
.owe-row .om { flex: 1; min-width: 0; }
.owe-row .om .o1 { font-weight: 700; font-size: 14.5px; }
.owe-row .om .o2 { font-size: 12px; color: var(--muted); margin-top: 1px; }
.owe-row .ov { font-weight: 800; font-size: 17px; font-variant-numeric: tabular-nums; }
.owe-row.hot .ov { color: var(--gain); }

/* ───────── 走勢圖 ───────── */
.bars { width: 100%; height: 150px; display: block; }
.bars .b-pos { fill: var(--gain); }
.bars .b-neg { fill: var(--loss); }
.bars .b-zero { fill: var(--line); }
.bars .b-lbl { fill: var(--muted); font-size: 10px; text-anchor: middle; }
.bars .b-axis { stroke: var(--line); stroke-width: 1; }

/* ───────── buttons ───────── */
.btn {
  appearance: none; border: none; border-radius: 13px; cursor: pointer;
  font-family: inherit; font-size: 15px; font-weight: 700; padding: 13px 18px;
  background: linear-gradient(135deg, var(--shrimp), #f97316); color: #fff;
  transition: transform .12s, opacity .15s; width: 100%;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn.ghost { background: #fff; color: var(--shrimp-d); border: 1.5px solid #fed7aa; }
.btn.gray { background: #f1f5f9; color: var(--ink); }
.btn.ocean { background: linear-gradient(135deg, var(--ocean), #0ea5e9); }
.btn.danger { background: #fef2f2; color: var(--gain); border: 1.5px solid #fecaca; }
.btn.sm { padding: 9px 14px; font-size: 13.5px; width: auto; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ───────── forms ───────── */
label.fld { display: block; margin-bottom: 12px; }
label.fld .lab { font-size: 13px; color: var(--muted); font-weight: 700; margin-bottom: 5px; display: block; }
input, select, textarea {
  font-family: inherit; font-size: 16px; width: 100%; padding: 12px 13px;
  border: 1.5px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--shrimp); }
textarea { resize: vertical; min-height: 56px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* 金額試算列 (數量 × 單價 = 金額) */
.calc-box {
  background: var(--shrimp-l); border: 1.5px solid #fed7aa; border-radius: 13px;
  padding: 12px 14px; margin-bottom: 12px; display: flex; align-items: center; gap: 10px;
}
.calc-box .cb-l { font-size: 13px; color: #9a3412; font-weight: 700; flex: 1; }
.calc-box .cb-v { font-size: 26px; font-weight: 900; color: var(--shrimp-d); font-variant-numeric: tabular-nums; }
.calc-box .cb-v small { font-size: 14px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 9px 15px; border-radius: 999px; border: 1.5px solid var(--line);
  background: #fff; font-size: 14px; font-weight: 600; cursor: pointer; transition: all .12s;
}
.chip.on { background: var(--shrimp); color: #fff; border-color: var(--shrimp); }
.chip:active { transform: scale(.95); }
.chip.sm { padding: 6px 12px; font-size: 13px; }
.chip.ocean.on { background: var(--ocean); border-color: var(--ocean); }
.chip.paid.on { background: var(--gain); border-color: var(--gain); }
.chip.unpaid.on { background: var(--amber); border-color: var(--amber); }
.chip .cp { font-size: 11px; opacity: .7; margin-left: 4px; }
.chip.on .cp { opacity: .9; }

/* 日期切換列 */
.dnav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.dnav button {
  flex: 0 0 46px; height: 44px; border-radius: 12px; border: 1.5px solid var(--line);
  background: #fff; font-size: 19px; cursor: pointer; font-family: inherit; color: var(--ink);
}
.dnav button:active { background: var(--shrimp-l); }
.dnav .dlab {
  flex: 1; text-align: center; font-weight: 800; font-size: 15.5px; padding: 11px 6px;
  background: #fff; border: 1.5px solid var(--line); border-radius: 12px; cursor: pointer;
}
.dnav .dlab small { display: block; font-size: 11.5px; color: var(--muted); font-weight: 600; }

/* ───────── list items ───────── */
.item {
  display: flex; align-items: center; gap: 11px; padding: 11px 2px;
  border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: none; }
.item .ib { font-size: 21px; width: 32px; text-align: center; flex: 0 0 auto; }
.item .im { flex: 1; min-width: 0; }
.item .im .i1 { font-weight: 700; font-size: 14.5px; }
.item .im .i2 { font-size: 12.5px; color: var(--muted); margin-top: 2px; word-break: break-word; }
.item .iright { text-align: right; flex: 0 0 auto; }
.item .iv { font-weight: 800; font-size: 15.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.item .iv.gain { color: var(--gain); }
.item .iv.cost { color: var(--cost); }
.item .del { color: var(--gain); background: none; border: none; font-size: 17px; padding: 6px 4px; cursor: pointer; opacity: .65; }
.item.tap { cursor: pointer; }
.item.tap:active { background: #f8fafc; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 14px; line-height: 1.6; }
.tot-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 12px; border-radius: 12px; background: #f8fafc; border: 1.5px solid var(--line);
  margin-bottom: 12px; font-weight: 700; font-size: 14px;
}
.tot-row .tv { font-size: 19px; font-weight: 900; font-variant-numeric: tabular-nums; }

/* ───────── 客戶 ───────── */
.cust-row {
  display: flex; align-items: center; gap: 10px; padding: 12px 10px;
  border-radius: 13px; margin-bottom: 9px; background: #fff;
  border: 1.5px solid var(--line); box-shadow: 0 2px 8px rgba(15,23,42,.04);
}
.cust-row .cm { flex: 1; min-width: 0; cursor: pointer; }
.cust-row .cn { font-weight: 800; font-size: 16px; }
.cust-row .cp2 { font-size: 13px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.cust-row .cstat { font-size: 12px; color: var(--muted); margin-top: 3px; }
.cust-row .cstat b { color: var(--gain); }
.call-btn {
  flex: 0 0 auto; width: 54px; height: 54px; border-radius: 16px; text-decoration: none;
  background: linear-gradient(140deg, #16a34a, #22c55e); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 22px; box-shadow: 0 3px 10px rgba(22,163,74,.32);
}
.call-btn small { font-size: 10px; font-weight: 700; margin-top: -2px; }
.call-btn:active { transform: scale(.94); }
.call-btn.off { background: #e2e8f0; color: #94a3b8; box-shadow: none; pointer-events: none; }
.searchbar { display: flex; gap: 8px; margin-bottom: 12px; }
.searchbar input { flex: 1; }

/* ───────── 報表 table ───────── */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.tbl th { color: var(--muted); font-size: 12px; font-weight: 700; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl td.gain { color: var(--gain); font-weight: 700; }
.tbl td.loss { color: var(--loss); font-weight: 700; }
.tbl-wrap { overflow-x: auto; }
.rank-row { display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--line); }
.rank-row:last-child { border-bottom: none; }
.rank-row .rn { width: 24px; height: 24px; border-radius: 8px; background: var(--shrimp-l); color: var(--shrimp-d); font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.rank-row .rm { flex: 1; min-width: 0; font-weight: 700; font-size: 14px; }
.rank-row .rm small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }
.rank-row .rv { font-weight: 800; font-variant-numeric: tabular-nums; }

/* ───────── bottom nav ───────── */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: rgba(255,255,255,.96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 14px rgba(15,23,42,.06);
}
.nav button {
  flex: 1; background: none; border: none; cursor: pointer; font-family: inherit;
  padding: 8px 0 9px; color: var(--muted); display: flex; flex-direction: column;
  align-items: center; gap: 3px; height: var(--nav-h);
}
.nav button .ne { font-size: 21px; transition: transform .15s; }
.nav button .nl { font-size: 11px; font-weight: 600; }
.nav button.on { color: var(--shrimp-d); }
.nav button.on .ne { transform: translateY(-2px) scale(1.12); }

/* ───────── modal / sheet ───────── */
.mask {
  position: fixed; inset: 0; z-index: 50; background: rgba(15,23,42,.42);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  background: #fff; width: 100%; max-width: 560px;
  border-radius: 22px 22px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto; animation: slideup .24s cubic-bezier(.2,.9,.3,1.1);
}
@keyframes slideup { from { transform: translateY(100%); } }
.sheet h3 { margin: 0 0 15px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.sheet h3 .h3r { margin-left: auto; font-size: 13px; color: var(--muted); font-weight: 600; }

/* ───────── misc ───────── */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 18px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 999px;
  font-size: 14px; font-weight: 600; z-index: 80; box-shadow: var(--shadow); max-width: 90%;
  animation: toastin .2s ease; text-align: center;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } }
.spinner {
  width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--shrimp);
  border-radius: 50%; animation: spin .7s linear infinite; margin: 30px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.guest { background: #fef3c7; color: #b45309; }
.badge.bound { background: #d1fae5; color: #047857; }
.badge.paid { background: #dcfce7; color: #15803d; }
.badge.unpaid { background: #fef3c7; color: #b45309; }
.foot { text-align: center; color: var(--muted); font-size: 11.5px; padding: 14px 0 4px; line-height: 1.7; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; line-height: 1.5; }
.linkcard {
  display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow); margin-bottom: 12px; cursor: pointer;
}
.linkcard:active { transform: scale(.99); }
.linkcard .le { font-size: 24px; }
.linkcard .lm { flex: 1; }
.linkcard .lm .l1 { font-weight: 800; font-size: 15px; }
.linkcard .lm .l2 { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.linkcard .lgo { color: var(--muted); font-size: 20px; }

/* ───────── auth gate ───────── */
.gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 18px; }
.gate-card {
  background: var(--card); border-radius: 22px; box-shadow: var(--shadow);
  padding: 30px 22px 22px; width: 100%; max-width: 400px; text-align: center; position: relative;
}
.gate-back {
  position: absolute; top: 14px; left: 14px; background: none; border: none;
  color: var(--muted); font-family: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; padding: 4px 6px;
}
.gate-back:active { color: var(--shrimp-d); }
.gate-logo { font-size: 54px; line-height: 1; }
.gate-title { margin: 8px 0 3px; font-size: 25px; font-weight: 800; }
.gate-sub { margin: 0 0 20px; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.gate-seg { display: flex; background: #f1f5f9; border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.gate-seg button {
  flex: 1; border: none; background: none; padding: 10px; border-radius: 9px;
  font-family: inherit; font-size: 15px; font-weight: 700; color: var(--muted); cursor: pointer;
}
.gate-seg button.on { background: #fff; color: var(--shrimp-d); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.gate-card .fld { text-align: left; }
.gate-ver { margin-top: 18px; color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.ver-upd {
  display: inline-block; margin-left: 6px; padding: 3px 10px; border-radius: 999px;
  background: var(--amber); color: #fff; border: none; font-size: 11.5px; font-weight: 700;
  cursor: pointer; vertical-align: middle;
}
.ver-upd:active { transform: scale(.95); }
