:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #667085;
  --line: #e3e6ea;
  --line-2: #eef0f3;
  --brand: #1f4e79;
  --brand-2: #173c5e;
  --brand-soft: #e8eff6;
  --ok: #1e7b4f;
  --ok-soft: #e3f3ea;
  --warn: #9a6100;
  --warn-soft: #fdf1dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --info: #3656a6;
  --info-soft: #e7ecfa;
  --radius: 8px;
  --side: 224px;
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--ink); background: var(--bg); line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.red { color: var(--bad); }
.green { color: var(--ok); }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.side { width: var(--side); background: #15202d; color: #c9d2dc; position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 20; }
.brand { padding: 18px 18px 14px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid #223142; }
.brand .logo-card { background: #fff; border-radius: 8px; padding: 8px 10px; width: 100%; }
.brand .logo-card img { display: block; width: 100%; height: auto; max-height: 86px; object-fit: contain; }
.auth-logo { display: block; width: 220px; max-width: 100%; margin: 0 auto 18px; }
.paper .doc-brand { display: flex; gap: 16px; align-items: flex-start; }
.paper .doc-logo { width: 150px; height: auto; flex: none; }
.nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.nav a { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 6px; color: #c9d2dc; font-weight: 500; margin-bottom: 1px; }
.nav a:hover { background: #1e2c3c; text-decoration: none; color: #fff; }
.nav a.on { background: #24384e; color: #fff; }
.nav a svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.nav .sep { font-size: 11px; color: #6c7d90; padding: 14px 10px 4px; font-weight: 600; }
.side .me { padding: 12px 16px; border-top: 1px solid #223142; font-size: 12px; display: flex; justify-content: space-between; align-items: center; }
.side .me b { color: #fff; display: block; font-size: 13px; }
.side .me button { background: none; border: 1px solid #34475c; color: #c9d2dc; border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 12px; }
.main { margin-left: var(--side); flex: 1; min-width: 0; }
.top { height: 58px; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 24px; position: sticky; top: 0; z-index: 10; }
.top h1 { font-size: 17px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .search { width: 260px; }
.menu-btn { display: none; }
#view { padding: 22px 24px 60px; max-width: 1400px; }

/* ---------- controls ---------- */
button, .btn { font: inherit; cursor: pointer; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 7px 12px; font-weight: 550; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; line-height: 1.3; }
button:hover, .btn:hover { background: #f7f8fa; text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: #17633f; }
.btn-danger { color: var(--bad); }
.btn-wa { background: #1f8f4e; border-color: #1f8f4e; color: #fff; }
.btn-wa:hover { background: #18773f; }
.btn-sm { padding: 4px 9px; font-size: 12.5px; }
.btn-link { border: none; background: none; color: var(--brand); padding: 0; font-weight: 550; }
.btn-link:hover { background: none; text-decoration: underline; }
button:disabled { opacity: .55; cursor: not-allowed; }
input, select, textarea { font: inherit; color: var(--ink); width: 100%; border: 1px solid #d5d9df; border-radius: 6px; padding: 7px 10px; background: #fff; }
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9bbbd9; outline-offset: -1px; border-color: #7aa3c9; }
input[type=checkbox], input[type=radio] { width: auto; }
label { display: block; font-size: 12.5px; font-weight: 600; color: #3d4757; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0 0; font-weight: 400; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
.span-all { grid-column: 1 / -1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; }
.toolbar input[type=search] { min-width: 240px; }

/* ---------- panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel > .ph { padding: 12px 16px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; gap: 10px; }
.panel > .ph h2 { flex: 1; }
.panel > .pb { padding: 16px; }
.panel + .panel { margin-top: 16px; }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.cols-even { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.stack > * + * { margin-top: 16px; }
.empty { padding: 26px 16px; text-align: center; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: block; color: inherit; }
a.stat:hover { border-color: #b9c7d6; text-decoration: none; }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 22px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat .s { font-size: 12px; color: var(--muted); }
.stat.alert .v { color: var(--bad); }
.stats.dept .stat { border-top: 3px solid var(--info); padding: 16px 18px; }
.stats.dept .stat .v { font-size: 30px; }
.stats.dept .stat.good { border-top-color: var(--ok); }
.stats.dept .stat.good .v { color: var(--ok); }
.stats.dept .stat.warn { border-top-color: #d08a12; }
.stats.dept .stat.bad { border-top-color: var(--bad); }
.stats.dept .stat.bad .v { color: var(--bad); }

.pipeline { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.pipeline a { display: flex; gap: 8px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 5px 6px 5px 12px; color: var(--ink); font-weight: 550; font-size: 13px; }
.pipeline a:hover { text-decoration: none; border-color: #b9c7d6; }
.pipeline a b { background: var(--line-2); border-radius: 12px; padding: 1px 8px; font-size: 12px; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; }
td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td { background: #f7f9fb; }
td .sub { display: block; font-size: 12px; color: var(--muted); }
tfoot td { font-weight: 650; border-top: 1px solid var(--line); }

.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: var(--line-2); color: #3d4757; white-space: nowrap; }
.st-received { background: var(--info-soft); color: var(--info); }
.st-diagnosing { background: #efe8fb; color: #5b3a9e; }
.st-quotation-sent { background: var(--warn-soft); color: var(--warn); }
.st-waiting-for-parts { background: #fdebdc; color: #a1460c; }
.st-in-repair { background: #e2f1f6; color: #12617a; }
.st-ready-for-pickup { background: var(--ok-soft); color: var(--ok); }
.st-done { background: #1e7b4f; color: #fff; }
.btn-done { background: var(--ok); border-color: var(--ok); color: #fff; width: 100%; justify-content: center; padding: 11px; font-size: 15px; }
.btn-done:hover { background: #17633f; }
.done-note { background: var(--ok-soft); color: #14532d; border-radius: 6px; padding: 10px 12px; font-size: 13px; }
.st-delivered { background: #eceef1; color: #4a5565; }
.st-not-carried-out { background: var(--bad-soft); color: var(--bad); }
.st-paid { background: var(--ok-soft); color: var(--ok); }
.st-partial { background: var(--warn-soft); color: var(--warn); }
.st-unpaid { background: var(--bad-soft); color: var(--bad); }
.st-void { background: #eceef1; color: #7a8594; text-decoration: line-through; }
.st-active { background: var(--ok-soft); color: var(--ok); }
.st-expiring { background: var(--warn-soft); color: var(--warn); }
.st-expired { background: var(--bad-soft); color: var(--bad); }
.pri-urgent { color: var(--bad); font-weight: 650; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 4px; background: var(--brand-soft); color: var(--brand); margin-left: 4px; }

/* ---------- detail lists ---------- */
dl.kv { display: grid; grid-template-columns: 130px 1fr; gap: 7px 12px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 12.5px; }
dl.kv dd { margin: 0; word-break: break-word; }
.totals { width: 100%; }
.totals td { padding: 5px 0; border: none; }
.totals tr.grand td { font-weight: 700; font-size: 15px; border-top: 1px solid var(--line); padding-top: 9px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--line); position: relative; margin-left: 5px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2px solid #9aa6b5; }
.timeline li.st::before { background: var(--brand); border-color: var(--brand); }
.timeline .when { font-size: 11.5px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid #d5d9df; border-radius: 16px; padding: 5px 11px; font-size: 13px; cursor: pointer; font-weight: 500; background: #fff; user-select: none; }
.chip input { margin: 0; }
.chip:has(input:checked) { background: var(--brand-soft); border-color: #8fb0cf; color: var(--brand-2); }
.devtypes { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-top: 6px; }
.devtypes label { border: 1px solid #d5d9df; border-radius: 8px; padding: 12px 8px; text-align: center; cursor: pointer; font-weight: 600; background: #fff; }
.devtypes label input { display: none; }
.devtypes label:has(input:checked) { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-2); }
.devtypes svg { display: block; margin: 0 auto 6px; width: 24px; height: 24px; }

/* onsite visit card */
.visit-card { margin-bottom: 16px; border-color: #b9c9da; }
.vc { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.vc-info { padding: 16px; }
.vc-map { border-left: 1px solid var(--line-2); min-height: 260px; }
.vc-map .mapframe { border-radius: 0 0 var(--radius) 0; height: 100% !important; min-height: 320px; }
.vc-ticket { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.vc-ticket span { color: var(--muted); font-size: 12px; font-weight: 600; }
.vc-ticket b { font-size: 22px; letter-spacing: .01em; }
.vc-arrive { background: var(--info-soft); color: var(--info); border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.vc-arrive span { font-size: 12px; font-weight: 600; width: 100%; }
.vc-arrive b { font-size: 17px; }
.vc-arrive em { font-style: normal; font-weight: 600; font-size: 13px; }
.vc-arrive.late { background: var(--bad-soft); color: var(--bad); }
.mapframe { width: 100%; border: 0; display: block; border-radius: 8px; background: #e9edf1; }
.mapbox { border: 1px solid var(--line); border-radius: 8px; min-height: 240px; display: grid; align-items: center; background: #fafbfc; }
.visits td .when { font-weight: 650; white-space: nowrap; }
.visits td .when.late { color: var(--bad); }
@media (max-width: 900px) { .vc { grid-template-columns: 1fr; } .vc-map { border-left: none; border-top: 1px solid var(--line-2); } }

/* customer picker */
.picker { position: relative; }
.pk-res { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(16, 24, 40, .12); z-index: 30; max-height: 290px; overflow-y: auto; }
.pk-res:empty { display: none; }
.pk-res div { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--line-2); }
.pk-res div:hover, .pk-res div.hl { background: var(--brand-soft); }
.pk-res div span { color: var(--muted); font-size: 12px; margin-left: 6px; }
.chosen { display: flex; justify-content: space-between; align-items: center; border: 1px solid #8fb0cf; background: var(--brand-soft); padding: 9px 12px; border-radius: 8px; }
.chosen span { color: var(--muted); margin-left: 8px; }

/* POS */
.pos { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.prod-results { max-height: 340px; overflow-y: auto; }
.prod-results .pr { display: flex; justify-content: space-between; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--line-2); cursor: pointer; }
.prod-results .pr:hover { background: #f7f9fb; }
.prod-results .pr.out { opacity: .5; }
.cart input { padding: 4px 7px; }
.cart .q { width: 70px; }
.cart .p { width: 100px; }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(16, 24, 40, .25); }
.modal.wide { max-width: 820px; }
.modal .mh { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal .mh h2 { flex: 1; font-size: 16px; }
.modal .mb { padding: 18px; }
.modal .mf { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: #fafbfc; border-radius: 0 0 10px 10px; }
.err { background: var(--bad-soft); color: var(--bad); padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; font-weight: 500; }
.x { border: none; background: none; font-size: 22px; line-height: 1; padding: 0 4px; color: var(--muted); }

#toasts { position: fixed; bottom: 18px; right: 18px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1b2430; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 8px 20px rgba(0, 0, 0, .2); font-weight: 500; max-width: 380px; }
.toast.bad { background: var(--bad); }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: 100%; max-width: 380px; }
.auth h1 { font-size: 20px; margin-bottom: 4px; }
.auth form > * + * { margin-top: 14px; }

/* chart */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding-top: 10px; }
.bars div { flex: 1; background: #7fa6cc; border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars div:hover { background: var(--brand); }
.bars-x { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }

/* paper (invoice / job card) */
.paper { background: #fff; color: #111; padding: 32px 36px; font-size: 13px; }
.paper .doc-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid #111; padding-bottom: 14px; margin-bottom: 16px; }
.paper .doc-head h1 { font-size: 20px; }
.paper .doc-title { text-align: right; }
.paper .doc-title h2 { font-size: 18px; letter-spacing: .04em; text-transform: uppercase; }
.paper table th { background: #f1f2f4; color: #111; }
.paper table td, .paper table th { padding: 7px 9px; border-bottom: 1px solid #ddd; }
.paper .two { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 16px; }
.paper .box { border: 1px solid #ccc; border-radius: 4px; padding: 10px 12px; }
.paper .box h3 { color: #555; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.paper .sum { width: 290px; margin-left: auto; margin-top: 12px; }
.paper .sum td { border: none; padding: 4px 9px; }
.paper .sum .grand td { border-top: 2px solid #111; font-weight: 700; font-size: 15px; }
.paper .terms { font-size: 11px; color: #444; margin-top: 18px; border-top: 1px solid #ddd; padding-top: 10px; }
.paper .sign { display: flex; justify-content: space-between; gap: 40px; margin-top: 44px; }
.paper .sign div { flex: 1; border-top: 1px solid #555; padding-top: 4px; font-size: 11px; text-align: center; }
.paper .big { font-size: 22px; font-weight: 700; }

#printarea { display: none; }
@media print {
  @page { margin: 12mm; }
  body { background: #fff; }
  #app, #toasts, .overlay { display: none !important; }
  #printarea { display: block; }
  #printarea .paper { padding: 0; }
}

@media (max-width: 1100px) {
  .cols, .pos { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .side { transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .top .search { display: none; }
  #view { padding: 16px 12px 60px; }
  .g2, .g3, .g4, .cols-even { grid-template-columns: 1fr; }
  .span2, .span3 { grid-column: auto; }
  .devtypes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .top .hide-sm { display: none; }
}

/* read-only jobs, invoice ready banner, pin link */
.readonly-note { background: #f4f5f7; border: 1px dashed #c9ced6; border-radius: 6px; padding: 10px 12px; color: var(--muted); font-size: 13px; }
.ready-banner { display: flex; align-items: center; gap: 16px; justify-content: space-between; flex-wrap: wrap; background: var(--ok-soft); border: 1px solid #a9d8bd; color: #14532d; border-radius: var(--radius); padding: 14px 18px; margin-bottom: 16px; max-width: 900px; }
.ready-banner span { display: block; font-size: 13px; margin-top: 2px; }
.pin-link { font-weight: 600; }
