:root {
  --bg: #f5f3ee;
  --panel: #ffffff;
  --ink: #1d2420;
  --ink-2: #4b5650;
  --ink-3: #7c8781;
  --line: #e3e0d7;
  --line-2: #efece5;
  --brand: #1f5d45;
  --brand-2: #2c7a5c;
  --brand-soft: #e5f0ea;
  --accent: #b8862b;
  --danger: #b4392f;
  --danger-soft: #fbeceb;
  --warn: #a8701a;
  --warn-soft: #fbf3e2;
  --info: #2f5f8a;
  --info-soft: #e9f1f8;
  --ok: #2c7a5c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 16px rgba(20, 30, 25, .05);
  --font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  --side: 248px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-weight: 600; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 20px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--ink-3); }
.num, td.n { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
th.n { text-align: right; white-space: nowrap; }
.muted { color: var(--ink-3); } .small { font-size: 12px; }
.pos { color: var(--ok); } .neg { color: var(--danger); }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { background: #173f30; color: #dfe9e3; position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 16px 10px 24px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.brand-mark { width: 30px; height: 30px; border-radius: 50%; background: #f4efe3; display: grid; place-items: center; flex: none; }
.brand-mark::after { content: ''; width: 12px; height: 12px; border-radius: 50%; background: var(--brand); }
.brand b { display: block; font-size: 15px; color: #fff; }
.brand span { font-size: 11px; color: #9fb8ab; }
.nav-group { margin-top: 10px; }
.nav-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #86a395; padding: 8px 10px 4px; }
.nav a { display: block; padding: 7px 10px; border-radius: 7px; color: #d5e2db; font-size: 13.5px; }
.nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; }
.nav a.active { background: #f4efe3; color: #173f30; font-weight: 500; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .who { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.btn.menu-btn { display: none; }
.content { padding: 20px 24px 60px; max-width: 1400px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 16px; }
.page-head .sub { color: var(--ink-3); font-size: 13px; margin-top: 3px; }
.page-head .actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 500; }

/* ---------- Cards & KPI ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
.card-h .right { margin-left: auto; }
.card-b { padding: 14px 16px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .l { font-size: 12px; color: var(--ink-3); }
.kpi .v { font-family: var(--mono); font-size: 19px; font-weight: 500; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .s { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.kpi.hl { border-color: var(--brand-2); background: var(--brand-soft); }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); margin: 22px 0 10px; font-weight: 600; }
.bar { height: 6px; background: var(--line-2); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--brand-2); }

/* ---------- Alerts ---------- */
.alerts { display: flex; flex-direction: column; gap: 6px; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; border-radius: 8px; font-size: 13px; border: 1px solid transparent; }
.alert::before { content: ''; flex: none; width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; }
.alert.danger { background: var(--danger-soft); border-color: #f1d0cc; } .alert.danger::before { background: var(--danger); }
.alert.warning { background: var(--warn-soft); border-color: #f0e0bd; } .alert.warning::before { background: var(--warn); }
.alert.info { background: var(--info-soft); border-color: #d3e3f1; } .alert.info::before { background: var(--info); }
.alert a { margin-left: auto; white-space: nowrap; }

/* ---------- Tables ---------- */
.tbl-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; font-weight: 500; color: var(--ink-3); font-size: 12px; padding: 9px 10px; border-bottom: 1px solid var(--line); background: #faf9f6; position: sticky; top: 0; white-space: nowrap; }
table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.t tr:hover td { background: #fbfaf7; }
table.t tfoot td { font-weight: 600; border-top: 1px solid var(--line); background: #faf9f6; }
table.t tr.sub td { background: #fcfbf8; color: var(--ink-2); font-size: 12.5px; }
table.t tr.grp td { background: #f4f2ec; font-weight: 600; }
table.t td.act { white-space: nowrap; text-align: right; }
table.t .clickable { cursor: pointer; }
.empty { padding: 28px; text-align: center; color: var(--ink-3); }
.tbl-tools { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.tbl-tools input[type=search] { max-width: 260px; }
.tbl-tools .count { color: var(--ink-3); font-size: 12px; margin-left: auto; }

/* ---------- Badges ---------- */
.b { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 500; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.b.green { background: var(--brand-soft); color: var(--brand); }
.b.red { background: var(--danger-soft); color: var(--danger); }
.b.amber { background: var(--warn-soft); color: var(--warn); }
.b.blue { background: var(--info-soft); color: var(--info); }

/* ---------- Forms ---------- */
input, select, textarea { font: inherit; color: inherit; border: 1px solid #d6d2c7; border-radius: 7px; padding: 7px 9px; background: #fff; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(44, 122, 92, .25); border-color: var(--brand-2); }
input[type=checkbox] { width: auto; }
input.num { text-align: right; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
label.f.chk { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.req::after { content: ' *'; color: var(--danger); }
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 13px; font-weight: 500; padding: 7px 13px; border-radius: 7px; border: 1px solid #d6d2c7; background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f7f5f0; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--danger); border-color: #ebc7c3; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters input, .filters select { width: auto; }
.lines { width: 100%; border-collapse: collapse; }
.lines th { font-size: 11.5px; font-weight: 500; color: var(--ink-3); text-align: left; padding: 4px 4px; }
.lines td { padding: 3px 4px; }
.lines td.x { width: 30px; }
.sum-row { display: flex; justify-content: flex-end; gap: 18px; padding: 8px 4px; font-size: 13px; }
.sum-row b { font-family: var(--mono); }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(20, 28, 24, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal.wide { max-width: 1000px; }
.modal-h { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-h .x { margin-left: auto; }
.modal-b { padding: 16px 18px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: #faf9f6; border-radius: 0 0 12px 12px; }
.err { color: var(--danger); font-size: 13px; margin-right: auto; align-self: center; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: #1d2420; color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); max-width: 360px; }
.toast.err { background: var(--danger); }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 500px at 20% 0%, #e2ede6, transparent), var(--bg); }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login h1 { margin: 14px 0 4px; }
.login form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }

/* ---------- Reports ---------- */
.report { max-width: 860px; }
.report table.t td { border-bottom-color: var(--line-2); }
.report .total td { font-weight: 600; border-top: 1px solid var(--ink-3); }
.report .grand td { font-weight: 700; border-top: 2px solid var(--ink); background: #faf9f6; }
.report .indent { padding-left: 26px; }
.kiosk { max-width: 520px; margin: 0 auto; text-align: center; }
.kiosk .clock { font-family: var(--mono); font-size: 48px; margin: 10px 0; }
.kiosk input { font-size: 22px; text-align: center; padding: 12px; }
#qr-reader { margin: 12px auto; max-width: 360px; }
.kiosk-result { margin-top: 16px; padding: 18px; border-radius: 10px; font-size: 18px; }
.idcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.idcard { border: 1px solid var(--line); border-radius: 10px; padding: 14px; text-align: center; background: #fff; page-break-inside: avoid; }
.idcard .qr { display: flex; justify-content: center; margin: 8px 0; }
.chart-box { position: relative; height: 240px; }
.slip { border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 14px; background: #fff; page-break-inside: avoid; }
.slip table { width: 100%; font-size: 12.5px; border-collapse: collapse; }
.slip td { padding: 2px 0; }
.print-only { display: none; }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 40; width: 270px; left: -280px; transition: left .2s; }
  .side.open { left: 0; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .btn.menu-btn { display: inline-flex; }
  .content { padding: 14px 14px 60px; }
  .topbar { padding: 8px 14px; }
  .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .topbar .who .role { display: none; }
  .modal-bg { padding: 0; }
  .modal { border-radius: 0; min-height: 100vh; }
}
@media print {
  .side, .topbar, .page-head .actions, .tabs, .tbl-tools, .no-print, .btn { display: none !important; }
  .shell { display: block; } .content { padding: 0; max-width: none; }
  body { background: #fff; font-size: 11px; }
  .card { box-shadow: none; border: none; }
  .print-only { display: block; }
  table.t th { position: static; }
}
