:root {
  --brand: #F5B00A; --brand-ink: #1c1608; --brand-soft: #fdf0cc;
  --bg: #fbf8f2; --card: #ffffff; --ink: #1d1a15; --mute: #6f685c; --line: #e8e1d3; --field: #fffdf8;
  --ok: #1d7a46; --ok-bg: #e2f4e9; --warn: #8a5a00; --warn-bg: #fdf0cc; --bad: #b3261e; --bad-bg: #fbe4e1; --mute-bg: #eeebe4;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 4px 16px rgba(40, 30, 10, .05);
  --r: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-soft: #3a2e10; --bg: #16130e; --card: #1f1b15; --ink: #f1ece2; --mute: #a8a090; --line: #342e24; --field: #191610;
    --ok: #6fd39a; --ok-bg: #173523; --warn: #f5c55a; --warn-bg: #3a2e10; --bad: #ff8a80; --bad-bg: #3d1c19; --mute-bg: #2a251d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand-soft: #3a2e10; --bg: #16130e; --card: #1f1b15; --ink: #f1ece2; --mute: #a8a090; --line: #342e24; --field: #191610;
  --ok: #6fd39a; --ok-bg: #173523; --warn: #f5c55a; --warn-bg: #3a2e10; --bad: #ff8a80; --bad-bg: #3d1c19; --mute-bg: #2a251d;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body.noscroll { overflow: hidden; }
svg { width: 20px; height: 20px; flex: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h3 { font-size: 16px; }
h4 { font-size: 14px; margin: 18px 0 6px; color: var(--mute); text-transform: uppercase; letter-spacing: .04em; }
small { font-size: 12px; }
.muted { color: var(--mute); }
.boot { padding: 40vh 0; text-align: center; color: var(--mute); }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--field); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand); padding: 0; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 14px; cursor: pointer; text-decoration: none; white-space: nowrap; font-weight: 500; }
.btn:hover { border-color: var(--brand); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.sm svg { width: 16px; height: 16px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(.95); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; background: transparent; border-radius: 8px; cursor: pointer; color: var(--ink); }
.icon-btn:hover:not(:disabled) { background: var(--mute-bg); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.sm svg { width: 16px; height: 16px; }
.link { border: 0; background: none; padding: 0; color: inherit; cursor: pointer; text-align: left; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.link:hover { text-decoration-color: var(--brand); }
.link.danger { color: var(--bad); font-size: 12px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 320px; text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 32px 24px; box-shadow: var(--shadow); }
.brand-big { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 18px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; }
.brand-big svg { width: 32px; height: 32px; }
.login h1 { font-size: 24px; }
.login form { margin-top: 20px; display: grid; gap: 10px; }
.login input { text-align: center; font-size: 22px; letter-spacing: .4em; padding: 12px; }
.err { color: var(--bad); min-height: 1.4em; margin: 0; font-size: 14px; }

/* shell */
.top { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--bg); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; }
.brand > svg { background: var(--brand); color: var(--brand-ink); padding: 6px; width: 32px; height: 32px; border-radius: 9px; }
.brand div { display: grid; line-height: 1.15; }
.brand small { color: var(--mute); }
.mpick { justify-self: center; display: flex; align-items: center; }
.mlabel { border: 0; background: none; font-weight: 600; cursor: pointer; padding: 4px 6px; min-width: 88px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 8px 16px 0; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { border: 0; background: none; padding: 8px 12px 10px; cursor: pointer; white-space: nowrap; color: var(--mute); border-bottom: 3px solid transparent; font-weight: 500; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--brand); }
.view { max-width: 1200px; margin: 0 auto; padding: 16px 16px 80px; display: grid; gap: 16px; }
.view > * { min-width: 0; }
.subnav { display: flex; gap: 6px; flex-wrap: wrap; }
.subnav button { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 5px 14px; cursor: pointer; font-size: 14px; }
.subnav button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card-head h3 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row select { width: auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); display: grid; gap: 10px; align-content: start; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.hint { color: var(--mute); font-size: 13px; margin: 0; }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 12px; margin: 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.empty { color: var(--mute); padding: 20px; text-align: center; }
.big { font-size: 32px; font-weight: 700; margin: 0; }
.big small { font-size: 15px; font-weight: 400; color: var(--mute); }
.todo { margin: 0; padding-left: 18px; display: grid; gap: 6px; }

/* kpis */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: grid; gap: 2px; box-shadow: var(--shadow); }
.kpi span { color: var(--mute); font-size: 13px; }
.kpi b { font-size: 22px; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--mute); }
.kpi.good { border-top: 3px solid var(--ok); }
.kpi.neg { border-top: 3px solid var(--bad); }
.neg-t { color: var(--bad); }

