/* ============================================================================
   Magcore Books — "The ledger, made precise."
   Newsreader (serif display) · IBM Plex Sans (UI) · IBM Plex Mono (figures).
   Calm financial-grade surface; debits left, credits right; the Balance Beam is
   the one signature element. Avoids the AI-default cream-serif / acid-green looks.
   ============================================================================ */

:root {
    --paper:    #FBFBFC;
    --surface:  #FFFFFF;
    --ink:      #171C26;
    --muted:    #5C6677;
    --faint:    #8A93A3;
    --rule:     #E5E8EF;
    --rule-2:   #EFF1F6;
    --pine:     #0F6E59;   /* brand / balanced / "in the black" */
    --pine-ink: #0A5544;
    --pine-bg:  #E8F2EE;
    --brick:    #A83246;   /* negative / out-of-balance / loss */
    --brick-bg: #F8EAEC;
    --amber-bg: #FBF3E4;
    --amber-ink:#8A5A12;

    --r-sm: 5px;
    --r-md: 9px;
    --r-lg: 14px;
    --shadow: 0 1px 2px rgba(23,28,38,.04), 0 6px 20px rgba(23,28,38,.05);
    --rail-w: 232px;

    --sans: "IBM Plex Sans", system-ui, -apple-system, Segoe UI, sans-serif;
    --serif: "Newsreader", Georgia, "Times New Roman", serif;
    --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: var(--sans);
    color: var(--ink);
    background: var(--paper);
    font-size: 14.5px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--pine-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

/* tabular figures everywhere numbers live */
.mono, td.num, th.num, .amount, .figure {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}

/* ---------- App shell: left rail + main ---------- */
.app { display: grid; grid-template-columns: var(--rail-w) 1fr; min-height: 100vh; }

.rail {
    background: var(--surface);
    border-right: 1px solid var(--rule);
    padding: 22px 16px;
    display: flex; flex-direction: column; gap: 4px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand {
    display: flex; align-items: center; gap: 10px;
    font-family: var(--serif); font-weight: 560; font-size: 20px;
    letter-spacing: -0.01em; color: var(--ink); margin: 2px 6px 18px;
}
.brand .beam-mark { color: var(--pine); flex: none; }
.rail .nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
    color: var(--faint); margin: 16px 8px 4px; }
.rail a.nav {
    display: flex; align-items: center; gap: 10px;
    padding: 7px 10px; border-radius: var(--r-sm);
    color: var(--muted); font-weight: 500; font-size: 14px;
}
.rail a.nav:hover { background: var(--rule-2); color: var(--ink); text-decoration: none; }
.rail a.nav.active { background: var(--pine-bg); color: var(--pine-ink); }
.rail a.nav .ic { width: 16px; text-align: center; opacity: .8; }
.rail .rail-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--rule);
    font-size: 12px; color: var(--faint); }

.main { display: flex; flex-direction: column; min-width: 0; }

/* ---------- Top bar: entity + period selector ---------- */
.topbar {
    display: flex; align-items: center; gap: 14px;
    padding: 12px 28px; border-bottom: 1px solid var(--rule); background: var(--surface);
    position: sticky; top: 0; z-index: 5;
}
.topbar .entity-switch { display: flex; align-items: center; gap: 8px; }
.topbar select, .topbar .pill {
    font-family: var(--sans); font-size: 13.5px; color: var(--ink);
    border: 1px solid var(--rule); border-radius: var(--r-sm); padding: 6px 10px; background: var(--surface);
}
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; color: var(--muted); }
.topbar .who b { color: var(--ink); font-weight: 600; }
.role-tag { font-size: 11px; padding: 2px 7px; border-radius: 20px; background: var(--rule-2);
    color: var(--muted); margin-left: 6px; }
.role-tag.admin { background: var(--pine-bg); color: var(--pine-ink); }

.content { padding: 28px; max-width: 1180px; width: 100%; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head h1 { font-family: var(--serif); font-weight: 540; font-size: 27px; letter-spacing: -0.015em; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.page-head .actions { display: flex; gap: 8px; flex: none; }

/* ---------- Cards / panels ---------- */
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg);
    box-shadow: var(--shadow); }
.card + .card { margin-top: 18px; }
.card .card-head { padding: 16px 20px; border-bottom: 1px solid var(--rule); display: flex;
    align-items: center; justify-content: space-between; gap: 12px; }
.card .card-head h2 { font-family: var(--serif); font-weight: 540; font-size: 18px; margin: 0; }
.card .card-body { padding: 18px 20px; }
.card .card-body.flush { padding: 0; }

.statement-title { font-family: var(--serif); font-size: 21px; font-weight: 540; }
.statement-meta { color: var(--muted); font-size: 13px; }

