:root {
  --navy: #0b2d5b;
  --navy-2: #123d78;
  --navy-deep: #071d3d;
  --yellow: #ffc20e;
  --yellow-2: #ffd75a;
  --blue: #1f6feb;
  --bg: #f2f4f8;
  --card: #ffffff;
  --text: #13213a;
  --muted: #5d6b82;
  --line: #e1e6ef;
  --ok: #15803d;
  --ok-bg: #e5f6eb;
  --soon: #b45309;
  --soon-bg: #fff3d6;
  --bad: #c62828;
  --bad-bg: #fde7e7;
  --info: #1d4ed8;
  --info-bg: #e3ecff;
  --grey-bg: #eef1f5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 33, 60, .06), 0 2px 8px rgba(16, 33, 60, .05);
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--blue); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
img { max-width: 100%; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.strike { text-decoration: line-through; color: var(--muted); }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.top { align-items: flex-start; }
.stack > * + * { margin-top: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.boot { min-height: 100vh; display: grid; place-items: center; background: var(--navy); }
.boot img { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; transform: scale(.94); } }

/* ---------- Shell ---------- */
.shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--navy); color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px; display: flex; align-items: center; gap: 12px;
}
.topbar .title { font-weight: 650; font-size: 17px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .back { color: #fff; display: grid; place-items: center; width: 34px; height: 34px; margin-left: -6px; border-radius: 10px; }
.topbar .back:active { background: rgba(255, 255, 255, .12); }
.topbar .company { font-size: 12px; opacity: .75; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; letter-spacing: -.3px; color: #fff; }
.brand b { color: var(--yellow); }
.brand img { width: 30px; height: 30px; }

.main { padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 24px); max-width: 1180px; margin: 0 auto; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: #fff; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
}
.bottomnav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); font-weight: 550; position: relative; }
.bottomnav a.active { color: var(--navy); }
.bottomnav a.active svg { stroke: var(--navy); }
.bottomnav .scan-btn { position: relative; }
.bottomnav .scan-btn span.fab {
  width: 56px; height: 56px; border-radius: 50%; background: var(--yellow); color: var(--navy); display: grid; place-items: center;
  margin-top: -26px; box-shadow: 0 4px 14px rgba(11, 45, 91, .3); border: 4px solid #fff;
}
.navbadge { position: absolute; top: 6px; right: calc(50% - 22px); background: var(--bad); color: #fff; font-size: 10px; font-weight: 700; border-radius: 9px; min-width: 18px; height: 18px; display: grid; place-items: center; padding: 0 4px; }

.sidebar { display: none; }

@media (min-width: 960px) {
  .shell { display: grid; grid-template-columns: 240px 1fr; }
  .sidebar {
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; background: var(--navy); color: #fff; padding: 18px 12px; overflow-y: auto;
  }
  .sidebar .brand { padding: 4px 10px 18px; }
  .sidebar nav a {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: rgba(255, 255, 255, .82); font-weight: 550; position: relative;
  }
  .sidebar nav a svg { stroke: currentColor; opacity: .9; }
  .sidebar nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
  .sidebar nav a.active { background: rgba(255, 194, 14, .16); color: var(--yellow); }
  .sidebar .navbadge { position: static; margin-left: auto; }
  .sidebar .who { margin-top: auto; padding: 12px; border-top: 1px solid rgba(255, 255, 255, .12); font-size: 13px; }
  .sidebar .who a { color: rgba(255, 255, 255, .7); }
  .bottomnav { display: none; }
  .topbar { position: sticky; background: var(--bg); color: var(--text); padding: 18px 24px 6px; }
  .topbar .back { color: var(--text); }
  .topbar .title { font-size: 22px; font-weight: 750; }
  .topbar .brand, .topbar .company { display: none; }
  .main { padding: 12px 24px 40px; }
}

.offline-bar { position: sticky; top: 0; z-index: 50; background: var(--soon-bg); color: var(--soon); text-align: center; font-size: 13px; font-weight: 600; padding: 6px 12px; }

/* ---------- Cards & lists ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card, .card + .section, .section + .card, .section + .section { margin-top: 14px; }
.card.flush { padding: 0; overflow: hidden; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-h h2 { display: flex; align-items: center; gap: 8px; }
.section { margin-top: 18px; }
.section > h2 { margin: 0 2px 10px; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li, .list > a { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-top: 1px solid var(--line); color: inherit; }
.list > :first-child { border-top: 0; }
.list > a:active, .list > a:hover { background: #f8fafc; }
.list .chev { color: #a0aabb; flex: none; }
.li-title { font-weight: 620; }
.li-sub { font-size: 13px; color: var(--muted); }

.grid { display: grid; gap: 12px; }
.grid.k4 { grid-template-columns: repeat(2, 1fr); }
.grid.k3 { grid-template-columns: repeat(2, 1fr); }
.grid.two { grid-template-columns: 1fr; }
@media (min-width: 720px) {
  .grid.k4 { grid-template-columns: repeat(4, 1fr); }
  .grid.k3 { grid-template-columns: repeat(3, 1fr); }
  .grid.two { grid-template-columns: 1fr 1fr; }
  .grid.two > .card + .card { margin-top: 0; }
}

.quick { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.quick .btn { white-space: normal; text-align: center; line-height: 1.2; }
.quick .btn:first-child { grid-column: span 2; }
@media (min-width: 720px) { .quick { grid-template-columns: repeat(3, 1fr); } .quick .btn:first-child { grid-column: auto; } }

.kpi { border-radius: var(--radius); padding: 14px; color: #fff; background: var(--navy); box-shadow: var(--shadow); display: block; }
.kpi .v { font-size: 28px; font-weight: 800; line-height: 1.1; }
.kpi .l { font-size: 13px; opacity: .9; font-weight: 550; }
.kpi.bad { background: #d92d20; }
.kpi.soon { background: #f08c00; }
.kpi.ok { background: #1f9d55; }
.kpi.light { background: var(--card); color: var(--text); }
.kpi.light .l { color: var(--muted); }

.stat { padding: 12px 14px; border-radius: 12px; background: var(--grey-bg); }
.stat .v { font-size: 20px; font-weight: 750; }
.stat .l { font-size: 12px; color: var(--muted); font-weight: 550; }

/* ---------- Pills & badges ---------- */
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 650; padding: 3px 9px; border-radius: 999px; background: var(--grey-bg); color: var(--muted); white-space: nowrap; }
.pill.ok, .pill.approved, .pill.active { background: var(--ok-bg); color: var(--ok); }
.pill.due_soon, .pill.submitted, .pill.high, .pill.trial { background: var(--soon-bg); color: var(--soon); }
.pill.overdue, .pill.rejected, .pill.down, .pill.urgent, .pill.suspended { background: var(--bad-bg); color: var(--bad); }
.pill.in_progress, .pill.open, .pill.info { background: var(--info-bg); color: var(--info); }
.pill.yellow { background: var(--yellow); color: var(--navy); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: #c5cdd9; }
.dot.ok { background: #22a35a; } .dot.due_soon { background: #f59e0b; } .dot.overdue { background: #dc2626; }

.progress { height: 6px; border-radius: 6px; background: var(--grey-bg); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 6px; background: #22a35a; }
.progress.due_soon > i { background: #f59e0b; }
.progress.overdue > i { background: #dc2626; }

/* ---------- Forms ---------- */
label.f { display: block; }
label.f > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--text); background: #fff; border: 1px solid #cfd6e2; border-radius: 10px; padding: 11px 12px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(31, 111, 235, .15); }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; padding: 0; accent-color: var(--navy); flex: none; }
textarea { min-height: 84px; resize: vertical; }
input:disabled, select:disabled, textarea:disabled { background: #f4f6f9; color: var(--muted); }
.form-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-grid.c2 { grid-template-columns: 1fr 1fr; } .form-grid .span2 { grid-column: span 2; } }
.check { display: flex; align-items: center; gap: 10px; font-weight: 550; }
.seg { display: flex; background: var(--grey-bg); border-radius: 12px; padding: 4px; gap: 4px; overflow-x: auto; }
.seg button, .seg a { flex: 1; border: 0; background: transparent; padding: 8px 10px; border-radius: 9px; font: inherit; font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap; cursor: pointer; text-align: center; }
.seg .on { background: #fff; color: var(--navy); box-shadow: var(--shadow); }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); stroke: var(--muted); }
.search input { padding-left: 38px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 11px; padding: 11px 16px; font: inherit; font-weight: 650;
  background: var(--navy); color: #fff; cursor: pointer; white-space: nowrap; min-height: 44px; text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.yellow { background: var(--yellow); color: var(--navy); }
.btn.ghost { background: var(--grey-bg); color: var(--text); }
.btn.outline { background: #fff; color: var(--navy); border: 1px solid #cfd6e2; }
.btn.green { background: #1f9d55; }
.btn.red { background: #d92d20; }
.btn.link { background: transparent; color: var(--blue); padding: 6px 8px; min-height: 0; }
.btn.sm { padding: 7px 12px; min-height: 36px; font-size: 14px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn.icon { padding: 0; width: 40px; min-height: 40px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.actions.end { justify-content: flex-end; }
.sticky-actions { position: sticky; bottom: calc(var(--nav-h) + var(--safe-b) + 10px); z-index: 10; margin-top: 16px; background: rgba(242, 244, 248, .92); backdrop-filter: blur(6px); padding: 10px; border-radius: 16px; box-shadow: 0 2px 12px rgba(16, 33, 60, .1); }
@media (min-width: 960px) { .sticky-actions { bottom: 12px; } }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); font-weight: 650; background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8fafc; }

/* ---------- Work order specifics ---------- */
.steps { display: flex; gap: 6px; }
.steps > div { flex: 1; text-align: center; font-size: 12px; font-weight: 650; color: var(--muted); }
.steps > div::before { content: ""; display: block; height: 5px; border-radius: 5px; background: var(--line); margin-bottom: 6px; }
.steps > div.done { color: var(--ok); }
.steps > div.done::before { background: #22a35a; }
.steps > div.cur { color: var(--navy); }
.steps > div.cur::before { background: var(--yellow); }
.steps > div.bad::before { background: #dc2626; }
.steps > div.bad { color: var(--bad); }

.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-top: 1px solid var(--line); }
.checklist li:first-child { border-top: 0; }
.checklist li.done .txt { color: var(--muted); }
.checklist .tick { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #c5cdd9; display: grid; place-items: center; flex: none; background: #fff; cursor: pointer; padding: 0; }
.checklist li.done .tick { background: #22a35a; border-color: #22a35a; }
.checklist li.done .tick svg { stroke: #fff; }

.line-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.line-item:first-child { border-top: 0; }
.line-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--soon-bg); color: var(--soon); }
.line-icon.part { background: var(--info-bg); color: var(--info); }

.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 720px) { .photos { grid-template-columns: repeat(5, 1fr); } }
.photo { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--grey-bg); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .tag { position: absolute; left: 6px; bottom: 6px; background: rgba(7, 29, 61, .75); color: #fff; font-size: 11px; font-weight: 650; padding: 2px 7px; border-radius: 6px; }
.photo .del { position: absolute; right: 4px; top: 4px; background: rgba(7, 29, 61, .7); border: 0; color: #fff; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; }
.sigpad { width: 100%; height: 170px; border: 1.5px dashed #b7c1d1; border-radius: 12px; background: #fff; touch-action: none; display: block; }
.sig-img { max-height: 120px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 6px; }

.banner { border-radius: 12px; padding: 12px 14px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.banner.bad { background: var(--bad-bg); color: #7f1d1d; }
.banner.ok { background: var(--ok-bg); color: #14532d; }
.banner.soon { background: var(--soon-bg); color: #78350f; }
.banner.info { background: var(--info-bg); color: #1e3a8a; }
.banner svg { flex: none; margin-top: 1px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; font-size: 14px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--navy-2); }
.timeline li::after { content: ""; position: absolute; left: 9px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }

/* ---------- Charts ---------- */
.chart svg { width: 100%; height: auto; display: block; }
.chart text { font: 11px system-ui, sans-serif; fill: var(--muted); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; align-items: center; gap: 10px; font-size: 13px; padding: 5px 0; }
.hbar .track { height: 10px; background: var(--grey-bg); border-radius: 6px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--navy-2); border-radius: 6px; }

/* ---------- Modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(7, 20, 41, .5); z-index: 100; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.modal { background: #fff; width: 100%; max-width: 520px; border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); max-height: 92vh; overflow-y: auto; animation: up .2s ease-out; }
@media (min-width: 640px) { .modal-back { align-items: center; } .modal { border-radius: 18px; padding: 22px; } }
.modal-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 200; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--navy-deep); color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 14px; font-weight: 550; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); animation: up .2s; }
.toast.err { background: #b42318; }
.toast.ok { background: #157a42; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; background: radial-gradient(1200px 600px at 10% -10%, #1b4d8f 0%, var(--navy) 45%, var(--navy-deep) 100%); display: flex; flex-direction: column; align-items: center; padding: calc(env(safe-area-inset-top, 0px) + 40px) 16px 40px; }
.auth .logo { display: flex; align-items: center; gap: 12px; color: #fff; margin-bottom: 8px; }
.auth .logo img { width: 56px; height: 56px; }
.auth .logo .name { font-size: 34px; font-weight: 850; letter-spacing: -.6px; }
.auth .logo .name b { color: var(--yellow); }
.auth .tag { color: rgba(255, 255, 255, .78); margin-bottom: 26px; text-align: center; }
.auth .card { width: 100%; max-width: 420px; padding: 22px; }
.auth.wide .card { max-width: 860px; }
.auth .foot { color: rgba(255, 255, 255, .7); margin-top: 18px; font-size: 14px; }
.auth .foot a { color: var(--yellow); font-weight: 650; }
.plans { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
@media (min-width: 720px) { .plans { grid-template-columns: repeat(4, 1fr); } }
.plan { border: 2px solid var(--line); border-radius: 14px; padding: 12px; cursor: pointer; position: relative; background: #fff; text-align: left; font: inherit; color: inherit; }
.plan.on { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(11, 45, 91, .12); }
.plan .pn { font-weight: 750; }
.plan .pp { font-size: 18px; font-weight: 800; color: var(--navy); margin: 4px 0; }
.plan .pm { font-size: 12px; color: var(--muted); }
.plan ul { margin: 8px 0 0; padding-left: 16px; font-size: 12px; color: var(--muted); }
.plan.current::after { content: "Current"; position: absolute; top: -9px; right: 10px; background: var(--yellow); color: var(--navy); font-size: 11px; font-weight: 750; padding: 2px 8px; border-radius: 6px; }

/* ---------- Scanner ---------- */
.scanner { position: relative; background: #000; border-radius: 18px; overflow: hidden; aspect-ratio: 3 / 4; max-height: 62vh; margin: 0 auto; width: 100%; max-width: 480px; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame { position: absolute; inset: 18%; border: 3px solid var(--yellow); border-radius: 18px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .35); }
.scanner .hint { position: absolute; left: 0; right: 0; bottom: 14px; text-align: center; color: #fff; font-weight: 600; text-shadow: 0 1px 3px #000; }

/* ---------- Store ---------- */
.product .cat { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; font-weight: 700; color: var(--muted); }
.product .price { font-size: 20px; font-weight: 800; color: var(--navy); }

/* ---------- Print: QR labels ---------- */
.labels { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.label-card { background: #fff; border: 2px solid var(--navy); border-radius: 14px; padding: 12px; text-align: center; break-inside: avoid; }
.label-card .lb { display: flex; justify-content: center; align-items: center; gap: 6px; font-weight: 850; color: var(--navy); }
.label-card .lb b { color: #e0a800; }
.label-card img { width: 100%; max-width: 190px; display: block; margin: 6px auto; }
.label-card .code { font-size: 20px; font-weight: 850; letter-spacing: .5px; }
@media print {
  .sidebar, .bottomnav, .topbar, .no-print, #toasts, .offline-bar { display: none !important; }
  body, .main { background: #fff; padding: 0; }
  .shell { display: block; }
  .labels { grid-template-columns: repeat(3, 1fr); }
}
