/* PNGNA ERP */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1c2230;
  --muted: #5d6676;
  --brand: #b71c1c;
  --brand-2: #d32f2f;
  --brand-ink: #ffffff;
  --gold: #f2b705;
  --sidebar: #1a1d24;
  --sidebar-text: #c9ced8;
  --sidebar-active: #2a2f3a;
  --green: #1b7f4b;
  --green-bg: #e3f4ea;
  --amber: #8a5a00;
  --amber-bg: #fff2cc;
  --red: #b3261e;
  --red-bg: #fde7e5;
  --blue: #1d5fb8;
  --blue-bg: #e3edfb;
  --grey: #59606d;
  --grey-bg: #eceef2;
  --income: #1b7f4b;
  --expense: #d32f2f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1a1e26;
    --surface-2: #222733;
    --border: #2d3340;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --sidebar: #0d0f13;
    --sidebar-active: #1d212a;
    --green: #6fd39c;
    --green-bg: #183a28;
    --amber: #f3c95c;
    --amber-bg: #3d3115;
    --red: #ff8a80;
    --red-bg: #46201e;
    --blue: #8ab4f8;
    --blue-bg: #1c2d4a;
    --grey: #b3b9c5;
    --grey-bg: #2a2f3a;
    --income: #6fd39c;
    --expense: #ff6f61;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--brand-2); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
