:root {
  --bg: #f5f6f8; --surface: #fff; --text: #1d2433; --muted: #667085; --border: #e2e5ea;
  --primary: #1f5eff; --primary-dark: #1848c7; --danger: #c62828; --warn: #b26a00; --ok: #1b7f3b;
  --danger-bg: #fdecea; --warn-bg: #fff4e0; --ok-bg: #e7f6ec; --info-bg: #e8f0ff;
  --radius: 8px; --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111418; --surface: #1a1e24; --text: #e6e8eb; --muted: #9aa3af; --border: #2c323b;
    --primary: #5b8cff; --primary-dark: #7aa2ff; --danger-bg: #3a1d1d; --warn-bg: #3a2c12; --ok-bg: #16301f; --info-bg: #1b2740; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
code, .mono { font-family: ui-monospace, Consolas, monospace; font-size: .85em; }

.topbar { display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); }
.mainnav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.mainnav a { padding: .35rem .6rem; border-radius: 6px; color: var(--muted); display: inline-flex; align-items: center; gap: .4rem; }
.mainnav .nav-icon { flex-shrink: 0; }
.mainnav a.active, .mainnav a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.usermenu { display: flex; gap: .75rem; align-items: center; color: var(--muted); font-size: .9em; }
.container { max-width: 1280px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.footer { display: flex; justify-content: space-between; max-width: 1280px; margin: 0 auto; padding: 1rem; color: var(--muted); font-size: .85em; }

.pagehead { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.card.narrow { max-width: 480px; }
.subcard { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1rem; }
.grid2 > .card { margin-bottom: 0; }
.grid2 { margin-bottom: 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; margin: .5rem 0; }
.btns { display: flex; gap: .5rem; flex-wrap: wrap; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; display: flex; flex-direction: column; color: var(--text); }
.tile:hover { border-color: var(--primary); text-decoration: none; }
.tile-label { color: var(--muted); font-size: .85em; font-weight: 600; }
.tile-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--muted); font-size: .85em; }
.tile-warn { border-left: 4px solid var(--warn); }
.tile-danger { border-left: 4px solid var(--danger); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td { padding: .5rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: .8em; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.table tfoot th { color: var(--text); font-size: .9em; }
.table.compact td, .table.compact th { padding: .3rem .5rem; }
.table .empty { text-align: center; color: var(--muted); padding: 1.5rem; }
.table tr.total td { border-top: 2px solid var(--text); font-weight: 600; }
.table tr.reversed td { color: var(--muted); text-decoration: line-through; }
.table tr.reversed td:last-child { text-decoration: none; }
.row-warn td { background: var(--warn-bg); }
.row-danger td { background: var(--danger-bg); }
.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.indent { padding-left: 1.5rem !important; }
.neg { color: var(--danger); }
.balance { font-size: 1.1rem; font-weight: 700; }

.btn { display: inline-block; padding: .45rem .9rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.btn:hover { border-color: var(--primary); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.small { padding: .2rem .5rem; font-size: .85em; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: wait; }
button.link { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }
form.inline { display: inline; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .75rem 1.25rem; }
.field { display: flex; flex-direction: column; gap: .25rem; }
.field.wide, .actions.wide { grid-column: 1 / -1; }
.field label { font-weight: 600; font-size: .9em; }
label.small { display: flex; flex-direction: column; font-size: .85em; gap: .2rem; }
.field label.check { font-weight: 400; display: flex; gap: .5rem; align-items: center; }
input, select, textarea { font: inherit; padding: .45rem .55rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); width: 100%; }
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.help { color: var(--muted); font-size: .85em; }
.error { color: var(--danger); font-size: .85em; }
.actions { display: flex; gap: .5rem; justify-content: flex-end; }

.filters { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; }
.tabs { display: flex; gap: .25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs a { padding: .4rem .8rem; color: var(--muted); text-transform: capitalize; border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--text); border-bottom-color: var(--primary); }
.pager { display: flex; gap: 1rem; justify-content: flex-end; margin-top: .75rem; }

.alert { padding: .65rem .9rem; border-radius: 6px; margin-bottom: 1rem; border-left: 4px solid; }
.alert ul { margin: .25rem 0 0; padding-left: 1.25rem; }
.alert-success { background: var(--ok-bg); border-color: var(--ok); }
.alert-error { background: var(--danger-bg); border-color: var(--danger); }
.alert-warning { background: var(--warn-bg); border-color: var(--warn); }
.alert-info { background: var(--info-bg); border-color: var(--primary); }
ul.alerts { list-style: none; padding: 0; margin: 0; }
ul.alerts li { padding: .4rem .6rem; border-left: 3px solid var(--warn); margin-bottom: .35rem; background: var(--warn-bg); border-radius: 4px; }
ul.alerts li.danger { border-color: var(--danger); background: var(--danger-bg); }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: .3rem 0; border-bottom: 1px solid var(--border); }

.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78em; font-weight: 600; background: var(--bg); color: var(--muted); text-transform: capitalize; white-space: nowrap; }
.b-active, .b-occupied, .b-current, .b-approved, .b-completed, .b-received, .b-refund { background: var(--ok-bg); color: var(--ok); }
.b-emergency, .b-denied, .b-terminated, .b-deduction { background: var(--danger-bg); color: var(--danger); }
.b-high, .b-warn, .b-notice, .b-make_ready, .b-pending, .b-conditional, .b-draft, .b-open { background: var(--warn-bg); color: var(--warn); }
.b-vacant, .b-assigned, .b-in_progress, .b-applicant { background: var(--info-bg); color: var(--primary); }

.dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.pre { white-space: pre-wrap; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
details.reverse summary { cursor: pointer; color: var(--primary); font-size: .85em; }
details.reverse form { display: flex; gap: .25rem; margin-top: .25rem; min-width: 260px; }

.login { max-width: 380px; margin: 8vh auto; text-align: center; }
.login form { text-align: left; display: flex; flex-direction: column; gap: .75rem; }

.statement { max-width: 760px; margin: 0 auto; }
.statement header { border-bottom: 2px solid var(--text); margin-bottom: 1rem; }

@media print {
  body { background: #fff; color: #000; }
  .no-print, .topbar, .footer, .alert { display: none !important; }
  .card { border: 0; padding: 0; }
  a { color: #000; }
}
