/* JobTab — a tool for tradespeople on the job. Phone first: bottom tab bar, big tap targets.
   Hi-vis orange accent on cool workshop greys. */
:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --ink: #101828;
  --mute: #5d6779;
  --line: #e0e5ec;
  --brand: #e2560b;
  --brand-ink: #ffffff;
  --brand-soft: #fff0e6;
  --info: #1d5bd8; --info-soft: #e8f0ff;
  --good: #137a3a; --good-soft: #e5f6ec;
  --warn: #a75a00; --warn-soft: #fff3df;
  --bad: #b42318; --bad-soft: #fdecea;
  --muted-soft: #eef1f5;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 14px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --paper: #ffffff; --paper-ink: #101828; --paper-mute: #5d6779; --paper-line: #e3e7ee; --paper-head: #101828;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1016; --surface: #151b23; --surface-2: #1b222c; --ink: #e8edf4; --mute: #9aa5b5; --line: #29313d;
    --brand: #ff7a2e; --brand-ink: #1a0d04; --brand-soft: #35210f;
    --info: #7aa7ff; --info-soft: #172338; --good: #57d18a; --good-soft: #12291c; --warn: #ffb44d; --warn-soft: #33250f;
    --bad: #ff8a80; --bad-soft: #351816; --muted-soft: #1f2631;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c1016; --surface: #151b23; --surface-2: #1b222c; --ink: #e8edf4; --mute: #9aa5b5; --line: #29313d;
  --brand: #ff7a2e; --brand-ink: #1a0d04; --brand-soft: #35210f;
  --info: #7aa7ff; --info-soft: #172338; --good: #57d18a; --good-soft: #12291c; --warn: #ffb44d; --warn-soft: #33250f;
  --bad: #ff8a80; --bad-soft: #351816; --muted-soft: #1f2631;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); }
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 1.55rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: .98rem; }
a { color: var(--info); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.mute { color: var(--mute); }
.small { font-size: .86rem; }

/* ---------- shell ---------- */
.shell { min-height: 100vh; min-height: 100dvh; }
.side { display: none; }
.main { padding: calc(14px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) calc(96px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); max-width: 1080px; margin: 0 auto; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px)); }
.tabbar a { display: grid; justify-items: center; gap: 2px; padding: 6px 2px; text-decoration: none; color: var(--mute); font-size: .72rem; font-weight: 600; border-radius: 10px; }
.tabbar a svg, .side nav a svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--brand); }
.fab { position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(78px + env(safe-area-inset-bottom, 0px)); z-index: 21;
  width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--brand); color: var(--brand-ink); box-shadow: 0 6px 20px rgba(226, 86, 11, .35); cursor: pointer; display: grid; place-items: center; }
.fab svg { width: 26px; height: 26px; stroke: currentColor; stroke-width: 2.4; fill: none; stroke-linecap: round; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); }
  .side { display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; padding: 20px 14px; border-right: 1px solid var(--line); background: var(--surface); }
  .side nav { display: grid; gap: 2px; }
  .side nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; text-decoration: none; color: var(--mute); font-weight: 600; }
  .side nav a:hover { background: var(--surface-2); color: var(--ink); }
  .side nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
  .side .newbtns { display: grid; gap: 8px; }
  .tabbar, .fab { display: none; }
  .main { padding: 28px 32px 48px; }
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; letter-spacing: -.01em; }
.brand img { width: 32px; height: 32px; border-radius: 9px; }
.brand small { display: block; font-weight: 500; font-size: .72rem; color: var(--mute); letter-spacing: 0; }

/* ---------- common ---------- */
.page-head { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-head .sub { color: var(--mute); font-size: .9rem; margin-top: 2px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--mute); text-decoration: none; font-weight: 600; font-size: .9rem; margin-bottom: 8px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 14px; }
.card > h2, .card > h3 { margin-bottom: 12px; }
.stack { display: grid; gap: 14px; }
.row-flex { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.spacer { flex: 1; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 650; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--mute); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.danger.armed { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: .88rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.f { display: grid; gap: 5px; min-width: 0; }
.f > span { font-size: .78rem; font-weight: 650; color: var(--mute); }
.f .hint { font-size: .78rem; color: var(--mute); }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-2); font-size: 16px; }
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.span2 { grid-column: 1 / -1; }
@media (max-width: 560px) { .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); } }

