/* Business Manager — Phase 1 */
:root {
  --ink: #1c2733;
  --ink-2: #3d4b59;
  --muted: #66727e;
  --paper: #eef1f3;
  --card: #ffffff;
  --line: #d6dce1;
  --line-soft: #e7ebee;
  --mark: #e3a21a;
  --in: #16784a;
  --out: #b3261e;
  --move: #4a5a6a;
  --focus: #2f6fb3;
  --r-sm: 4px;
  --r-md: 8px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--paper); line-height: 1.5; }
a { color: var(--focus); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2 { line-height: 1.25; margin: 0; }
h2 { font-size: 1.05rem; font-weight: 650; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.sub { color: var(--muted); font-size: .86rem; }
.amt-in { color: var(--in); }
.amt-out { color: var(--out); }
.amt-move { color: var(--move); }
.mt { margin-top: 1.25rem; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--ink); color: #c9d3dc; display: flex; flex-direction: column; padding: 18px 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 650; font-size: 1rem; padding: 4px 20px 18px; line-height: 1.25; }
.brand:hover { text-decoration: none; }
.brand-mark { flex: none; width: 16px; height: 16px; border-radius: 2px;
  background: repeating-linear-gradient(135deg, var(--mark) 0 4px, var(--ink) 4px 7px); box-shadow: 0 0 0 2px var(--mark); }
.nav { display: flex; flex-direction: column; }
.nav a { color: #c9d3dc; padding: 9px 20px; border-left: 3px solid transparent; font-size: .95rem; }
.nav a:hover { background: rgba(255,255,255,.05); color: #fff; text-decoration: none; }
.nav a.on { color: #fff; border-left-color: var(--mark); background: rgba(255,255,255,.07); font-weight: 600; }
.nav a.nav-new { color: var(--mark); font-weight: 600; }
.side-user { margin-top: auto; padding: 16px 20px 0; border-top: 1px solid rgba(255,255,255,.1); font-size: .88rem; }
.side-user .who { color: #fff; font-weight: 600; }
.side-user .role { color: #8e9ba7; }
.side-links { display: flex; gap: 14px; margin-top: 8px; }
.side-links a { color: #c9d3dc; }

.main { min-width: 0; }
.top { display: flex; align-items: center; gap: 14px; padding: 18px 28px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.top h1 { font-size: 1.35rem; font-weight: 650; flex: 1; min-width: 180px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.nav-toggle { display: none; }
.content { padding: 24px 28px 48px; max-width: 1200px; }

/* ---------- Panels ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); padding: 20px 22px; margin-bottom: 20px; }
.panel.flush { padding: 0; overflow: hidden; }
.panel.narrow { max-width: 480px; }
.pad { padding: 16px 20px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel.flush .panel-head { margin-bottom: 0; border-bottom: 1px solid var(--line-soft); }
.panel h2 + .tbl, .panel h2 + p { margin-top: 10px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.cols > .panel { margin-bottom: 20px; }
.empty { color: var(--muted); padding: 8px 0; margin: 0; }
.panel.flush .empty { padding: 20px; }
.notes { margin: 14px 0 0; color: var(--ink-2); }

.figures { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.figure { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); padding: 18px 22px; }
.figure-main { background: var(--ink); color: #fff; border-color: var(--ink); }
.figure-main .sub { color: #aab6c1; }
.fig-label { font-size: .9rem; color: var(--muted); }
.figure-main .fig-label { color: #aab6c1; }
.fig-value { font-size: 1.7rem; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -.01em; }
.figure-main .amt-in, .figure-main .amt-out { color: #fff; }

.meter { height: 6px; background: var(--line-soft); border-radius: 3px; margin: 6px 0 3px; overflow: hidden; max-width: 260px; }
.meter span { display: block; height: 100%; background: var(--ink-2); }
.meter-lg { height: 8px; max-width: none; background: rgba(255,255,255,.18); }
.meter-lg span { background: var(--mark); }

.facts { display: flex; flex-wrap: wrap; gap: 14px 36px; margin: 0; }
.facts div { min-width: 120px; }
.facts dt { font-size: .82rem; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 500; }

.badge { display: inline-block; font-size: .76rem; font-weight: 600; padding: 1px 8px; border-radius: 10px; background: var(--line-soft); color: var(--ink-2); vertical-align: 1px; }
.badge-active { background: #dff1e7; color: #135f3b; }
.badge-planning { background: #fdf1d6; color: #7a5507; }
.badge-on_hold { background: #f6e0de; color: #8c1f18; }
.tag { display: inline-block; font-size: .8rem; padding: 0 7px; border: 1px solid var(--line); border-radius: var(--r-sm); color: var(--ink-2); white-space: nowrap; }
.sep { color: var(--line); margin: 0 6px; }

.steps { margin: 12px 0 0; padding-left: 22px; }
.steps li { margin: 6px 0; }
.steps li.done { color: var(--muted); text-decoration: line-through; }
.steps li.done a { color: var(--muted); }
.start { border-left: 4px solid var(--mark); }
.plain-list { margin: 6px 0 12px; padding-left: 20px; }
.warn-box { background: #fdf6e3; border: 1px solid #f0d9a0; border-radius: var(--r-sm); padding: 10px 14px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { white-space: nowrap; text-align: left; font-size: .82rem; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: #f8f9fa; }
.tbl th.num { text-align: right; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tfoot td { border-top: 2px solid var(--line); font-weight: 600; background: #f8f9fa; }
.panel:not(.flush) .tbl td:first-child, .panel:not(.flush) .tbl th:first-child { padding-left: 0; }
.panel:not(.flush) .tbl td:last-child, .panel:not(.flush) .tbl th:last-child { padding-right: 0; }
.tbl tr.opening td { background: #f8f9fa; color: var(--ink-2); }
.tbl tr.is-deleted td { color: var(--muted); }
.tbl tr.is-deleted td a { color: var(--muted); }
.tbl .sub { margin-top: 1px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: .92rem; font-weight: 600;
  padding: 8px 14px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; text-decoration: none; line-height: 1.2; }
.btn:hover { background: #f4f6f7; text-decoration: none; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #2b3a48; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-quiet:hover { background: var(--line-soft); }
.btn-danger { border-color: #e2b4b0; color: var(--out); }
.btn-danger:hover { background: #fbeeed; }
.btn-block { width: 100%; }
.linkish { background: none; border: none; padding: 0; margin-left: 12px; font: inherit; color: var(--focus); cursor: pointer; }
.linkish:hover { text-decoration: underline; }
form.inline { display: inline; }

/* ---------- Forms ---------- */
.form label { display: block; font-size: .9rem; font-weight: 600; color: var(--ink-2); margin-bottom: 14px; }
.form input:not([type=checkbox]):not([type=radio]), .form select, .form textarea,
.filters input, .filters select, .inline-form input, .inline-form select {
  display: block; width: 100%; margin-top: 5px; font: inherit; font-weight: 400; color: var(--ink);
  padding: 9px 11px; border: 1px solid #bfc8d0; border-radius: var(--r-sm); background: #fff; }
.form textarea { resize: vertical; }
.form input:focus, .form select:focus, .form textarea:focus, .filters input:focus, .filters select:focus { border-color: var(--focus); outline: 2px solid rgba(47,111,179,.25); outline-offset: 0; }
.amount-input { font-variant-numeric: tabular-nums; font-size: 1.1rem !important; font-weight: 600 !important; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.form fieldset { border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 16px 2px; margin: 0 0 16px; }
.form legend { font-weight: 650; padding: 0 6px; font-size: .92rem; }
.form .check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 17px; height: 17px; margin: 0; }
.hint { font-size: .86rem; color: var(--muted); margin: -8px 0 14px; }
.hint-link { display: inline-block; font-size: .82rem; font-weight: 500; margin-top: 5px; }
.amount-words { display: block; margin-top: 4px; min-height: 1.3em; font-size: .84rem; font-weight: 400; font-style: italic; color: var(--muted); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.radio-card { display: flex !important; gap: 10px; align-items: flex-start; padding: 8px 0; margin: 0 !important; }
.radio-card input { margin-top: 4px; }
.radio-card > span { display: flex; flex-direction: column; font-weight: 400; }
.radio-card .sub { font-weight: 400; }

.entry-form { max-width: 760px; }
.type-switch { display: flex; gap: 0; margin-bottom: 14px; border: 1px solid #bfc8d0; border-radius: var(--r-sm); overflow: hidden; width: fit-content; max-width: 100%; }
.type-opt { margin: 0 !important; }
.type-opt input { position: absolute; opacity: 0; pointer-events: none; }
.type-opt span { display: block; padding: 9px 18px; cursor: pointer; font-weight: 600; color: var(--ink-2); border-right: 1px solid #bfc8d0; }
.type-opt:last-child span { border-right: none; }
.type-opt input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: -3px; }
.type-payment input:checked + span { background: var(--out); color: #fff; }
.type-receipt input:checked + span { background: var(--in); color: #fff; }
.type-transfer input:checked + span { background: var(--move); color: #fff; }
.entry-form[data-type=transfer] .not-transfer { display: none; }
.entry-form:not([data-type=transfer]) .only-transfer { display: none; }

.filters { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px 16px; margin-bottom: 14px; }
.filters label { font-size: .82rem; font-weight: 600; color: var(--muted); min-width: 140px; flex: 1 1 140px; max-width: 220px; }
.filters label.check { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 0 0 auto; padding-bottom: 10px; }
.filters input, .filters select { padding: 7px 9px; margin-top: 3px; }
.filter-btns { display: flex; gap: 6px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; }
.inline-form label { font-size: .86rem; font-weight: 600; color: var(--ink-2); flex: 1 1 200px; }
.inline-form.tight { flex-wrap: nowrap; gap: 6px; align-items: center; }
.inline-form.tight input { margin-top: 0; }

.totals-bar { display: flex; flex-wrap: wrap; gap: 8px 22px; align-items: center; padding: 4px 2px 12px; font-size: .92rem; color: var(--ink-2); }
.totals-bar .spacer { flex: 1; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chips a { padding: 5px 13px; border-radius: 16px; border: 1px solid var(--line); background: var(--card); color: var(--ink-2); font-size: .88rem; font-weight: 500; }
.chips a.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chips a:hover { text-decoration: none; border-color: var(--ink-2); }
.pager { display: flex; justify-content: center; align-items: center; gap: 16px; margin-top: 16px; color: var(--muted); font-size: .9rem; }

.flash { padding: 11px 15px; border-radius: var(--r-sm); margin-bottom: 14px; border: 1px solid; font-weight: 500; }
.flash-ok { background: #e6f4ec; border-color: #b5dcc6; color: #135f3b; }
.flash-err { background: #fbeeed; border-color: #eec2be; color: #8c1f18; }
.danger-zone { max-width: 760px; }
.danger-zone form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.danger-zone label { flex: 1 1 280px; font-size: .88rem; font-weight: 600; color: var(--ink-2); }
.danger-zone input { display: block; width: 100%; margin-top: 5px; font: inherit; padding: 8px 10px; border: 1px solid #bfc8d0; border-radius: var(--r-sm); }

/* ---------- Voucher ---------- */
.voucher { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); padding: 28px 32px; margin-bottom: 20px; max-width: 760px; }
.v-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding-bottom: 16px; border-bottom: 2px solid var(--ink); }
.v-company { font-size: 1.25rem; font-weight: 700; }
.v-title { color: var(--ink-2); font-weight: 600; margin-top: 2px; }
.v-meta { margin: 0; text-align: right; }
.v-meta div { display: flex; gap: 10px; justify-content: flex-end; }
.v-meta dt { color: var(--muted); }
.v-meta dd { margin: 0; font-weight: 650; font-variant-numeric: tabular-nums; min-width: 96px; }
.v-body { margin: 18px 0 0; }
.v-body div { display: grid; grid-template-columns: 150px 1fr; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.v-body dt { color: var(--muted); }
.v-body dd { margin: 0; font-weight: 500; }
.v-amount { margin-top: 22px; padding: 14px 18px; border: 2px solid var(--ink); border-radius: var(--r-sm); display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 22px; }
.v-amount-fig { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.v-amount-words { color: var(--ink-2); font-style: italic; }
.v-foot { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; margin-top: 56px; }
.v-sign { border-top: 1px solid var(--ink-2); padding-top: 6px; font-size: .85rem; display: flex; flex-direction: column; }
.v-sign span { color: var(--muted); }
.v-note { font-size: .8rem; color: var(--muted); margin: 22px 0 0; }

/* ---------- Plain pages (login, setup) ---------- */
body.plain { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 24px; background: var(--ink); }
.plain-box { background: var(--card); border-radius: var(--r-md); padding: 30px 32px; width: 100%; max-width: 400px; }
.plain-box.wide { max-width: 560px; }
.plain-box h1 { font-size: 1.4rem; margin-bottom: 18px; }
.login-brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--ink-2); margin-bottom: 22px; }
.checks { padding-left: 20px; }
.checks .ok { color: var(--in); }
.checks .bad { color: var(--out); font-weight: 600; }

.print-only { display: none; }

/* ---------- Small screens ---------- */
@media (max-width: 880px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; z-index: 20; transform: translateX(-100%); transition: transform .2s ease; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .nav-toggle { display: inline-flex; font: inherit; font-weight: 600; padding: 7px 12px; border: 1px solid var(--line); background: var(--card); border-radius: var(--r-sm); cursor: pointer; }
  .top { padding: 14px 16px; }
  .top h1 { font-size: 1.15rem; }
  .content { padding: 16px 14px 40px; }
  .cols, .figures, .grid { grid-template-columns: 1fr; }
  .panel { padding: 16px; }
  .filters label { max-width: none; }
  .voucher { padding: 20px 18px; }
  .v-body div { grid-template-columns: 1fr; gap: 0; }
  .v-foot { grid-template-columns: 1fr; margin-top: 30px; gap: 30px; }
  .type-switch { width: 100%; }
  .type-opt { flex: 1; }
  .type-opt span { text-align: center; padding: 9px 6px; }
}
@media (prefers-reduced-motion: reduce) { .side { transition: none; } }

/* ---------- Print ---------- */
@media print {
  body { background: #fff; font-size: 12px; }
  .side, .top, .filters, .no-print, .flash, .totals-bar, .pager, .chips, .danger-zone { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .panel, .voucher { border: none; padding: 0; max-width: none; }
  .print-only { display: inline; color: #555; }
  .panel:not(.print-area):not(.voucher) { display: none; }
  .panel.print-area { display: block; }
  a { color: inherit; }
  .tbl th { background: none; }
}
.linkish-danger { color: var(--out); }

/* ---------- Accounting (v1.2) ---------- */
.nav-label { margin: 16px 20px 4px; font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #7f8c98; }
.intro { margin: 0 0 14px; max-width: 760px; }
.code { font-variant-numeric: tabular-nums; color: var(--muted); }
.ok-mark { color: var(--in); font-weight: 600; }
.mt-sm { margin-top: 8px; }
.plain-list.small { font-size: .88rem; margin: 6px 0 0; }

.journal { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: 12px; overflow: hidden; }
.journal-bad { border-color: var(--out); border-width: 2px; }
.j-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; padding: 10px 14px; background: #f8f9fa; border-bottom: 1px solid var(--line-soft); }
.j-date { font-weight: 600; white-space: nowrap; }
.j-ref { font-weight: 650; white-space: nowrap; }
.j-src { font-size: .78rem; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; white-space: nowrap; }
.j-memo { color: var(--ink-2); font-size: .9rem; flex: 1 1 260px; }
.j-lines th { background: none; font-size: .76rem; padding-top: 6px; padding-bottom: 6px; }
.j-lines td { padding-top: 6px; padding-bottom: 6px; }
.j-lines td.j-cr { padding-left: 42px; }
.j-lines tfoot td { background: none; border-top: 1px solid var(--line); font-weight: 600; color: var(--ink-2); }
.j-lines { table-layout: fixed; min-width: 620px; }
.j-lines th:nth-child(1) { width: 44%; }
.j-lines th:nth-child(2) { width: 28%; }
.j-lines th:nth-child(3), .j-lines th:nth-child(4) { width: 14%; }
.party-balance .fig-value { font-size: 1.4rem; }

.posting-panel { max-width: 760px; }
.narrow-report { max-width: 760px; }
.report td { border-bottom: none; padding-top: 5px; padding-bottom: 5px; }
.report tr.grp td { font-weight: 650; color: var(--ink-2); padding-top: 14px; }
.report tr.head-row td { font-size: 1rem; font-weight: 700; padding-top: 20px; border-bottom: 2px solid var(--ink); }
.report td.indent { padding-left: 28px; }
.report tr.subtotal td { border-top: 1px solid var(--line); font-weight: 600; }
.report tr.total td { border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); font-weight: 700; font-size: 1.02rem; }
.check-ok { border-left: 4px solid var(--in); }
.check-bad { border-left: 4px solid var(--out); }
.checks-tbl td:first-child { width: 70px; }
@media print { .journal { break-inside: avoid; border: 1px solid #ccc; } }

/* ---------- Bills (v1.3) ---------- */
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.figures-4 { grid-template-columns: 1.3fr 1fr 1fr 1fr; }
a.figure-link { color: inherit; text-decoration: none; }
a.figure-link:hover { border-color: var(--ink-2); }
.figure-alert { border-color: var(--out); }
.figure-alert .fig-value { color: var(--out); }
.bill-form { max-width: 1100px; }
.bill-lines td { padding: 6px 6px; vertical-align: middle; }
.bill-lines th { padding: 8px 6px; }
.bill-lines input, .bill-lines select, .pay-items input { width: 100%; font: inherit; padding: 7px 8px; border: 1px solid #bfc8d0; border-radius: var(--r-sm); background: #fff; }
.bill-lines td:nth-child(1) { min-width: 200px; }
.bill-lines td:nth-child(2) { min-width: 210px; }
.bill-lines td:nth-child(3) { min-width: 160px; }
.bill-lines td:nth-child(4) { width: 80px; }
.bill-lines td:nth-child(5), .bill-lines td:nth-child(6) { width: 120px; }
.num-in { text-align: right; font-variant-numeric: tabular-nums; }
.bill-lines input[readonly] { background: #f4f6f7; }
.pay-items td { vertical-align: middle; }
.pay-items td:last-child { width: 150px; }
.pay-items input[type=checkbox] { width: 18px; height: 18px; }
.pay-form h2 { margin-bottom: 10px; }
.filters label.wide { max-width: 480px; flex-basis: 360px; }
.badge.bs-paid { background: #dff1e7; color: #135f3b; }
.badge.bs-part { background: #fdf1d6; color: #7a5507; }
.badge.bs-overdue { background: #f6e0de; color: #8c1f18; }
.badge.bs-unpaid { background: var(--line-soft); color: var(--ink-2); }
@media (max-width: 880px) { .grid-3, .figures-4 { grid-template-columns: 1fr; } }
