/* Apollo Electrical Services — light UI, Apollo blue, AA contrast, tabular numbers. */

:root {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --ink: #101828;
  --ink2: #344054;
  --muted: #5b6472;
  --line: #e4e9f2;
  --line2: #c9d4e8;
  --accent: #4a74c9;
  --accent-deep: #2f57a8;
  --accent-soft: #eaf1fb;
  --ok: #116149;
  --ok-bg: #e4f4ec;
  --warn: #8a5200;
  --warn-bg: #fdf0dc;
  --bad: #a3231a;
  --bad-bg: #fde7e4;
  --paid: #1d4e89;
  --paid-bg: #e2edfb;
  --r: 12px;
  --sh: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 26px; }
h3 { font-size: 15px; }
p { margin: 0; }

button { font: inherit; }

.num-strong, .stat .v, td.num, .card-rows span.num-strong { font-variant-numeric: tabular-nums; }

.sub { color: var(--muted); font-size: 13px; }
.strong { font-weight: 650; color: var(--ink); }
.err { color: var(--bad); font-size: 13.5px; min-height: 20px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- shell ---------- */

.splash { min-height: 100vh; display: grid; place-items: center; color: var(--muted); }

.app { min-height: 100vh; }

.side {
  display: flex; flex-direction: column; gap: 20px;
  padding: 22px 18px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.side-logo svg { width: 100%; height: auto; display: block; }

.navs { display: grid; gap: 4px; }

.nav {
  all: unset; cursor: pointer;
  padding: 10px 12px; border-radius: 10px;
  font-size: 14.5px; font-weight: 600; color: var(--ink2);
}
.nav:hover { background: var(--accent-soft); color: var(--accent-deep); }
.nav.on { background: var(--accent-soft); color: var(--accent-deep); box-shadow: inset 3px 0 0 var(--accent); }

.side-foot { margin-top: auto; display: grid; gap: 10px; padding: 0 4px; }
.side-foot .sub { font-size: 12.5px; }
.count {
  display: inline-block; min-width: 22px; text-align: center;
  background: var(--accent); color: #fff; border-radius: 999px;
  padding: 1px 7px; font-weight: 700; font-size: 12px;
  margin-right: 4px;
}

.link {
  all: unset; cursor: pointer;
  color: var(--accent-deep); font-size: 13px; font-weight: 600;
  text-decoration: underline; text-underline-offset: 2px;
  padding: 2px 4px; border-radius: 4px;
}
.link:hover { color: var(--accent); }

.main { padding: 26px 30px 60px; min-width: 0; container-type: inline-size; }

/* ---------- topbar ---------- */

.topbar { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; margin-bottom: 18px; }
.role-note {
  max-width: 100%; text-align: right;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 12.5px;
}

.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line2); border-radius: 10px; overflow: hidden; }
.seg-btn { all: unset; cursor: pointer; padding: 8px 14px; font-size: 13px; font-weight: 650; color: var(--ink2); }
.seg-btn.on { background: var(--accent); color: #fff; }
.seg-btn:focus-visible { outline-offset: -2px; }

/* ---------- headers, buttons ---------- */

.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 20px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 11.5px; font-weight: 700; color: var(--accent-deep); margin-bottom: 2px; }
.lede { color: var(--muted); font-size: 14px; margin-top: 6px; max-width: 68ch; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line2); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  padding: 9px 16px; font-size: 14px; font-weight: 650; cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent-deep); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #3f66b4; color: #fff; box-shadow: 0 4px 14px rgba(74, 116, 201, 0.35); }
.btn:disabled { opacity: 0.55; cursor: default; }

/* ---------- cards, stats, pills ---------- */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--sh);
  padding: 18px 20px; margin-bottom: 20px;
}

.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 20px; }
@container (max-width: 899px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.stat .k { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.stat .v { font-size: 21px; font-weight: 700; margin-top: 2px; }
.stat .s { font-size: 12px; color: var(--muted); margin-top: 2px; }

.pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.pill {
  all: unset; cursor: pointer;
  border: 1px solid var(--line2); border-radius: 999px;
  padding: 6px 13px; font-size: 13px; font-weight: 600; color: var(--ink2);
  background: var(--surface);
}
.pill:hover { border-color: var(--accent); color: var(--accent-deep); }
.pill.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill-n { opacity: 0.75; font-weight: 500; margin-left: 4px; font-variant-numeric: tabular-nums; }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line);
}
th.right, td.num-strong { text-align: right; }
td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tr.row { cursor: pointer; }
tr.row:hover td { background: var(--accent-soft); }
tr.row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
td.empty { text-align: center; color: var(--muted); padding: 26px; font-size: 14px; }
td.ok-empty { color: var(--ok); }

