:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1d2330;
  --muted: #667085;
  --line: #e2e5ea;
  --brand: #c82824;
  --brand-ink: #ffffff;
  --ok: #138a4b;
  --warn: #b25e00;
  --bad: #c22b2b;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: .95rem; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: Consolas, "Cascadia Mono", monospace; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* header */
.top {
  display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 56px;
  background: #121826; color: #e8ebf2; position: sticky; top: 0; z-index: 10;
}
.top .brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 600; white-space: nowrap; }
.top .brand img { height: 30px; display: block; }
.top .brand span { border-left: 1px solid #39445a; padding-left: 10px; color: #c5cbd8; }
.login-logo { display: block; height: 56px; margin-bottom: 12px; }
.top nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.top nav a { color: #c5cbd8; padding: 8px 12px; border-radius: 6px; white-space: nowrap; }
.top nav a:hover { background: #263043; color: #fff; text-decoration: none; }
.top nav a.on { background: var(--brand); color: #fff; text-decoration: none; }
#scan-form input {
  width: 220px; padding: 8px 10px; border-radius: 6px; border: 1px solid #39445a;
  background: #1c2434; color: #fff; font: inherit;
}
#scan-form input::placeholder { color: #8b94a7; }
.top .who { color: #c5cbd8; white-space: nowrap; font-size: .9rem; }
.top .who a { color: #9fb6ff; }

main { max-width: 1280px; margin: 0 auto; padding: 20px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  margin-bottom: 16px; flex-wrap: wrap; }

/* panels & layout */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.job-layout { display: grid; gap: 16px; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
@media (max-width: 900px) {
  .cols-2, .cols-3, .job-layout { grid-template-columns: 1fr; }
  #scan-form input { width: 140px; }
}

/* stat cards */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px;
  margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; color: var(--ink); display: block; }
.stat:hover { text-decoration: none; border-color: var(--brand); }
.stat .n { font-size: 1.7rem; font-weight: 700; line-height: 1.2; }
.stat .l { color: var(--muted); font-size: .85rem; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr.link { cursor: pointer; }
tr.link:hover td { background: #fbf5f5; }
td.num, th.num { text-align: right; white-space: nowrap; }
.empty { color: var(--muted); padding: 18px 10px; text-align: center; }
.table-wrap { overflow-x: auto; }

/* forms */
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 4px; color: #344054; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #cfd4dc; border-radius: 6px; font: inherit;
  background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #f3c2c0; border-color: var(--brand); }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { width: auto; }
.field { margin-bottom: 12px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.inline { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline > * { margin-bottom: 0; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 6px;
  border: 1px solid #cfd4dc; background: #fff; color: var(--ink); font: inherit; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f2f4f7; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: #a61f1b; border-color: #a61f1b; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: .85rem; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* statuses */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .8rem;
  font-weight: 600; background: #eef0f4; color: #344054; white-space: nowrap; }
.st-booked-in { background: #e8efff; color: #1f45b3; }
.st-diagnosing { background: #f1e9ff; color: #6430b5; }
.st-awaiting-approval { background: #fff3db; color: #8a5a00; }
.st-insurance-claim { background: #fde8f3; color: #9b1c63; }
.st-awaiting-parts { background: #ffe9d6; color: #a14800; }
.st-in-repair { background: #dff4ff; color: #00658f; }
.st-testing { background: #e1f7f3; color: #0c6e5e; }
.st-ready-for-collection { background: #dcf5e5; color: #11743f; }
.st-collected { background: #eceef1; color: #4b5565; }
.st-cancelled { background: #fbe4e4; color: #a12525; }
.pr-high { color: var(--warn); font-weight: 600; }
.pr-urgent { color: var(--bad); font-weight: 700; }
.badge-low { color: var(--bad); font-weight: 700; }

/* flash + toasts */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; border: 1px solid; }
.flash.ok { background: #ecfbf2; border-color: #b4e6c8; color: #0d5c33; }
.flash.error { background: #fdeeee; border-color: #f2c1c1; color: #8c1d1d; }
.flash.warn { background: #fff6e5; border-color: #f3d39b; color: #7a4a00; }
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { padding: 10px 16px; border-radius: 6px; color: #fff; background: #1d2330; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.toast.error { background: var(--bad); }
.toast.ok { background: #1d2330; }

/* timeline */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.timeline li:last-child { border-bottom: 0; }
.timeline .meta { font-size: .8rem; color: var(--muted); }
.timeline .k-note .text { white-space: pre-wrap; }
.timeline .k-status .text { font-weight: 600; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
dl.facts dt { color: var(--muted); font-size: .85rem; }
dl.facts dd { margin: 0; white-space: pre-wrap; }

.scan-hint { display: flex; gap: 10px; align-items: center; background: #f7f8fa; border: 1px dashed #c4c9d2;
  border-radius: 6px; padding: 10px 12px; color: #475467; font-size: .9rem; margin-bottom: 12px; }
.big-scan { font-size: 1.6rem; text-align: center; padding: 18px; }
.totals td { border: 0; padding: 3px 10px; }
.totals .grand td { font-weight: 700; font-size: 1.05rem; border-top: 2px solid var(--ink); }

/* login */
.login { max-width: 560px; margin: 8vh auto; }
.user-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.user-tiles label { margin: 0; }
.user-tiles input { display: none; }
.user-tiles span { display: block; padding: 14px; border: 2px solid var(--line); border-radius: var(--radius);
  background: #fff; cursor: pointer; text-align: center; font-weight: 600; font-size: 1rem; }
.user-tiles span small { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; }
.user-tiles input:checked + span { border-color: var(--brand); background: #fdf0ef; }
.pin { font-size: 1.6rem; letter-spacing: .4em; text-align: center; }

.bar { height: 8px; background: #f6dddc; border-radius: 4px; overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--brand); }

/* self-service menu */
.top .who { margin-left: auto; }
.menu-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.menu-tile { display: flex; flex-direction: column; gap: 6px; padding: 20px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); color: var(--ink); }
.menu-tile:hover { text-decoration: none; border-color: var(--brand); box-shadow: 0 4px 14px rgba(16, 24, 40, .08); }
.menu-icon { width: 48px; height: 48px; border-radius: 10px; display: grid; place-items: center;
  background: #fdf0ef; color: var(--brand); margin-bottom: 6px; }
.menu-title { font-size: 1.15rem; font-weight: 700; }
.menu-desc { color: var(--muted); font-size: .9rem; }
.pill.atera { background: #fdf0ef; color: var(--brand); font-size: .7rem; }

/* photos */
.photo-pick { cursor: pointer; }
.photo-preview { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.photo-preview img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin-bottom: 12px; }
.photo-grid figure { margin: 0; position: relative; }
.photo-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; }
.photo-grid figcaption { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.photo-grid form { position: absolute; top: 4px; right: 4px; }
.photo-grid .del { background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 50%; width: 26px; height: 26px;
  line-height: 22px; text-align: center; cursor: pointer; color: var(--bad); font-weight: 700; padding: 0; }

/* serial scan on Book in */
.serial-info { margin-top: 8px; padding: 8px 10px; border-radius: 6px; background: #f7f8fa; border: 1px solid var(--line); font-size: .9rem; line-height: 1.6; }
.cam-dialog { width: min(560px, 94vw); border: 0; border-radius: var(--radius); padding: 16px; }
.cam-dialog::backdrop { background: rgba(0,0,0,.5); }

/* scan page */
.scan-layout { display: grid; gap: 16px; grid-template-columns: minmax(280px, 1fr) minmax(0, 1.4fr); align-items: start; }
@media (max-width: 900px) { .scan-layout { grid-template-columns: 1fr; } }
.camera-box { margin-top: 12px; border-radius: var(--radius); overflow: hidden; background: #000; }
.camera-box video { width: 100% !important; display: block; }
.scan-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.scan-card.none { color: var(--muted); }
.scan-card-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.scan-no { font-size: 1.5rem; font-weight: 700; }
.scan-qty { font-size: 2rem; font-weight: 700; line-height: 1; }
.scan-photos { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.scan-photos img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.labels-due { border-color: var(--brand); }
.pill.atera-open { background: #e8efff; color: #1f45b3; }
.pill.atera-pending { background: #fff3db; color: #8a5a00; }
.pill.atera-resolved { background: #dcf5e5; color: #11743f; }
.pill.atera-closed { background: #eceef1; color: #4b5565; }

/* public front page */
.front { max-width: 640px; margin: 8vh auto 0; text-align: center; }
.front-logo { height: 64px; margin-bottom: 12px; }
.front-tiles { margin-top: 24px; text-align: left; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

.warn-text { color: var(--warn); }

/* sign-in */
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; margin: 16px 0; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.totp-qr svg { display: block; max-width: 220px; height: auto; border: 1px solid var(--line); border-radius: 6px; }
