:root {
    --bg: #f4f5f7; --panel: #fff; --text: #1d2330; --muted: #6b7385; --line: #e3e6ec;
    --brand: #e8590c; --brand-dark: #c2410c; --side: #161b26; --side-text: #c9cfdc;
    --green: #1f8f4e; --green-bg: #e3f6ea; --red: #c92a2a; --red-bg: #fde8e8;
    --amber: #a15c00; --amber-bg: #fff1d6; --grey-bg: #eceef2; --info-bg: #e5f0ff;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f131b; --panel: #181e2a; --text: #e8ebf2; --muted: #98a1b5; --line: #2a3243;
        --side: #0a0d13; --green-bg: #12301f; --red-bg: #3a1717; --amber-bg: #3a2a0a; --grey-bg: #262d3b; --info-bg: #14263f;
        --green: #5fd38b; --red: #ff8a8a; --amber: #ffc861;
    }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); display: flex; min-height: 100vh; }
body.bare { display: block; }
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
@media (prefers-color-scheme: dark) { a { color: #ff9a5c; } }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h3 { font-size: 1.05rem; margin-bottom: .6rem; }
h3.spaced { margin-top: 1.4rem; }
h3.day { margin: 1.4rem 0 .5rem; color: var(--muted); font-size: .9rem; text-transform: uppercase; letter-spacing: .04em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
small, .muted { color: var(--muted); }
code { background: var(--grey-bg); padding: 1px 5px; border-radius: 4px; }

/* layout */
.sidebar { width: 220px; flex: none; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding: 1rem 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { color: #fff; font-weight: 700; font-size: 1.15rem; padding: 0 1.2rem 1rem; }
.sidebar nav { flex: 1; }
.sidebar nav a { display: block; padding: .55rem 1.2rem; color: var(--side-text); border-left: 3px solid transparent; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.sidebar nav a.on { color: #fff; border-left-color: var(--brand); background: rgba(255,255,255,.08); }
.who { padding: 1rem 1.2rem 0; border-top: 1px solid rgba(255,255,255,.1); font-size: .9rem; }
.who a, .who .link { color: var(--side-text); display: block; margin-top: .4rem; padding: 0; }
.main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.5rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 1.35rem; flex: 1; }
.topbar .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.burger { display: none; font-size: 1.4rem; cursor: pointer; }
.content { padding: 1.5rem; max-width: 1200px; }

/* components */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 1.1rem 1.2rem; margin-bottom: 1.2rem; }
.card.flush { padding: 0; overflow-x: auto; }
.card.narrow { max-width: 640px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 0 1.2rem; align-items: start; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.2rem; color: var(--muted); }
.stat span { display: block; font-size: 1.8rem; font-weight: 700; color: var(--text); line-height: 1.2; }
.stat small { display: block; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.center { text-align: center; }
.r { text-align: right; }
.note { background: var(--grey-bg); padding: .6rem .8rem; border-radius: 8px; }
.dim { opacity: .6; }
.big { font-size: 1.4rem; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: .6rem .9rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.card:not(.flush) th, .card:not(.flush) td { padding-left: 0; padding-right: .6rem; }
.card:not(.flush) td.r, .card:not(.flush) th.r { padding-right: 0; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }

dl.kv { display: grid; grid-template-columns: 9em 1fr; gap: .35rem .8rem; margin: .5rem 0 1rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--grey-bg); color: var(--muted); white-space: nowrap; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }

.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid transparent; }
.alert.success { background: var(--green-bg); color: var(--green); }
.alert.error { background: var(--red-bg); color: var(--red); }
.alert.warning { background: var(--amber-bg); color: var(--amber); }
.alert.info { background: var(--info-bg); }

/* forms */
.form label { display: block; margin-bottom: .9rem; font-weight: 500; }
.form label.check { font-weight: 400; }
.form label small { display: block; font-weight: 400; margin-top: .2rem; }
.form .row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form .row > label { flex: 1 1 140px; }
input, select, textarea { width: 100%; font: inherit; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); color: var(--text); margin-top: .25rem; }
input[type=checkbox] { width: auto; margin-right: .4rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; margin: 0; }
.filters input[type=search] { flex: 1 1 220px; }
.inline-form { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: .8rem; }
.inline-form input { flex: 1 1 240px; margin: 0; }

.btn, button.btn { display: inline-block; font: inherit; font-weight: 600; padding: .5rem .95rem; border-radius: 7px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--red); }
.btn.small { padding: .2rem .6rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btns { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }
.btns form { margin: 0; }
form.inline { display: inline; margin: 0; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--brand-dark); cursor: pointer; }
button.link:hover { text-decoration: underline; }
@media (prefers-color-scheme: dark) { button.link { color: #ff9a5c; } }

.tabs a { display: inline-block; padding: .35rem .9rem; border-radius: 999px; color: var(--muted); }
.tabs a.on { background: var(--text); color: var(--bg); }
.pager { display: flex; gap: .3rem; flex-wrap: wrap; margin: 1rem 0; }
.pager a, .pager span { padding: .3rem .7rem; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.pager a.current { background: var(--brand); color: #fff; border-color: var(--brand); }
.pager .disabled { color: var(--muted); }

/* charts */
.bar { height: 8px; border-radius: 4px; margin: 3px 0; min-width: 2px; }
.bar.green { background: var(--green); }
.bar.red { background: var(--red); }
.hist { display: flex; gap: 3px; align-items: flex-end; height: 140px; padding-bottom: 1.2rem; }
.hist div { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.hist i { display: block; width: 100%; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; }
.hist b { position: absolute; bottom: -1.2rem; font-size: .7rem; color: var(--muted); font-weight: 400; }

.receipt { max-width: 520px; margin: 0 auto 1rem; }

/* bare pages (login / install) */
.bare-card { max-width: 440px; margin: 8vh auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 2rem; }
.bare-card h2 { margin-bottom: .3rem; }

@media (max-width: 800px) {
    .sidebar { position: fixed; z-index: 10; left: -240px; transition: left .2s; width: 220px; }
    #navtoggle:checked ~ .sidebar { left: 0; }
    .burger { display: block; }
    .content { padding: 1rem; }
    .grid2 { grid-template-columns: 1fr; }
    dl.kv { grid-template-columns: 7em 1fr; }
}
@media print {
    .sidebar, .topbar, .noprint { display: none !important; }
    body { background: #fff; color: #000; }
    .card { border: 0; }
}

/* ---- v2 additions ---- */
.badge.blue { background: var(--info-bg); color: #2a6fdb; }
@media (prefers-color-scheme: dark) { .badge.blue { color: #8ab4ff; } }
.overdue { color: var(--red); font-weight: 600; }
a.stat { display: block; text-decoration: none; color: var(--muted); }
a.stat:hover { border-color: var(--brand); }
.more { font-size: .8rem; font-weight: 400; margin-left: .5rem; }
.count { background: var(--grey-bg); border-radius: 999px; padding: 0 7px; font-size: .78rem; margin-left: .2rem; }
.searchbox input { width: 16rem; margin: 0; }
.logo { max-height: 28px; margin-right: .5rem; vertical-align: middle; border-radius: 4px; }
.receipt-logo { max-height: 64px; margin-bottom: .4rem; }
details { margin: .5rem 0; }
details > summary { cursor: pointer; font-weight: 600; padding: .35rem 0; }
details.mini { display: inline-block; }
details.mini[open] { display: block; }
.inline-input { width: 8rem; text-align: right; margin: 0; }
.fu { margin-bottom: .8rem; padding: .8rem 1rem; }
.fu-over { border-left: 4px solid var(--red); }
.fu-form { margin-top: .6rem; }
.permgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; margin-top: .6rem; }
.permgrid fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .9rem; }
.permgrid legend { font-weight: 600; padding: 0 .4rem; }
.permgrid label.check { margin-bottom: .35rem; font-size: .92rem; }
.idcard { max-width: 380px; margin: 1rem auto; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 1.4rem; text-align: center; box-shadow: 0 6px 24px rgba(0,0,0,.08); }
.idcard-name { font-size: 1.4rem; font-weight: 700; margin-top: .6rem; }
.idcard-code { font-size: 1.8rem; letter-spacing: .12em; font-weight: 700; color: var(--brand-dark); margin: .2rem 0 .6rem; }
.barcode { width: 100%; height: 80px; background: #fff; border-radius: 6px; }
.idcard-status { margin: .8rem 0; padding: .4rem; border-radius: 8px; font-weight: 600; }
.idcard-status.ok { background: var(--green-bg); color: var(--green); }
.idcard-status.no { background: var(--red-bg); color: var(--red); }
.note { white-space: normal; }
td .form label { margin-bottom: .5rem; }
@media print {
    .noprint, .searchbox, .burger, nav.pager { display: none !important; }
    .main { width: 100%; }
    .content { padding: 0; max-width: none; }
    .receipt, .idcard { box-shadow: none; border: 1px solid #999; max-width: 100%; }
    .topbar { border: 0; }
    a { color: inherit; text-decoration: none; }
    table { font-size: 11pt; }
    .stat { border: 1px solid #ccc; }
    details > *:not(summary) { display: none; }
}
