:root {
  --bg: #f6f7f9; --card: #fff; --text: #17202a; --muted: #6b7280; --line: #e5e7eb;
  --brand: #0f766e; --brand-soft: #ccfbf1; --in: #15803d; --in-soft: #dcfce7; --out: #b91c1c; --out-soft: #fee2e2;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419; --card: #182028; --text: #e6e9ee; --muted: #9aa4b1; --line: #2a3440;
    --brand: #2dd4bf; --brand-soft: #134e4a; --in: #4ade80; --in-soft: #14532d; --out: #f87171; --out-soft: #4c1d1d;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0 0 .6em; line-height: 1.2; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.08rem; } h3 { font-size: .95rem; color: var(--muted); }
h2 small { font-weight: 500; color: var(--muted); font-size: .85rem; margin-left: .3em; }
p { margin: .4em 0; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.lead { margin: 0; }
.boot { max-width: 420px; margin: 20vh auto; text-align: center; padding: 0 16px; }

/* layout */
.shell { display: flex; min-height: 100vh; }
.side { width: 220px; flex-shrink: 0; position: sticky; top: 0; height: 100vh; padding: 18px 12px; border-right: 1px solid var(--line); background: var(--card); }
.brand { font-weight: 700; font-size: 1.05rem; padding: 4px 10px 16px; }
.side nav a { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 10px; color: var(--text); text-decoration: none; margin-bottom: 2px; }
.side nav a:hover { background: var(--bg); }
.side nav a.on { background: var(--brand-soft); font-weight: 600; }
main { flex: 1; min-width: 0; padding: 18px 28px 40px; max-width: 1100px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.top h1 { margin: 0; }
.status { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.status.ok { color: var(--in); } .status.bad { color: var(--out); }
.tabbar { display: none; }

@media (max-width: 760px) {
  .side { display: none; }
  main { padding: 12px 16px calc(84px + env(safe-area-inset-bottom)); }
  .top { padding-top: env(safe-area-inset-top); }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 10; }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; text-decoration: none; color: var(--muted); font-size: 1.25rem; padding: 2px 0; }
  .tabbar a small { font-size: .7rem; }
  .tabbar a.on { color: var(--brand); }
  .tabbar a.on small { font-weight: 700; }
}

/* cards & stats */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.intro { border-color: var(--brand); }
.steps { margin: .5em 0 0; padding-left: 1.3em; } .steps li { margin: .35em 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stats.small { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; min-width: 0; }
.card .stat { background: var(--bg); border: 0; }
.stat span { font-size: .78rem; color: var(--muted); }
.stat b { font-size: 1.25rem; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats.small .stat b { font-size: 1.02rem; }
.stat small { color: var(--muted); font-size: .75rem; }
.stat.in b { color: var(--in); } .stat.out b { color: var(--out); }

.catrow { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; margin: 8px 0; }
.catrow b { font-variant-numeric: tabular-nums; }
.bar { grid-column: 1 / -1; height: 7px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand); border-radius: 99px; width: 0; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; margin-bottom: 12px; }

/* items */
.item { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 8px; color: var(--text); text-decoration: none; }
.item:last-child { border-bottom: 0; }
.item:hover { background: var(--bg); }
.item.faded { opacity: .5; }
.item.head { border-bottom: 0; padding: 0 0 10px; }
.item.head:hover { background: none; }
.ic { width: 36px; height: 36px; flex-shrink: 0; border-radius: 10px; background: var(--bg); display: grid; place-items: center; overflow: hidden; }
.ic img { width: 22px; height: 22px; }
.ic .emo { font-size: 1.2rem; }
.main { flex: 1; min-width: 0; }
.name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { font-size: .8rem; color: var(--muted); }
.amt { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt small { display: block; font-weight: 400; font-size: .75rem; color: var(--muted); }
.go { width: 32px; height: 32px; flex-shrink: 0; display: grid; place-items: center; border-radius: 8px; text-decoration: none; color: var(--brand); border: 1px solid var(--line); font-weight: 700; }
.go:hover { background: var(--brand-soft); }

.evlist { list-style: none; margin: 0; padding: 0; }
.ev { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.ev:last-child { border-bottom: 0; }
.ev.in .amt { color: var(--in); } .ev.out .amt { color: var(--out); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 99px; padding: 6px 11px; font: inherit; font-size: .85rem; cursor: pointer; }
.chip:hover { border-color: var(--brand); }
.chip.ic1 { padding: 4px 7px; font-size: 1.1rem; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 8px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #042f2e; } }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--out); border-color: var(--out); background: transparent; }
.btn.small { padding: 4px 10px; font-size: .85rem; }

/* forms */
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 14px; margin: 8px 0 12px; }
.f { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.f em { font-style: normal; opacity: .8; }
.f.wide { grid-column: 1 / -1; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.affix { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 9px; background: var(--card); }
.affix span { padding: 0 0 0 10px; color: var(--muted); }
.affix.suf span { padding: 0 10px 0 0; }
.affix input { border: 0; background: transparent; }
.affix:focus-within { outline: 2px solid var(--brand); outline-offset: -1px; }
.affix input:focus { outline: none; }
.chk { display: flex; gap: 8px; align-items: center; margin: 6px 0; cursor: pointer; }
.chk input { width: 18px; height: 18px; accent-color: var(--brand); }
.iconpick { display: flex; flex-direction: column; gap: 8px; }
.iconin { width: 80px; font-size: 1.3rem; text-align: center; }
.earner { border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 12px; }

/* tables */
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.breakdown td { padding: 7px 4px; border-bottom: 1px solid var(--line); }
.breakdown td:last-child { text-align: right; white-space: nowrap; }
.breakdown tr.tot td { font-weight: 700; border-bottom: 0; font-size: 1.05rem; }
.breakdown small { color: var(--muted); font-weight: 400; }
.plan th, .plan td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; font-size: .88rem; }
.plan th:first-child, .plan td:first-child { text-align: left; }
.plan th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--card); }
.plan .affix { width: 120px; margin-left: auto; }
.plan .affix input { padding: 5px 8px; text-align: right; }
.plan tr.ov td { background: var(--brand-soft); }
details { margin-top: 10px; }
summary { cursor: pointer; font-weight: 600; color: var(--brand); padding: 6px 0; }
details .tablewrap { max-height: 480px; overflow: auto; }
.notes { padding-left: 1.2em; margin: 10px 0 0; } .notes li { margin: 5px 0; }

/* charts */
.chart svg { width: 100%; height: auto; display: block; }
.chart text { font-size: 11px; fill: var(--muted); }
.chart .grid { stroke: var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .82rem; margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 4px; border-radius: 2px; display: inline-block; }

/* calendar */
.calhead { display: flex; align-items: center; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.calhead h2 { margin: 0 6px; min-width: 170px; text-align: center; }
.seg { margin-left: auto; display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--card); color: var(--muted); font: inherit; font-weight: 600; padding: 7px 14px; cursor: pointer; }
.seg button.on { background: var(--brand); color: #fff; }
.calsum { display: flex; flex-wrap: wrap; gap: 6px 22px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; }
.calsum div { display: flex; flex-direction: column; }
.calsum span { font-size: .75rem; color: var(--muted); }
.calsum b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.tin { color: var(--in); } .tout { color: var(--out); }

.aday { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.aday header { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--bg); border-bottom: 1px solid var(--line); }
.aday.istoday { border-color: var(--brand); }
.aday.istoday header { background: var(--brand-soft); }
.adate { width: 40px; text-align: center; line-height: 1.05; flex-shrink: 0; }
.adate b { display: block; font-size: 1.35rem; }
.adate span { font-size: .7rem; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.adtitle { flex: 1; font-weight: 600; min-width: 0; }
.adtot { display: flex; gap: 10px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.aday .evlist { padding: 2px 10px; }
.aday .none { padding: 10px 14px; margin: 0; }
.adbal { padding: 8px 14px; border-top: 1px dashed var(--line); font-size: .85rem; color: var(--muted); text-align: right; }
.adbal b { color: var(--text); font-variant-numeric: tabular-nums; }
.adbal.neg, .adbal.neg b { color: var(--out); }
.pastdays { margin: 0 0 10px; }
.pastdays summary { padding: 8px 2px; }
.pastdays .aday { opacity: .7; }
.addrow { margin-top: 6px; }

.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; margin-bottom: 14px; }
.wd { text-align: center; font-size: .75rem; color: var(--muted); padding: 2px 0; }
.day { min-height: 78px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 6px; text-align: left; font: inherit; color: var(--text); display: flex; flex-direction: column; gap: 2px; cursor: pointer; overflow: hidden; }
.day:hover { border-color: var(--brand); }
.day.dim { opacity: .35; }
.day.past:not(.today) .dn { color: var(--muted); }
.day.today .dn { background: var(--brand); color: #fff; border-radius: 99px; padding: 0 7px; }
.day.sel { outline: 2px solid var(--brand); outline-offset: -1px; }
.dn { font-weight: 700; font-size: .85rem; align-self: flex-start; }
.cin, .cout { font-size: .8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.cin { color: var(--in); } .cout { color: var(--out); }
.dots { display: flex; gap: 3px; margin-top: auto; }
.dots i { width: 6px; height: 6px; border-radius: 50%; }
.dots i.in { background: var(--in); } .dots i.out { background: var(--out); }
@media (max-width: 760px) {
  .cal { gap: 2px; }
  .day { min-height: 58px; padding: 4px 3px; border-radius: 8px; }
  .cin, .cout { font-size: .66rem; }
  .calhead h2 { min-width: 0; flex: 1; font-size: 1rem; }
  .seg { margin-left: 0; width: 100%; }
  .seg button { flex: 1; }
  .aday header { padding: 8px 10px; gap: 10px; }
  .adtitle { font-size: .9rem; }
  .adtot { flex-direction: column; gap: 0; text-align: right; font-size: .85rem; }
}

/* who chips & filter */
.who { display: inline-block; font-size: .7rem; font-weight: 600; padding: 1px 7px; border-radius: 99px; margin-left: 6px; vertical-align: 1px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.who.w0 { background: #ccfbf1; color: #115e59; border-color: transparent; }
.who.w1 { background: #ede9fe; color: #5b21b6; border-color: transparent; }
.who.w2 { background: #fef3c7; color: #92400e; border-color: transparent; }
.who.w3 { background: #fce7f3; color: #9d174d; border-color: transparent; }
@media (prefers-color-scheme: dark) {
  .who.w0 { background: #134e4a; color: #99f6e4; } .who.w1 { background: #3b0764; color: #ddd6fe; }
  .who.w2 { background: #451a03; color: #fde68a; } .who.w3 { background: #500724; color: #fbcfe8; }
}
.whofilter { margin-bottom: 12px; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.ev.note .ic { background: var(--brand-soft); }
.ntime { color: var(--muted); font-weight: 600; }
.dots i.note { background: #3b82f6; }

/* week view */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px; }
.wday { background: var(--card); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; min-height: 220px; overflow: hidden; }
.wday.istoday { border-color: var(--brand); }
.wday.past { opacity: .65; }
.wday header { display: flex; align-items: baseline; gap: 6px; padding: 8px 8px 6px; border-bottom: 1px solid var(--line); background: var(--bg); flex-wrap: wrap; }
.wday.istoday header { background: var(--brand-soft); }
.wday header > span:first-child { font-size: .72rem; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.wday header b { font-size: 1.1rem; }
.wtot { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; font-size: .72rem; font-weight: 700; line-height: 1.2; }
.witem { display: grid; grid-template-columns: auto 1fr; gap: 0 6px; padding: 6px 8px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: .8rem; }
.witem:hover { background: var(--bg); }
.wic { grid-row: span 2; font-size: 1rem; }
.wname { font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.wname .who { margin-left: 4px; }
.wamt { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--muted); }
.witem.in .wamt { color: var(--in); } .witem.out .wamt { color: var(--out); }
.witem.note { background: color-mix(in srgb, var(--brand-soft) 45%, transparent); }
.wnone { padding: 6px 10px; margin: 0; }
.wday footer { margin-top: auto; padding: 5px 8px; font-size: .72rem; color: var(--muted); text-align: right; border-top: 1px dashed var(--line); font-variant-numeric: tabular-nums; }
.wday footer.neg { color: var(--out); font-weight: 700; }
@media (max-width: 1000px) {
  .week { grid-template-columns: 1fr; }
  .wday { min-height: 0; }
  .wday.past { opacity: .55; }
  .witem { grid-template-columns: auto 1fr auto; align-items: center; font-size: .9rem; padding: 8px 10px; }
  .wic { grid-row: auto; }
}
.person { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); margin: 4px 0; }

.fw.wide { grid-column: 1 / -1; }
.fw[hidden] { display: none; }
.pv { background: var(--bg); border-radius: 10px; padding: 8px 12px; }
.paytable th { text-align: right; font-size: .85rem; padding: 6px 4px; }
.paytable th small { display: block; font-weight: 400; color: var(--muted); }
.paytable td { text-align: right; }
.paytable td:first-child { text-align: left; }

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 12px; overflow-y: auto; z-index: 50; }
.modal { background: var(--card); border-radius: 16px; padding: 18px; width: 100%; max-width: 620px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
@media (max-width: 760px) { .modal-bg { padding: 0; align-items: flex-end; } .modal { border-radius: 16px 16px 0 0; padding-bottom: calc(18px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto; } }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .9rem; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 32px); z-index: 60; }
#toast.show { opacity: 1; transform: translateX(-50%); }
.morelist { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 10px; }
