:root {
  --bg: #f6f7f9; --card: #fff; --ink: #1d2433; --muted: #6b7385; --line: #e3e6ec;
  --brand: #1f3a5f; --primary: #2563eb; --primary-ink: #fff;
  --st-received: #8a94a6; --st-awaiting: #d97706; --st-ready: #1e3a8a; --st-approved: #0d9488;
  --st-scheduled: #7c3aed; --st-paid: #16a34a;
  --hold: #dc2626; --late: #b91c1c; --warn-bg: #fef2f2;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 6px; } h2 { font-size: 15px; margin: 0 0 12px; } h3 { font-size: 13px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 52px; background: var(--brand); color: #fff; }
.topbar a, .topbar .link { color: #dfe7f3; }
.topbar .brand { color: #fff; font-weight: 700; font-size: 16px; line-height: 20px; }
.topbar nav { display: flex; align-items: center; gap: 18px; flex: 1; }
/* Every header item gets the same box; the underline is always there, just transparent until active, so text lines up. */
.topbar nav a, .topbar nav span, .topbar .menu summary { display: block; line-height: 20px; padding: 3px 0; border-bottom: 2px solid transparent; border-top: 2px solid transparent; }
.topbar nav a.active { color: #fff; border-bottom-color: #fff; }
.topbar nav .muted { color: #8ea3c0; }
.topbar .who { display: flex; gap: 12px; align-items: center; font-size: 13px; }
.topbar form { margin: 0; }

.page { max-width: 1400px; margin: 0 auto; padding: 20px; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.crumb { margin: 0 0 8px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }

.btn { display: inline-block; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 14px; border-radius: 7px; font: inherit; cursor: pointer; }
.btn:hover { border-color: #b8bfcc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.wide { width: 100%; text-align: center; }
.link { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; }

.messages { margin-bottom: 14px; }
.msg { padding: 10px 14px; border-radius: 8px; margin-bottom: 6px; background: #eef4ff; border: 1px solid #c9d9fb; }
.msg.error { background: var(--warn-bg); border-color: #f5c2c2; color: var(--late); }
.msg.success { background: #ecfdf3; border-color: #b7ebc9; }

.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.kpi span { display: block; color: var(--muted); font-size: 12px; }
.kpi strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.kpi.warn { background: var(--warn-bg); border-color: #f5c2c2; } .kpi.warn strong { color: var(--late); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 18px; }
.filters input[type=text], .filters select { padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; font: inherit; background: #fff; }
.filters input[type=text] { width: 220px; }
.check { display: flex; gap: 6px; align-items: center; }

.group { margin-bottom: 22px; }
.group h2 { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.group .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.group .count { background: #e9ecf2; border-radius: 10px; padding: 1px 8px; font-size: 12px; color: var(--muted); }
.group .gtotal { margin-left: auto; color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.st-received { --c: var(--st-received); } .st-awaiting_receipt_qc { --c: var(--st-awaiting); }
.st-ready_for_approval { --c: var(--st-ready); } .st-approved { --c: var(--st-approved); }
.st-scheduled { --c: var(--st-scheduled); } .st-paid { --c: var(--st-paid); }
.empty { color: var(--muted); margin: 0 0 0 18px; }

.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 8px; background: var(--card); }
table.grid { width: 100%; border-collapse: collapse; table-layout: fixed; min-width: 1240px; }
table.grid.small { min-width: 0; }
.grid th, .grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; overflow: hidden; text-overflow: ellipsis; }
.grid th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
.grid th.num, .grid td.num { text-align: right; }
.grid tbody tr { cursor: pointer; } .grid tbody tr:hover { background: #f7f9fc; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid .sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-vendor { width: auto; } .c-inv { width: 120px; } .c-po { width: 64px; } .c-co { width: 130px; } .c-due { width: 116px; }
.grid td.due, .grid td.num { white-space: nowrap; }
.c-amt { width: 112px; } .c-method { width: 88px; } .c-owner { width: 120px; } .c-flags { width: 180px; }
.overdue { color: var(--late); font-weight: 600; }

.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 10px; margin: 0 3px 3px 0; white-space: nowrap; }
.tag.hold { background: #fde2e2; color: var(--hold); } .tag.late { background: #fde2e2; color: var(--late); }
.tag.norec { background: #fff1d6; color: #92400e; } .tag.review { background: #e0e7ff; color: #3730a3; }
.tag.bank { background: #ede9fe; color: #5b21b6; } .tag.part { background: #dcfce7; color: #166534; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 12px; color: #fff; background: var(--c); font-weight: 600; font-size: 12px; margin-right: 6px; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; } .kv dd.num { text-align: left; }
.step { margin: 0 0 10px; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.step.row { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 8px; }
.step input, .step select { padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; font: inherit; }
.inline { display: inline; margin-left: 8px; }
.ok { color: var(--st-paid); font-weight: 600; }
.error { color: var(--late); }

.formgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 16px; }
.formgrid.compact { grid-template-columns: repeat(3, 1fr); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field span { font-size: 12px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea { padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; font: inherit; background: #fff; width: 100%; }
.field small { color: var(--muted); font-size: 11px; } .field.err input { border-color: var(--late); }
.actions { grid-column: 1 / -1; display: flex; gap: 14px; align-items: center; margin-top: 6px; }
.form .actions { margin-top: 18px; }

.history { list-style: none; padding: 0; margin: 0; max-height: 420px; overflow-y: auto; }
.history li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.history time { color: var(--muted); font-size: 12px; margin-right: 6px; font-variant-numeric: tabular-nums; }
.history .note { color: var(--muted); margin-top: 2px; }

.login { max-width: 380px; margin: 80px auto; text-align: center; }
.login .dev { margin-top: 10px; }

@media (max-width: 900px) {
  .cols { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .formgrid, .formgrid.compact { grid-template-columns: 1fr; }
  .page { padding: 16px; }
  .topbar { gap: 12px; padding: 0 16px; } .topbar .who { display: none; }
}

.docs { margin-bottom: 16px; } .docs p { margin: 0 0 8px; }
.grid tr.plain { cursor: default; } .grid tr.plain:hover { background: none; }
.grid.intake { min-width: 900px; } .grid.intake td { white-space: normal; }
.tag.out-created { background: #dcfce7; color: #166534; } .tag.out-duplicate { background: #e9ecf2; color: var(--muted); }
.tag.out-not_invoice { background: #e9ecf2; color: var(--muted); } .tag.out-no_pdf { background: #e9ecf2; color: var(--muted); }
.tag.out-failed { background: #fde2e2; color: var(--late); }
.ro { background: rgba(255,255,255,.15); border-radius: 8px; padding: 1px 7px; font-size: 11px; margin-left: 4px; }
.access td select { padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; font: inherit; background: #fff; }
.invite { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.invite .field { min-width: 180px; }
.invite-msg { background: #f7f9fc; border: 1px dashed var(--line); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; font-size: 13px; }
.grid.access { min-width: 720px; } .grid.access td { vertical-align: middle; } .grid.access select { width: 100%; }
.people-cols { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 16px; align-items: start; }
.people-cols .field { margin-bottom: 12px; }
.boardlist { margin: 4px 0 14px; }
.boardrow { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.boardrow:last-child { border-bottom: 1px solid var(--line); }
.seg { display: inline-flex; border: 1px solid #c9cfda; border-radius: 7px; overflow: hidden; flex-shrink: 0; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; width: 0; height: 0; }
.seg label span { display: block; padding: 5px 12px; font-size: 12px; color: var(--muted); border-left: 1px solid #e3e6ec; min-width: 50px; text-align: center; }
.seg label:first-child span { border-left: 0; }
.seg input:checked + span { background: #e0e9fd; color: #1d4ed8; font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: -2px; }
.people { border-top: 1px solid var(--line); }
.person { border-bottom: 1px solid var(--line); }
.person summary { list-style: none; display: grid; grid-template-columns: minmax(0, 1fr) auto 16px; gap: 12px; align-items: center; padding: 11px 4px; cursor: pointer; }
.person summary::-webkit-details-marker { display: none; }
.person summary:hover { background: #f7f9fc; }
.person .who-cell { min-width: 0; } .person .nm, .person .who-cell .sub { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .chips { display: block; margin-top: 5px; }
.person .when { color: var(--muted); font-size: 12px; text-align: right; }
.person .caret { font-style: normal; color: var(--muted); transition: transform .15s; }
.person[open] .caret { transform: rotate(90deg); }
.chip { display: inline-block; white-space: nowrap; font-size: 12px; padding: 2px 8px; border-radius: 10px; background: #eef1f6; color: #3b4456; margin: 2px 4px 2px 0; }
.chip.admin { background: #e0e9fd; color: #1d4ed8; }
.person-edit { padding: 2px 4px 14px; max-width: 420px; }
.small { font-size: 12px; margin-left: 10px; }
@media (max-width: 900px) { .people-cols { grid-template-columns: 1fr; } }
.ar-invoiced { --c: var(--st-ready); } .ar-in_process { --c: var(--st-scheduled); } .ar-paid { --c: var(--st-paid); }
.grid.ar { min-width: 1240px; } .c-cust { width: auto; }
.aging { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.age { padding: 10px 14px; border-left: 1px solid var(--line); } .age:first-child { border-left: 0; }
.age span { display: block; font-size: 12px; color: var(--muted); } .age strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.age.late strong { color: #9a3412; }
.small-kpi { font-size: 17px !important; }
.row-actions { display: flex; gap: 8px; align-items: center; } .row-actions form { margin: 0; }
.small-p { font-size: 12px; margin: 4px 0 0; }
.grid.custs { min-width: 560px; } .grid.custs td { vertical-align: middle; }
@media (max-width: 900px) { .aging { grid-template-columns: repeat(2, 1fr); } .age { border-left: 0; border-top: 1px solid var(--line); } }
.grid.custs .sub { display: block; } .step.row input[name=note] { flex: 1; min-width: 200px; }
.tag.unbilled { background: #fff1d6; color: #92400e; }
.so-card { margin-bottom: 16px; } .grid.so { min-width: 720px; } .grid.so .sub { display: block; }
.unbilled-cell { color: #92400e; font-weight: 600; }
.topbar nav { flex: 0 1 auto; }
.topbar .menu { position: relative; margin-right: auto; }
.topbar .menu summary { list-style: none; cursor: pointer; color: #dfe7f3; user-select: none; }
.topbar .menu summary::-webkit-details-marker { display: none; }
.topbar .menu summary .chev { display: inline-block; vertical-align: 0; margin-left: 5px; transition: transform .15s; }
.topbar .menu[open] summary .chev { transform: rotate(180deg); }
.topbar .menu.active summary { color: #fff; border-bottom-color: #fff; }
.topbar .menu-pop { position: absolute; top: calc(100% + 10px); left: 0; min-width: 200px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(15, 23, 42, .14); padding: 6px; z-index: 20; }
.topbar .menu-pop a { display: block; color: var(--ink); padding: 8px 10px; border-radius: 6px; }
.topbar .menu-pop a:hover { background: #f1f4f9; }
.topbar .menu-pop a.current { background: #e0e9fd; color: #1d4ed8; font-weight: 600; }
.topbar .who { margin-left: 0; }
@media (max-width: 900px) { .topbar .menu-pop { left: auto; right: -40px; } }
@media (max-width: 600px) {
  .topbar { height: auto; flex-wrap: wrap; gap: 6px 16px; padding: 10px 16px; }
  .topbar .brand { width: 100%; }
  .topbar nav { gap: 14px; }
  .topbar .menu { margin-right: 0; }
  .topbar .menu-pop { left: auto; right: 0; }
}

/* Receivables: Ready to invoice group */
.ar-ready { --c: var(--st-awaiting); }
.kpis.six { grid-template-columns: repeat(6, 1fr); }
.kpi em { display: block; font-style: normal; font-size: 12px; color: var(--muted); margin-top: 2px; }
.tag.ok-tag { background: #dcfce7; color: #166534; }
.grid .sub-inline { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; white-space: nowrap; }
@media (max-width: 900px) { .kpis.six { grid-template-columns: repeat(2, 1fr); } }
.grid.ship { min-width: 560px; } .grid.ship td.trk { font-variant-numeric: tabular-nums; white-space: nowrap; }
