:root {
  --brand: #0f6bff;
  /* Computed by JS: dark text when the brand colour is light, white otherwise. */
  --brand-fg: #fff;
  --text: #17233b;
  --muted: #5b6b85;
  --border: #e3e8ee;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: #fff; color: var(--text); font-size: 15px; }

#app { display: flex; flex-direction: column; height: 100%; }
#app.loading, #app.error {
  align-items: center; justify-content: center; color: var(--muted); padding: 24px; text-align: center;
}

/* Hosted page: center the widget in a soft page frame */
body.hosted { background: #f6f8fa; }
body.hosted #app {
  max-width: 720px; margin: 0 auto; height: 100%;
  background: #fff; border-left: 1px solid var(--border); border-right: 1px solid var(--border);
}

header {
  display: flex; align-items: center; gap: 10px;
  background: var(--brand); color: var(--brand-fg, #fff); padding: 14px 16px; flex-shrink: 0;
}
header .avatar {
  width: 30px; height: 30px; border-radius: 50%; background: rgba(255, 255, 255, 0.22);
  display: grid; place-items: center; font-size: 15px; font-weight: 700;
}
header .name { font-weight: 650; font-size: 15px; }
header .close {
  margin-left: auto; background: none; border: none; color: var(--brand-fg, #fff); font-size: 20px;
  cursor: pointer; line-height: 1; padding: 4px 6px; opacity: 0.85;
}
body.hosted header .close { display: none; }

.log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 84%; padding: 10px 13px; border-radius: 14px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.msg.bot { align-self: flex-start; background: #eef1f6; border-bottom-left-radius: 4px; }
.msg.me { align-self: flex-end; background: var(--brand); color: var(--brand-fg, #fff); border-bottom-right-radius: 4px; }
.msg .src { margin-top: 7px; padding-top: 6px; border-top: 1px solid rgba(0,0,0,.09); font-size: 11.5px; color: var(--muted); }
.typing { align-self: flex-start; color: var(--muted); font-size: 13px; padding: 4px 2px; }
.msg .rate button {
  background: none; border: none; cursor: pointer; font-size: 14px; padding: 0 3px;
  opacity: 0.75; line-height: 1;
}
.msg .rate button:hover { opacity: 1; }

/* The chat composer only - page forms (.pform) lay out as documents. */
form#form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); flex-shrink: 0; }
input {
  flex: 1; padding: 10px 13px; border: 1px solid var(--border); border-radius: 20px;
  font-size: 14px; font-family: inherit; outline: none; min-width: 0;
}
input:focus { border-color: var(--brand); }
button.send {
  border: none; background: var(--brand); color: var(--brand-fg, #fff); border-radius: 20px;
  padding: 0 18px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
}
button.send:disabled { opacity: 0.45; cursor: default; }
footer { text-align: center; font-size: 11px; color: var(--muted); padding: 0 0 8px; }
footer a { color: var(--muted); }
.msg .body { display: block; white-space: pre-wrap; }

/* ── Booking / quote pages ─────────────────────────────────────────── */
body.page #app { max-width: 560px; }
.page-body { flex: 1; overflow-y: auto; padding: 18px; }
.page-body .lead { color: #57534e; margin-bottom: 14px; }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choices.slots { flex-direction: row; flex-wrap: wrap; }
.choice {
  text-align: left; background: #fff; border: 1px solid #e7e5e4; border-radius: 10px;
  padding: 12px 14px; font: inherit; cursor: pointer; display: flex; flex-direction: column; gap: 2px;
}
.choice:hover { border-color: var(--brand); }
.choice.slot { flex-direction: row; width: auto; font-weight: 600; }
.c-name { font-weight: 600; }
.c-desc { color: #78716c; font-size: 13.5px; }
.c-meta { color: #57534e; font-size: 13.5px; }
.back { margin-top: 14px; }
.back a { color: var(--brand); }
.pform label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
.pform input, .pform textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #e7e5e4; border-radius: 8px;
  font: inherit; box-sizing: border-box;
}
.pform .hint, .page-body .hint { color: #78716c; font-size: 13.5px; margin-top: 10px; }
button.primary {
  margin-top: 14px; background: var(--brand); color: var(--brand-fg, #fff); border: none; border-radius: 9px;
  padding: 12px 20px; font: inherit; font-weight: 650; cursor: pointer;
}
button.ghost {
  margin-top: 14px; background: transparent; color: #57534e; border: 1px solid #e7e5e4;
  border-radius: 9px; padding: 12px 20px; font: inherit; font-weight: 600; cursor: pointer;
}
button.danger {
  margin-top: 14px; background: transparent; color: #b91c1c; border: 1px solid #e7e5e4;
  border-radius: 9px; padding: 12px 20px; font: inherit; font-weight: 600; cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: default; }
.form-err { color: #b91c1c; font-size: 13.5px; margin-top: 8px; min-height: 1em; }
.done { text-align: center; padding: 28px 8px; }
.done .tick {
  width: 52px; height: 52px; margin: 0 auto 12px; border-radius: 50%;
  background: #dcfce7; color: #15803d; font-size: 26px; line-height: 52px;
}
.done h2 { margin: 0 0 8px; }
.q-title { margin: 0 0 12px; }
.q-lines { width: 100%; border-collapse: collapse; }
.q-lines td { padding: 9px 0; border-bottom: 1px solid #e7e5e4; vertical-align: top; }
.q-lines .num { text-align: right; white-space: nowrap; }
.q-unit { display: block; color: #78716c; font-size: 13px; }
.q-lines tfoot td { border-bottom: none; padding: 6px 0; color: #57534e; }
.q-total td { font-weight: 700; color: #1c1917; font-size: 17px; }
.q-notes { margin-top: 14px; color: #57534e; }
.q-terms { margin-top: 10px; color: #78716c; font-size: 13px; }
.q-actions { display: flex; gap: 10px; flex-wrap: wrap; }
/*
 * The accept gate (issue 118). Deliberately looks like part of the document
 * rather than a barrier in front of it: a customer who cannot get past it can
 * still read every figure and ring the tradesperson.
 */
.q-gate { margin-top: 18px; padding-top: 14px; border-top: 1px solid #e7e5e4; }
.q-gate label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
.q-gate input {
  width: 100%; padding: 10px 12px; border: 1px solid #e7e5e4; border-radius: 8px;
  font: inherit; box-sizing: border-box;
}
/* Four digits need a keypad, not a keyboard, and nowhere near full width. */
.q-gate input#acc-four { max-width: 8em; letter-spacing: 0.25em; }
.q-gate .hint { margin-top: 6px; }

/* ── The scannable square (issue 119) ──────────────────────────────────── */
.doc-qr { margin-top: 18px; }
.qr-toggle {
  background: none; border: 1px solid #e7e5e4; border-radius: 8px;
  padding: 9px 14px; font: inherit; color: #57534e; cursor: pointer;
}
.qr-panel { margin-top: 12px; }
/*
 * 180px, not the 132px the presence QR uses. These URLs are 71-99 characters,
 * which puts the code at version 6-7 (~41-45 modules): at 132px that is about
 * 3px per module, which a phone camera struggles with off a screen, at an
 * angle, or through a screen protector.
 */
.qr-img { width: 180px; max-width: 100%; }
.qr-img svg { display: block; width: 100%; height: auto; }
/* The address in text, always. The square is the shortcut, not the route. */
.qr-url { font-size: 13px; color: #78716c; margin-top: 8px; word-break: break-all; }

/*
 * Business identity for print only. The page header is hidden on paper (it is
 * a full-bleed brand band that eats a print cartridge), and for two of the
 * three invoice themes the name and logo live nowhere else - so a printed
 * invoice said nothing about who sent it.
 */
.print-id { display: none; gap: 12px; align-items: center; margin-bottom: 16px; }
.print-id img { max-height: 48px; width: auto; }

/*
 * Quotes never had a print stylesheet at all, though a quote is the document
 * people most want on paper - to lay beside two other tradespeople's prices.
 */
@media print {
  header, footer, .i-print, .qr-toggle, .q-actions, .q-gate { display: none !important; }
  body { background: #fff; }
  .qr-panel[hidden] { display: block !important; }
  .print-id { display: flex !important; }
  .page-body { max-width: none; padding: 0; }
}
.q-state { margin-top: 16px; font-weight: 600; }
.q-state.ok { color: #15803d; }
.stars { display: flex; gap: 6px; margin: 6px 0 4px; }
.star {
  background: none; border: none; font-size: 34px; line-height: 1; padding: 4px;
  cursor: pointer; color: #d6d3d1;
}
.star.on { color: #f59e0b; }
.primary-link {
  display: inline-block; margin-top: 6px; background: var(--brand); color: var(--brand-fg, #fff);
  border-radius: 9px; padding: 12px 20px; font-weight: 650; text-decoration: none;
}
header .book-cta {
  margin-left: auto; margin-right: 10px; background: rgba(255,255,255,.16); color: var(--brand-fg, #fff);
  padding: 6px 14px; border-radius: 16px; font-size: 13px; font-weight: 650;
  text-decoration: none; white-space: nowrap;
}
header .book-cta:hover { background: rgba(255,255,255,.26); }
header .doc-logo { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; margin-right: 10px; }
.doc-footer { color: #78716c; font-size: 12.5px; margin-top: 18px; border-top: 1px solid #e7e5e4; padding-top: 10px; }
/* `anywhere`, not `break-all`: a URL moves whole to the next line when it
   fits and only splits when it is wider than the bubble on its own, so a
   hostname never wraps as "makerbay.a pp" (tester finding V3). */
.msg.bot a { color: var(--brand); font-weight: 600; text-decoration: underline; overflow-wrap: anywhere; word-break: normal; }

/* Identity lockup + quick actions + instant cards */
header .avatar.photo { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }
header .who { min-width: 0; }
header .who .name { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header .who .sub { font-size: 11.5px; opacity: .85; }
/* A horizontal scroller on purpose (eight chips would take three rows of a
   380px bubble). The scrollbar is hidden, so the fade at the right edge and
   the trailing space are what say "there is more" (tester finding V2). */
.chips {
  display: flex; gap: 8px; padding: 8px 12px 0; overflow-x: auto; flex-shrink: 0; scrollbar-width: none;
  scroll-snap-type: x proximity;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent);
}
.chips::-webkit-scrollbar { display: none; }
.chips::after { content: ''; flex: none; width: 24px; }
.chip { scroll-snap-align: start; }
.chip {
  flex: none; border: 1px solid var(--border); background: #fff; color: var(--text);
  border-radius: 16px; padding: 6px 13px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip:hover { border-color: var(--brand); color: var(--brand); }
.msg.card { background: #fff; border: 1px solid var(--border); max-width: 92%; }
.card-title { font-weight: 700; font-size: 13px; margin-bottom: 8px; }
.svc-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--border); }
.svc-nm { font-weight: 600; font-size: 14px; }
.svc-ds { color: var(--muted); font-size: 12.5px; }
.svc-pr { white-space: nowrap; font-size: 13px; color: var(--text); }
.hrs-row { display: flex; justify-content: space-between; gap: 14px; padding: 3px 0; font-size: 13.5px; }
.hrs-row span:first-child { font-weight: 600; }
.open-label { color: #15803d; font-weight: 650; font-size: 13px; margin-bottom: 6px; }
.about-p { font-size: 13.5px; margin: 4px 0 6px; white-space: pre-wrap; }
/* Cards are .msg.bot bubbles, so the answer-link rule (.msg.bot a, brand
   text) outranks a bare class - these selectors must match its specificity
   or the button becomes brand-on-brand and disappears (issue 44). */
.card-act,
.msg.bot a.card-act {
  display: inline-block; margin: 10px 8px 0 0; background: var(--brand); color: var(--brand-fg, #fff);
  border-radius: 8px; padding: 8px 14px; font-size: 13px; font-weight: 650; text-decoration: none;
}
.card-act.ghosted,
.msg.bot a.card-act.ghosted { background: transparent; color: var(--brand); border: 1px solid var(--border); }