.msg { font-size: .9rem; min-height: 1.3em; }
.msg.err { color: var(--bad); }
.msg.ok { color: var(--good); }

.chip { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: .74rem; font-weight: 700; white-space: nowrap; }
.chip.muted { background: var(--muted-soft); color: var(--mute); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }

.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.filters button { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 13px; font-weight: 600; font-size: .86rem; cursor: pointer; color: var(--mute); }
.filters button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* list rows */
.list { display: grid; gap: 8px; }
.item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 14px; align-items: center; padding: 13px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; text-decoration: none; color: inherit; }
.item:hover { border-color: var(--mute); }
.item .t { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { color: var(--mute); font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .r { text-align: right; display: grid; justify-items: end; gap: 4px; }
.item .amt { font-weight: 750; font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: 36px 16px; color: var(--mute); }
.empty h3 { color: var(--ink); margin-bottom: 6px; font-size: 1.05rem; }
.empty p { max-width: 44ch; margin: 0 auto 16px; }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 18px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 13px; padding: 13px 14px; text-decoration: none; color: inherit; }
.stat .k { color: var(--mute); font-size: .78rem; font-weight: 650; }
.stat .v { font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat.alert .v { color: var(--bad); }
.section-h { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 0 10px; }
.section-h a { font-size: .88rem; font-weight: 600; text-decoration: none; }
.activity { display: grid; gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; }
.activity a { display: flex; gap: 12px; align-items: center; padding: 12px 14px; text-decoration: none; color: inherit; border-top: 1px solid var(--line); }
.activity a:first-child { border-top: 0; }
.activity .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--info); flex: none; }
.activity .dot.good { background: var(--good); } .activity .dot.bad { background: var(--bad); }
.activity .w { margin-left: auto; color: var(--mute); font-size: .8rem; white-space: nowrap; }

