*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:    #0a1628;
  --navy2:   #0f2044;
  --sky:     #1a73e8;
  --sky-lt:  #4da3ff;
  --grey1:   #f4f6f9;
  --grey2:   #e8ecf2;
  --grey3:   #c8d0dc;
  --grey4:   #8a97a8;
  --grey5:   #4a5568;
  --text:    #1a202c;
  --white:   #ffffff;
  --green:   #00875a;
  --green-lt:#e3fcef;
  --amber:   #c05621;
  --amber-lt:#fffbeb;
  --red:     #c0392b;
  --red-lt:  #fdf2f2;
  --purple:  #553c9a;
  --purple-lt:#f3f0ff;
  --font:    'IBM Plex Sans', sans-serif;
  --mono:    'IBM Plex Mono', monospace;
  --fs:      11px;
  --sidebar: 220px;
  --topbar:  48px;
}

html, body { height: 100%; font-family: var(--font); font-size: var(--fs); color: var(--text); background: var(--grey1); }

/* ── TOPBAR ── */
#topbar {
  position: fixed; top:0; left:0; right:0; height: var(--topbar);
  background: var(--navy); color: var(--white);
  display: flex; align-items: center; padding: 0 16px; gap: 12px;
  z-index: 200; border-bottom: 1px solid var(--navy2);
}
#topbar .logo { height: 36px; width: auto; }
#topbar .brand { font-size: 13px; font-weight: 600; letter-spacing: .5px; color: var(--sky-lt); }
#topbar .sub   { font-size: 10px; color: var(--grey3); margin-top: 1px; }
#topbar .spacer { flex:1; }
#topbar .user-pill {
  display:flex; align-items:center; gap:6px;
  background: var(--navy2); border-radius: 20px; padding: 4px 10px 4px 4px;
  font-size: 10px; color: var(--grey3);
}
#topbar .user-pill .avatar {
  width:22px; height:22px; border-radius:50%;
  background: var(--sky); color:#fff;
  display:flex; align-items:center; justify-content:center;
  font-size:9px; font-weight:600;
}
#topbar .badge {
  background: var(--red); color:#fff; border-radius:10px;
  padding: 1px 5px; font-size:9px; font-weight:600; margin-left:2px;
}

/* ── SIDEBAR ── */
#sidebar {
  position: fixed; top: var(--topbar); left:0; bottom:0;
  width: var(--sidebar); background: var(--navy2);
  overflow-y: auto; z-index: 100;
  display: flex; flex-direction: column;
  border-right: 1px solid rgba(255,255,255,.05);
}
.nav-section { padding: 16px 12px 6px; font-size:9px; font-weight:600; letter-spacing:1px; color: var(--grey4); text-transform:uppercase; }
.nav-item {
  display:flex; align-items:center; gap:8px;
  padding: 7px 14px; font-size:11px; color: var(--grey3);
  cursor:pointer; border-radius:0; transition: background .15s;
  border-left: 3px solid transparent;
  user-select: none;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(26,115,232,.18); color: var(--sky-lt); border-left-color: var(--sky); }
.nav-item .icon { font-size:13px; width:16px; text-align:center; }
.nav-item .count {
  margin-left:auto; background:var(--red); color:#fff;
  border-radius:10px; padding:1px 5px; font-size:9px; font-weight:600;
}
.nav-item .count.amber { background: var(--amber); }
.nav-item .count.green { background: var(--green); }
#sidebar .footer { margin-top:auto; padding:12px; font-size:9px; color:var(--grey4); text-align:center; border-top: 1px solid rgba(255,255,255,.05); }

/* ── MAIN ── */
#main {
  margin-left: var(--sidebar); margin-top: var(--topbar);
  padding: 20px; min-height: calc(100vh - var(--topbar));
}

/* ── PAGE HEADER ── */
.page-header { margin-bottom:16px; }
.page-header h1 { font-size:16px; font-weight:600; color: var(--navy); }
.page-header .sub { font-size:10px; color: var(--grey4); margin-top:2px; }
.breadcrumb { font-size:10px; color: var(--grey4); margin-bottom:6px; }
.breadcrumb span { color: var(--sky); }

