:root {
  --bg: #f4f6f3; --card: #ffffff; --ink: #17241d; --muted: #66746b; --line: #e1e6df; --soft: #eef3ee;
  --brand: #1c3a2c; --brand-2: #24513b; --accent: #1f6b47; --accent-ink: #fff; --accent-soft: #e2f0e7;
  --warn: #9a5b12; --warn-soft: #fff3dc; --bad: #a12b2b; --bad-soft: #f8e3e1; --info-soft: #e6eef8;
  --radius: 14px; --shadow: 0 1px 2px rgba(20, 40, 30, .05);
  --g1: #1f6b47; --g2: #4d9677; --g3: #9cc5a6; --g4: #c9a35b; --g5: #d98a5f; --g6: #8b7fbf; --g7: #5f9bd9; --gl: #c9cfc8;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.layout { display: flex; min-height: 100vh; }

/* sidebar */
aside { width: 230px; flex: none; background: var(--brand); color: #dfe9e2; display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 8px 22px; }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--brand-2); display: grid; place-items: center; font-size: 18px; color: #bfe0cc; }
.brand b { display: block; color: #fff; font-size: 16px; }
.brand small { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: #9bb8a6; }
.navlabel { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: #8aa898; padding: 14px 10px 6px; }
aside nav a { display: flex; align-items: center; gap: 10px; color: #dfe9e2; padding: 8px 12px; border-radius: 10px; font-size: 14px; }
aside nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; }
aside nav a.active { background: var(--brand-2); color: #fff; font-weight: 600; }
aside nav a .ic { width: 18px; text-align: center; opacity: .85; }
aside .foot { margin-top: auto; font-size: 12px; color: #9bb8a6; padding: 12px 10px 0; border-top: 1px solid rgba(255, 255, 255, .1); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #5fd08f; margin-right: 6px; }
.dot.bad { background: #f07b6f; }

main { flex: 1; min-width: 0; padding: 22px 32px 48px; max-width: 1280px; }
.crumb { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.pagehead { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.pagehead h1 { font-size: 28px; margin: 0; letter-spacing: -.01em; }
.pagehead p { margin: 4px 0 0; color: var(--muted); }
.pagehead .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
h2 { font-size: 17px; margin: 0 0 4px; }
h3 { font-size: 15px; margin: 14px 0 8px; }
.sub { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card.tight { padding: 12px 16px; }
.cardhead { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.cardhead .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpis.six { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 700px) { .kpis.six { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 2px 0; letter-spacing: -.01em; }
.kpi .hint { color: var(--muted); font-size: 12px; }
.kpi.accent { background: var(--accent-soft); border-color: #bcd9c6; }
.kpi.good .value { color: var(--accent); }
.kpi.bad .value { color: var(--bad); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.totals td { font-weight: 700; border-top: 2px solid var(--line); }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--soft); }
.scroll { overflow-x: auto; }
.mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }

form .fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
input, select, textarea { font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid #cfd8cf; border-radius: 9px; background: #fff; color: var(--ink); min-width: 0; width: 100%; }
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc5a6; outline-offset: 0; border-color: var(--accent); }
td input, td select { padding: 6px 8px; }
.btn, button { font: inherit; font-size: 14px; font-weight: 600; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover, button:hover { filter: brightness(1.05); text-decoration: none; }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary, button.secondary { background: #fff; color: var(--accent); border-color: #c6d8cc; }
.btn.danger, button.danger { background: #fff; color: var(--bad); border-color: #e6c3bf; }
.btn.small, button.small { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--soft); color: var(--muted); white-space: nowrap; }
.badge.draft, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.received, .badge.active, .badge.good, .badge.graded { background: var(--accent-soft); color: var(--accent); }
.badge.cancelled, .badge.reversed, .badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.mixed { background: var(--info-soft); color: #2d5b8a; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600; font-size: 14px; }
.tabs a.active { color: var(--accent); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--ink); }

.bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--soft); }
.bar > span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.callout { border-radius: 12px; padding: 12px 14px; background: var(--soft); font-size: 14px; }
.callout.good { background: var(--accent-soft); }
.callout.warn { background: var(--warn-soft); }
.callout.bad { background: var(--bad-soft); }
.summary td:first-child { color: var(--muted); }
.summary td.n { vertical-align: top; }
table.summary td.n.amt, table.plain td.n.amt { white-space: nowrap; word-break: normal; padding-left: 12px; }
.summary tr.totals td:first-child { color: var(--ink); }
p.cmp { margin: 0 0 10px; line-height: 1.55; color: var(--ink); }
p.cmp:last-child { margin-bottom: 0; }
.summary td { padding: 6px 4px; }
.empty { color: var(--muted); padding: 18px 4px; text-align: center; }
.check-ok { color: var(--accent); font-weight: 700; }
.check-bad { color: var(--bad); font-weight: 700; }
.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; max-width: 92vw; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
#toast.error { background: var(--bad); }
#menu { display: none; }

.tabbar { display: none; }

@media (max-width: 900px) {
  .layout { display: block; }
  aside { width: auto; height: auto; position: sticky; top: 0; z-index: 30; padding: 10px 14px; }
  .brand { padding: 0; }
  .brand small { display: none; }
  #menu { display: inline-flex; margin-left: auto; background: transparent; border-color: rgba(255,255,255,.3); min-height: 44px; }
  aside .topline { display: flex; align-items: center; }
  aside nav, aside .foot, .navlabel { display: none; }
  aside.open nav, aside.open .navlabel { display: block; }
  aside.open nav a { padding: 12px; font-size: 16px; }
  main { padding: 16px 16px 110px; }
  .pagehead h1 { font-size: 24px; }
  .grid2 { grid-template-columns: 1fr; }

  /* bottom tab bar for the main sections */
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--brand);
            padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; color: #cfe0d5; font-size: 11px;
              padding: 6px 2px; border-radius: 10px; min-height: 48px; text-decoration: none; }
  .tabbar a .ic { font-size: 18px; line-height: 1.1; }
  .tabbar a.active { background: var(--brand-2); color: #fff; font-weight: 600; }
  /* keep messages above the tab bar and the sticky save bar */
  #toast { bottom: calc(150px + env(safe-area-inset-bottom)); width: calc(100% - 32px); text-align: center; }
}

@media (max-width: 700px) {
  body { font-size: 16px; }
  .crumb { display: none; }
  .card { padding: 14px; border-radius: 14px; }
  .pagehead { margin-bottom: 14px; }
  .pagehead .actions { width: 100%; }
  .pagehead .actions > * { flex: 1 1 auto; justify-content: center; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpis > .kpi.accent:first-child { grid-column: 1 / -1; }
  .kpi { padding: 12px; }
  .kpi .value { font-size: 21px; word-break: break-word; }
  .kpi.accent .value { font-size: 30px !important; }
  form .fields { grid-template-columns: 1fr; }

  /* comfortable touch targets; 16px stops iOS zooming into fields */
  input, select, textarea { font-size: 16px; min-height: 46px; }
  button, .btn { min-height: 46px; padding: 10px 16px; font-size: 16px; justify-content: center; }
  .btn.small, button.small { min-height: 40px; padding: 8px 12px; font-size: 14px; }
  input[type=checkbox] { width: 24px; height: 24px; min-height: 0; flex: none; }
  label.check { font-size: 15px; align-items: flex-start; }

  /* sticky save bar above the tab bar */
  .actionbar { position: sticky; bottom: calc(66px + env(safe-area-inset-bottom)); z-index: 20; background: var(--bg);
               padding: 10px 0; margin: 0 -2px; }
  .actionbar > button, .actionbar > .btn { flex: 1; }
  .actionbar > .btn.secondary { flex: 0 0 auto; }
  .actionbar > span { display: none; }

  /* tables become one card per row */
  .scroll { overflow: visible; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr.headrow { display: none; }
  table.stack tr { border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px; margin-bottom: 10px; background: var(--card); }
  .card table.stack tr { background: #fbfcfa; }
  table.stack td { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: none;
                   padding: 7px 0; text-align: right; min-height: 0; }
  table.stack td + td { border-top: 1px dashed var(--line); }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; flex: none; max-width: 48%; }
  table.stack td[data-label=""]::before { content: none; }
  table.stack td:first-child { font-weight: 600; }
  table.stack td:has(input:not([type=checkbox]), select) { flex-direction: column; align-items: stretch; text-align: left; gap: 4px; }
  table.stack td:has(input:not([type=checkbox]), select)::before { max-width: none; }
  table.stack td input:not([type=checkbox]), table.stack td select { width: 100% !important; min-width: 0 !important; }
  table.stack td:has(> button:only-child) { justify-content: flex-end; }
  table.stack tr.totals { background: var(--accent-soft); }
  table.stack td.n { white-space: normal; }
  table.summary td { padding: 8px 2px; }
  table.summary td.n { white-space: normal; }
  .bar { height: 18px; }

  /* line editors inside forms: compact two-column cards */
  form table.stack tr:has(input:not([type=checkbox]), select) { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 10px; padding: 10px 12px; }
  form table.stack tr:has(input:not([type=checkbox]), select) td { border-top: none !important; padding: 4px 0; }
  form table.stack td:first-child { grid-column: 1 / -1; }
  form table.stack td:not(:has(input, select, button)) { font-size: 14px; }
  form table.stack td:has(> button:only-child) { grid-column: 1 / -1; padding-top: 2px; }
  form table.stack td:has(> button:only-child) button { width: 100%; }
  input[type=checkbox] { width: 26px; height: 26px; }
  .kpis > .kpi.perf { grid-column: 1 / -1; }
  table.plain td, table.plain td.n { white-space: normal; word-break: break-word; }
}
@media print {
  aside, .actions, button, .btn, .tabs { display: none !important; }
  main { padding: 0; max-width: none; }
  .card { border: none; box-shadow: none; padding: 0; }
}
table.nostack td:first-child { white-space: nowrap; }
@media (max-width: 700px) { table.nostack td, table.nostack th { padding-left: 4px; padding-right: 4px; font-size: 14px; } }

/* investor summary (only this page uses these) */
.inv .kpis.inv4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.inv .kpis.inv4 .kpi .value { font-size: 26px; }
.invchart { width: 100%; height: auto; max-height: 230px; display: block; margin: 4px 0 12px; }
@media (max-width: 1000px) { .inv .kpis.inv4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media print {
  @page { size: A4; margin: 12mm; }
  .tabbar, .crumb, #toast { display: none !important; }
  body { background: #fff; font-size: 12px; }
  .layout { display: block; }
  .inv .kpis.inv4 { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .inv .kpi { border: 1px solid var(--line); padding: 8px 10px; }
  .inv .kpi .value { font-size: 19px !important; }
  .inv .grid2 { grid-template-columns: 1fr 1fr; gap: 12px; }
  .inv .card { margin-bottom: 10px; break-inside: avoid; }
  .inv table.stack tr.headrow { display: table-row; }
  .inv table.stack, .inv table.stack tbody { display: table; width: 100%; }
  .inv table.stack tr { display: table-row; border: none; padding: 0; margin: 0; background: none; }
  .inv table.stack td { display: table-cell; text-align: inherit; padding: 4px 6px; }
  .inv table.stack td::before { content: none; }
  .invchart { max-height: 150px; }
  .pagehead { margin-bottom: 8px; }
  .pagehead h1 { font-size: 22px; }
}
