:root {
    --bg: #f5f6f8;
    --card: #ffffff;
    --ink: #1f2430;
    --muted: #6b7280;
    --line: #e5e7eb;
    --primary: #2563eb;
    --primary-ink: #ffffff;
    --danger: #dc2626;
    --ok-bg: #ecfdf5; --ok-ink: #065f46;
    --err-bg: #fef2f2; --err-ink: #991b1b;
    --info-bg: #eff6ff; --info-ink: #1e40af;
    --neg: #b91c1c;
    --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg); color: var(--ink); line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .75rem; }
.muted { color: var(--muted); }
.neg { color: var(--neg); }
.pos { color: #15803d; }

/* Layout */
.container { max-width: 980px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.topbar { background: var(--card); border-bottom: 1px solid var(--line); }
.topbar__inner { max-width: 980px; margin: 0 auto; display: flex; align-items: center; gap: 1.25rem; padding: .65rem 1.25rem; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand--lg { font-size: 1.6rem; text-align: center; display: block; margin-bottom: 1rem; }
.nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.nav a { padding: .35rem .6rem; border-radius: 6px; color: var(--muted); font-size: .92rem; }
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.is-active { color: var(--ink); background: var(--bg); font-weight: 600; }
.topbar__right { display: flex; align-items: center; gap: .75rem; }
.footer { border-top: 1px solid var(--line); padding: 1.25rem 0; margin-top: 2rem; font-size: .85rem; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }

/* Cards & stats */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin: 1rem 0 1.5rem; }
.stat { display: flex; flex-direction: column; gap: .35rem; }
.stat__label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat__value { font-size: 1.6rem; font-weight: 700; }
.stat__value--link { font-size: 1.1rem; }

/* Pills */
.pill { background: var(--info-bg); color: var(--info-ink); padding: .2rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.pill--sm { font-size: .72rem; padding: .1rem .45rem; margin-left: .35rem; }

/* Tables */
.table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--line); }
.table th { background: #fafbfc; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.table tr:last-child td { border-bottom: none; }
.table .num, .num { text-align: right; font-variant-numeric: tabular-nums; }
.row--active { background: var(--info-bg); }
.row-actions { display: flex; gap: .4rem; justify-content: flex-end; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 1rem; max-width: 640px; }
.form.card { padding: 1.5rem; }
.form label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; font-weight: 600; }
.form input[type=text], .form input[type=email], .form input[type=password],
.form input[type=number], .form input[type=date], .form select, .form textarea, .filters input, .filters select {
    font: inherit; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-weight: 400;
}
.form textarea { resize: vertical; width: 100%; }
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.check { flex-direction: row !important; align-items: center; gap: .5rem; font-weight: 400; }

/* Buttons */
.btn { display: inline-block; font: inherit; font-size: .9rem; cursor: pointer; padding: .5rem .9rem; border-radius: 8px;
    border: 1px solid var(--line); background: #fff; color: var(--ink); text-decoration: none; line-height: 1.2; }
.btn:hover { text-decoration: none; background: var(--bg); }
.btn--primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn--primary:hover { background: #1d4ed8; }
.btn--ghost { background: transparent; }
.btn--danger { color: var(--danger); border-color: #f2c2c2; }
.btn--danger:hover { background: var(--err-bg); }
.btn--sm { padding: .3rem .6rem; font-size: .82rem; }
.btn--block { width: 100%; }
.linkbtn { background: none; border: none; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }
.inline { display: inline; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; }
.filters label { display: flex; flex-direction: column; gap: .3rem; font-size: .82rem; font-weight: 600; }
.filters__spacer { flex: 1; }

/* Alerts */
.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: .92rem; }
.alert--success { background: var(--ok-bg); color: var(--ok-ink); }
.alert--error { background: var(--err-bg); color: var(--err-ink); }
.alert--info { background: var(--info-bg); color: var(--info-ink); }

/* Auth */
.centered { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.card--auth { width: 100%; max-width: 380px; margin: 1rem; }

/* Report frame (on-screen preview of the printable document) */
.report-frame { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; overflow-x: auto; }
.report-frame table { width: 100%; border-collapse: collapse; }
.report-frame th, .report-frame td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); text-align: left; }
.report-frame th { font-size: .78rem; text-transform: uppercase; color: var(--muted); }
.report-frame .emp td { background: #fafbfc; font-weight: 700; }
.report-frame .net td { border-top: 2px solid #cbd5e1; font-weight: 700; }
.report-frame .grand td { border-top: 3px double #64748b; font-weight: 700; }
.report-frame .meta { color: var(--muted); font-size: .85rem; margin-bottom: 1rem; }

/* Status badges */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .03em; vertical-align: middle; }
.badge--draft { background: #f1f5f9; color: #475569; }
.badge--submitted { background: #fef3c7; color: #92400e; }
.badge--approved { background: #dcfce7; color: #166534; }

.pill--muted { background: #f1f5f9; color: #64748b; }
.row--archived td { opacity: .6; }

/* Period action bar */
.actionbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.actionbar__buttons { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.period-reports { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }

/* Amount mode toggle */
.modeset { border: 1px solid var(--line); border-radius: 8px; padding: 1rem; }
.modeset legend { font-weight: 600; font-size: .9rem; padding: 0 .4rem; }
.radio { flex-direction: row !important; align-items: center; gap: .4rem; font-weight: 400 !important; display: inline-flex !important; margin-right: 1.25rem; }
.mode-flat, .mode-rate { margin-top: .75rem; }

/* Audit trail */
.audit { list-style: none; padding: 0; margin: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.audit li { padding: .5rem .8rem; border-bottom: 1px solid var(--line); font-size: .9rem; }
.audit li:last-child { border-bottom: none; }
.audit__action { font-weight: 600; margin-right: .4rem; }

.form-actions { margin-top: 1rem; }
button[disabled] { opacity: .5; cursor: not-allowed; }

/* Fast-entry grid */
.grid-scroll { overflow-x: auto; }
.grid-table select, .grid-table input { width: 100%; font: inherit; padding: .35rem .4rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.grid-table td { padding: .3rem .35rem; }
.grid-table th { white-space: nowrap; }

@media (max-width: 640px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .nav { display: none; }
}
