:root {
  --bg: #f4f7fd;
  --card: #ffffff;
  --line: #dbe4f3;
  --line2: #c4d3ec;
  --fg: #0b1f44;
  --mut: #4b5f82;
  --faint: #7c8db0;
  --blue: #1d4ed8;
  --blue2: #2563eb;
  --sky: #e8f0ff;
  --in: #0f8a5f;
  --out: #c2334d;
  --warn: #a16207;
  --radius: 14px;
  --display: "Sora", "Inter", system-ui, sans-serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 15px/1.5 var(--body); min-height: 100vh; }
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 18px 16px 48px; outline: none; }
.muted { color: var(--mut); }
.faint { color: var(--faint); }
.num { font-variant-numeric: tabular-nums; }
.in { color: var(--in); }
.out { color: var(--out); }

/* top bar */
.top { position: sticky; top: 0; z-index: 20; background: var(--blue); color: #fff; box-shadow: 0 2px 10px rgba(29, 78, 216, 0.25); }
.top .bar1 { display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); max-width: 1100px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; font: 700 1.05rem var(--display); white-space: nowrap; }
.brand img { background: #fff; border-radius: 8px; padding: 2px; }
.who { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 0.85rem; }
.who a { color: #fff; opacity: 0.9; }
.who .role { padding: 1px 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.18); text-transform: capitalize; }
.tabs { display: flex; gap: 4px; padding: 0 12px; max-width: 1100px; margin: 0 auto; overflow-x: auto; }
.tabs button { background: none; border: 0; color: rgba(255, 255, 255, 0.82); padding: 10px 16px 12px; font-weight: 600; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button[aria-current="page"] { color: #fff; border-bottom-color: #fff; }
@media (max-width: 520px) { .who > span:first-child { display: none; } }

h1 { font: 700 clamp(1.35rem, 3vw, 1.75rem)/1.2 var(--display); margin: 4px 0 2px; }
h2 { font: 700 1.05rem/1.3 var(--display); margin: 0 0 12px; }
.head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 2px rgba(11, 31, 68, 0.04); }

input, select, textarea { width: 100%; background: #fff; border: 1px solid var(--line2); border-radius: 10px; padding: 9px 11px; min-height: 42px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--blue2); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16); }
input[disabled] { background: #f1f4fa; color: var(--faint); }
label { display: grid; gap: 5px; font-size: 0.83rem; color: var(--mut); font-weight: 500; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line2); background: #fff; color: var(--blue); cursor: pointer; font-weight: 600; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--blue2); background: var(--sky); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue2); }
.btn.excel { background: #107c41; border-color: #107c41; color: #fff; }
.btn.excel:hover { background: #0d6a37; }
.btn.danger { color: var(--out); border-color: #f0c2cb; }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 0.83rem; }
.btn[disabled] { opacity: 0.55; cursor: wait; }

/* daily book */
.daily { width: 100%; border-collapse: separate; border-spacing: 0; }
.daily th { background: var(--sky); color: var(--blue); font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; padding: 10px 8px; text-align: right; border-bottom: 1px solid var(--line2); }
.daily th:first-child { text-align: left; }
.daily td { padding: 5px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.daily td.date { white-space: nowrap; font-weight: 600; padding-left: 12px; }
.daily td.date small { display: block; font-weight: 500; color: var(--faint); font-size: 0.75rem; }
.daily tr.today td { background: #eef4ff; }
.daily tr.sun td.date small { color: var(--out); }
.daily tr.future td { opacity: 0.45; }
.daily input { text-align: right; font-variant-numeric: tabular-nums; min-height: 38px; padding: 6px 9px; }
.daily td.st { width: 26px; text-align: center; font-size: 0.85rem; }
.daily tfoot td { font-weight: 700; padding: 12px 8px; text-align: right; background: var(--sky); color: var(--blue); border-top: 1px solid var(--line2); }
.daily tfoot td:first-child { text-align: left; padding-left: 12px; }
.tablecard { padding: 0; overflow: hidden; }
.tablecard .scroll { overflow-x: auto; }
@media (max-width: 560px) {
  .daily th { font-size: 0.64rem; padding: 8px 3px; letter-spacing: 0; }
  .daily td { padding: 4px 2px; }
  .daily td.date { padding-left: 8px; font-size: 0.85rem; }
  .daily input { font-size: 0.86rem; padding: 6px 5px; min-width: 0; }
  .daily td.st { width: 14px; font-size: 0.7rem; }
  .daily tfoot td { padding: 10px 4px; font-size: 0.82rem; }
}

/* expenses */
.addform { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 16px; }
.addform .wide { grid-column: 1 / -1; }
.addform .full { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
@media (min-width: 820px) { .addform { grid-template-columns: 150px 1fr 1.4fr 140px 130px; align-items: end; } .addform .wide { grid-column: auto; } }
table.list { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.list th { text-align: left; color: var(--blue); background: var(--sky); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.03em; padding: 10px; }
table.list td { padding: 10px; border-bottom: 1px solid var(--line); }
table.list td.r, table.list th.r { text-align: right; }
table.list tr.void td, table.list tr.rejected td { text-decoration: line-through; color: var(--faint); }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover td { background: #f8fbff; }
table.list tfoot td { font-weight: 700; color: var(--blue); background: var(--sky); padding: 12px 10px; }
.chip { display: inline-block; font-size: 0.7rem; font-weight: 700; padding: 1px 8px; border-radius: 99px; margin-left: 6px; text-decoration: none; }
.chip.pending { background: #fef3c7; color: var(--warn); }
.chip.void, .chip.rejected { background: #fde2e7; color: var(--out); }
.chip.bill, .chip.active { background: var(--sky); color: var(--blue); }
.cats { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.cats span { background: #fff; border: 1px solid var(--line); border-radius: 99px; padding: 4px 12px; font-size: 0.84rem; }
.cats b { color: var(--blue); }
.empty { padding: 30px 12px; text-align: center; color: var(--mut); }
.err { color: var(--out); font-size: 0.88rem; min-height: 1em; }
@media (max-width: 640px) { table.list .hide-sm { display: none; } table.list td, table.list th { padding: 9px 6px; } }

/* sheet */
dialog { width: min(520px, calc(100vw - 24px)); max-height: 90vh; padding: 0; border: 0; border-radius: 16px; background: #fff; color: var(--fg); box-shadow: 0 20px 60px rgba(11, 31, 68, 0.25); }
dialog::backdrop { background: rgba(11, 31, 68, 0.35); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--sky); }
.sheet-body { padding: 16px 18px 20px; display: grid; gap: 12px; }
.x { background: none; border: 0; color: var(--mut); font-size: 1.5rem; cursor: pointer; min-width: 40px; min-height: 40px; }
.detail { display: grid; grid-template-columns: 120px 1fr; gap: 8px 14px; font-size: 0.92rem; margin: 0; }
.detail dt { color: var(--faint); }
.detail dd { margin: 0; overflow-wrap: anywhere; }
.bill { max-width: 100%; border-radius: 10px; border: 1px solid var(--line); }
.hist { font-size: 0.82rem; color: var(--mut); display: grid; gap: 4px; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--fg); color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; transition: 0.25s; pointer-events: none; z-index: 60; max-width: calc(100vw - 32px); }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.signin { max-width: 460px; margin: 10vh auto; text-align: center; }
.signin .card { padding: 28px; }
.signin code { background: var(--sky); padding: 2px 8px; border-radius: 6px; color: var(--blue); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- v3 polish ---------- */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
@media (min-width: 760px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; box-shadow: 0 1px 2px rgba(11, 31, 68, 0.04); }
.stat .label { color: var(--mut); font-size: 0.8rem; font-weight: 600; }
.stat .value { font: 700 clamp(1.1rem, 3vw, 1.5rem)/1.25 var(--display); margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat .value small { font-size: 0.6em; color: var(--faint); font-weight: 600; }
.stat .sub { color: var(--faint); font-size: 0.76rem; margin-top: 2px; }
.stat.blue { background: linear-gradient(135deg, var(--blue), #3b82f6); border-color: var(--blue); color: #fff; }
.stat.blue .label, .stat.blue .sub { color: rgba(255, 255, 255, 0.85); }
.stat.pos .value { color: var(--in); }
.stat.neg .value { color: var(--out); }
.monthbar { display: flex; align-items: center; gap: 6px; }
.monthbar input { width: 170px; }
.btn.icon { min-width: 42px; padding: 0; font-size: 1.3rem; line-height: 1; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.daily td.net { text-align: right; font-weight: 700; padding-right: 12px; white-space: nowrap; }
.daily th:nth-child(4) { padding-right: 12px; }
.tip { font-size: 0.82rem; margin: 10px 2px 0; }
.grid-set { display: grid; gap: 14px; }
@media (min-width: 760px) { .grid-set { grid-template-columns: repeat(3, minmax(0, 1fr)); } .grid-set .wide { grid-column: 1 / -1; } }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chipx { display: inline-flex; align-items: center; gap: 4px; background: var(--sky); color: var(--blue); border-radius: 99px; padding: 4px 6px 4px 12px; font-size: 0.86rem; font-weight: 600; }
.chipx button { border: 0; background: rgba(29, 78, 216, 0.12); color: var(--blue); width: 22px; height: 22px; border-radius: 50%; cursor: pointer; font-size: 0.95rem; line-height: 1; }
.chipx:last-child { padding-right: 12px; }
.addcat { display: flex; gap: 8px; max-width: 460px; }
.switch { display: flex; align-items: center; gap: 10px; font-size: 0.92rem; color: var(--fg); cursor: pointer; }
.switch input { width: 20px; height: 20px; min-height: 0; accent-color: var(--blue); }
.savebar { grid-column: 1 / -1; display: flex; justify-content: flex-end; align-items: center; gap: 12px; position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 35%); }
@media (max-width: 640px) {
  .head .actions { width: 100%; }
  .monthbar { flex: 1 1 100%; }
  .monthbar input { flex: 1; width: auto; min-width: 0; }
  .actions .btn.excel { flex: 1 1 100%; }
  .daily td.net { padding-right: 4px; font-size: 0.85rem; }
}
@media (max-width: 420px) { .tabs { padding: 0 4px; gap: 0; } .tabs button { padding: 10px 10px 12px; font-size: 0.9rem; } }
