:root {
  --ink: #061A24;
  --ink-2: #0D2D3C;
  --side-text: #A8BCC6;
  --paper: #F3F6F7;
  --panel: #FFFFFF;
  --line: #DAE3E7;
  --muted: #5E7079;
  --accent: #0B7F86;
  --accent-d: #08666B;
  --accent-soft: #E3F2F3;
  --good: #16794C;
  --warn: #9A6200;
  --bad: #B42318;
  --bs-body-font-family: 'Public Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --bs-body-color: var(--ink);
  --bs-body-bg: var(--paper);
  --bs-link-color: var(--accent);
  --bs-link-hover-color: var(--accent-d);
  --bs-border-color: var(--line);
}
body { font-size: 14.5px; font-variant-numeric: tabular-nums; }
h1, h2, h3, h4 { letter-spacing: -0.01em; }
a { text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Layout */
.side { position: fixed; inset: 0 auto 0 0; width: 236px; background: var(--ink); color: var(--side-text); display: flex; flex-direction: column; z-index: 30; }
.brand { padding: 20px 20px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand b { display: block; color: #fff; font-size: 16px; font-weight: 700; line-height: 1.2; }
.brand small { color: var(--side-text); font-size: 12px; }
.side nav { padding: 12px 0; flex: 1; overflow-y: auto; }
.side nav a { display: block; padding: 9px 20px; color: var(--side-text); border-left: 3px solid transparent; font-weight: 500; }
.side nav a:hover { color: #fff; background: rgba(255,255,255,.04); text-decoration: none; }
.side nav a.on { color: #fff; background: var(--ink-2); border-left-color: #35C2CA; }
.side-foot { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.side-foot .who { color: #fff; font-weight: 600; }
.side-foot a, .side-foot button { color: var(--side-text); background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
.side-foot a:hover, .side-foot button:hover { color: #fff; text-decoration: underline; }
.main { margin-left: 236px; min-height: 100vh; }
.topbar { display: none; align-items: center; gap: 12px; padding: 10px 16px; background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar button { background: none; border: 1px solid rgba(255,255,255,.35); color: #fff; border-radius: 6px; padding: 4px 10px; }
.content { padding: 28px 32px 56px; max-width: 1240px; }
body.bare { background: var(--ink); }
body.bare .content { max-width: none; padding: 0; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 24px; font-weight: 700; margin: 0; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Panels and tables */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 20px; }
.panel > .panel-h { padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.panel > .panel-b { padding: 16px; }
.table { margin: 0; --bs-table-bg: transparent; }
.table > :not(caption) > * > * { padding: 10px 14px; border-bottom-color: var(--line); vertical-align: middle; }
.table thead th { font-size: 12.5px; font-weight: 600; color: var(--muted); background: #F8FAFB; white-space: nowrap; border-bottom: 1px solid var(--line); }
.table-hover > tbody > tr:hover > * { background: #F6FAFA; }
.num { text-align: right; white-space: nowrap; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.muted { color: var(--muted); }
.small-muted { color: var(--muted); font-size: 12.5px; }

/* Figures */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 20px; }
.fig { padding: 16px 18px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 0 -1px -1px 0; }
.fig .l { color: var(--muted); font-size: 13px; }
.fig .v { font-size: 24px; font-weight: 700; margin-top: 2px; letter-spacing: -0.02em; }
.fig .n { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.fig.bad .v { color: var(--bad); }
.fig.good .v { color: var(--good); }

.bars { display: flex; align-items: flex-end; gap: 14px; height: 130px; padding: 8px 4px 0; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 6px; }
.bars .bar i { display: block; width: 100%; max-width: 54px; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; }
.bars .bar span { font-size: 12px; color: var(--muted); }
.bars .bar em { font-style: normal; font-size: 11.5px; color: var(--ink); }

/* Status */
.st { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; text-transform: capitalize; background: #E8EEF1; color: #3C4F58; white-space: nowrap; }
.st-new, .st-open, .st-sent, .st-unpaid { background: #E2EEFB; color: #1B4F8F; }
.st-contacted, .st-in_progress, .st-partial, .st-quoted, .st-waiting { background: #FDF0D5; color: var(--warn); }
.st-won, .st-paid, .st-accepted, .st-resolved { background: #DDF3E8; color: var(--good); }
.st-lost, .st-rejected, .st-cancelled, .st-overdue, .st-urgent { background: #FBE4E1; color: var(--bad); }
.st-draft, .st-closed, .st-low { background: #E8EEF1; color: #4A5D66; }
.st-high { background: #FDE8D3; color: #A24A00; }
.st-medium { background: #E8EEF1; color: #3C4F58; }

/* Forms */
.form-label { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.form-control, .form-select { border-color: #C5D1D7; border-radius: 6px; font-size: 14.5px; }
.form-control:focus, .form-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(11,127,134,.18); }
.btn { border-radius: 6px; font-weight: 600; font-size: 14px; }
.btn-primary { --bs-btn-bg: var(--accent); --bs-btn-border-color: var(--accent); --bs-btn-hover-bg: var(--accent-d); --bs-btn-hover-border-color: var(--accent-d); --bs-btn-active-bg: var(--accent-d); --bs-btn-active-border-color: var(--accent-d); --bs-btn-disabled-bg: var(--accent); --bs-btn-disabled-border-color: var(--accent); }
.btn-outline-secondary { --bs-btn-color: #33464F; --bs-btn-border-color: #BFCCD2; --bs-btn-hover-bg: #EAF0F2; --bs-btn-hover-color: var(--ink); --bs-btn-hover-border-color: #AEBDC4; }
.btn-outline-danger { --bs-btn-color: var(--bad); --bs-btn-border-color: #E2B7B2; --bs-btn-hover-bg: var(--bad); --bs-btn-hover-border-color: var(--bad); }
.alert { border-radius: 8px; border-width: 1px; font-size: 14px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters .form-control, .filters .form-select { width: auto; min-width: 150px; }
.filters .grow { flex: 1; min-width: 200px; }
.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px 16px; }
.form-grid > .c3 { grid-column: span 3; } .form-grid > .c4 { grid-column: span 4; } .form-grid > .c6 { grid-column: span 6; } .form-grid > .c8 { grid-column: span 8; } .form-grid > .c12 { grid-column: span 12; }
.dl { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; margin: 0; }
.dl dt { color: var(--muted); font-weight: 500; }
.dl dd { margin: 0; }

/* Line items */
.items-head, .item-row { display: grid; grid-template-columns: minmax(180px, 1fr) 84px 118px 76px 118px 30px; gap: 8px; align-items: center; }
.items-head { font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 0 0 6px; }
.item-row { margin-bottom: 8px; }
.item-row .amt { text-align: right; font-weight: 600; padding-right: 4px; }
.btn-x { border: 0; background: none; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; border-radius: 6px; }
.btn-x:hover { color: var(--bad); background: #FBE4E1; }
.totals-box { margin-left: auto; width: 320px; max-width: 100%; margin-top: 14px; }
.totals-box .row-t { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; gap: 12px; }
.totals-box .row-t.total { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 10px; font-size: 18px; font-weight: 700; }
.totals-box input { width: 120px; text-align: right; }

/* Ticket thread */
.thread .msg { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.thread .msg:last-child { border-bottom: 0; }
.thread .msg.internal { background: #FFF8E6; }
.thread .who { font-weight: 600; }
.thread .when { color: var(--muted); font-size: 12.5px; margin-left: 8px; }
.thread .body { white-space: pre-wrap; margin-top: 4px; }
.late { color: var(--bad); font-weight: 600; }

/* Login */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 380px; background: #fff; border-radius: 10px; padding: 32px 30px; }
.auth-card h1 { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.auth-card .brand-line { color: var(--accent); font-weight: 700; margin-bottom: 18px; }

@media (max-width: 900px) {
  .side { transform: translateX(-100%); transition: transform .18s ease; }
  body.nav-open .side { transform: none; }
  .main { margin-left: 0; }
  .topbar { display: flex; }
  .content { padding: 18px 14px 48px; }
  .form-grid > .c3, .form-grid > .c4, .form-grid > .c6, .form-grid > .c8 { grid-column: span 12; }
  .items-head { display: none; }
  .item-row { grid-template-columns: 1fr 1fr 1fr; padding-bottom: 10px; border-bottom: 1px dashed var(--line); }
  .item-row input[name="desc"] { grid-column: 1 / -1; }
  .dl { grid-template-columns: 1fr; gap: 2px; } .dl dd { margin-bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) { .side { transition: none; } }
@media print { .side, .topbar, .actions, .filters { display: none !important; } .main { margin: 0; } }
