:root {
  --bg: #f3f6f6;
  --card: #ffffff;
  --text: #0f1f1e;
  --muted: #5a6866;
  --line: #d8e1e0;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --wa: #128c4a;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --good: #15803d;
  --danger: #b91c1c;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1211;
    --card: #142120;
    --text: #e6eeed;
    --muted: #9db0ad;
    --line: #263533;
    --brand: #2dd4bf;
    --brand-ink: #04201d;
    --wa: #1faa5c;
    --warn: #fbbf24;
    --warn-bg: #3a2c0a;
    --good: #4ade80;
    --danger: #f87171;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; margin-bottom: 8px; }
p { margin: 0; }
[hidden] { display: none !important; }

.wrap { max-width: 760px; margin: 0 auto; padding: 0 12px; }
#app { padding-top: 14px; padding-bottom: 24px; }
.stack { display: grid; gap: 14px; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.big { font-size: 1.2rem; font-weight: 600; }
.center { text-align: center; }
.pad { padding: 24px 0; }
.error { color: var(--danger); font-weight: 600; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* top bar */
.top { position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; justify-content: space-between; height: 56px; gap: 8px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* bottom nav (phones) */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a { display: grid; justify-items: center; gap: 2px; padding: 8px 0; font-size: .78rem; color: var(--muted); text-decoration: none; min-height: 56px; }
.bottom-nav .ic { font-size: 1.2rem; line-height: 1.2; }
.bottom-nav a.on { color: var(--brand); font-weight: 700; }

/* cards & forms */
.card, fieldset.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0; min-width: 0; }
fieldset.card { padding-top: 6px; }
legend { font-weight: 700; padding: 0 4px; }
.field { display: grid; gap: 4px; min-width: 0; }
.lbl { font-weight: 600; font-size: .92rem; }
input, select, textarea {
  font: inherit; font-size: 16px; width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text);
}
textarea { resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.check { display: flex; align-items: center; gap: 6px; }
.check input { width: 20px; min-height: 20px; height: 20px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; }
.inline-form input, .inline-form select { flex: 1 1 110px; width: auto; }
.login { max-width: 420px; margin: 40px auto; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 2px solid var(--brand);
  background: var(--brand); color: var(--brand-ink); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.btn-small { min-height: 38px; padding: 0 14px; font-size: .92rem; }
.btn-ghost { background: transparent; color: var(--brand); }
.btn-wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); justify-self: start; }
.btn-block { width: 100%; }
.btn:disabled, .btn.busy { opacity: .6; pointer-events: none; }
.btn-wrap, .btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.top .btn { flex: none; }
.x { border: 0; background: none; color: var(--muted); font-size: 1.4rem; line-height: 1; padding: 4px 8px; cursor: pointer; }
:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }

/* list */
.search-bar input { background: var(--card); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .88rem; cursor: pointer; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.list { display: grid; gap: 10px; }
.job-card { display: grid; gap: 4px; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); text-decoration: none; }
.job-card.late { border-color: var(--warn); }
.job-no { font-size: .95rem; }
.job-main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name { font-weight: 600; }
.owes { color: var(--warn); font-weight: 600; }
.late-note { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 4px 8px; font-size: .85rem; font-weight: 600; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; background: var(--bg); border: 1px solid var(--line); }
.st-received { color: #2563eb; }
.st-checking, .st-repairing { color: #7c3aed; }
.st-waiting_parts { color: var(--warn); }
.st-ready { background: var(--good); color: #fff; border-color: var(--good); }
.st-collected { color: var(--muted); }
.st-returned { color: var(--danger); }
@media (prefers-color-scheme: dark) {
  .st-received { color: #93c5fd; }
  .st-checking, .st-repairing { color: #c4b5fd; }
  .st-ready { color: #04201d; }
}

/* job page */
.job-title { font-size: 1.6rem; }
.notice { border-color: var(--good); display: grid; gap: 8px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: var(--bg); border-radius: 10px; padding: 10px; display: grid; gap: 2px; min-width: 0; }
.tile span { font-size: .8rem; color: var(--muted); }
.tile strong { font-size: 1.05rem; overflow-wrap: anywhere; }
.stack > .tiles .tile { background: var(--card); border: 1px solid var(--line); }
.tile.warn strong { color: var(--warn); }
.tile.good strong { color: var(--good); }
.lines { list-style: none; padding: 0; margin: 0; }
.lines li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.lines li > :first-child { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; display: block; background: var(--bg); }
.photo { position: relative; }
.photo .x { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.55); color: #fff; border-radius: 50%; width: 30px; height: 30px; padding: 0; font-size: 1.1rem; }
details summary { cursor: pointer; font-weight: 600; }
.history { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 4px; font-size: .9rem; }
.quote { background: var(--bg); border-radius: 10px; padding: 10px; white-space: pre-wrap; }

/* modal */
.modal-back { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.45); display: grid; align-items: end; justify-items: center; }
.modal { background: var(--card); width: 100%; max-width: 520px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); display: grid; gap: 14px; }
@media (min-width: 600px) { .modal-back { align-items: center; } .modal { border-radius: 18px; } }

/* toast */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 40; max-width: calc(100% - 32px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.toast.bad { background: var(--danger); color: #fff; }

/* ticket */
.ticket { background: #fff; color: #000; border: 1px dashed #999; border-radius: 8px; padding: 18px; display: grid; gap: 12px; }
.ticket header { text-align: center; }
.ticket h1 { font-size: 1.3rem; }
.ticket h2 { font-size: 1.05rem; text-align: center; border-top: 1px solid #ccc; border-bottom: 1px solid #ccc; padding: 6px 0; }
.ticket .facts dt { color: #555; }
.ticket .terms { font-size: .8rem; color: #333; }
.ticket .sign { display: flex; justify-content: space-between; gap: 24px; padding-top: 36px; font-size: .8rem; }
.ticket .sign span { flex: 1; border-top: 1px solid #000; padding-top: 4px; }

@media (min-width: 900px) {
  .bottom-nav { padding-left: calc(50% - 380px); padding-right: calc(50% - 380px); }
  .bottom-nav a { grid-auto-flow: column; align-items: center; justify-content: center; gap: 6px; font-size: .95rem; }
}

@media print {
  body { background: #fff; padding: 0; }
  .top, .bottom-nav, .no-print, .toast { display: none !important; }
  #app { padding: 0; }
  .ticket { border: 0; padding: 0; }
}
