:root {
  --paper: #f4f5f3;
  --panel: #ffffff;
  --ink: #18222b;
  --muted: #5f6b73;
  --line: #d8dcd9;
  --primary: #0d5c6e;
  --primary-dark: #094755;
  --danger: #b3261e;
  --ok-bg: #e2f2e7; --ok-line: #8cc5a0;
  --err-bg: #fbe7e5; --err-line: #e0a19c;
  --radius: 6px;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; line-height: 1.45; }
a { color: var(--primary); }
h1 { font-size: 1.6rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; }
h3 { font-size: 1rem; margin: 1rem 0 .3rem; }
.muted { color: var(--muted); font-size: .92em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.pre { white-space: pre-wrap; margin: 0; }

/* top bar */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.5rem; background: #12303a; color: #fff; padding: .6rem 1.2rem; }
.topbar a { color: #dbe9ec; text-decoration: none; }
.topbar .brand { font-weight: 700; font-size: 1.1rem; color: #fff; }
.topbar nav { display: flex; gap: 1rem; flex: 1; flex-wrap: wrap; }
.topbar nav a { padding: .3rem 0; border-bottom: 2px solid transparent; }
.topbar nav a.on, .topbar nav a:hover { color: #fff; border-bottom-color: #f2b632; }
.topbar .who { display: flex; gap: 1rem; font-size: .92rem; }
.wrap { max-width: 1150px; margin: 0 auto; padding: 1.2rem; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: 1rem; }
.page-head h1 { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }
.head-actions { display: flex; gap: .5rem; }

/* panels & forms */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.panel.narrow { max-width: 460px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .8rem 1rem; margin-bottom: .8rem; }
label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: .7rem; }
label > input, label > select, label > textarea, label .inline input { margin-top: .25rem; }
input, select, textarea { width: 100%; font: inherit; color: inherit; padding: .5rem .6rem; border: 1px solid #b9c0bc; border-radius: var(--radius); background: #fff; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible, button:focus-visible { outline: 3px solid #f2b632; outline-offset: 1px; }
.inline { display: flex; gap: .5rem; }
.inline .btn { margin-top: .25rem; }
.form-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: .8rem; }

.btn { display: inline-block; font: inherit; font-weight: 600; padding: .5rem .95rem; border: 1px solid #b9c0bc; border-radius: var(--radius); background: #fff; color: var(--ink); text-decoration: none; cursor: pointer; }
.btn:hover { background: #eef1ef; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.block { width: 100%; }
button.link { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: .2rem; text-decoration: underline; }

.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.flash ul { margin: .3rem 0 0 1.1rem; padding: 0; }
.flash-ok { background: var(--ok-bg); border-color: var(--ok-line); }
.flash-err { background: var(--err-bg); border-color: var(--err-line); }
.danger-zone { border-color: var(--err-line); }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters input[type=search] { flex: 1; min-width: 220px; width: auto; }
.filters select { width: auto; }

/* tables */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: .55rem .7rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { font-size: .85rem; background: #eceeeb; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 1.6rem; }
.actions { white-space: nowrap; }
.actions a { margin-right: .7rem; }
td.out { color: var(--danger); font-weight: 700; }
td.low { color: #9a6700; font-weight: 700; }
.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1rem; }

.badge { display: inline-block; font-size: .8rem; font-weight: 600; padding: .15rem .55rem; border-radius: 99px; background: #e6e8e5; color: #333; vertical-align: middle; }
.st-received { background: #e6e8e5; }
.st-diagnosing { background: #dbe8f7; color: #16406e; }
.st-waiting-for-parts { background: #fbeac2; color: #6b4a00; }
.st-in-repair { background: #d3ecef; color: #08505f; }
.st-ready-for-pickup { background: #d6f0dc; color: #17552a; }
.st-completed { background: #17552a; color: #fff; }
.st-cancelled { background: #eadcdc; color: #6b2a2a; }

/* parts table */
table.parts input, table.parts select { margin: 0 0 .3rem; padding: .4rem .5rem; }
table.parts td.num input { text-align: right; }
table.parts .part-qty { width: 5rem; }
table.parts .part-price { width: 7rem; }
table.parts td.pick { min-width: 230px; }
.part-hint { display: block; font-size: .8rem; }

.totals { display: grid; grid-template-columns: 1fr auto; gap: .2rem 1.2rem; max-width: 300px; margin: 1rem 0 0 auto; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.totals .grand { color: var(--ink); font-weight: 700; border-top: 1px solid var(--line); padding-top: .3rem; }
.facts { display: grid; grid-template-columns: 170px 1fr; gap: .35rem 1rem; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.barcode-box { border-top: 1px solid var(--line); padding-top: 1rem; margin-top: .4rem; }
.barcode-preview { min-height: 70px; padding: .5rem; background: #fff; border: 1px dashed var(--line); border-radius: var(--radius); display: inline-block; }


@media (max-width: 640px) {
  .facts { grid-template-columns: 1fr; }
  .wrap { padding: .8rem; }
}

/* labels */
.labels-page { background: #fff; }
.label-toolbar { padding: 1rem; }
.label-sheet { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 1rem 1rem; }
.label { width: 2.25in; height: 1.25in; border: 1px dashed #aaa; padding: 4px 6px; text-align: center; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; page-break-inside: avoid; }
.label-name { font-weight: 700; font-size: 11px; line-height: 1.1; max-height: 2.2em; overflow: hidden; }
.label-model { font-size: 9px; color: #333; }
.label-price { font-weight: 700; font-size: 12px; }
.label svg { max-width: 100%; height: auto; }

/* printed work order */
.print-page { background: #e9ebe8; }
.print-toolbar { max-width: 8.5in; margin: 1rem auto 0; display: flex; gap: .5rem; }
.sheet { width: 8.5in; max-width: 100%; margin: 1rem auto; background: #fff; padding: .55in; font-size: 12px; line-height: 1.4; }
.sheet h1 { font-size: 20px; }
.sheet h2 { font-size: 12px; margin: 1rem 0 .3rem; border-bottom: 1px solid #999; padding-bottom: 2px; }
.sheet p { margin: 0; }
.sheet-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.sheet-id { text-align: right; }
.sheet-id .wo-no strong { font-size: 22px; }
.sheet-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.sheet .box { border: 1px solid #999; min-height: 90px; padding: 6px; }
.sheet table th, .sheet table td { padding: 4px 6px; border: 1px solid #bbb; }
.sheet .totals { max-width: 260px; }
.sheet-foot { margin-top: 1.2rem; }
.terms { font-size: 10px; color: #444; }
.sign { display: flex; gap: 2rem; margin-top: 1.6rem; }
.sign div { flex: 1; font-size: 11px; }
.sign span { display: block; border-top: 1px solid #000; margin-top: 26px; }

@media print {
  .no-print { display: none !important; }
  body, .print-page, .labels-page { background: #fff; }
  .wrap { max-width: none; padding: 0; }
  .sheet { margin: 0; padding: 0; width: auto; }
  .label { border: 0; }
  .label-sheet { padding: 0; gap: 0; }
}

/* work order number in red */
.wo-number, a.wo-number { color: #c8161d; }
.sheet .wo-no strong { color: #c8161d; }

/* logo */
.topbar .logo-chip { display: inline-flex; align-items: center; background: #fff; border-radius: 6px; padding: 2px 8px; }
.topbar .logo-chip img { height: auto; width: auto; max-height: 34px; max-width: 240px; display: block; }
.sheet-brand img { width: 3.2in; height: auto; display: block; }
.sheet-contact { font-size: 12px; line-height: 1.5; padding-top: .02in; }
.sheet-contact strong { font-size: 13px; }

/* login page */
body.login-page { margin: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: linear-gradient(135deg, #0a3a86 0%, #0b57c2 100%);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; }
.login-card { width: 100%; max-width: 440px; background: #fff; border-radius: 16px; padding: 34px 40px 40px; text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .28); }
.login-logo { width: 300px; max-width: 100%; height: auto; display: block; margin: 0 auto 26px; }
.login-title { font-size: 1.9rem; line-height: 1.25; font-weight: 700; color: #4169e1; margin: 0 0 .6rem; display: block; }
.login-title span { color: #e0161e; }
.login-sub { color: #6b7480; font-size: 1.15rem; margin: 0 0 1.7rem; }
.login-card form { text-align: left; }
.login-card label { display: block; font-weight: 600; font-size: 1rem; margin: 0 0 .4rem; color: #1a1a1a; }
.login-card input { width: 100%; padding: .8rem .9rem; margin: 0 0 1.1rem; font: 1rem Arial, Helvetica, sans-serif; border: 1px solid #d9dee5; border-radius: 10px; background: #eef3fb; }
.login-card input:focus { outline: 2px solid #111; outline-offset: 0; border-color: #111; }
.login-btn { width: 100%; padding: .85rem; margin-top: .3rem; font: 1.2rem Arial, Helvetica, sans-serif; color: #fff; background: #0b5ed7; border: 0; border-radius: 10px; cursor: pointer; }
.login-btn:hover { background: #0a52bd; }
.login-btn:focus-visible { outline: 3px solid #f2b632; outline-offset: 2px; }
.login-error { background: #fbe7e5; border: 1px solid #e0a19c; color: #7a1a14; border-radius: 10px; padding: .7rem .9rem; margin: 0 0 1.1rem; text-align: left; }
.sheet-name { font-size: 24px; margin: 0; padding-top: .15in; color: #12303a; }