/* ---------- KPI tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.tile { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 16px 18px; }
.tile .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tile .value { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 24px;
    font-weight: 500; margin-top: 6px; letter-spacing: -.01em; }
.tile .value.pos { color: var(--pine-ink); }
.tile .value.neg { color: var(--brick); }
.tile .foot { font-size: 12px; color: var(--faint); margin-top: 4px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--muted); font-weight: 600; padding: 11px 14px; border-bottom: 1px solid var(--rule); }
tbody td { padding: 10px 14px; border-bottom: 1px solid var(--rule-2); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FCFDFE; }
td.num, th.num { text-align: right; }
.code { font-family: var(--mono); color: var(--muted); font-size: 13px; }
.neg { color: var(--brick); }
tfoot td { padding: 11px 14px; border-top: 2px solid var(--ink); font-weight: 600; }
tr.subtotal td { border-top: 1px solid var(--rule); font-weight: 600; }
tr.section-head td { background: var(--rule-2); font-weight: 600; font-size: 12px;
    text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

/* ---------- The Balance Beam (signature element) ---------- */
.beam {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 14px;
    padding: 14px 18px; border: 1px solid var(--rule); border-radius: var(--r-md);
    background: var(--surface);
}
.beam .side { display: flex; flex-direction: column; }
.beam .side.cr { text-align: right; }
.beam .side .lab { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.beam .side .amt { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 19px; font-weight: 500; }
.beam .fulcrum { display: flex; flex-direction: column; align-items: center; gap: 3px;
    font-size: 12px; font-weight: 600; padding: 0 6px; }
.beam .fulcrum .glyph { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
    font-size: 15px; }
.beam.is-balanced { border-color: var(--pine); background: linear-gradient(0deg, var(--pine-bg), var(--surface)); }
.beam.is-balanced .fulcrum { color: var(--pine-ink); }
.beam.is-balanced .fulcrum .glyph { background: var(--pine); color: #fff; }
.beam.is-unbalanced { border-color: var(--brick); }
.beam.is-unbalanced .fulcrum { color: var(--brick); }
.beam.is-unbalanced .fulcrum .glyph { background: var(--brick-bg); color: var(--brick); }

/* "Balanced" seal for statements */
.seal { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600;
    padding: 5px 12px; border-radius: 30px; }
.seal.ok { background: var(--pine-bg); color: var(--pine-ink); }
.seal.bad { background: var(--brick-bg); color: var(--brick); }

/* ---------- Buttons ---------- */
.btn { font-family: var(--sans); font-size: 13.5px; font-weight: 500; cursor: pointer;
    border: 1px solid var(--rule); background: var(--surface); color: var(--ink);
    padding: 8px 14px; border-radius: var(--r-sm); display: inline-flex; align-items: center; gap: 7px; }
.btn:hover { background: var(--rule-2); text-decoration: none; }
.btn.primary { background: var(--pine); border-color: var(--pine); color: #fff; }
.btn.primary:hover { background: var(--pine-ink); }
.btn.danger { color: var(--brick); border-color: #E8C9CF; }
.btn.danger:hover { background: var(--brick-bg); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
input[type=text], input[type=email], input[type=date], input[type=number], select, textarea {
    font-family: var(--sans); font-size: 14px; color: var(--ink); width: 100%;
    border: 1px solid var(--rule); border-radius: var(--r-sm); padding: 8px 11px; background: var(--surface);
}
input.amount, input.num, td input.num { font-family: var(--mono); text-align: right; font-variant-numeric: tabular-nums; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--pine); box-shadow: 0 0 0 3px var(--pine-bg); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }

/* journal line editor */
table.lines td { padding: 6px 8px; border-bottom: 1px solid var(--rule-2); }
table.lines input, table.lines select { padding: 6px 9px; }
table.lines .rm { color: var(--brick); cursor: pointer; border: none; background: none; font-size: 16px; }

/* ---------- Flash ---------- */
.flash { padding: 11px 16px; border-radius: var(--r-md); margin-bottom: 16px; font-size: 13.5px; }
.flash.success { background: var(--pine-bg); color: var(--pine-ink); }
.flash.error { background: var(--brick-bg); color: var(--brick); }
.flash.info { background: var(--rule-2); color: var(--muted); }

/* ---------- Badges / status ---------- */
.badge { font-size: 11.5px; padding: 2px 8px; border-radius: 20px; background: var(--rule-2); color: var(--muted); }
.badge.posted { background: var(--pine-bg); color: var(--pine-ink); }
.badge.reversed { background: var(--amber-bg); color: var(--amber-ink); }
.badge.locked { background: var(--brick-bg); color: var(--brick); }
.badge.open { background: var(--pine-bg); color: var(--pine-ink); }

.empty { text-align: center; color: var(--faint); padding: 40px 20px; }
.empty .big { font-family: var(--serif); font-size: 18px; color: var(--muted); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background:
    radial-gradient(1200px 500px at 50% -10%, var(--pine-bg), var(--paper)); }
.login-card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg);
    box-shadow: var(--shadow); padding: 34px; width: 360px; text-align: center; }
.login-card .brand { justify-content: center; font-size: 24px; margin-bottom: 6px; }
.login-card .tag { color: var(--muted); font-size: 13.5px; margin-bottom: 22px; }

@media (max-width: 820px) {
    .app { grid-template-columns: 1fr; }
    .rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
    .rail .nav-group, .rail .rail-foot { display: none; }
}
