:root {
  --blue: #1d4ed8;
  --blue-dark: #1e3a8a;
  --blue-light: #dbeafe;
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --ok: #16a34a;
  --ok-bg: #f0fdf4;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--ink);
  font-family: -apple-system, "Noto Sans TC", "PingFang TC", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; }

/* ── 按鈕 ── */
.btn { border: none; border-radius: 10px; padding: 11px 16px; font-size: 15px; font-weight: 600; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:active { background: var(--blue-dark); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-block { display: block; width: 100%; margin-top: 10px; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn-link { background: none; border: none; color: var(--blue); font-size: 14px; margin-top: 12px; text-decoration: underline; }
.btn-menu-btn { background: rgba(255,255,255,.18); border: none; color: #fff; font-size: 14px;
  font-weight: 600; padding: 6px 12px; border-radius: 20px; }
.btn-menu-btn:active { background: rgba(255,255,255,.3); }
.btn-icon-sq { background: var(--card); border: 1px solid var(--line); color: var(--blue);
  font-size: 20px; font-weight: 700; width: 38px; height: 38px; border-radius: 10px; }
.btn-icon-sq:active { background: var(--blue-light); }

/* ── 登入彈窗 ── */
.auth-modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; }
.auth-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.55); }
.auth-card { position: relative; background: #fff; border-radius: 20px; padding: 32px 26px; width: 100%; max-width: 360px;
  box-shadow: 0 20px 40px rgba(0,0,0,.3); text-align: center; }
.auth-logo { font-size: 44px; }
.auth-title { font-size: 24px; margin-top: 6px; }
.auth-sub { color: var(--muted); font-size: 14px; margin: 4px 0 20px; }
.auth-card input { display: block; width: 100%; padding: 12px 14px; margin-bottom: 10px;
  border: 1px solid var(--line); border-radius: 10px; }
.auth-error { background: var(--danger-bg); color: var(--danger); padding: 10px; border-radius: 8px;
  font-size: 14px; margin-bottom: 12px; text-align: left; }
.auth-error.auth-info { background: var(--blue-light); color: var(--blue-dark); }

/* ── 頂部與分頁 ── */
.app { max-width: 720px; margin: 0 auto; min-height: 100dvh; background: var(--bg); }
.topbar { position: sticky; top: 0; z-index: 10; background: var(--blue); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; padding-top: max(14px, env(safe-area-inset-top));
  box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.topbar-title { font-size: 18px; font-weight: 700; }
.topbar-logo { margin-right: 4px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.mode-badge { font-size: 11px; color: rgba(255,255,255,.75); font-weight: 400; letter-spacing: .3px;
  pointer-events: none; margin-left: 8px; vertical-align: middle; white-space: nowrap; }
.tabs { position: sticky; top: 52px; z-index: 9; display: flex; background: var(--card);
  border-bottom: 1px solid var(--line); }
.tab { flex: 1; border: none; background: none; padding: 13px 4px; font-size: 14px; font-weight: 600;
  color: var(--muted); border-bottom: 3px solid transparent; }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }

.content { padding: 16px; padding-bottom: 40px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── 卡片 ── */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px; }
.card-title { font-size: 15px; font-weight: 700; margin-bottom: 12px; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; font-size: 14px; }
.empty .btn { margin-top: 12px; }

.row-inline { display: flex; gap: 8px; }
.row-inline input { flex: 1; padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px; }

/* ── 月份切換 ── */
.month-switch { display: flex; align-items: center; justify-content: center; gap: 18px; margin-bottom: 14px; }
.month-label { font-size: 17px; font-weight: 700; min-width: 110px; text-align: center; }

/* ── 廠商清單 ── */
.vendor-row { display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--line); }
.vendor-row:last-child { border-bottom: none; }
.vendor-name { font-size: 15px; font-weight: 600; }

/* ── 發票填寫 ── */
.invoice-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.invoice-row:last-child { border-bottom: none; }
.invoice-row-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.invoice-amount { display: flex; align-items: center; gap: 6px; }
.invoice-amount input { width: 130px; padding: 9px 10px; border: 1px solid var(--line);
  border-radius: 8px; text-align: right; font-size: 15px; }
.invoice-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.save-flag { font-size: 12px; color: var(--ok); opacity: 0; transition: opacity .2s; margin-left: 6px; }
.save-flag.show { opacity: 1; }

/* ── 異動紀錄 ── */
.log-row { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.log-row:last-child { border-bottom: none; }
.log-row .log-vendor { font-weight: 600; }
.log-row .log-diff { margin-top: 2px; }
.log-row .log-diff .old { color: var(--muted); text-decoration: line-through; }
.log-row .log-diff .new { color: var(--blue); font-weight: 700; }
.log-row .log-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── 電腦/平板（web 模式）：資訊同一行呈現、版面更寬鬆 ───────────── */
@media (min-width: 768px) {
  .app { max-width: 880px; }
  .topbar { padding: 16px 28px; }
  .tabs { top: 56px; }
  .tab { padding: 15px 4px; font-size: 15px; }
  .content { padding: 24px 28px 48px; }
  .card { padding: 22px 26px; }

  .row-inline { max-width: 420px; }

  .vendor-row { padding: 14px 4px; }
  .vendor-row:hover { background: var(--blue-light); border-radius: 8px; }

  .invoice-row { display: flex; align-items: center; gap: 20px; padding: 14px 4px; }
  .invoice-row:hover { background: var(--blue-light); border-radius: 8px; }
  .invoice-row-top { flex: 1; }
  .invoice-meta { margin-top: 0; min-width: 190px; text-align: right; white-space: nowrap; }

  .log-row { display: flex; align-items: center; gap: 20px; padding: 12px 4px; }
  .log-row .log-vendor { min-width: 180px; }
  .log-row .log-diff { flex: 1; margin-top: 0; }
  .log-row .log-meta { margin-top: 0; min-width: 190px; text-align: right; white-space: nowrap; }

  .btn-menu-btn, .btn-icon-sq { cursor: pointer; }
  .tab:hover:not(.active) { color: var(--blue-dark); }
}
