:root {
  --bg: #f6f4ef; --surface: #fffefb; --surface-2: #f0ede6; --line: #e6e2d8;
  --ink: #1d2421; --ink-2: #566059; --ink-3: #8a928c;
  --brand: #1f6f5c; --brand-ink: #ffffff; --brand-soft: #e1efe9;
  --in: #1b8a5f; --out: #c8553d; --out-soft: #f8e6e1; --in-soft: #dff1e8;
  --bar: #2f7f6c; --bar-2: #e0ddd3;
  --shadow: 0 1px 2px rgba(20,30,25,.05), 0 6px 20px rgba(20,30,25,.05);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121714; --surface: #1a211d; --surface-2: #232b26; --line: #2c352f;
    --ink: #eef2ee; --ink-2: #aab4ad; --ink-3: #7b857e;
    --brand: #3aa88c; --brand-ink: #0c1311; --brand-soft: #1f3a32;
    --in: #46c28e; --out: #ee7d63; --out-soft: #3a2420; --in-soft: #1d3a2d;
    --bar: #3aa88c; --bar-2: #34403a;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
.num { font-variant-numeric: tabular-nums; }

/* shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 24px 16px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; padding: 4px 10px 22px; }
.logo i { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); display: grid; place-items: center; }
.logo svg { width: 20px; height: 20px; fill: var(--brand-ink); }
.nav a { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px; color: var(--ink-2); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav .ic { width: 20px; text-align: center; }
.side .sp { flex: 1; }
.linkbtn { background: none; border: 0; color: var(--ink-3); padding: 10px 12px; text-align: left; border-radius: 10px; }
.linkbtn:hover { background: var(--surface-2); }
.main { padding: 28px 32px 60px; max-width: 1120px; width: 100%; margin: 0 auto; }
.tabbar { display: none; }

.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.head h1 { font-size: 26px; }
.monthnav { display: flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.monthnav button { border: 0; background: none; width: 34px; height: 34px; border-radius: 9px; font-size: 18px; color: var(--ink-2); }
.monthnav button:hover { background: var(--surface-2); }
.monthnav span { min-width: 130px; text-align: center; font-weight: 600; text-transform: capitalize; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.card h3 { font-size: 15px; color: var(--ink-2); font-weight: 600; margin-bottom: 14px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(3, 1fr); margin-bottom: 16px; }
.cols { grid-template-columns: 1.15fr 1fr; margin-bottom: 16px; }
.kpi .lbl { color: var(--ink-2); font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.kpi .dot { width: 8px; height: 8px; border-radius: 50%; }
.kpi .val { font-size: 28px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }
.kpi .sub { font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.kpi.main-k { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.kpi.main-k .lbl, .kpi.main-k .sub { color: inherit; opacity: .85; }
.up { color: var(--out); } .down { color: var(--in); }

/* category bars */
.catrow { display: grid; grid-template-columns: 28px 1fr auto; gap: 4px 12px; align-items: center; padding: 8px 0; cursor: pointer; border-radius: 10px; }
.catrow:hover { background: var(--surface-2); }
.catrow .em { font-size: 18px; text-align: center; }
.catrow .nm { font-weight: 500; display: flex; justify-content: space-between; gap: 8px; }
.catrow .nm small { color: var(--ink-3); font-weight: 400; }
.catrow .v { font-weight: 600; }
.catrow .track { grid-column: 2 / 4; height: 6px; background: var(--bar-2); border-radius: 3px; overflow: hidden; }
.catrow .fill { height: 100%; background: var(--bar); border-radius: 3px; }

/* charts */
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--ink-3); font-size: 11px; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); margin-bottom: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--ink); color: var(--bg); padding: 7px 10px; border-radius: 9px; font-size: 12.5px; line-height: 1.35; box-shadow: 0 6px 20px rgba(0,0,0,.25); }

