:root {
  --green: #145431;
  --green-2: #1f7a4a;
  --blue: #0b4f8a;
  --sky: #a6d1ee;
  --yellow: #ffcb05;
  --red: #b3261e;
  --red-bg: #fde8e6;
  --amber-bg: #fff4d6;
  --ink: #0a1a2e;
  --muted: #55657a;
  --line: #d5dee8;
  --bg: #f3f6f9;
  --card: #ffffff;
  --radius: 16px;
  --tabbar: 78px;
}
/* Theme: follows the phone by default; the 🌓 button forces light or dark (saved on this device). */
:root[data-theme="dark"] { --ink: #eef3f8; --muted: #a7b4c4; --line: #2b3a4d; --bg: #0f1722; --card: #17212f; --red-bg: #3a1c1a; --amber-bg: #3a3012; --sky: #1d3a52; --green: #7cd1a0; --green-2: #7cd1a0; --blue: #8ec5f5; color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --ink: #eef3f8; --muted: #a7b4c4; --line: #2b3a4d; --bg: #0f1722; --card: #17212f; --red-bg: #3a1c1a; --amber-bg: #3a3012; --sky: #1d3a52; --green: #7cd1a0; --green-2: #7cd1a0; --blue: #8ec5f5; color-scheme: dark; }
}
.top h1 small { display: block; font-size: .68rem; font-weight: 600; opacity: .85; line-height: 1.1; }
.theme-float { position: fixed; top: 10px; right: 12px; z-index: 5; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 20px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: 'Noto Sans TC', 'PingFang HK', 'Microsoft JhengHei', system-ui, sans-serif;
  line-height: 1.5; padding-bottom: calc(var(--tabbar) + 24px); overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* header */
.top { position: sticky; top: 0; z-index: 20; background: #145431; color: #fff; padding: 10px 14px; display: flex; align-items: center; gap: 10px; }
.top h1 { font-size: 1rem; margin: 0; flex: 1; font-weight: 800; white-space: nowrap; }
.top .who { font-size: .72rem; opacity: .9; max-width: 4.5em; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: rgba(255,255,255,.18); border: 0; color: #fff; border-radius: 12px; min-height: 48px; min-width: 48px; padding: 0 12px; font-size: .9rem; font-weight: 700; white-space: nowrap; }
.searchbar { padding: 12px 14px 4px; }
.searchbar input { width: 100%; min-height: 56px; border: 2px solid var(--line); border-radius: var(--radius); padding: 0 16px; background: var(--card); font-size: 1.05rem; }
.searchbar input:focus { outline: 3px solid var(--blue); border-color: var(--blue); }

/* tab bar */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--card); border-top: 2px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tab { border: 0; background: none; min-height: var(--tabbar); padding: 6px 2px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-weight: 700; font-size: .8rem; color: var(--muted); position: relative; }
.tab .n { font-size: 1.25rem; font-weight: 900; color: var(--ink); }
.tab[aria-selected="true"] { color: var(--green); background: color-mix(in srgb, var(--green) 10%, transparent); box-shadow: inset 0 4px 0 var(--green); }
.tab[aria-selected="true"] .n { color: var(--green); }
.tab.alert .n { color: #fff; background: var(--red); border-radius: 999px; padding: 0 12px; }

/* controls */
.controls { padding: 8px 14px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.controls label { font-size: .72rem; color: var(--muted); font-weight: 700; display: block; margin-bottom: 2px; }
.controls select { width: 100%; min-height: 52px; border: 2px solid var(--line); border-radius: 12px; background: var(--card); padding: 0 10px; font-size: .95rem; }
.controls .wide { grid-column: 1 / -1; }

/* lists */
.section-title { margin: 18px 14px 6px; font-size: .95rem; font-weight: 900; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.section-title .pill { background: #145431; color: #fff; border-radius: 999px; padding: 0 10px; font-size: .8rem; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 1rem; }
.card { background: var(--card); margin: 10px 14px; border-radius: var(--radius); border: 2px solid var(--line); padding: 14px 16px; display: block; width: calc(100% - 28px); text-align: left; }
button.card:active { transform: scale(.99); background: color-mix(in srgb, var(--blue) 8%, var(--card)); }
.card .row1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card .nm { font-size: 1.2rem; font-weight: 900; }
.chip { display: inline-block; border-radius: 999px; padding: 1px 10px; font-size: .78rem; font-weight: 800; background: var(--sky); color: var(--blue); }
.chip.red { background: var(--red-bg); color: var(--red); }
.chip.amber { background: var(--amber-bg); color: #7a5800; }
.chip.green { background: #d9f2e3; color: var(--green); }
.card .row2 { color: var(--muted); font-size: .88rem; margin-top: 2px; }
.card .money { margin-top: 6px; font-size: 1.05rem; font-weight: 800; }
.card .money small { font-weight: 600; color: var(--muted); }
.reasons { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.reason { background: var(--red-bg); color: var(--red); border-radius: 10px; padding: 6px 10px; font-size: .88rem; font-weight: 700; }
.group-head { margin: 18px 14px 0; display: flex; align-items: center; gap: 8px; font-weight: 900; font-size: 1.05rem; }
.group-head .hint { font-weight: 600; font-size: .78rem; color: var(--muted); }

/* receipt approvals */
.approve { border-color: var(--yellow); background: color-mix(in srgb, var(--yellow) 14%, var(--card)); }
.approve .btns { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; margin-top: 10px; }

/* buttons */
.btn { min-height: 56px; border-radius: 14px; border: 0; font-weight: 800; font-size: 1.02rem; padding: 0 18px; background: #0b4f8a; color: #fff; width: 100%; }
.btn.green { background: #1f7a4a; color: #fff; }
.btn.ghost { background: transparent; border: 2px solid var(--line); color: var(--ink); }
.btn.red { background: #b3261e; color: #fff; }
.btn.small { min-height: 48px; font-size: .92rem; }
.btn:disabled { opacity: .5; }
.btn-row { display: grid; gap: 10px; margin: 12px 14px; }
.btn-row.two { grid-template-columns: 1fr 1fr; }

/* detail overlay */
.overlay { position: fixed; inset: 0; z-index: 50; background: var(--bg); overflow-y: auto; padding-bottom: 40px; }
.overlay .bar { position: sticky; top: 0; background: #145431; color: #fff; display: flex; align-items: center; gap: 10px; padding: 8px 12px; z-index: 2; }
.overlay .bar .title { font-weight: 800; flex: 1; font-size: 1.05rem; }
.box { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); margin: 12px 14px; padding: 14px 16px; }
.box h3 { margin: 0 0 8px; font-size: .95rem; color: var(--muted); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.kv:last-child { border-bottom: 0; }
.kv b { text-align: right; }
.big-money { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 12px 14px; }
.big-money div { background: var(--card); border: 2px solid var(--line); border-radius: 14px; text-align: center; padding: 8px 4px; }
.big-money small { display: block; color: var(--muted); font-size: .72rem; font-weight: 700; }
.big-money strong { font-size: 1rem; white-space: nowrap; }
.big-money .owe strong { color: var(--red); }
.big-money .ok strong { color: var(--green); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(5,12,22,.6); z-index: 80; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--card); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto; }
@media (min-width: 700px) { .modal-bg { align-items: center; } .modal { border-radius: 22px; } }
.modal h2 { margin: 0 0 10px; font-size: 1.25rem; }
.field { margin: 12px 0; }
.field > label { display: block; font-weight: 800; margin-bottom: 4px; font-size: .95rem; }
.field input, .field select, .field textarea { width: 100%; min-height: 56px; border: 2px solid var(--line); border-radius: 12px; padding: 0 12px; background: var(--bg); font-size: 1.1rem; }
.field input[type=number] { font-size: 1.5rem; font-weight: 900; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.quick button { min-height: 48px; border-radius: 12px; border: 2px solid var(--blue); background: transparent; color: var(--blue); padding: 0 12px; font-weight: 800; font-size: .92rem; }
.toggle { display: flex; align-items: center; gap: 14px; background: var(--bg); border: 2px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 10px 0; min-height: 64px; }
.toggle input { width: 34px; height: 34px; accent-color: var(--green-2); flex: none; }
.toggle span { font-weight: 800; }
.toggle small { display: block; color: var(--muted); font-weight: 600; font-size: .78rem; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.compare div { background: var(--bg); border-radius: 12px; padding: 8px 10px; }
.compare small { color: var(--muted); font-weight: 700; display: block; }
.compare .new { background: #d9f2e3; color: #0b3d22; }
.notice { background: var(--amber-bg); border-radius: 12px; padding: 10px 12px; font-size: .9rem; margin: 10px 0; }
.toast { position: fixed; left: 14px; right: 14px; bottom: calc(var(--tabbar) + 14px); z-index: 100; background: var(--ink); color: var(--bg); border-radius: 14px; padding: 14px 16px; font-weight: 700; text-align: center; box-shadow: 0 8px 28px rgba(0,0,0,.35); }
.toast.err { background: var(--red); color: #fff; }
.spinner { text-align: center; padding: 36px; color: var(--muted); font-weight: 700; }

/* login */
.login { max-width: 460px; margin: 0 auto; padding: 28px 18px; }
.login h1 { color: var(--green); font-size: 1.6rem; margin: 10px 0 2px; }
.login p { color: var(--muted); margin: 0 0 16px; }
.who-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.who-btns button { min-height: 72px; border-radius: 16px; border: 3px solid var(--line); background: var(--card); font-size: 1.2rem; font-weight: 900; }
.who-btns button[aria-pressed="true"] { border-color: var(--green-2); background: #d9f2e3; color: #0b3d22; }
.login input { width: 100%; min-height: 60px; border: 2px solid var(--line); border-radius: 14px; padding: 0 14px; background: var(--card); font-size: 1.2rem; margin-bottom: 12px; }
.err-text { color: var(--red); font-weight: 800; min-height: 1.5em; }

/* card split: tap the main area to open; reminder row below */
.card { padding: 0; overflow: hidden; }
.card .cardmain { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 14px 16px; }
.card .cardmain:active { background: color-mix(in srgb, var(--blue) 8%, var(--card)); }
.cardact { display: flex; align-items: center; gap: 12px; padding: 0 16px 14px; }
.cardact .btn { width: auto; flex: none; }
.cardact .lastr { color: var(--muted); font-size: .85rem; font-weight: 700; }
.linkbtn { background: none; border: 0; color: var(--blue); font-weight: 800; text-decoration: underline; padding: 6px 0; min-height: 44px; text-align: left; }
.icon-btn.themeLogin { background: var(--card); color: var(--ink); border: 2px solid var(--line); }
.tabsub { margin: 10px 14px 0; color: var(--muted); font-size: .9rem; font-weight: 700; }