.b {
  display: inline-block; border-radius: 999px; padding: 2px 10px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.b.ok { background: var(--ok-bg); color: var(--ok); }
.b.warn { background: var(--warn-bg); color: var(--warn); }
.b.bad { background: var(--bad-bg); color: var(--bad); }
.b.paid { background: var(--paid-bg); color: var(--paid); }
.b.app { background: var(--accent-soft); color: var(--accent-deep); }
.b.mute { background: #eef0f4; color: var(--muted); }

/* ---------- budgets ---------- */

.job-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 10px; }
.job-total { text-align: right; }
.job-total .k { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.job-total .v { font-size: 22px; font-weight: 750; color: var(--accent-deep); font-variant-numeric: tabular-nums; }

.delta {
  display: inline-block; margin-left: 8px;
  background: var(--accent-soft); color: var(--accent-deep);
  border-radius: 999px; padding: 1px 9px;
  font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
}
td.old { color: var(--muted); }
td.hl { background: var(--accent-soft); font-weight: 700; }
.bar { display: inline-block; vertical-align: middle; width: 110px; height: 7px; border-radius: 999px; background: #e8edf6; margin-right: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.footnote { font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.ok-line { color: var(--ok); font-weight: 650; font-size: 14px; margin: -8px 0 16px; }

/* ---------- PO form ---------- */

.po-form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 10px; }
.po-form label { display: grid; gap: 5px; font-size: 12.5px; font-weight: 650; color: var(--ink2); }
.po-form .grow { grid-column: 1 / 3; }
.po-form select, .po-form input {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line2);
  border-radius: 8px; background: var(--surface); color: var(--ink); min-width: 0;
}
.po-form .btn { align-self: end; height: 38px; }
.po-card .err { margin-top: 10px; }

/* ---------- log ---------- */

.log h3 { margin-bottom: 8px; }
.log ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.log li { font-size: 13.5px; color: var(--ink2); border-left: 2px solid var(--line2); padding-left: 10px; }

/* ---------- invoice detail overlay ---------- */

.scrim { position: fixed; inset: 0; background: rgba(16, 24, 40, 0.42); z-index: 19; }

.panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(500px, 100vw);
  background: var(--surface); z-index: 20;
  padding: 22px 24px 40px; overflow-y: auto;
  border-left: 1px solid var(--line); box-shadow: -12px 0 40px rgba(16, 24, 40, 0.12);
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.panel-head h2 { font-size: 22px; }
.x {
  all: unset; cursor: pointer; font-size: 16px; line-height: 1;
  width: 32px; height: 32px; display: grid; place-items: center;
  border-radius: 8px; color: var(--muted);
}
.x:hover { background: var(--accent-soft); color: var(--accent-deep); }

.panel-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.panel-meta p { font-size: 13.5px; font-weight: 600; }
.panel-meta span { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 1px; }

.panel h3 { margin: 12px 0 8px; }

.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.check { display: flex; gap: 9px; align-items: flex-start; font-size: 13.5px; }
.ck {
  flex: none; width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center; font-size: 11px; font-weight: 800; margin-top: 1px;
}
.check.ok .ck { background: var(--ok-bg); color: var(--ok); }
.check.ok { color: var(--ok); }
.check.warn .ck { background: var(--warn-bg); color: var(--warn); }
.check.warn { color: var(--warn); }
.check.bad .ck { background: var(--bad-bg); color: var(--bad); }
.check.bad { color: var(--bad); font-weight: 600; }

.side-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.side-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: grid; gap: 4px; align-content: start; }
.card-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.card-rows { display: flex; justify-content: space-between; gap: 8px; font-size: 13.5px; color: var(--ink2); margin-top: 4px; }

.panel-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 20px; }
.hint { font-size: 13.5px; color: var(--ink2); background: var(--accent-soft); padding: 10px 14px; border-radius: 10px; width: 100%; }

/* ---------- toast ---------- */

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 16px);
  background: var(--ink); color: #fff; font-size: 13.5px; font-weight: 600;
  border-radius: 10px; padding: 10px 18px; z-index: 30;
  opacity: 0; pointer-events: none; transition: opacity 0.18s, transform 0.18s;
  max-width: min(480px, calc(100vw - 40px)); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive shell (>=1100px: 3 columns) ---------- */

@media (min-width: 1100px) {
  .app { display: grid; grid-template-columns: 232px minmax(0, 1fr) 356px; }
  .app.no-chat { grid-template-columns: 232px minmax(0, 1fr); }
  .side { position: sticky; top: 0; height: 100vh; }
  .chat.closed { display: none; }
  .chat-fab { display: none; }
}

@media (max-width: 1099px) {
  .app { display: block; }
  .side { flex-direction: row; align-items: center; gap: 14px; padding: 10px 14px; border-right: none; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
  .side-logo svg { width: 96px; }
  .navs { display: flex; gap: 2px; overflow-x: auto; }
  .nav { white-space: nowrap; padding: 7px 10px; font-size: 13.5px; }
  .nav.on { box-shadow: inset 0 -2px 0 var(--accent); }
  .side-foot { margin: 0 0 0 auto; display: flex; align-items: center; gap: 12px; }
  .side-foot .sub { display: none; }
  .main { padding: 18px 16px 80px; }
  .topbar { align-items: flex-start; }
  .role-note { text-align: left; }
}

@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .po-form { grid-template-columns: 1fr; }
  .po-form .grow { grid-column: auto; }
  .po-form .btn { height: 44px; }
  .side-cards { grid-template-columns: 1fr; }
  .head { flex-direction: column; align-items: stretch; }
  .head .btn { width: 100%; }
  .head-actions { flex-direction: column; }
  th, td { padding: 9px 7px; font-size: 13px; }
  /* No horizontal overflow: the top bar wraps navs to their own row. */
  .side { flex-wrap: wrap; gap: 6px 10px; }
  .navs { order: 3; flex: 1 0 100%; overflow-x: auto; }
  .side-foot { margin: 0; padding: 0; }
  .side-foot .link { padding: 10px 4px; }
  /* Touch targets >= 44px. */
  .btn { min-height: 44px; }
  .seg-btn { min-height: 44px; display: inline-flex; align-items: center; }
  .pill { min-height: 44px; display: inline-flex; align-items: center; }
  .nav { min-height: 44px; display: flex; align-items: center; }
  .link { min-height: 44px; display: inline-flex; align-items: center; }
  .x { width: 44px; height: 44px; }
}

@media (max-width: 480px) {
  .panel-meta { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