h1, h2, h3 { font-family: Outfit, Inter, sans-serif; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.boot, .loading { padding: 48px; color: var(--muted); text-align: center; }

/* ---------- Layout ---------- */
#app { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 248px; overflow-y: auto;
  background: var(--sidebar); color: var(--sidebar-text); z-index: 20;
  border-top: 4px solid var(--brand);
}
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; text-decoration: none; color: #fff; border-bottom: 1px solid rgba(255,255,255,.06); }
.brand-name { font-family: Outfit, sans-serif; font-weight: 700; font-size: 18px; letter-spacing: .3px; }
.brand-sub { font-size: 11px; color: var(--sidebar-text); }
.sidebar { display: flex; flex-direction: column; }
.nav { padding: 8px 0 24px; flex: 1; }
.sidebar-user { padding: 14px 18px 20px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.sidebar-user .user-name { color: #fff; }
.user-email { color: #8b93a3; word-break: break-all; }
.sidebar-links { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 8px; }
.sidebar-links a { color: var(--sidebar-text); }
.btn.signout { background: transparent; color: #fff; border-color: rgba(255,255,255,.25); }
.btn.signout:hover { background: var(--sidebar-active); }
.nav-heading { padding: 14px 18px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #8b93a3; font-weight: 600; }
.nav-link { display: flex; justify-content: space-between; align-items: center; padding: 7px 18px; color: var(--sidebar-text); text-decoration: none; border-left: 3px solid transparent; }
.nav-link:hover { background: var(--sidebar-active); color: #fff; }
.nav-link.active { background: var(--sidebar-active); color: #fff; border-left-color: var(--gold); font-weight: 600; }
.count { background: var(--brand-2); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 7px; }

.main { margin-left: 248px; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  padding: 12px 28px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.title-wrap { flex: 1; min-width: 0; }
.page-title { font-size: 21px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.user { text-align: right; font-size: 12px; max-width: 280px; }
.user-name { font-weight: 600; font-size: 13px; }
.user-roles { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-links a { color: var(--muted); }
.menu-btn { display: none; }
.page-body { padding: 24px 28px 48px; display: flex; flex-direction: column; gap: 18px; max-width: 1400px; width: 100%; }

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.card.narrow { max-width: 520px; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.card > p:first-child { margin-top: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.notice { background: var(--amber-bg); color: var(--amber); border-radius: var(--radius); padding: 12px 16px; font-weight: 500; }
.notice code { background: var(--surface); padding: 2px 6px; border-radius: 4px; color: var(--text); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn.danger:hover { background: var(--red-bg); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer; padding: 2px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; text-transform: capitalize; white-space: nowrap; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.grey { background: var(--grey-bg); color: var(--grey); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); border-top: 3px solid var(--border); }
.stat.amber { border-top-color: var(--gold); }
.stat.red { border-top-color: var(--brand-2); }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 500; }
.stat-value { font-family: Outfit, sans-serif; font-size: 22px; font-weight: 600; margin: 2px 0; }
.stat-sub { font-size: 12px; color: var(--muted); }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td, table.data tr.clickable:focus td { background: var(--surface-2); }
table.data tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; }
table.data.edit td { padding: 4px 6px; }
table.data.edit input, table.data.edit select { width: 100%; }
table.statement td { border-bottom: 0; padding: 5px 10px; }
table.statement tr.sect td { font-weight: 700; padding-top: 14px; border-bottom: 1px solid var(--border); }
table.statement tr.sub td { font-weight: 600; border-top: 1px solid var(--border); }
table.statement tr.grand td { font-weight: 700; font-size: 15px; border-top: 2px solid var(--text); padding-top: 10px; }
.strong { font-weight: 700; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-weight: 600; font-size: 13px; }
.field.check { flex-direction: row-reverse; justify-content: flex-end; align-items: center; gap: 8px; }
.req { color: var(--brand-2); }
.hint { font-size: 12px; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); }
textarea { resize: vertical; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand-2) 40%, transparent); border-color: var(--brand-2); }
.form-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.form-error { color: var(--red); font-weight: 600; margin-top: 10px; }
.form-error:empty { display: none; }
.section-label { font-size: 14px; margin: 20px 0 8px; }
.lines-editor .btn { margin-top: 8px; }
.form.inline .form-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); align-items: end; }
.form.inline { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.form.inline .form-grid { flex: 1; }
.form.inline .form-actions { margin-top: 0; }
fieldset.roles { border: 1px solid var(--border); border-radius: var(--radius); margin: 16px 0 0; padding: 10px 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 6px; }
fieldset.roles legend { font-weight: 600; padding: 0 6px; }
.role { display: flex; gap: 8px; align-items: center; }

/* Document view */
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.doc-title { font-family: Outfit, sans-serif; font-size: 20px; font-weight: 600; }
.doc-status { text-align: right; }
.doc-amount { font-family: Outfit, sans-serif; font-size: 24px; font-weight: 700; margin-top: 4px; }
.stepper { list-style: none; display: flex; padding: 0; margin: 0; gap: 0; overflow-x: auto; }
.stepper li { flex: 1; min-width: 150px; display: flex; gap: 8px; align-items: flex-start; padding: 12px 10px 12px 0; position: relative; color: var(--muted); }
.stepper li small { display: block; font-size: 11px; color: var(--muted); }
.stepper li > span:last-child { font-weight: 600; font-size: 13px; }
.stepper .dot { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; background: var(--grey-bg); color: var(--grey); }
.stepper li.done { color: var(--text); }
.stepper li.done .dot { background: var(--green); color: #fff; }
.stepper li.current { color: var(--text); }
.stepper li.current .dot { background: var(--gold); color: #1c2230; box-shadow: 0 0 0 4px var(--amber-bg); }
.stepper li.rejected .dot { background: var(--red); color: #fff; }
.decision { border-color: var(--gold); border-width: 2px; }
dl.fields { display: grid; grid-template-columns: minmax(160px, max-content) 1fr; gap: 8px 20px; margin: 0; }
dl.fields dt { color: var(--muted); font-weight: 500; }
dl.fields dd { margin: 0; white-space: pre-wrap; }
ul.related { margin: 0; padding-left: 18px; }
ul.related li { margin: 4px 0; }
.ledger-sum { font-weight: 600; margin-bottom: 10px; }
.pager { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; color: var(--muted); }
.meter { position: relative; width: 120px; height: 18px; background: var(--grey-bg); border-radius: 4px; overflow: hidden; }
.meter span { position: absolute; inset: 0 auto 0 0; background: var(--green); opacity: .5; }
.meter span.warn { background: var(--gold); opacity: .7; }
.meter span.over { background: var(--red); opacity: .6; }
.meter em { position: relative; font-style: normal; font-size: 11px; font-weight: 700; padding-left: 6px; line-height: 18px; }

/* Chart */
.chart .legend { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.chart .key { width: 12px; height: 12px; border-radius: 3px; display: inline-block; margin-left: 10px; }
.chart .key.income, .bar.income { background: var(--income); }
.chart .key.expense, .bar.expense { background: var(--expense); }
.bars { display: flex; gap: 10px; align-items: flex-end; height: 180px; border-bottom: 1px solid var(--border); }
.bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.bar-pair { display: flex; gap: 3px; align-items: flex-end; height: calc(100% - 20px); width: 100%; justify-content: center; }
.bar { width: 40%; max-width: 22px; border-radius: 3px 3px 0 0; min-height: 1px; }
.bar-label { font-size: 11px; color: var(--muted); height: 20px; line-height: 20px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(160deg, #1a1d24 0%, #3a0d0d 100%); }
.login-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: 14px; padding: 32px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.35); border-top: 5px solid var(--brand); }
.login-card h1 { font-size: 26px; margin: 10px 0 4px; }
.login-card .form { text-align: left; margin-top: 18px; }
.login-card .form-actions .btn { width: 100%; }

/* Toasts */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1c2230; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 380px; transition: opacity .4s; border-left: 4px solid var(--green); }
.toast.err { border-left-color: var(--brand-2); }
.toast.out { opacity: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .main { margin-left: 0; }
  .menu-btn { display: block; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .user { display: none; }
  .page-actions { order: 3; width: 100%; }
  .page-body { padding: 16px; }
  .two-col { grid-template-columns: 1fr; }
  dl.fields { grid-template-columns: 1fr; gap: 2px 0; }
  dl.fields dd { margin-bottom: 8px; }
}

@media print {
  body:has(.payslip-print) .topbar { display: none !important; }
  body:has(.payslip-print) .page-body { padding: 0 !important; max-width: none !important; }
  .sidebar, .topbar .page-actions, .menu-btn, .user, .decision, .form-actions, #toasts, form.inline { display: none !important; }
  .main { margin: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
  body { background: #fff; color: #000; }
}

.form-section { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }
.form-section .hint { margin-top: 0; }

/* A printed payslip fills one A4 page */
@media print {
  @page { size: A4; margin: 12mm; }
}

/* Tax forms: completed IRC form viewer */
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.seg button { border: 1px solid var(--border); background: var(--surface, #fff); color: inherit; border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 13px; cursor: pointer; }
.seg button.active { background: var(--brand, #b71c1c); border-color: var(--brand, #b71c1c); color: #fff; }
.viewer-pick { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-bottom: 12px; }
.viewer-field { display: grid; gap: 4px; }
.form-viewer { max-height: 85vh; min-height: 300px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.form-viewer .pdf-page { max-width: 100%; height: auto; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18); }
.row-actions { display: flex; gap: 6px; flex-wrap: nowrap; }
