/* ============================================================================
   Shared styles — small, mobile-first, no framework.
   ============================================================================ */
:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #66707d;
  --line: #e2e7ee;
  --brand: #1f6feb;
  --brand-ink: #ffffff;
  --ok: #1a7f44;
  --warn: #9a6b00;
  --warn-bg: #fff7e6;
  --danger: #b3261e;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 30, 50, .08), 0 6px 18px rgba(20, 30, 50, .05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

.wrap { max-width: 560px; margin: 0 auto; padding: 16px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar .brand { font-weight: 700; }
.topbar .who { color: var(--muted); font-size: 13px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin: 16px 0;
}

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 16px; }

label { display: block; font-size: 14px; font-weight: 600; margin: 14px 0 6px; }
.hint { font-weight: 400; color: var(--muted); font-size: 13px; }

input, select, textarea, button {
  font: inherit; width: 100%; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
  color: var(--ink);
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, .15);
}

.btn {
  background: var(--brand); color: var(--brand-ink); border: none;
  font-weight: 600; cursor: pointer; padding: 13px 16px; border-radius: 10px;
}
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: #eef1f6; color: var(--ink); }
.btn.link {
  background: none; color: var(--brand); width: auto; padding: 4px;
  text-decoration: underline; cursor: pointer; border: none;
}
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.seg { display: flex; gap: 8px; }
.seg label {
  flex: 1; margin: 0; text-align: center; padding: 12px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 10px; font-weight: 600;
  background: #fff;
}
.seg input { display: none; }
.seg input:checked + span { color: var(--brand); }
.seg label:has(input:checked) {
  border-color: var(--brand); background: rgba(31,111,235,.06);
}

