:root {
  --bg: #f5f6f8; --card: #fff; --text: #1b1f24; --muted: #6a7280; --line: #e2e5ea;
  --brand: #1f4fd1; --brand-text: #fff; --danger: #c62828; --ok: #2e7d32;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111418; --card: #1b2026; --text: #e8eaed; --muted: #9aa3ad; --line: #2c333b; --brand: #5b86ff; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 1.5rem; margin: .2em 0; } h2 { font-size: 1.1rem; margin: 1.5em 0 .5em; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-text); position: sticky; top: 0; z-index: 10; }
.topbar a, .topbar .linklike { color: var(--brand-text); }
.topbar nav { display: flex; gap: 16px; align-items: center; }
.topbar form { margin: 0; }
.brand { font-weight: 700; }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; padding: 0; }

.container { max-width: 960px; margin: 0 auto; padding: 16px; }
.pagehead { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 10px; }
.narrow { max-width: 380px; margin: 10vh auto; }
.muted { color: var(--muted); }
.error, .errorlist { color: var(--danger); }
.errorlist { margin: 4px 0 0; padding-left: 18px; font-size: .9rem; }
.tag { display: inline-block; font-size: .78rem; padding: 1px 8px; border-radius: 99px; background: var(--line); color: var(--text); }
.notes { white-space: normal; margin-bottom: 0; }

.btn { display: inline-block; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; cursor: pointer; min-height: 42px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-text); }
.btn.subtle { background: transparent; }
.btn.wide { width: 100%; }

input, select, textarea { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--text); font: inherit; margin-top: 4px; }
input[type=checkbox] { width: auto; }
label { display: block; margin-bottom: 12px; font-size: .92rem; }
.search { display: flex; gap: 8px; margin: 12px 0; }
.search input { margin: 0; }

.rows { list-style: none; padding: 0; margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.rows li { border-bottom: 1px solid var(--line); }
.rows li:last-child { border-bottom: 0; }
.rows a, .rows li.muted { display: flex; flex-direction: column; padding: 12px 16px; color: var(--text); }
.rows a:hover { background: var(--bg); }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }

.facts { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid .full { grid-column: 1 / -1; }
fieldset.grid { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin: 0 0 12px; }
.actions { display: flex; gap: 8px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: var(--card); border-left: 4px solid var(--brand); }
.flash-success { border-left-color: var(--ok); }

@media (max-width: 600px) {
  .grid { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 90px 1fr; }
}

/* Jobs */
.rowline { display: flex !important; flex-direction: row !important; justify-content: space-between; align-items: center; gap: 8px; color: var(--text); }
.clip { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .92rem; margin: 2px 0 0; }
.status { font-size: .75rem; padding: 2px 8px; border-radius: 99px; white-space: nowrap; font-weight: 600;
  background: var(--line); color: var(--text); vertical-align: middle; }
.s-needs_scheduling { background: #fff1d6; color: #8a5a00; }
.s-scheduled { background: #e3ebff; color: #1f4fd1; }
.s-on_my_way { background: #e6f4ff; color: #0b6aa8; }
.s-in_progress { background: #fde7d2; color: #a14b00; }
.s-completed { background: #e3f4e5; color: #2e7d32; }
.s-canceled { background: #f1f1f1; color: #888; text-decoration: line-through; }
.tabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 12px; color: var(--muted); white-space: nowrap; border-bottom: 2px solid transparent; }
.tabs a.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.daynav { display: flex; gap: 8px; align-items: center; margin: 8px 0 14px; }
.daynav form { margin: 0; } .daynav input { margin: 0; width: auto; min-height: 42px; }
.actions.wrap { flex-wrap: wrap; margin-top: 10px; } .actions form { margin: 0; }
.job-card > a:not(.rowline) { color: var(--text); }
.btn.big { font-size: 1.1rem; min-height: 54px; margin-bottom: 12px; }
.note-form { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 10px; }
.note-form textarea { margin: 0; }
ul.rows ul, label ul { list-style: none; padding: 0; margin: 4px 0 0; display: flex; flex-wrap: wrap; gap: 4px 16px; }

/* Dispatch calendar: one column per technician, 1px per minute */
.cal { display: flex; overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.cal-hours { flex: 0 0 52px; }
.cal-col { flex: 1 0 170px; border-left: 1px solid var(--line); }
.cal-head { height: 40px; padding: 10px 8px; font-weight: 600; font-size: .9rem; border-bottom: 1px solid var(--line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: sticky; top: 0; background: var(--card); }
.cal-body { position: relative; height: var(--cal-height); }
.cal-hours span { position: absolute; right: 6px; font-size: .72rem; color: var(--muted); transform: translateY(-50%); }
.cal-body i { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.cal-job { position: absolute; left: 3px; right: 3px; overflow: hidden; padding: 4px 6px; font-size: .78rem; line-height: 1.3;
  color: var(--text); background: var(--bg); border-left: 4px solid; border-radius: 6px; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.cal-job.s-completed { opacity: .65; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.container:has(.cal) { max-width: 1400px; }

/* Phones: the brand gets its own line and the links scroll sideways instead of overflowing. */
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; row-gap: 6px; padding-bottom: 6px; }
  .brand { white-space: nowrap; }
  .topbar nav { width: 100%; gap: 18px; overflow-x: auto; white-space: nowrap; padding-bottom: 4px; }
}

/* Estimates & invoices */
.small { font-size: .85rem; }
.d-draft { background: var(--line); color: var(--text); }
.d-sent { background: #e3ebff; color: #1f4fd1; }
.d-approved, .d-paid { background: #e3f4e5; color: #2e7d32; }
.d-declined, .d-void { background: #f1f1f1; color: #888; }
table.doc-lines { width: 100%; border-collapse: collapse; }
table.doc-lines td, table.doc-lines th { padding: 7px 0; border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; }
table.doc-lines .amt { text-align: right; white-space: nowrap; padding-left: 12px; }
table.doc-lines tr.sect th { color: var(--brand); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; padding-top: 14px; }
table.doc-lines tr.sub td, table.doc-lines tr.sum td { font-weight: 600; }
.line-row { display: grid; grid-template-columns: 120px 1fr 80px 110px auto auto; gap: 0 10px; align-items: end;
  border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 0 0 8px; background: var(--card); }
.line-row .d { grid-column: 1 / -1; margin-bottom: 0; }
.line-row label.t { white-space: nowrap; padding-bottom: 12px; }
.public { max-width: 640px; }
.pub-head { display: flex; flex-direction: column; padding: 12px 0; border-bottom: 3px solid var(--brand); margin-bottom: 12px; }
.public form .btn { margin-top: 8px; }
@media (max-width: 600px) {
  .line-row { grid-template-columns: 1fr 1fr; }
  .line-row .n { grid-column: 1 / -1; }
}

/* Payments */
.d-partial, .d-partially_refunded { background: #fff1d6; color: #8a5a00; }
.d-refunded { background: #f1f1f1; color: #888; }
.balance { display: flex; justify-content: space-between; align-items: baseline; }
.balance strong { font-size: 1.6rem; }
.pay-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.pay-card { text-align: center; }
.pay-card h3 { margin: 0 0 8px; }
.qr, .qr svg { display: block; width: 220px; height: 220px; margin: 0 auto 10px; background: #fff; border-radius: 8px; }
.checks { display: flex; gap: 8px; margin-bottom: 10px; }
.checks img { max-width: 100%; max-height: 220px; border-radius: 8px; border: 1px solid var(--line); }
.checkrow { display: flex; gap: 12px; padding: 12px 16px; margin: 0; align-items: flex-start; }
.checkrow span { display: flex; flex-direction: column; }

/* Offline */
.sync-bar { background: #fff1d6; color: #5c3d00; padding: 8px 16px; font-size: .9rem; border-bottom: 1px solid #f0d9a8; }
.sync-bar.warn { background: #fde7e7; color: #7a1c1c; border-color: #f3c2c2; }
.sync-bar a, .sync-bar .linklike { color: inherit; text-decoration: underline; }
.card.pending { border-style: dashed; }
details.card summary { cursor: pointer; padding: 2px 0 10px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.thumbs img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.thumbs video { width: 100%; max-width: 360px; max-height: 240px; border-radius: 8px; background: #000; }
.recorder { margin: 0 0 14px; }
.rec-status { color: var(--danger); font-weight: 600; margin-left: 8px; }
.memo { padding: 6px 0; }
.memo-card { width: 100%; }
.memo-card audio { width: 100%; max-width: 420px; }
.narrow:has(+ .dev-login) { margin-bottom: 16px; }
.narrow.dev-login { margin-top: 0; border-style: dashed; }
.dev-login form { margin: 0 0 6px; }
.dev-login .btn { text-align: left; }

/* Customer texts */
.chat { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.bubble { max-width: 80%; padding: 8px 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); }
.bubble.out { align-self: flex-end; background: var(--brand); color: var(--brand-text); border-color: var(--brand); }
.bubble.out a { color: inherit; text-decoration: underline; }
.bubble small { display: block; opacity: .75; font-size: .75rem; margin-top: 4px; }
.sms-failed, .sms-undelivered { font-weight: 700; }
.send-box { position: sticky; bottom: 0; background: var(--bg); padding: 8px 0; }
.send-box textarea { margin-bottom: 8px; }
.templates { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 6px; }
.small-btn { min-height: 34px; padding: 4px 10px; font-size: .85rem; white-space: nowrap; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px; background: var(--danger); color: #fff;
  font-size: .75rem; font-weight: 700; text-align: center; }
.clip.unread { color: var(--text); font-weight: 600; }

/* Calls and phone settings */
.call-form { display: inline; margin: 0; }
.call-row { padding: 12px 16px; display: flex; flex-direction: column; gap: 4px; }
.call-row audio { width: 100%; max-width: 420px; margin-top: 4px; }
.call-missed, .call-failed { background: #fde7e7; color: #a11; }
.call-voicemail { background: #fff1d6; color: #8a5a00; }
.call-answered { background: #e3f4e5; color: #2e7d32; }
.call-ai_agent { background: #ece3ff; color: #5b2bb5; }
.hours-row { display: grid; grid-template-columns: 110px 1fr auto 1fr auto; gap: 8px; align-items: center; margin-bottom: 6px; }
.hours-row input { margin: 0; }
label.inline { display: flex; gap: 8px; align-items: center; }
@media (max-width: 600px) { .hours-row { grid-template-columns: 1fr 1fr; } .hours-row span { display: none; } }
.call-form .linklike { color: var(--brand); }