/* badges */
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--mute-bg); color: var(--mute); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }

/* bars */
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr auto; gap: 10px; align-items: center; font-size: 14px; }
.bar-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row b { font-weight: 500; font-variant-numeric: tabular-nums; font-size: 13px; }
.bar { height: 8px; background: var(--mute-bg); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }

/* attendance */
.daybar { display: flex; align-items: center; gap: 8px; }
.daylabel { display: grid; text-align: center; flex: 1; }
.daylabel small { color: var(--mute); }
.att-sum { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.att-list { display: grid; gap: 8px; }
.att-row { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; grid-template-columns: minmax(140px, 1fr) auto; gap: 8px 12px; align-items: center; }
.att-row.st-P, .att-row.st-W { border-left-color: var(--ok); }
.att-row.st-H { border-left-color: var(--warn); }
.att-row.st-A { border-left-color: var(--bad); }
.att-row.st-O { border-left-color: var(--mute); }
.who { display: grid; }
.who small { color: var(--mute); }
.late { color: var(--bad); font-weight: 600; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; border-left: 1px solid var(--line); background: var(--card); padding: 7px 11px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--mute); min-width: 40px; }
.seg button:first-child { border-left: 0; }
.seg button.on.ok { background: var(--ok); color: #fff; }
.seg button.on.warn { background: var(--brand); color: var(--brand-ink); }
.seg button.on.bad { background: var(--bad); color: #fff; }
.seg button.on.mute { background: var(--mute); color: var(--bg); }
.times { grid-column: 1 / -1; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.times:empty { display: none; }
.times input[type=time] { width: 120px; }
.times .note { flex: 1; min-width: 140px; }

/* tables */
.tablewrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
thead th { font-size: 12px; color: var(--mute); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: var(--card); white-space: nowrap; }
tfoot th, tfoot td { border-bottom: 0; background: var(--mute-bg); }
.num { text-align: right; white-space: nowrap; }
th.num { text-align: right; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--brand-soft); }
tr.unchecked td:first-child { box-shadow: inset 3px 0 var(--brand); }
tr.cur td { background: var(--brand-soft); }
tr.gone td { color: var(--mute); }
.sticky { position: sticky; left: 0; background: var(--card); z-index: 1; }
tfoot .sticky { background: var(--mute-bg); }
td small.rc { display: block; color: var(--mute); white-space: nowrap; }
td small.ev { display: block; color: var(--warn); }
td small.by { display: block; color: var(--mute); }
table.list td { font-size: 14px; }

table.grid { width: auto; font-size: 12px; }
table.grid th, table.grid td { padding: 0; border: 1px solid var(--line); text-align: center; }
table.grid thead th { padding: 4px 0; min-width: 26px; text-transform: none; letter-spacing: 0; }
table.grid thead th small { display: block; font-weight: 400; }
table.grid th.sticky { text-align: left; padding: 4px 8px; white-space: nowrap; font-size: 13px; }
table.grid td.num { padding: 4px 8px; }
table.grid td button { width: 26px; height: 26px; border: 0; background: none; cursor: pointer; font-weight: 700; font-size: 11px; color: inherit; }
table.grid .off { background: var(--mute-bg); }
table.grid td.ok { background: var(--ok-bg); color: var(--ok); }
table.grid td.warn { background: var(--warn-bg); color: var(--warn); }
table.grid td.bad { background: var(--bad-bg); color: var(--bad); }
table.grid td.mute { background: var(--mute-bg); color: var(--mute); }
table.grid td.lt { box-shadow: inset 0 0 0 2px var(--bad); }

table.pay th, table.pay td { padding: 6px; vertical-align: middle; }
table.pay th.sticky { min-width: 150px; }
table.pay th.sticky small { display: block; color: var(--mute); font-weight: 400; }
table.pay input { padding: 5px 6px; text-align: right; }
.w4 { width: 56px; } .w5 { width: 66px; } .w6 { width: 84px; } .w8 { width: 100px; }

table.stmt td { padding: 6px 0; }
table.stmt td small { color: var(--mute); }
table.stmt tr.sub td { font-weight: 600; border-top: 1px solid var(--ink); }
table.stmt tr.total td { font-weight: 700; font-size: 16px; border-bottom: 0; border-top: 2px solid var(--ink); }
table.stmt tr.muted td { color: var(--mute); border-bottom: 0; }

/* cards grid */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.pcard { text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: grid; gap: 4px; cursor: pointer; box-shadow: var(--shadow); align-content: start; }
.pcard:hover { border-color: var(--brand); }
.pcard.gone { opacity: .6; }
.pcard small { color: var(--mute); }
.pc-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.pc-sal { font-size: 18px; font-weight: 700; margin-top: 4px; }
.pc-sal small { font-weight: 400; }
.pcard .warn-t { color: var(--warn); font-weight: 600; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 13px; }
.chip b { font-weight: 600; margin-left: 4px; }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.chk { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.chk input { width: 18px; }
ul.mini { margin: 0; padding-left: 18px; display: grid; gap: 4px; font-size: 14px; }
ul.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 420px; overflow: auto; font-size: 14px; }
ul.log small { color: var(--mute); display: block; }

/* forms */
.form { display: grid; gap: 12px; }
.form fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 12px; min-width: 0; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 12px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { font-size: 13px; color: var(--mute); font-weight: 500; }
.span2 { grid-column: 1 / -1; }
.rates { display: grid; gap: 6px; }
.rate { display: grid; grid-template-columns: 150px 120px 1fr 36px; gap: 6px; align-items: center; }
.rates-wrap { display: grid; gap: 6px; justify-items: start; }
.rates-wrap .rates { width: 100%; }
.rates-wrap .hint { margin: 0; }
.actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.actions .danger { margin-right: auto; }
.inline-form { display: flex; gap: 6px; flex-wrap: wrap; }
.inline-form input { width: auto; flex: 1 1 120px; }
.photo { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.photo label { cursor: pointer; }
img.bill { max-width: 100%; max-height: 260px; border-radius: 10px; border: 1px solid var(--line); justify-self: start; }
img.bill.full { max-height: none; width: 100%; }

/* sheet */
.scrim { position: fixed; inset: 0; background: rgba(20, 15, 5, .45); z-index: 20; }
.sheet { position: fixed; z-index: 21; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); overflow: auto; background: var(--card); border-radius: 16px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.sheet.wide { width: min(780px, calc(100vw - 24px)); }
.sheet-head { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 14px 16px 10px; background: var(--card); border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 18px; }
.sheet-body { padding: 16px; }
.sheet-body > p { margin: 0; }

#toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translate(-50%, 30px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 640px) {
  .top { grid-template-columns: auto 1fr auto; padding-left: 12px; padding-right: 8px; }
  .brand small { display: none; }
  .view { padding: 12px 12px 80px; }
  .tabs { padding: 6px 8px 0; }
  .att-row { grid-template-columns: 1fr; }
  .seg { width: 100%; }
  .seg button { flex: 1; }
  .sheet { top: auto; bottom: 0; transform: translateX(-50%); width: 100vw; max-height: 92vh; border-radius: 16px 16px 0 0; }
  .sheet.wide { width: 100vw; }
  .sheet-body { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .rate { grid-template-columns: 1fr 1fr 36px; }
  .rate .r-note { grid-column: 1 / 3; }
  .bar-row { grid-template-columns: 1fr auto; }
  .bar-row .bar { grid-column: 1 / -1; grid-row: 2; }
  .kpi b { font-size: 19px; }
}