/* ── CARDS ── */
.card { background: #fff; border-radius:6px; border:1px solid var(--grey2); margin-bottom:12px; }
.card-header {
  padding: 10px 14px; border-bottom: 1px solid var(--grey2);
  display:flex; align-items:center; gap:8px;
  font-size:11px; font-weight:600; color: var(--navy);
}
.card-header .spacer { flex:1; }
.card-body { padding: 12px 14px; }

/* ── STAT TILES ── */
.stat-grid { display:grid; grid-template-columns: repeat(5,1fr); gap:10px; margin-bottom:16px; }
.stat-tile {
  background:#fff; border-radius:6px; border:1px solid var(--grey2);
  padding:12px 14px;
}
.stat-tile .label { font-size:9px; color:var(--grey4); text-transform:uppercase; letter-spacing:.5px; }
.stat-tile .value { font-size:22px; font-weight:600; color:var(--navy); margin:4px 0 2px; line-height:1; }
.stat-tile .delta { font-size:10px; }
.stat-tile .delta.up { color:var(--green); }
.stat-tile .delta.down { color:var(--red); }

/* ── TABLE ── */
.tbl-wrap { overflow-x:auto; }
table { width:100%; border-collapse:collapse; font-size:11px; }
th { background:var(--grey1); padding:7px 10px; text-align:left; font-weight:600; font-size:10px; color:var(--grey5); border-bottom:1px solid var(--grey2); white-space:nowrap; }
td { padding:7px 10px; border-bottom:1px solid var(--grey2); vertical-align:middle; }
tr:last-child td { border-bottom:none; }
tr:hover td { background: #fafbfd; }
.tbl-actions { display:flex; gap:4px; }
.truncate { display:block; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:100%; }
/* Applied to every data table so columns stay fixed-width (set via each
   table's own <colgroup>) and content never wraps a row onto multiple
   lines or forces the page to scroll sideways — an overlong value is
   ellipsis-truncated within its own column instead (hover for the full
   value via each cell's title attribute, where one is set). */
.fit-table { table-layout:fixed; }
.fit-table td { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.fit-table .chip { max-width:100%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; display:inline-block; vertical-align:middle; }
.fit-table td:has(.tbl-actions), .fit-table td:has(button) { overflow:visible; }
#inbox-table { table-layout:fixed; }
.coding-table { table-layout:fixed; }
.dup-table { table-layout:fixed; }
.coding-table td, .coding-table th { padding:6px 8px; font-size:10.5px; }
.coding-table select.truncate { text-overflow:ellipsis; }
#inbox-table td { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
#inbox-table .chip { max-width:100%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; display:inline-block; vertical-align:middle; }
#inbox-table td:last-child { overflow:visible; }
#inbox-table td:first-child { overflow:visible; }
#inbox-table td:first-child .text-mono { display:inline-block; max-width:100px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; vertical-align:middle; }

/* ── BADGES ── */
.badge { display:inline-block; border-radius:3px; padding:2px 6px; font-size:10px; font-weight:500; white-space:nowrap; }
.badge-new       { background:#e8f4fd; color:#1a73e8; }
.badge-pending   { background:var(--amber-lt); color:var(--amber); }
.badge-approved  { background:var(--green-lt); color:var(--green); }
.badge-rejected  { background:var(--red-lt); color:var(--red); }
.badge-posted    { background:#f0f0ff; color:var(--purple); }
.badge-exported  { background:var(--grey1); color:var(--grey4); }
.badge-review    { background:#fff3e0; color:#e65100; }

/* ── BUTTONS ── */
.btn { display:inline-flex; align-items:center; gap:5px; border:none; border-radius:4px; padding:5px 11px; font-size:11px; font-family:var(--font); cursor:pointer; font-weight:500; transition: opacity .15s, background .15s; }
.btn:hover { opacity:.88; }
.btn:disabled { background:var(--grey2)!important; color:var(--grey4)!important; cursor:not-allowed; opacity:.7; }
.btn:disabled:hover { opacity:.7; }
.btn-primary   { background: var(--sky); color:#fff; }
.btn-secondary { background: var(--grey2); color: var(--grey5); }
.btn-danger    { background: var(--red); color:#fff; }
.btn-success   { background: var(--green); color:#fff; }
.btn-ghost     { background: transparent; color: var(--sky); border:1px solid var(--sky); }
.btn-sm        { padding: 3px 8px; font-size:10px; }
.btn-icon      { padding:5px 7px; }

/* ── FORMS ── */
.form-row { display:flex; gap:10px; margin-bottom:10px; flex-wrap:wrap; }
.form-group { display:flex; flex-direction:column; gap:3px; flex:1; min-width:120px; }
.form-group label { font-size:10px; font-weight:600; color:var(--grey5); }
input[type=text], input[type=number], input[type=email], input[type=date], select, textarea {
  border:1px solid var(--grey3); border-radius:4px; padding:5px 8px;
  font-size:11px; font-family:var(--font); color:var(--text);
  background:#fff; outline:none; width:100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--sky); box-shadow:0 0 0 2px rgba(26,115,232,.15); }
input[readonly] { background: var(--grey1); color:var(--grey5); }
/* Remove spinner arrows from all number inputs except qty fields */
input[type=number]:not(.keep-spinner) { -webkit-appearance:textfield; -moz-appearance:textfield; appearance:textfield; }
input[type=number]:not(.keep-spinner)::-webkit-inner-spin-button,
input[type=number]:not(.keep-spinner)::-webkit-outer-spin-button { -webkit-appearance:none; margin:0; }

/* ── DETAIL GRID (Invoice Detail: Vendor Info / GL Coding row-aligned columns) ── */
.detail-grid {
  display:grid; grid-template-columns:1fr 1fr;
  column-gap:14px; row-gap:10px;
  margin-bottom:14px; align-items:start;
}
.detail-grid .form-row { margin-bottom:0; }
@media (max-width: 640px) {
  .detail-grid { grid-template-columns:1fr; }
  .detail-grid .detail-spacer { display:none; }
}

/* ── MODAL ── */
.modal-overlay {
  position:fixed; inset:0; background:rgba(0,0,0,.5);
  display:flex; align-items:center; justify-content:center;
  z-index:500; padding:20px;
}
.modal {
  background:#fff; border-radius:8px; width:100%; max-width:960px;
  max-height:92vh; display:flex; flex-direction:column;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-header {
  padding:14px 18px; border-bottom:1px solid var(--grey2);
  display:flex; align-items:center; gap:8px;
  font-size:13px; font-weight:600; color:var(--navy);
}
.modal-header .spacer { flex:1; }
.modal-body { padding:16px 18px; overflow-y:auto; flex:1; }
.modal-footer { padding:12px 18px; border-top:1px solid var(--grey2); display:flex; gap:8px; justify-content:flex-end; }

/* Vendor modal can open nested on top of Capture Invoice (its "new vendor"
   option) — force it above regardless of DOM order. */
#vendor-modal.modal-overlay { z-index:600; }

/* ── INVOICE DETAIL — full-screen split-pane (scoped to this modal only) ── */
#detail-modal.modal-overlay {
  align-items:stretch; justify-content:stretch; padding:0; inset:0;
}
#detail-modal .modal {
  width:100%; max-width:none; height:100%; max-height:none; border-radius:0;
}
#detail-modal .modal-body {
  display:flex; padding:0; overflow:hidden;
}
#detail-modal .detail-left-pane {
  width:55%; overflow-y:auto; padding:16px 18px;
}
#detail-modal .detail-right-pane {
  width:45%; border-left:1px solid var(--grey2);
  display:flex; flex-direction:column; padding:14px; overflow:hidden;
}
@media (max-width: 1280px) {
  #detail-modal.modal-overlay { align-items:center; justify-content:center; padding:20px; left:0; top:0; }
  #detail-modal .modal { max-width:960px; height:auto; max-height:92vh; border-radius:8px; }
  #detail-modal .modal-body { display:block; padding:16px 18px; overflow-y:auto; }
  #detail-modal .detail-left-pane, #detail-modal .detail-right-pane { width:100%; border-left:none; padding:0; overflow:visible; }
  #detail-modal .detail-right-pane { margin-top:14px; }
}

/* ── INVOICE DETAIL — density reduction (scoped to this modal only, so
   Capture Invoice / Admin forms elsewhere keep their current sizing) ──
   The left pane only gets 55% of the viewport (see .detail-left-pane
   above), so the Line Items table (8 fixed-width columns) needs both a
   smaller footprint and a tighter grid above it to avoid horizontal
   scroll on a ~1366-1920px screen. */
#detail-modal .detail-grid { row-gap:7px; column-gap:10px; margin-bottom:10px; }
#detail-modal .form-row { gap:8px; margin-bottom:7px; }
#detail-modal .form-group label { font-size:9px; }
#detail-modal .section-title { margin-bottom:6px; padding-bottom:3px; }
#detail-modal .detail-left-pane input[type=text],
#detail-modal .detail-left-pane input[type=number],
#detail-modal .detail-left-pane input[type=date],
#detail-modal .detail-left-pane select {
  padding:4px 6px; font-size:10px;
}

/* Line Items table itself — column widths are trimmed in invoice-detail.js's
   colgroup/inline input styles (inline styles win over CSS, so padding/width
   there had to move too); this covers font-size and cell padding, which
   aren't inline. Keeps the bold per-row Total Incl. (fw600) legible at 10px
   — a modest reduction from the table default, not a token-sized shrink. */
#detail-lines-table { font-size:10px; }
#detail-lines-table th { padding:4px 5px; font-size:9px; }
#detail-lines-table td { padding:3px 5px; }

/* Caps very long invoices (13+ lines in the sample data) so the table
   doesn't push Reconciliation/Audit History far down the page — short
   invoices never reach this height, so no scrollbar appears for them. */
.detail-lines-wrap { max-height:360px; overflow-y:auto; }
#detail-lines-table thead th { position:sticky; top:0; z-index:1; }

/* ── TABS ── */
.tabs { display:flex; border-bottom:1px solid var(--grey2); margin-bottom:14px; }
.tab { padding:7px 14px; font-size:11px; cursor:pointer; color:var(--grey4); border-bottom:2px solid transparent; margin-bottom:-1px; }
.tab:hover { color:var(--text); }
.tab.active { color:var(--sky); border-bottom-color:var(--sky); font-weight:600; }

/* ── MISC ── */
.hidden { display:none !important; }
.flex { display:flex; }
.flex-center { display:flex; align-items:center; }
.gap-4 { gap:4px; } .gap-8 { gap:8px; }
.ml-auto { margin-left:auto; }
.text-muted { color:var(--grey4); }
.text-sm { font-size:10px; }
.text-mono { font-family:var(--mono); }
.text-right { text-align:right; }
.text-green { color:var(--green); }
.text-red { color:var(--red); }
.text-amber { color:var(--amber); }
.text-sky { color:var(--sky); }
.fw600 { font-weight:600; }
.divider { height:1px; background:var(--grey2); margin:12px 0; }
.chip {
  display:inline-flex; align-items:center; gap:4px;
  background:var(--grey1); border:1px solid var(--grey2);
  border-radius:12px; padding:2px 8px; font-size:10px; color:var(--grey5);
}
.section-title { font-size:12px; font-weight:600; color:var(--navy); margin-bottom:8px; padding-bottom:4px; border-bottom:1px solid var(--grey2); }
.amount { font-family:var(--mono); text-align:right; }
.search-bar {
  display:flex; align-items:center; gap:6px;
  background:#fff; border:1px solid var(--grey3); border-radius:4px;
  padding:4px 8px; font-size:11px;
}
.search-bar input { border:none; outline:none; flex:1; font-size:11px; font-family:var(--font); }
.filter-bar { display:flex; gap:8px; align-items:center; margin-bottom:12px; flex-wrap:wrap; }
.progress-bar-wrap { background:var(--grey2); border-radius:3px; height:6px; overflow:hidden; }
.progress-bar-fill { height:100%; border-radius:3px; background:var(--sky); transition:width .3s; }
.toast {
  position:fixed; bottom:20px; right:20px; z-index:999;
  background:var(--navy); color:#fff; border-radius:6px;
  padding:10px 16px; font-size:11px; max-width:320px;
  box-shadow:0 4px 20px rgba(0,0,0,.3);
  display:flex; align-items:center; gap:8px;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform:translateY(10px); opacity:0; } to { transform:translateY(0); opacity:1; } }

/* ── LINE ITEMS ── */
.line-item-row { display:grid; grid-template-columns:1fr 90px 90px 90px 110px 110px 30px; gap:6px; align-items:center; margin-bottom:6px; }
.line-header   { display:grid; grid-template-columns:1fr 90px 90px 90px 110px 110px 30px; gap:6px; margin-bottom:4px; font-size:10px; font-weight:600; color:var(--grey5); }
.totals-row { display:flex; justify-content:flex-end; gap:20px; padding:8px 14px; background:var(--grey1); border-radius:4px; font-size:11px; }
.totals-row .total-item { display:flex; flex-direction:column; align-items:flex-end; gap:2px; }
.totals-row .total-label { font-size:9px; color:var(--grey4); text-transform:uppercase; }
.totals-row .total-val { font-family:var(--mono); font-weight:600; font-size:13px; }

/* ── RECON BOX ── */
.recon-box { border:1px solid var(--grey2); border-radius:6px; overflow:hidden; }
.recon-row { display:grid; grid-template-columns:200px 1fr 1fr 80px; gap:0; border-bottom:1px solid var(--grey2); }
.recon-row:last-child { border-bottom:none; }
.recon-cell { padding:7px 10px; font-size:11px; }
.recon-cell.header { background:var(--grey1); font-weight:600; font-size:10px; color:var(--grey5); }
.recon-match { font-size:10px; font-weight:600; }
.recon-match.ok  { color:var(--green); }
.recon-match.warn{ color:var(--amber); }
.recon-match.bad { color:var(--red); }
/* Corrected-field indicator */
input[style*="border-left:3px solid"], select[style*="border-left:3px solid"] { background:#fffbf0 !important; }

/* ── UPLOAD DROP ZONE ── */
.drop-zone {
  border:2px dashed var(--grey3); border-radius:6px; padding:30px;
  text-align:center; color:var(--grey4); cursor:pointer;
  transition: border-color .2s, background .2s;
}
.drop-zone:hover, .drop-zone.dragover { border-color:var(--sky); background:#f0f7ff; color:var(--sky); }
.drop-zone .icon { font-size:28px; margin-bottom:8px; }

/* ── DASHBOARD ── */
.dash-welcome {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy2) 60%, #0d3060 100%);
  border-radius: 8px; padding: 20px 24px; margin-bottom: 16px;
  color: #fff; display: flex; align-items: center; gap: 20px;
  border: 1px solid rgba(255,255,255,.08);
}
.dash-welcome .greeting { flex: 1; }
.dash-welcome h2 { font-size: 18px; font-weight: 600; margin-bottom: 3px; }
.dash-welcome .sub { font-size: 11px; color: var(--grey3); }
.dash-welcome .date-pill {
  background: rgba(255,255,255,.08); border-radius: 20px;
  padding: 6px 14px; font-size: 11px; color: var(--grey3);
  border: 1px solid rgba(255,255,255,.1);
}
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi-tile {
  background: #fff; border-radius: 6px; border: 1px solid var(--grey2);
  padding: 12px 14px; position: relative; overflow: hidden;
}
.kpi-tile::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--accent, var(--sky));
}
.kpi-tile .kpi-icon { font-size: 18px; margin-bottom: 6px; }
.kpi-tile .kpi-label { font-size: 9px; text-transform: uppercase; letter-spacing: .6px; color: var(--grey4); margin-bottom: 4px; }
.kpi-tile .kpi-val { font-size: 20px; font-weight: 700; color: var(--navy); line-height: 1; }
.kpi-tile .kpi-sub { font-size: 10px; color: var(--grey4); margin-top: 4px; }
.kpi-tile .kpi-delta { font-size: 10px; font-weight: 600; margin-top: 3px; }
.kpi-tile .kpi-delta.up { color: var(--green); }
.kpi-tile .kpi-delta.down { color: var(--red); }
.kpi-tile .kpi-delta.warn { color: var(--amber); }

.pipeline-wrap {
  display: flex; gap: 0; margin-bottom: 16px;
  background: #fff; border: 1px solid var(--grey2); border-radius: 6px; overflow: hidden;
}
.pipeline-stage {
  flex: 1; padding: 14px 16px; position: relative; cursor: pointer;
  border-right: 1px solid var(--grey2); transition: background .15s;
}
.pipeline-stage:last-child { border-right: none; }
.pipeline-stage:hover { background: var(--grey1); }
.pipeline-stage .ps-label { font-size: 9px; text-transform: uppercase; letter-spacing: .6px; color: var(--grey4); margin-bottom: 6px; }
.pipeline-stage .ps-count { font-size: 28px; font-weight: 700; color: var(--navy); line-height: 1; }
.pipeline-stage .ps-amount { font-size: 10px; color: var(--grey4); margin-top: 3px; font-family: var(--mono); }
.pipeline-stage .ps-bar { height: 3px; border-radius: 2px; margin-top: 10px; }
.pipeline-arrow {
  display: flex; align-items: center; padding: 0 4px;
  color: var(--grey3); font-size: 16px; background: #fff;
  border-right: 1px solid var(--grey2); position: relative; z-index: 1;
}

.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.dash-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; margin-bottom: 14px; }

.bar-chart { padding: 4px 0; }
.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.bar-label { font-size: 10px; color: var(--grey5); width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 0; }
.bar-track { flex: 1; background: var(--grey2); border-radius: 3px; height: 8px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 3px; background: var(--sky); transition: width .4s; }
.bar-amount { font-family: var(--mono); font-size: 10px; color: var(--grey5); width: 90px; text-align: right; flex-shrink: 0; }

.activity-feed { max-height: 280px; overflow-y: auto; }
.activity-item {
  display: flex; gap: 10px; padding: 7px 0;
  border-bottom: 1px solid var(--grey2); align-items: flex-start;
}
.activity-item:last-child { border-bottom: none; }
.activity-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 3px; flex-shrink: 0; }
.activity-item .act-text { font-size: 11px; color: var(--text); flex: 1; }
.activity-item .act-time { font-size: 10px; color: var(--grey4); white-space: nowrap; }

.due-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 0; border-bottom: 1px solid var(--grey2);
}
.due-item:last-child { border-bottom: none; }
.due-badge { border-radius: 3px; padding: 2px 7px; font-size: 10px; font-weight: 600; white-space: nowrap; }
.due-overdue { background: var(--red-lt); color: var(--red); }
.due-soon    { background: var(--amber-lt); color: var(--amber); }
.due-ok      { background: var(--green-lt); color: var(--green); }

.donut-wrap { display: flex; align-items: center; gap: 16px; padding: 8px 0; }
.donut-legend { flex: 1; }
.donut-legend-item { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; font-size: 10px; }
.donut-legend-dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }

/* ── PRINT ── */
@media print {
  #topbar, #sidebar { display:none; }
  #main { margin:0; padding:0; }
}