.msg { padding: 12px 14px; border-radius: 10px; margin: 12px 0; font-size: 14px; }
.msg.err { background: #fdeceb; color: var(--danger); border: 1px solid #f3c9c6; }
.msg.ok  { background: #eaf6ef; color: var(--ok); border: 1px solid #c3e6d1; }
.msg.warn{ background: var(--warn-bg); color: var(--warn); border: 1px solid #f0dca8; }

.tabs { display: flex; gap: 8px; margin-bottom: 8px; }
.tabs button {
  width: auto; background: none; border: none; color: var(--muted);
  font-weight: 600; padding: 8px 4px; cursor: pointer; border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

.muted { color: var(--muted); }
.center { text-align: center; }
.mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; }
.hidden { display: none !important; }

.pill {
  display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px;
  border-radius: 999px; text-transform: uppercase; letter-spacing: .03em;
}
.pill.open      { background: #eef1f6; color: #51607a; }
.pill.onsite    { background: #e6f0ff; color: #1f5bd6; }
.pill.quote     { background: #fff2d9; color: #8a5b00; }
.pill.complete  { background: #eaf6ef; color: #1a7f44; }
.pill.cancelled { background: #fdeceb; color: #b3261e; }

.joblist { list-style: none; padding: 0; margin: 8px 0 0; }
.joblist li {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
  margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center;
}
.joblist li.tappable { cursor: pointer; }
.joblist li.tappable:hover { border-color: var(--brand); background: rgba(31,111,235,.04); }
.joblist li.tappable:active { background: rgba(31,111,235,.08); }
.joblist .meta { color: var(--muted); font-size: 13px; }

/* ---- Job-detail panel (Piece 3) ---- */
.back {
  background: none; border: none; color: var(--brand); width: auto; padding: 4px 0;
  cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 4px;
  margin-bottom: 6px;
}
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.detail-head h1 { margin: 0; }
.detail-row { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.detail-row:first-of-type { border-top: none; }
.detail-row .k { color: var(--muted); font-size: 14px; min-width: 96px; }
.detail-row .v { font-weight: 600; }
.detail-row .v.normal { font-weight: 400; white-space: pre-wrap; }
.btn.arrive { background: var(--ok); }
.btn.big { padding: 16px; font-size: 17px; }

/* ---- Piece 4: completion sections (inventory + quote lines) ---- */
.small { font-size: 13px; }

.lines { list-style: none; padding: 0; margin: 8px 0 0; }
.lines li {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 8px;
}
.lines .line-text { flex: 1; min-width: 0; }
.lines .line-text > div:first-child { font-weight: 600; word-break: break-word; }
.lines .line-amt { font-weight: 700; white-space: nowrap; }
.lines .btn.link.del { color: var(--danger); width: auto; padding: 4px; }

/* add-a-line control row */
.line-add { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.line-add.stacked { display: block; }
.line-add .qty { max-width: 90px; }
.line-add .btn.add { width: auto; white-space: nowrap; }
.line-add .btn.add.full { width: 100%; margin-top: 8px; }
.line-add.stacked .row { margin-top: 8px; }
.line-add.stacked select,
.line-add.stacked input { margin-top: 6px; }
#cat-new { margin-top: 8px; }
#cat-new select { margin-top: 6px; }

/* ---- Piece 6: grouped job lists + category view ---- */
.jobs-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin: 4px 0 4px;
}
.jobs-head h1 { margin: 0; }
.jobs-head .btn.add { width: auto; white-space: nowrap; }

/* Section title acts as a button that opens the full category view */
.group-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; width: 100%; background: none; border: none; padding: 0;
  cursor: pointer; text-align: left; margin-bottom: 4px;
}
.group-head h2 { margin: 0; }
.group-head .group-go { color: var(--brand); font-size: 13px; font-weight: 600; white-space: nowrap; }
.group-head:hover .group-go { text-decoration: underline; }

/* Capped group list: ~5 rows tall, then scroll. Row ~64px incl. gap. */
.joblist.capped { max-height: 340px; overflow-y: auto; }

/* category view: search box + status chips */
#cat-search { margin: 4px 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  width: auto; padding: 7px 13px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font-size: 13px; font-weight: 600;
}
.chip:hover { border-color: var(--brand); }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* ---- Piece 8: home menu, inventory, users ---- */
.menu { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.menu-item {
  display: flex; align-items: center; gap: 14px; text-align: left;
  width: 100%; padding: 16px; background: #fff; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.menu-item:hover { border-color: var(--brand); background: rgba(31,111,235,.04); }
.menu-ico { font-size: 26px; line-height: 1; }
.menu-tx { display: flex; flex-direction: column; }
.menu-tx b { font-size: 16px; }
.menu-tx small { color: var(--muted); font-size: 13px; }
.home-back { margin-bottom: 2px; }

/* disabled job-type segment */
.seg label.disabled { opacity: .45; cursor: not-allowed; }

/* dimmed (inactive/deactivated) list rows */
.lines li.dim { opacity: .55; }

/* permission checkboxes */
.perms { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.chk { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 500; }
.chk input { width: auto; }

/* let inventory/users rows wrap their action buttons on small screens */
#invcat-list .btn.link, #users-list .btn.link, #pending-list .btn.link { white-space: nowrap; }

/* ---- Piece 5: customer signature ---- */
.sig-pad-frame {
  position: relative; margin-top: 8px;
  border: 1px dashed var(--line); border-radius: 10px;
  background: #fff; overflow: hidden;
}
.sig-pad {
  display: block; width: 100%; height: 180px;
  touch-action: none;            /* let the finger draw, not scroll */
  cursor: crosshair;
}
.sig-clear {
  position: absolute; top: 8px; right: 8px; width: auto;
  padding: 4px 10px; font-size: 13px; font-weight: 600;
  background: #eef1f6; color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer;
}
.sig-clear:hover { filter: brightness(.97); }
.sig-saved-img {
  display: block; width: 100%; max-height: 200px; object-fit: contain;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
  margin: 4px 0 8px;
}

/* outcome (reschedule / cancel) buttons under the advance step */
.outcome { display: flex; gap: 8px; margin-top: 12px; }
.outcome .btn { flex: 1; }
.btn.danger-outline {
  background: #fff; color: var(--danger); border: 1px solid #f0c5c2;
}
.btn.danger-outline:hover { background: #fdf2f1; filter: none; }

/* ---- Piece 11: serial numbers on Job Card material lines ---- */
/* A material row with serials is a vertical stack (head row + serial editor),
   overriding the default flex/centered .lines li layout. */
.lines li.inv-row { display: block; }
.inv-row .inv-head { display: flex; align-items: center; gap: 10px; }
.inv-row .inv-head .line-text { flex: 1; min-width: 0; }

.serial-box {
  margin-top: 10px; padding: 10px 12px;
  border: 1px dashed var(--line); border-radius: 8px; background: var(--bg);
}
.serial-cap { margin: 0 0 8px; color: var(--muted); }
.serial-cap b.ok   { color: var(--ok); }
.serial-cap b.warn { color: var(--warn); }

.serial-slot {
  display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
}
.serial-slot:last-child { margin-bottom: 0; }
.serial-slot .serial-input { flex: 1; min-width: 0; }
.serial-photo-chip.ok { color: var(--ok); font-weight: 600; white-space: nowrap; }

/* Inline serial counter / status text helpers */
b.ok   { color: var(--ok); }
b.warn { color: var(--warn); }

/* ---- Piece 9: Business Profile ---- */
.btn.ghost {
  background: #fff; color: var(--ink); border: 1px solid var(--line, #d9dee7);
}
.btn.ghost:hover { background: #f5f7fa; filter: none; }
.btn.ghost.small, .btn.small { width: auto; padding: 8px 12px; font-size: 13px; }
/* two inputs side by side that should still stack nicely on narrow phones */
.row .col { flex: 1; min-width: 0; }
.row .col label { margin-top: 0; }
.logo-row { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.logo-box {
  width: 96px; height: 96px; border: 1px solid var(--line, #d9dee7);
  border-radius: 10px; background: #fafbfc; display: flex; align-items: center;
  justify-content: center; overflow: hidden; flex: 0 0 auto;
}
.logo-box img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-actions { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 160px; }
.logo-actions .btn { width: auto; }
.logo-actions p { margin: 0; }
.colour-row { display: flex; gap: 10px; align-items: center; }
.colour-row input[type="color"] {
  width: 48px; height: 44px; padding: 2px; border: 1px solid var(--line, #d9dee7);
  border-radius: 10px; background: #fff; cursor: pointer; flex: 0 0 auto;
}
.colour-row input[type="text"] { flex: 1; min-width: 0; }

/* ---- photos / attachments ------------------------------------------------ */
.att-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  margin-top: 4px;
}
.att-item {
  position: relative;
  margin: 0;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg);
}
.att-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: pointer;
}
.att-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  line-height: 22px;
  text-align: center;
  border: none;
  border-radius: 50%;
  background: rgba(20, 30, 50, .62);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  padding: 0;
}
.att-del:hover { background: var(--danger); }
.att-del.inline {
  position: static;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  line-height: 28px;
  font-size: 20px;
}
.btn.full { width: 100%; }

/* voice notes */
.att-audio { list-style: none; margin: 8px 0 0; padding: 0; }
.att-audio-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.att-audio-row audio { flex: 1 1 auto; min-width: 0; height: 36px; }

/* photo + record action buttons */
.att-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.att-actions .btn { flex: 1 1 auto; }
.att-rec.recording {
  background: #fdecea;
  color: var(--danger);
  border-color: #f0c5c2;
}
.att-rec.recording::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--danger);
  vertical-align: middle;
  animation: att-pulse 1s infinite;
}
@keyframes att-pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }
.att-timer {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--danger);
}

/* ---- Piece 12: Customers ---- */
/* Tappable customer rows live in a .lines list (not .joblist) — give them the
   same affordance. */
.lines li.tappable { cursor: pointer; }
.lines li.tappable:hover { border-color: var(--brand); background: rgba(31,111,235,.04); }
.lines li.tappable:active { background: rgba(31,111,235,.08); }
/* Standalone "Edit →" affordance on a list row (group-go is otherwise scoped
   to .group-head). */
.lines .group-go { color: var(--brand); font-size: 13px; font-weight: 600; white-space: nowrap; }
/* "Primary" badge on a contact row. */
.tag {
  display: inline-block; font-size: 11px; font-weight: 700; line-height: 1;
  padding: 3px 7px; border-radius: 999px; vertical-align: middle;
}
.tag.primary { background: rgba(31,111,235,.12); color: var(--brand); }
/* Add-contact stack under each contact group. */
.contact-add { display: flex; flex-direction: column; gap: 8px; }
.contact-add .chk { margin-top: 0; }
.contact-add .btn.add { width: auto; align-self: flex-start; }
/* Danger ghost button (delete customer). */
.btn.ghost.danger { color: var(--danger); border-color: #f0c5c2; }
.btn.ghost.danger:hover { background: #fdf2f1; }