/* editor */
.doc-layout { display: grid; gap: 16px; align-items: start; }
@media (min-width: 1100px) { .doc-layout { grid-template-columns: minmax(0, 1fr) 340px; } .doc-aside { position: sticky; top: 20px; } }
.li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) 46px; gap: 8px; align-items: end; padding: 12px 0; border-top: 1px dashed var(--line); }
.li:first-child { border-top: 0; padding-top: 0; }
.li .desc { grid-column: 1 / -1; }
.li .amt { text-align: right; font-weight: 750; font-variant-numeric: tabular-nums; min-height: 46px; display: flex; align-items: center; justify-content: flex-end; padding-right: 4px; }
.icon-btn { width: 46px; height: 46px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface); color: var(--mute); cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { color: var(--bad); border-color: var(--bad); }
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }
@media (max-width: 420px) { .li .amt { font-size: .92rem; padding-right: 0; } }
.totals { display: grid; gap: 6px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.totals div { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.totals .big { font-size: 1.25rem; font-weight: 800; }
.quick { border-color: var(--brand); box-shadow: inset 4px 0 0 var(--brand); }
.quick p { margin: 0 0 10px; color: var(--mute); font-size: .88rem; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.timeline li { display: grid; grid-template-columns: 12px minmax(0, 1fr); gap: 10px; font-size: .9rem; }
.timeline li::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--line); margin-top: 6px; }
.timeline li.on::before { background: var(--brand); }
.timeline .w { color: var(--mute); font-size: .8rem; }
.bigstatus { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.bigstatus .amt { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.actions { display: grid; gap: 8px; }

/* dialog */
.dlg-back { position: fixed; inset: 0; background: rgba(8, 12, 18, .45); z-index: 50; display: grid; align-items: end; justify-items: center; }
@media (min-width: 640px) { .dlg-back { align-items: center; } }
.dlg { width: min(100%, 480px); max-height: 90vh; overflow: auto; background: var(--surface); border-radius: 18px 18px 0 0; padding: 18px max(18px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) max(18px, env(safe-area-inset-left, 0px)); box-shadow: var(--shadow); }
@media (min-width: 640px) { .dlg { border-radius: 18px; } }
.dlg h2 { margin-bottom: 4px; }
.dlg .sub { color: var(--mute); margin: 0 0 14px; font-size: .9rem; }
.dlg .btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.send-opts { display: grid; gap: 10px; }
.send-opts .btn { justify-content: flex-start; min-height: 54px; }
.linkbox { display: flex; gap: 8px; }
.linkbox input { font-size: .85rem; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom, 0px)); z-index: 60; background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 12px; font-weight: 600; font-size: .92rem; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
@media (min-width: 900px) { .toast { bottom: 28px; } }

/* auth */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
.auth .card { width: min(100%, 420px); padding: 24px; }
.auth .brand { margin-bottom: 18px; }
.auth h1 { font-size: 1.35rem; margin-bottom: 4px; }
.auth p.lead { color: var(--mute); margin: 0 0 18px; }
.auth .alt { text-align: center; margin-top: 14px; font-size: .9rem; color: var(--mute); }
.loading { min-height: 60vh; display: grid; place-items: center; color: var(--mute); }

.pw { position: relative; }
.pw input { padding-right: 72px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); min-height: 34px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: var(--info); font-weight: 650; font-size: .85rem; cursor: pointer; }
.pw-toggle:hover { background: var(--muted-soft); }

/* ---------- the paper (white in both themes, like a printed page) ---------- */
.paper { background: var(--paper); color: var(--paper-ink); border: 1px solid var(--line); border-radius: 8px; padding: 28px 26px; font-size: 13px; line-height: 1.45; box-shadow: var(--shadow); }
.paper .ph { opacity: .5; }
.pp-head { display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between; padding-bottom: 16px; border-bottom: 2px solid var(--paper-head); }
.pp-biz { display: flex; gap: 12px; min-width: 0; color: var(--paper-mute); font-size: 12px; }
.pp-biz img { width: 52px; height: 52px; object-fit: contain; flex: none; }
.pp-name { font-size: 16px; font-weight: 800; color: var(--paper-ink); }
.pp-meta { text-align: right; color: var(--paper-mute); font-size: 12px; }
.pp-kind { font-size: 24px; font-weight: 800; letter-spacing: .06em; color: #e2560b; }
.pp-bill { margin: 18px 0; color: var(--paper-mute); font-size: 12px; }
.pp-lbl { font-size: 10.5px; font-weight: 800; letter-spacing: .08em; color: var(--paper-mute); margin-bottom: 3px; }
.pp-cust { font-size: 14px; font-weight: 750; color: var(--paper-ink); }
.pp-table { overflow-x: auto; }
.pp-table table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.pp-table th { background: var(--paper-head); color: #fff; font-size: 11px; font-weight: 700; text-align: right; padding: 8px; }
.pp-table td { padding: 9px 8px; text-align: right; border-bottom: 1px solid var(--paper-line); vertical-align: top; }
.pp-table .d { text-align: left; min-width: 130px; overflow-wrap: anywhere; }
.pp-tot { margin: 14px 0 0 auto; width: min(100%, 260px); font-variant-numeric: tabular-nums; }
.pp-tot div { display: flex; justify-content: space-between; padding: 3px 0; }
.pp-tot .big { font-weight: 800; font-size: 16px; border-top: 2px solid var(--paper-head); margin-top: 6px; padding-top: 8px; }
.pp-tot .big + div { margin-top: 4px; }
.pp-notes { margin-top: 18px; color: var(--paper-mute); font-size: 12px; }
.pp-notes p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 520px) { .paper { padding: 18px 14px; } .pp-meta { text-align: left; } }

/* printing: only the paper */
#print-root { display: none; }
@media print {
  @page { margin: 14mm; }
  body { background: #fff; }
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing #print-root { display: block; }
  .paper { border: 0; box-shadow: none; padding: 0; font-size: 12px; }
  .no-print { display: none !important; }
  .pp-table th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
