/* =========================================================
   Uniwin Work Orders — app styles
   ========================================================= */
:root {
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #222;              /* paper form rules */
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --bg: #f4f6fb;
  --card: #fff;
  --brand: #1f4e8c;
  --brand-600: #1a4379;
  --brand-50: #eef4fc;
  --brand-100: #dbe7f8;
  --fill: #c0392b;           /* handwritten-red, like the paper form */
  --edit-bg: #fffdf2;
  --edit-ring: #f5c542;
  --ok: #15803d;   --ok-bg: #e8f7ee;
  --err: #b42318;  --err-bg: #fdeceb;
  --warn: #8a5a00; --warn-bg: #fff5d6;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 8px 24px -12px rgba(15, 23, 42, .12);
  --shadow-lg: 0 20px 50px -20px rgba(15, 23, 42, .35);
  --ring: 0 0 0 3px rgba(31, 78, 140, .18);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; color: var(--ink); background: var(--bg);
  font: 14px/1.5 "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
main { max-width: 1240px; margin: 0 auto; padding: 28px 20px 64px; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-600); text-decoration: underline; text-underline-offset: 2px; }
h2 { margin: 0 0 14px; font-size: 20px; font-weight: 650; letter-spacing: -.01em; }
h3 { font-size: 14px; font-weight: 650; margin: 22px 0 10px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 12.5px; }
:focus-visible { outline: none; box-shadow: var(--ring); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 10px 24px; background: rgba(255, 255, 255, .88);
  backdrop-filter: saturate(180%) blur(10px); -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { display: inline-flex; align-items: center; gap: 10px; margin-right: 18px; color: var(--ink); font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.topbar .brand:hover { text-decoration: none; color: var(--ink); }
.topbar .brand img { height: 30px; width: auto; border-radius: 6px; border: 1px solid var(--border); background: #fff; padding: 2px; }
.topbar .nav-link { padding: 7px 12px; border-radius: 999px; color: var(--ink-2); font-weight: 500; }
.topbar .nav-link:hover { background: #f1f5f9; color: var(--ink); text-decoration: none; }
.topbar .nav-link.active { background: var(--brand-50); color: var(--brand); font-weight: 600; }
.topbar .nav-cta { margin-left: 6px; }
.spacer { flex: 1; }
.nav-menu { display: flex; align-items: center; gap: 6px; flex: 1; }
.nav-toggle, .menu-btn, .topbar .nav-cta-mobile, .sm-only { display: none; }
.user-chip { display: inline-flex; align-items: center; gap: 10px; padding: 4px 12px 4px 4px; border-radius: 999px; color: var(--ink); }
.user-chip:hover { background: #f1f5f9; text-decoration: none; color: var(--ink); }
.user-chip .avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, var(--brand), #3b7dd8); color: #fff; font-weight: 700; font-size: 12.5px; letter-spacing: .02em; }
.user-chip .who { display: flex; flex-direction: column; line-height: 1.2; }
.user-chip .who strong { font-size: 13px; font-weight: 600; }
.user-chip .who small { font-size: 11.5px; color: var(--muted); }
.topbar .logout { padding: 7px 12px; border-radius: 999px; color: var(--muted); font-weight: 500; }
.topbar .logout:hover { background: var(--err-bg); color: var(--err); text-decoration: none; }

form.inline { display: inline; margin: 0; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); cursor: pointer; }
.link:hover { text-decoration: underline; text-underline-offset: 2px; }
.link.danger { color: var(--err); }

/* ---------- Generic UI ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); margin-bottom: 20px; }
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 480px; }
.cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }
.row { display: flex; gap: 10px; align-items: center; }
.row-between { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.row-between h2 { margin: 0; flex: 1; }

.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-head .grow { flex: 1; min-width: 220px; }
.card-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head h2 { margin: 0; font-size: 16px; flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: #fff; color: var(--ink); font: inherit; font-weight: 550; cursor: pointer;
  text-decoration: none; box-shadow: var(--shadow-sm); transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #f8fafc; border-color: #b8c2d0; text-decoration: none; color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(31,78,140,.3), inset 0 1px 0 rgba(255,255,255,.12); }
.btn.primary:hover { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.btn.danger { color: var(--err); border-color: #f1c4c0; }
.btn.danger:hover { background: var(--err-bg); color: var(--err); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--ink-2); }
.btn.ghost:hover { background: #eef1f6; }
.btn.block { width: 100%; padding: 10px 14px; }
.btn svg { width: 16px; height: 16px; flex: none; }

/* Forms */
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; color: var(--ink-2); }
.stack input:not([type=checkbox]), .stack select, .search input, .login input {
  padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font: inherit; font-weight: 400; color: var(--ink); background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.stack input:not([type=checkbox]):focus, .stack select:focus, .search input:focus, .login input:focus {
  outline: none; border-color: var(--brand); box-shadow: var(--ring);
}
input[type=checkbox] { accent-color: var(--brand); width: 16px; height: 16px; margin: 2px 0 0; }
label.check { flex-direction: row !important; align-items: flex-start; gap: 10px !important; font-weight: 400 !important; color: var(--ink) !important; cursor: pointer; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px 14px; margin: 0; display: flex; flex-direction: column; gap: 8px; background: #fbfcfe; }
legend { font-weight: 650; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 0 6px; }

.search { display: flex; gap: 8px; position: relative; }
.search input { width: 340px; max-width: 100%; padding-left: 36px; }
.search .ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }

.flash { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 18px; background: var(--ok-bg); color: var(--ok); border: 1px solid #bfe5cc; font-weight: 500; }
.flash::before { content: "✓"; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: currentColor; color: #fff; font-size: 12px; flex: none; }
.flash.err { background: var(--err-bg); color: var(--err); border-color: #f5c6c2; }
.flash.err::before { content: "!"; font-weight: 700; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: separate; border-spacing: 0; }
table.list th, table.list td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list th { position: sticky; top: 0; background: #f8fafc; font-size: 11.5px; font-weight: 600; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; white-space: nowrap; }
table.list tbody tr { transition: background .12s; }
table.list tbody tr:hover { background: #f8fafd; }
table.list tbody tr:last-child td { border-bottom: 0; }
table.list td.nowrap { white-space: nowrap; }
.card:not(.flush) table.list th:first-child, .card:not(.flush) table.list td:first-child { padding-left: 4px; }
.card:not(.flush) table.list th { background: transparent; }
.ctrl-no { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-weight: 600; font-size: 13px; color: var(--brand); background: var(--brand-50); padding: 3px 8px; border-radius: 6px; }
a.ctrl-no:hover { text-decoration: none; background: var(--brand-100); }
.actions { white-space: nowrap; text-align: right; }
.actions > * + * { margin-left: 4px; }
.actions > * { vertical-align: middle; }
.icon-btn { display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; border-radius: 7px; color: var(--ink-2); font-weight: 500; font-size: 13px; border: 0; background: none; cursor: pointer; font-family: inherit; }
.icon-btn:hover { background: #eef1f6; color: var(--ink); text-decoration: none; }
.icon-btn.danger { color: var(--err); }
.icon-btn.danger:hover { background: var(--err-bg); }
.icon-btn svg { width: 15px; height: 15px; }

.tag { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef1f5; color: var(--ink-2); white-space: nowrap; }
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.tag.open { background: var(--brand-50); color: var(--brand); }
.tag.accepted, .tag.active { background: var(--ok-bg); color: var(--ok); }
.tag.unacceptable, .tag.not_performed { background: var(--err-bg); color: var(--err); }
.tag.correction, .tag.incomplete { background: var(--warn-bg); color: var(--warn); }
.tag.disabled { background: #f1f5f9; color: var(--muted); }
.count { display: inline-block; min-width: 24px; padding: 1px 8px; border-radius: 999px; background: #eef1f5; color: var(--ink-2); font-size: 12px; font-weight: 600; text-align: center; }

.empty { padding: 56px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 40px; height: 40px; color: #b6c0ce; margin-bottom: 8px; }
.empty strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }

/* ---------- Login ---------- */
body.auth {
  min-height: 100vh; display: grid; place-items: center;
  background:
    radial-gradient(1200px 600px at 10% -10%, #dbe7f8 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 110%, #e3ecfa 0%, transparent 55%),
    var(--bg);
}
body.auth main { width: 100%; padding: 24px 16px; }
.login { max-width: 400px; margin: 0 auto; background: #fff; padding: 36px 32px 28px; border-radius: 16px; border: 1px solid var(--border); box-shadow: var(--shadow-lg); text-align: center; }
.login img { max-width: 230px; border-radius: 8px; }
.login h1 { font-size: 20px; font-weight: 700; letter-spacing: -.01em; margin: 18px 0 4px; }
.login p { margin: 0 0 24px; }
.login form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.login label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; color: var(--ink-2); }
.login input { padding: 10px 12px; }
.login .btn { margin-top: 6px; }
.login .foot { margin: 22px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- Work order toolbar ---------- */
.toolbar {
  position: sticky; top: 61px; z-index: 10;
  display: flex; gap: 8px; align-items: center; max-width: 860px; margin: 0 auto 14px;
  padding: 10px 12px; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.toolbar .back { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-weight: 500; padding: 6px 10px; border-radius: 7px; }
.toolbar .back:hover { background: #eef1f6; text-decoration: none; color: var(--ink); }
.toolbar .title { font-weight: 650; color: var(--ink); }
.hint { display: flex; align-items: center; gap: 10px; max-width: 860px; margin: 0 auto 14px; padding: 9px 14px; color: #6b4e00; font-size: 13px; background: var(--edit-bg); border: 1px solid #f3e2a6; border-radius: var(--radius-sm); }
.hint .swatch { width: 14px; height: 14px; border-radius: 4px; background: var(--edit-bg); border: 2px solid var(--edit-ring); flex: none; }

/* ---------- The paper form ---------- */
.paper { background: #fff; max-width: 860px; margin: 0 auto; padding: 32px 34px 22px; border-radius: 6px; border: 1px solid var(--border); box-shadow: var(--shadow-lg); font-family: Arial, Helvetica, sans-serif; font-size: 13px; color: #111; }
.paper .head { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.paper .head td { border: 2px solid var(--line); padding: 6px 8px; vertical-align: middle; }
.paper .head .logo { width: 26%; }
.paper .head .logo img { max-width: 100%; display: block; }
.paper .head .title { text-align: center; }
.paper .head .t1 { font-weight: 700; font-size: 16px; }
.paper .head .t2 { font-size: 11px; margin-top: 4px; }
.paper .head .ctrl { width: 26%; text-align: center; }
.paper .head .ctrl .no { font-size: 30px; color: var(--fill); letter-spacing: 2px; }
.paper .pending { font-size: 14px; color: var(--muted); letter-spacing: 0; }

.paper .boxed { border: 2px solid var(--line); padding: 8px 10px; margin-bottom: 4px; }
.paper .sec.editable { background: var(--edit-bg); outline: 2px solid var(--edit-ring); outline-offset: 3px; border-radius: 1px; transition: box-shadow .2s; }
.paper .sec.editable:focus-within { box-shadow: 0 0 0 6px rgba(245, 197, 66, .22); }
.paper .shaded { background: #e9ecf3; }
.paper .shaded.editable { background: var(--edit-bg); }
.paper .lbl { white-space: nowrap; margin-right: 6px; }
.paper .lbl.caps { text-transform: uppercase; font-size: 12px; }
.paper .lbl.b, .paper .b { font-weight: 700; }
.paper .lbl.sm { font-size: 12px; }

.paper .line { display: flex; align-items: flex-end; margin: 5px 0; min-height: 24px; }
.paper .line.tight { margin: 0; }
.paper .blank { flex: 1; min-width: 40px; border: 0; border-bottom: 1px solid #444; background: transparent; padding: 2px 6px; font: inherit; font-size: 15px; color: var(--fill); min-height: 22px; border-radius: 0; transition: background .15s, border-color .15s; }
.paper .blank.center { text-align: center; }
.paper span.blank { display: inline-block; }
.paper input.blank:hover { background: rgba(255,255,255,.7); }
.paper input.blank:focus { outline: none; border-bottom: 2px solid var(--brand); background: #fff; box-shadow: none; }
.paper input.blank[type=date] { font-size: 14px; }

.paper .grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 30px; }
.paper .grid2.wide-left { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.paper .grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); column-gap: 16px; }
.paper .line > .blank { width: 0; }

.paper .types { display: grid; grid-template-columns: 1fr 1fr; column-gap: 30px; row-gap: 4px; padding: 4px 0 6px 30px; }
.paper .box { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; white-space: nowrap; margin-right: 6px; }
.paper .box input { position: absolute; opacity: 0; pointer-events: none; }
.paper .box .sq { width: 18px; height: 18px; border: 2px solid var(--line); display: inline-block; flex: none; position: relative; transition: background .12s; }
.paper .box:hover input:not(:disabled):not(:checked) + .sq { background: #f3e9c4; }
.paper .box input:checked + .sq { background: var(--fill); }
.paper .box input:focus-visible + .sq { outline: 2px solid var(--brand); outline-offset: 2px; }
.paper .box input:disabled + .sq { cursor: default; }
.paper .box:has(input:disabled) { cursor: default; }
.paper .results { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin: 4px 0 6px; }

.paper .note-row { display: grid; grid-template-columns: 200px 1fr; gap: 10px; margin: 12px 0 4px; align-items: end; }
.paper .side-title { font-weight: 700; font-size: 12px; text-transform: uppercase; }
.paper .side-title.fin { font-size: 14px; margin: 26px 0 4px; }
.paper .note { font-size: 11px; }
.paper .note.small { font-size: 9.5px; }

.paper .split { display: grid; grid-template-columns: 1fr 1fr; gap: 0; padding: 0; }
.paper .split > div { padding: 8px 10px; }
.paper .split > div + div { border-left: 2px solid var(--line); }

.paper .three { display: grid; grid-template-columns: 1fr 1fr 1fr; padding: 0; }
.paper .three .sig { padding: 6px 8px; display: flex; flex-direction: column; min-height: 96px; }
.paper .three .sig + .sig { border-left: 2px solid var(--line); }
.paper .three .sig .blank { flex: none; margin-top: auto; border-bottom: 0; }
.paper .three .cap { text-align: center; }

.paper .foot-note { font-size: 9.5px; margin: 6px 0 0; }
.paper .doc-no { text-align: right; font-weight: 700; font-size: 12px; margin: 10px 0 0; }


/* ---------- PDF / print preview: a half-letter sheet ---------- */
.preview-bar { max-width: 760px; }
.sheet-wrap { display: flex; justify-content: center; max-width: 760px; margin: 0 auto; }
.sheet {
  flex: none; width: 5.5in; height: 8.5in; padding: .25in; overflow: hidden;
  background: #fff; border-radius: 4px; box-shadow: var(--shadow-lg); border: 1px solid var(--border);
  transform-origin: top center;
}
.paper.fixed { width: 760px; max-width: none; margin: 0; padding: 0; border: 0; border-radius: 0; box-shadow: none; }
.sheet .paper.fixed { zoom: .63; }
.pdf-capture { position: fixed; left: -10000px; top: 0; width: 760px; background: #fff; }
.btn:disabled { opacity: .7; cursor: progress; }

/* =========================================================
   Phones & small tablets
   ========================================================= */
@media screen and (max-width: 760px) {
  /* Inputs at 16px stop iOS from zooming in on focus */
  .stack input:not([type=checkbox]), .stack select, .search input, .login input, .paper:not(.fixed) .blank { font-size: 16px; }

  /* Header: logo, New, avatar/menu; links fold into a dropdown */
  .topbar { position: sticky; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); gap: 8px; }
  .topbar .brand { margin-right: auto; }
  .topbar .brand span { display: none; }
  .topbar .brand img { height: 34px; }
  .topbar .nav-cta-mobile { display: inline-flex; padding: 8px 12px; }
  .menu-btn { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px 3px 3px; border: 1px solid var(--border); border-radius: 999px; cursor: pointer; color: var(--ink-2); background: #fff; -webkit-tap-highlight-color: transparent; }
  .menu-btn .avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, var(--brand), #3b7dd8); color: #fff; font-weight: 700; font-size: 12.5px; }
  .menu-btn svg { width: 20px; height: 20px; }
  .nav-toggle:checked + .menu-btn { background: var(--brand-50); border-color: var(--brand-100); }
  .nav-toggle:focus-visible + .menu-btn { box-shadow: var(--ring); }
  .nav-menu {
    display: none; position: absolute; top: calc(100% + 6px); left: 10px; right: 10px;
    flex-direction: column; align-items: stretch; gap: 2px; padding: 8px;
    background: #fff; border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg);
  }
  .nav-toggle:checked ~ .nav-menu { display: flex; animation: drop .14s ease-out; }
  @keyframes drop { from { opacity: 0; transform: translateY(-4px); } }
  .nav-menu .spacer { display: none; }
  .nav-menu .nav-link { padding: 12px 14px; border-radius: 10px; font-size: 15px; }
  .nav-menu .nav-cta { display: none; }
  .nav-menu .user-chip { order: -1; padding: 8px 10px 12px; margin-bottom: 4px; border-bottom: 1px solid var(--border); border-radius: 10px 10px 0 0; }
  .nav-menu .user-chip .who { display: flex; }
  .sm-only { display: inline; }
  .nav-menu .user-chip.active { background: var(--brand-50); }
  .nav-menu form.inline { display: block; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }
  .nav-menu .logout { display: block; width: 100%; text-align: left; padding: 12px 14px; border-radius: 10px; font-size: 15px; }

  main { padding: 16px 12px 40px; padding-bottom: max(40px, env(safe-area-inset-bottom)); }
  .card { padding: 16px; border-radius: 14px; }
  .card.flush { padding: 0; }
  .card.narrow { max-width: none; }

  /* Page heading + search */
  .page-head { gap: 12px; margin-bottom: 14px; }
  .page-head h1 { font-size: 21px; }
  .page-head .search { flex: 1 1 100%; }
  .page-head .search input { flex: 1; width: auto; min-width: 0; }
  .btn { padding: 10px 14px; }

  /* Tables become stacked cards */
  table.stack-sm, table.stack-sm tbody, table.stack-sm tr, table.stack-sm td { display: block; width: 100%; }
  table.stack-sm thead { display: none; }
  table.stack-sm tbody tr { position: relative; padding: 14px 16px; border-bottom: 1px solid var(--border); }
  table.stack-sm tbody tr:last-child { border-bottom: 0; }
  table.stack-sm tbody tr:hover { background: none; }
  table.stack-sm td { border: 0; padding: 3px 0 !important; display: flex; gap: 12px; justify-content: space-between; text-align: right; }
  table.stack-sm td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; flex: none; }
  table.stack-sm td[data-label]:empty { display: none; }
  table.stack-sm td.c-head { font-size: 15px; padding-bottom: 6px !important; text-align: left; }
  table.stack-sm td.actions { justify-content: flex-start; gap: 8px; padding-top: 10px !important; text-align: left; }
  table.stack-sm td.actions > * + * { margin-left: 0; }
  table.stack-sm .icon-btn { padding: 8px 14px; background: #f1f5f9; border-radius: 8px; }
  table.stack-sm .icon-btn.danger { background: var(--err-bg); }
  table.stack-sm tr.empty-row { padding: 0; }
  table.stack-sm tr.empty-row td { display: block; text-align: center; }
  .card:not(.flush) table.stack-sm tbody tr { padding: 14px 0; }

  /* Work order list: control no. + date + status on top, whole card is tappable */
  .wo-list td.c-no { padding-bottom: 8px !important; }
  .wo-list td.c-result { position: absolute; top: 14px; right: 16px; width: auto; padding: 0 !important; }
  .wo-list td.c-date { position: absolute; top: 17px; left: 84px; width: auto; padding: 0 !important; font-size: 13px; color: var(--muted); }
  .wo-list td.c-date::before { display: none; }
  .wo-list td.actions { display: none; }
  .wo-list td.c-no a::after { content: ""; position: absolute; inset: 0; }
  .wo-list tbody tr:active { background: #f1f5f9; }

  /* Order page: compact toolbar, Save pinned to the bottom */
  .toolbar { top: 62px; padding: 6px 8px; gap: 6px; backdrop-filter: none; -webkit-backdrop-filter: none; background: #fff; }
  .toolbar .back { padding: 8px; font-size: 0; }
  .toolbar .back svg { width: 20px; height: 20px; }
  .toolbar > .muted { display: none; }
  .toolbar .btn { padding: 8px 10px; }
  .toolbar .btn .lbl-txt { display: none; }
  .toolbar .btn svg { width: 18px; height: 18px; }
  .toolbar .save-btn {
    position: fixed; z-index: 30; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom));
    padding: 14px; font-size: 16px; border-radius: 12px; box-shadow: 0 10px 30px -8px rgba(31,78,140,.55);
  }
  body:has(.toolbar.has-save) main { padding-bottom: 100px; }
  .hint { font-size: 12.5px; }
  .preview-bar .title .muted { display: none; }

  /* The paper form, reflowed for a narrow screen */
  .paper:not(.fixed) { padding: 12px; border-radius: 10px; font-size: 14px; }
  .paper:not(.fixed) .head, .paper:not(.fixed) .head tbody, .paper:not(.fixed) .head tr, .paper:not(.fixed) .head td { display: block; width: 100% !important; }
  .paper:not(.fixed) .head td + td { border-top: 0; }
  .paper:not(.fixed) .head .logo img { max-width: 220px; margin: 0 auto; }
  .paper:not(.fixed) .head .ctrl { display: flex !important; align-items: center; justify-content: center; gap: 10px; }
  .paper:not(.fixed) .head .ctrl .no { font-size: 24px; }
  .paper:not(.fixed) .grid2, .paper:not(.fixed) .grid2.wide-left, .paper:not(.fixed) .grid3, .paper:not(.fixed) .types, .paper:not(.fixed) .split, .paper:not(.fixed) .three, .paper:not(.fixed) .note-row { grid-template-columns: 1fr; }
  .paper:not(.fixed) .split > div + div, .paper:not(.fixed) .three .sig + .sig { border-left: 0; border-top: 2px solid var(--line); }
  .paper:not(.fixed) .types { padding-left: 0; row-gap: 0; }
  .paper:not(.fixed) .line { flex-wrap: wrap; margin: 8px 0; }
  .paper:not(.fixed) .lbl { white-space: normal; }
  .paper:not(.fixed) .line > .blank { flex: 1 1 160px; width: auto; min-height: 30px; }
  .paper:not(.fixed) .box { padding: 6px 0; white-space: normal; }
  .paper:not(.fixed) .box .sq { width: 22px; height: 22px; }
  .paper:not(.fixed) .results { gap: 2px 16px; }
  .paper:not(.fixed) .three .sig { min-height: 0; gap: 6px; }
  .paper:not(.fixed) .three .sig .blank { border-bottom: 1px solid #444; }
  .paper:not(.fixed) .note-row { gap: 4px; }
  .paper:not(.fixed) .note, .paper:not(.fixed) .note.small, .paper:not(.fixed) .foot-note { font-size: 11px; }

  /* Login */
  body.auth { place-items: start center; }
  body.auth main { padding-top: 8vh; }
  .login { padding: 28px 20px 22px; }
}

@media print {
  /* Half-letter (5.5in x 8.5in). Printable area 5in x 8in = 480 x 768 CSS px.
     The form is laid out at 760px wide and scaled to fit, so it keeps the paper layout. */
  @page { size: 5.5in 8.5in; margin: 0.25in; }
  html, body { background: #fff; width: auto; }
  main { padding: 0; margin: 0; max-width: none; }
  .no-print, .topbar { display: none !important; }
  .paper {
    width: 760px; max-width: none; margin: 0; padding: 0; zoom: .63;
    box-shadow: none; border: 0; border-radius: 0;
  }
  .sheet-wrap { display: block; height: auto !important; max-width: none; }
  .sheet { width: auto; height: auto; padding: 0; border: 0; box-shadow: none; transform: none !important; overflow: visible; }
  .paper .sec.editable { background: none; outline: none; box-shadow: none; }
  .paper .shaded, .paper .shaded.editable { background: #e9ecf3; }
  .paper .note, .paper .note.small, .paper .foot-note { font-size: 11px; }
  .paper, .paper .boxed, .paper .head { break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
