/* ============================================================
   City of Linton — Billing & Invoicing
   Pitch/demo styling. Municipal navy + civic gold palette.
   ============================================================ */

:root {
  --navy: #102a43;
  --navy-2: #1c3a5e;
  --steel: #486581;
  --slate: #627d98;
  --mist: #f0f4f8;
  --line: #d9e2ec;
  --paper: #ffffff;
  --ink: #243b53;
  --gold: #b58a2c;
  --gold-soft: #f7eccf;
  --green: #18794e;
  --green-soft: #e3f3ea;
  --red: #b42318;
  --red-soft: #fdeceb;
  --amber: #b25c00;
  --amber-soft: #fcefdc;
  --blue: #1d4ed8;
  --blue-soft: #e6edfd;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16,42,67,.08), 0 4px 16px rgba(16,42,67,.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--mist);
  display: flex;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--navy), var(--navy-2));
  color: #cdd9e5;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 22px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-seal { font-size: 30px; line-height: 1; }
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { color: #fff; font-size: 15px; }
.brand-text span { font-size: 11.5px; color: #9fb3c8; letter-spacing: .02em; }

.nav { display: flex; flex-direction: column; padding: 14px 12px; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  background: none; border: none; cursor: pointer;
  color: #bcccdc; font-size: 14px; font-family: var(--font);
  padding: 11px 13px; border-radius: 8px; text-align: left;
  transition: background .12s, color .12s;
}
.nav-item span { font-size: 16px; width: 20px; text-align: center; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }

.sidebar-footer {
  padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.08);
  display: flex; flex-direction: column; gap: 8px;
}
.link-btn {
  background: none; border: none; color: #9fb3c8; font-size: 12.5px;
  cursor: pointer; text-align: left; font-family: var(--font); padding: 0;
}
.link-btn:hover { color: #fff; text-decoration: underline; }
.version { font-size: 11px; color: #627d98; }

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; background: var(--paper);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 21px; color: var(--navy); font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.search {
  width: 280px; padding: 9px 13px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 13.5px; font-family: var(--font); background: var(--mist);
}
.search:focus { outline: none; border-color: var(--steel); background: #fff; }

.view-container { padding: 26px 28px; flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font); font-size: 13.5px; font-weight: 600;
  padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  cursor: pointer; transition: filter .12s, background .12s; white-space: nowrap;
}
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-gold { background: var(--gold); color: #fff; }
.btn-gold:hover { filter: brightness(1.05); }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--mist); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { filter: brightness(1.08); }
.btn-danger { background: #fff; color: var(--red); border-color: var(--line); }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }

/* ---------- Cards / KPIs ---------- */
.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px;
}
.kpi {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 18px 16px; box-shadow: var(--shadow);
}
.kpi-label { font-size: 12.5px; color: var(--slate); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 27px; font-weight: 700; color: var(--navy); margin-top: 6px; }
.kpi-sub { font-size: 12.5px; margin-top: 5px; color: var(--slate); }
.kpi-accent { width: 34px; height: 3px; border-radius: 3px; margin-top: 12px; }

.panel {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 22px; overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 15px; color: var(--navy); font-weight: 700; }
.panel-head .muted { font-size: 12.5px; color: var(--slate); font-weight: 500; }
.panel-body { padding: 4px 0; }
.panel-pad { padding: 20px; }

.two-col { display: grid; grid-template-columns: 1.6fr 1fr; gap: 22px; align-items: start; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; padding: 11px 20px; color: var(--slate);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  font-weight: 700; border-bottom: 1px solid var(--line); background: #fafcfe;
}
tbody td { padding: 13px 20px; border-bottom: 1px solid var(--mist); }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #f7fafd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-variant-numeric: tabular-nums; }
.cell-strong { font-weight: 600; color: var(--navy); }
.cell-sub { font-size: 12px; color: var(--slate); margin-top: 2px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 20px;
  letter-spacing: .02em;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-paid { background: var(--green-soft); color: var(--green); }
.badge-sent { background: var(--blue-soft); color: var(--blue); }
.badge-partial { background: var(--amber-soft); color: var(--amber); }
.badge-overdue { background: var(--red-soft); color: var(--red); }
.badge-draft { background: #eef2f6; color: var(--slate); }

.pill {
  font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 6px;
  background: var(--mist); color: var(--steel);
}

/* ---------- Filters ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  font-family: var(--font); font-size: 13px; font-weight: 600;
  padding: 7px 13px; border-radius: 20px; border: 1px solid var(--line);
  background: #fff; color: var(--steel); cursor: pointer;
}
.chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.spacer { flex: 1; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--steel); }
.field input, .field select, .field textarea {
  font-family: var(--font); font-size: 14px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--steel); box-shadow: 0 0 0 3px rgba(72,101,129,.12);
}
.field textarea { resize: vertical; min-height: 64px; }

/* line items editor */
.li-row { display: grid; grid-template-columns: 2.4fr 1.3fr .7fr 1fr 1fr 32px; gap: 8px; align-items: center; margin-bottom: 8px; }
.li-row input, .li-row select { padding: 8px 9px; font-size: 13px; }
.li-head { font-size: 11.5px; font-weight: 700; color: var(--slate); text-transform: uppercase; letter-spacing: .03em; }
.li-del { background: none; border: none; color: var(--red); cursor: pointer; font-size: 18px; line-height: 1; }
.li-total { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; padding-right: 6px; }

/* ---------- Modal ---------- */
.modal-root { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-start; justify-content: center; }
.modal-root.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(16,42,67,.45); backdrop-filter: blur(2px); }
.modal {
  position: relative; background: var(--paper); border-radius: 14px;
  width: min(880px, 94vw); margin: 5vh 0 5vh; max-height: 90vh; overflow: auto;
  box-shadow: 0 24px 60px rgba(16,42,67,.32); animation: pop .16s ease;
}
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 2; }
.modal-head h2 { font-size: 18px; color: var(--navy); }
.modal-close { background: none; border: none; font-size: 24px; color: var(--slate); cursor: pointer; line-height: 1; }
.modal-body { padding: 22px 24px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: #fff; }

/* ---------- Invoice document (print) ---------- */
.invoice-doc { background: #fff; color: #1a2733; }
.inv-top { display: flex; justify-content: space-between; align-items: flex-start; padding-bottom: 22px; border-bottom: 3px solid var(--navy); }
.inv-city { display: flex; gap: 13px; align-items: center; }
.inv-seal { font-size: 42px; }
.inv-city h3 { font-size: 19px; color: var(--navy); }
.inv-city p { font-size: 12.5px; color: var(--slate); line-height: 1.5; }
.inv-meta { text-align: right; }
.inv-meta h2 { font-size: 30px; color: var(--navy); letter-spacing: .04em; }
.inv-meta .inv-num { font-size: 14px; color: var(--steel); margin-top: 2px; font-weight: 600; }
.inv-parties { display: flex; justify-content: space-between; margin: 22px 0; gap: 30px; }
.inv-parties .blk { font-size: 13px; line-height: 1.6; }
.inv-parties .blk .lab { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--slate); font-weight: 700; margin-bottom: 4px; }
.inv-parties .blk strong { color: var(--navy); font-size: 14px; }
.inv-dates { text-align: right; }
.inv-dates .row { display: flex; justify-content: space-between; gap: 24px; font-size: 13px; padding: 2px 0; }
.inv-dates .lab { color: var(--slate); }
.inv-table { margin: 8px 0 0; }
.inv-table table { font-size: 13px; }
.inv-table thead th { background: var(--navy); color: #fff; border: none; padding: 10px 14px; }
.inv-table tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line); }
.inv-totals { display: flex; justify-content: flex-end; margin-top: 16px; }
.inv-totals .box { width: 280px; }
.inv-totals .row { display: flex; justify-content: space-between; padding: 7px 14px; font-size: 13.5px; }
.inv-totals .row.grand { background: var(--navy); color: #fff; font-weight: 700; font-size: 16px; border-radius: 6px; margin-top: 4px; }
.inv-totals .row.paid { color: var(--green); }
.inv-totals .row.due { font-weight: 700; color: var(--red); border-top: 1px solid var(--line); margin-top: 4px; padding-top: 9px; }
.inv-foot { margin-top: 26px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--slate); line-height: 1.6; }
.inv-stamp { position: absolute; top: 40%; left: 50%; transform: translate(-50%,-50%) rotate(-16deg); font-size: 70px; font-weight: 800; color: rgba(24,121,78,.12); border: 6px solid rgba(24,121,78,.12); padding: 6px 26px; border-radius: 12px; pointer-events: none; letter-spacing: .05em; }

/* ---------- Misc ---------- */
.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 78px; align-items: center; gap: 12px; font-size: 13px; }
.bar-track { background: var(--mist); border-radius: 6px; height: 12px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--steel), var(--navy)); }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.empty { text-align: center; padding: 50px 20px; color: var(--slate); }
.empty .em-ico { font-size: 38px; margin-bottom: 8px; }
.muted { color: var(--slate); }
.right { text-align: right; }
.hidden { display: none !important; }
.aging-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; }
.aging-cell { border: 1px solid var(--line); border-radius: 10px; padding: 15px; text-align: center; }
.aging-cell .ac-lab { font-size: 12px; color: var(--slate); font-weight: 600; }
.aging-cell .ac-val { font-size: 22px; font-weight: 700; color: var(--navy); margin-top: 5px; }
.aging-cell.warn .ac-val { color: var(--amber); }
.aging-cell.danger .ac-val { color: var(--red); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 12px 22px; border-radius: 10px;
  font-size: 13.5px; font-weight: 600; box-shadow: 0 10px 30px rgba(16,42,67,.3); z-index: 200;
  animation: toastin .2s ease;
}
@keyframes toastin { from { transform: translate(-50%, 12px); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .modal-head, .modal-foot, .sidebar-footer { display: none !important; }
  body, .main, .view-container { display: block; background: #fff; padding: 0; margin: 0; }
  .modal-root { position: static; }
  .modal-root.hidden { display: block !important; }
  .modal-backdrop { display: none; }
  .modal { box-shadow: none; width: 100%; max-height: none; margin: 0; border-radius: 0; }
  .modal-body { padding: 0; }
  .inv-stamp { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .inv-table thead th, .inv-totals .row.grand { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { margin: 16mm; }
}

@media (max-width: 1080px) {
  .kpi-grid { grid-template-columns: repeat(2,1fr); }
  .two-col { grid-template-columns: 1fr; }
}
