:root {
  --bg: #f4f5f7; --card: #fff; --ink: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --brand: #2563eb; --brand-ink: #fff; --ok: #15803d; --warn: #b45309; --bad: #b91c1c;
  --radius: 12px; --nav-h: 64px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; -webkit-tap-highlight-color: transparent; }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.right { text-align: right; }

.topbar { position: sticky; top: 0; z-index: 10; background: var(--ink); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; display: flex; align-items: center; gap: 12px; }
.topbar .title { font-weight: 700; font-size: 17px; flex: 1; }
.topbar .who { font-size: 13px; opacity: .75; }
.topbar nav.desk { display: none; gap: 4px; }
.topbar nav.desk a { color: #cbd5e1; padding: 6px 10px; border-radius: 8px; font-size: 14px; }
.topbar nav.desk a.on { background: #1e293b; color: #fff; }

main { max-width: 1100px; margin: 0 auto; padding: 16px 14px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }

nav.bottom { position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: #fff; border-top: 1px solid var(--line);
  display: flex; z-index: 10; }
nav.bottom a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 11px; color: var(--muted); gap: 2px; }
nav.bottom a .ic { font-size: 21px; line-height: 1; }
nav.bottom a.on { color: var(--brand); font-weight: 600; }
nav.bottom a.plus .ic { background: var(--brand); color: #fff; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-size: 26px; }

@media (min-width: 900px) {
  nav.bottom { display: none; }
  .topbar nav.desk { display: flex; }
  main { padding-bottom: 32px; }
}

.card { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 2px rgba(15,23,42,.06); margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 520px) { .grid3 { grid-template-columns: 1fr 1fr; } }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field { margin-bottom: 12px; }
input, select, textarea { width: 100%; font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--brand); }
textarea { min-height: 70px; resize: vertical; }

button, .btn { font: inherit; font-size: 15px; font-weight: 600; border: 0; border-radius: 10px; padding: 11px 16px;
  background: #e2e8f0; color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
button.primary, .btn.primary { background: var(--brand); color: var(--brand-ink); }
button.ok { background: var(--ok); color: #fff; }
button.bad { background: #fee2e2; color: var(--bad); }
button.ghost { background: transparent; color: var(--brand); padding: 8px 10px; }
button.block { width: 100%; padding: 14px; font-size: 16px; }
button:disabled { opacity: .5; }
button.sm { padding: 7px 11px; font-size: 13px; }

.seg { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.seg button { white-space: nowrap; background: #fff; border: 1px solid var(--line); font-weight: 500; padding: 8px 12px; font-size: 14px; }
.seg button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.seg .n { background: rgba(100,116,139,.18); border-radius: 99px; padding: 0 7px; font-size: 12px; margin-left: 4px; }
.seg button.on .n { background: rgba(255,255,255,.2); }

.order { display: block; color: inherit; }
.order .top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.order .pn { font-weight: 700; font-family: ui-monospace, Menlo, monospace; font-size: 15px; }
.order .meta { font-size: 13px; color: var(--muted); margin-top: 4px; line-height: 1.45; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 99px; white-space: nowrap; }
.s-requested { background: #dbeafe; color: #1d4ed8; }
.s-ordered { background: #ede9fe; color: #6d28d9; }
.s-backorder { background: #fef3c7; color: #92400e; }
.s-shipped { background: #e0f2fe; color: #0369a1; }
.s-received { background: #dcfce7; color: #166534; }
.s-installed { background: #f1f5f9; color: #334155; }
.s-returned, .s-cancelled { background: #f1f5f9; color: #94a3b8; }
.rush { background: #fee2e2; color: #b91c1c; }

.price { background: #0f172a; color: #fff; border-radius: var(--radius); padding: 14px; margin: 4px 0 14px; }
.price .line { display: flex; justify-content: space-between; font-size: 14px; padding: 3px 0; color: #cbd5e1; }
.price .line.total { border-top: 1px solid #334155; margin-top: 6px; padding-top: 8px; color: #fff; font-weight: 600; }
.price .big { display: flex; justify-content: space-between; align-items: baseline; margin-top: 8px; }
.price .big b { font-size: 26px; color: #4ade80; }
.price .hint { font-size: 12px; color: #94a3b8; margin-top: 6px; }

.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 10px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.photo { max-width: 100%; max-height: 320px; border-radius: 10px; display: block; }
.timeline { font-size: 13px; }
.timeline div { padding: 6px 0; border-bottom: 1px solid var(--line); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
.tablewrap { overflow-x: auto; }
tr.r-mismatch td:first-child { border-left: 3px solid var(--bad); }
tr.r-missing_on_job td:first-child { border-left: 3px solid var(--warn); }
.pos { color: var(--warn); font-weight: 600; }
.neg { color: var(--bad); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: #fff; border-radius: var(--radius); padding: 12px; box-shadow: 0 1px 2px rgba(15,23,42,.06); }
.stat b { display: block; font-size: 24px; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.bad b { color: var(--bad); } .stat.warn b { color: var(--warn); } .stat.ok b { color: var(--ok); }

.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
.login { max-width: 380px; margin: 10vh auto; }
.login .logo { font-size: 44px; text-align: center; }
.err { color: var(--bad); font-size: 14px; margin: 8px 0; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; background: #fff; cursor: pointer; }
.drop.has { border-color: var(--ok); background: #f0fdf4; }

#toast { position: fixed; left: 50%; transform: translateX(-50%) translateY(20px); bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.install { background: #eff6ff; border: 1px solid #bfdbfe; }