/* lists */
.daygroup { margin-bottom: 18px; }
.daygroup .dh { display: flex; justify-content: space-between; padding: 0 6px 6px; color: var(--ink-3); font-size: 13px; font-weight: 600; text-transform: capitalize; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tx { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.tx:last-child { border-bottom: 0; }
.tx:hover { background: var(--surface-2); }
.tx .bub { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 19px; }
.tx .d { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .m { font-size: 12.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .a { font-weight: 600; text-align: right; }
.tx .a.in { color: var(--in); }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); margin-left: 6px; font-weight: 500; }
.empty { text-align: center; color: var(--ink-3); padding: 48px 16px; }

/* forms */
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filters > * { flex: 1 1 140px; }
.filters .grow { flex: 2 1 220px; }
input, select, textarea { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; width: 100%; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
label.f { display: block; font-size: 13px; color: var(--ink-2); font-weight: 500; margin-bottom: 12px; }
label.f > :last-child { margin-top: 5px; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 16px; font-weight: 600; }
.btn:hover { background: var(--surface-2); }
.btn.pri { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.pri:hover { filter: brightness(1.06); }
.btn.danger { color: var(--out); }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.seg button { border: 0; background: none; border-radius: 10px; padding: 9px; font-weight: 600; color: var(--ink-2); }
.seg button.on.out { background: var(--out); color: #fff; }
.seg button.on.in { background: var(--in); color: #fff; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fab { position: fixed; right: 28px; bottom: 28px; width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--brand); color: var(--brand-ink); font-size: 28px; box-shadow: 0 8px 24px rgba(31,111,92,.35); z-index: 20; }

/* modal */
.scrim { position: fixed; inset: 0; background: rgba(10,15,12,.5); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { background: var(--surface); border-radius: 20px; padding: 22px; width: 100%; max-width: 460px; max-height: 92vh; overflow: auto; }
.modal h2 { font-size: 20px; margin-bottom: 16px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* import */
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 36px 20px; text-align: center; color: var(--ink-2); background: var(--surface); }
.drop.over { border-color: var(--brand); background: var(--brand-soft); }
.drop b { color: var(--ink); }
.check { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 12px; margin: 14px 0; font-weight: 500; }
.check.ok { background: var(--in-soft); color: var(--in); }
.check.warn { background: var(--out-soft); color: var(--out); }
.ptable { width: 100%; border-collapse: collapse; }
.ptable th { text-align: left; font-size: 12px; color: var(--ink-3); font-weight: 600; padding: 8px 10px; position: sticky; top: 0; background: var(--surface); }
.ptable td { padding: 7px 10px; border-top: 1px solid var(--line); vertical-align: middle; }
.ptable select { padding: 6px 8px; border-radius: 9px; min-width: 170px; }
.ptable tr.dup { opacity: .45; }
.ptable td.r { text-align: right; white-space: nowrap; font-weight: 600; }
.pscroll { max-height: 56vh; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.stickybar { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; display: flex; gap: 10px; justify-content: space-between; align-items: center; flex-wrap: wrap; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 100%; max-width: 380px; padding: 28px; }
.auth .logo { justify-content: center; padding-bottom: 8px; font-size: 26px; }
.auth p { text-align: center; color: var(--ink-2); margin: 0 0 20px; }
.err { color: var(--out); font-size: 13.5px; margin-bottom: 10px; min-height: 18px; }

.catedit { display: grid; grid-template-columns: 44px 1fr 44px auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.catedit input[type=color] { padding: 2px; height: 38px; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 12px; z-index: 60; font-weight: 500; }

@media (max-width: 860px) {
  .shell { display: block; }
  .side { display: none; }
  .main { padding: 18px 16px 110px; }
  .head h1 { font-size: 22px; }
  .kpis { grid-template-columns: 1fr; gap: 10px; }
  .kpi .val { font-size: 24px; }
  .cols { grid-template-columns: 1fr; }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a { flex: 1; text-align: center; text-decoration: none; color: var(--ink-3); font-size: 11px; font-weight: 600; padding: 6px 0; border-radius: 10px; }
  .tabbar a .ic { display: block; font-size: 20px; line-height: 1.2; }
  .tabbar a.on { color: var(--brand); }
  .fab { right: 18px; bottom: 82px; }
  .row2 { grid-template-columns: 1fr; }
  .modal { align-self: end; border-radius: 22px 22px 0 0; max-width: none; }
  .scrim { padding: 0; align-items: end; }
  .ptable .hm { display: none; }
  .ptable select { min-width: 130px; }
  .toast { bottom: 100px; }
}
