:root {
    --bg: #f5f6f8;
    --card: #fff;
    --ink: #1d2330;
    --muted: #6b7280;
    --line: #e3e6eb;
    --accent: #2f5bd3;
    --accent-ink: #fff;
    --ok: #157347;
    --ok-bg: #e6f4ec;
    --warn: #9a5b00;
    --warn-bg: #fdf3e1;
    --bad: #b42318;
    --bad-bg: #fdecea;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header.top { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; background: #1d2330; color: #fff; padding: 10px 24px; }
header.top a { color: #cfd6e4; }
header.top .brand { color: #fff; font-weight: 700; font-size: 17px; }
header.top .menu { display: flex; align-items: center; gap: 24px; flex: 1; flex-wrap: wrap; }
header.top .nav-toggle, header.top .nav-btn { display: none; }
header.top nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
header.top nav a { padding: 6px 10px; border-radius: 6px; }
header.top nav a.active, header.top nav a:hover { background: #2e3647; color: #fff; text-decoration: none; }
header.top .who { display: flex; gap: 14px; font-size: 14px; color: #9aa3b5; }

main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }
h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 28px 0 10px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; margin-bottom: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.stat .n { font-size: 24px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }

table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f0f2f5; font-size: 13px; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

form.stack { display: grid; gap: 12px; max-width: 560px; }
form.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: #374151; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #cdd2da; border-radius: 6px; background: #fff; width: 100%; }
form.inline input, form.inline select { width: auto; }
textarea { min-height: 90px; resize: vertical; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: auto; }

.btn, button { display: inline-block; font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); cursor: pointer; text-decoration: none; }
.btn:hover, button:hover { filter: brightness(1.08); text-decoration: none; }
.btn.ghost, button.ghost { background: #fff; color: var(--accent); }
.btn.small, button.small { padding: 4px 10px; font-size: 13px; }
button.danger { background: #fff; color: var(--bad); border-color: var(--bad); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.paid { background: var(--ok-bg); color: var(--ok); }
.badge.unpaid { background: var(--warn-bg); color: var(--warn); }
.badge.off { background: #eef0f3; color: var(--muted); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.error { background: var(--bad-bg); color: var(--bad); }

.login { max-width: 380px; margin: 10vh auto; }
.login h1 { text-align: center; }

.timeline .entry { border-left: 3px solid var(--accent); padding: 4px 0 4px 14px; margin: 0 0 18px; }
.timeline .entry .meta { font-size: 13px; color: var(--muted); }
.timeline .entry p { margin: 4px 0; white-space: pre-line; }

.invoice { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 32px; }
.invoice .head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 24px; }
.invoice .total td { font-weight: 700; }
.invoice .foot { margin-top: 24px; white-space: pre-line; color: var(--muted); font-size: 14px; }
.invoice .head-r { text-align: right; }

.bulkbar { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0; margin-bottom: 4px; }

/* ---------- phones & small tablets ---------- */
@media (max-width: 760px) {
    body { font-size: 15px; }
    main { padding: 16px 12px 48px; }
    h1 { font-size: 21px; }

    /* collapsible menu */
    header.top { padding: 10px 14px; gap: 0; position: sticky; top: 0; z-index: 20; }
    header.top .brand { flex: 1; }
    header.top .nav-btn { display: flex; flex-direction: column; justify-content: center; gap: 5px; width: 44px; height: 44px; padding: 10px; margin: -6px -10px -6px 0; cursor: pointer; }
    header.top .nav-btn span { display: block; height: 2px; background: #fff; border-radius: 2px; transition: transform .2s, opacity .2s; }
    header.top .nav-toggle:checked + .nav-btn span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
    header.top .nav-toggle:checked + .nav-btn span:nth-child(2) { opacity: 0; }
    header.top .nav-toggle:checked + .nav-btn span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
    header.top .menu { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; gap: 8px; padding-top: 10px; }
    header.top .nav-toggle:checked ~ .menu { display: flex; }
    header.top nav { flex-direction: column; gap: 2px; }
    header.top nav a { padding: 11px 12px; font-size: 16px; }
    header.top .who { flex-wrap: wrap; gap: 4px 16px; padding: 10px 12px 4px; border-top: 1px solid #2e3647; }
    header.top .who span { flex-basis: 100%; }
    header.top .who a { padding: 6px 0; }

    /* bigger touch targets; 16px inputs stop iOS zooming in */
    input, select, textarea { font-size: 16px; padding: 10px 12px; }
    .btn, button { padding: 11px 16px; }
    .btn.small, button.small { padding: 7px 12px; }
    input[type="checkbox"] { width: 22px; height: 22px; }

    .card { padding: 14px; }
    .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat { padding: 10px 12px; }
    .stat:last-child:nth-child(odd) { grid-column: span 2; }
    .stat .n { font-size: 19px; }

    form.inline { gap: 10px; }
    form.inline > label:not(.check) { flex: 1 1 calc(50% - 10px); min-width: 140px; }
    form.inline input, form.inline select { width: 100%; }
    .spread > .btn { width: 100%; text-align: center; }

    /* tables become a list of cards */
    .table-wrap:has(table.stack) { overflow: visible; }
    table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
    table.stack { border: 0; background: transparent; border-radius: 0; }
    table.stack tr:has(th) { display: none; }
    table.stack tr { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; padding: 8px 14px; }
    table.stack td { border: 0; padding: 5px 0 5px 112px; text-align: left; min-height: 30px; }
    table.stack td::before { content: attr(data-label); position: absolute; left: 14px; width: 92px; color: var(--muted); font-size: 12px; font-weight: 600; line-height: 1.9; }
    table.stack td:not([data-label]) { padding-left: 0; }
    table.stack td:not([data-label]):not(.pick):last-child { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }
    table.stack td:not([data-label]):last-child a { display: inline-block; padding: 4px 0; }
    table.stack td:empty { display: none; }
    table.stack td.pick { position: absolute; top: 10px; right: 12px; width: auto; padding: 0; min-height: 0; }
    table.stack tr:has(td.pick) td:nth-child(2) { padding-right: 36px; }
    #bulk.has-sel tr:has(td.pick input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
    .bulkbar { top: 52px; gap: 8px; }
    .bulkbar label.check { order: 1; }
    .bulkbar #selinfo { order: 2; flex: 1 1 55%; text-align: right; font-size: 13px; }
    .bulkbar button { order: 3; flex: 1 1 40%; padding: 9px 8px; font-size: 14px; }

    .invoice { padding: 16px; }
    .invoice .head-r { text-align: left; }
    .invoice th, .invoice td { padding: 8px 6px; font-size: 14px; }
    .hide-sm { display: none; }

    .timeline .entry { padding-left: 10px; }
    .login { margin: 6vh auto; }
}

@media print {
    header.top, .no-print, .flash { display: none !important; }
    body { background: #fff; }
    main { padding: 0; max-width: none; }
    .invoice { border: 0; padding: 0; }
}
