/* Components. Every color/type value comes from themes.css tokens. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 var(--font-body);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: env(safe-area-inset-top, 0px) env(safe-area-inset-bottom, 0px);
}
h1, h2, h3 { font-family: var(--font-display); line-height: 1.2; text-wrap: balance; margin: 0; font-weight: var(--display-weight, 600); }
h1 { font-size: clamp(1.6rem, 4vw, 2.1rem); }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

.wrap { max-width: 640px; margin: 0 auto; padding-block: 16px 64px; display: grid; gap: 16px; }
.wrap.wide { max-width: 1120px; }
.eyebrow { font: 600 .75rem/1.2 var(--font-label); text-transform: var(--label-case); letter-spacing: var(--label-track); color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1 1 200px; min-width: 0; }
.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }

/* header */
.masthead { display: grid; justify-items: center; gap: 6px; text-align: center; padding-top: 8px; }
.masthead img { width: 200px; max-width: 65%; height: auto; border-radius: 6px; }
.masthead .tag { font-style: italic; color: var(--brand); }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar .brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.topbar .brand img { width: 44px; height: 44px; object-fit: cover; object-position: top; border-radius: 10px; }
.topbar .brand b { font-family: var(--font-display); font-size: 1.15rem; }

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); display: grid; gap: 12px; min-width: 0; }
.card > header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.step { display: flex; align-items: baseline; gap: 10px; }
.step .n { font: 600 .8rem/1 var(--font-label); color: var(--on-brand); background: var(--brand); border-radius: 999px; width: 24px; height: 24px; display: inline-grid; place-items: center; flex: none; transform: translateY(-2px); }
.sub { padding: 12px; border: 1px dashed var(--line); border-radius: var(--radius-sm); display: grid; gap: 10px; }

/* controls */
.btn { min-height: 44px; padding: 10px 16px; border-radius: var(--radius-sm); border: 2px solid var(--brand); background: var(--surface); color: var(--ink); font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn.primary { background: var(--brand); color: var(--on-brand); }
.btn.ghost { border-color: var(--line); }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:not(:disabled):hover { filter: brightness(1.06); }
label, .label { font-weight: 600; font-size: .9rem; display: grid; gap: 4px; }
label .hint { font-weight: 400; color: var(--muted); font-size: .82rem; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); color: var(--ink);
}
textarea { min-height: 80px; resize: vertical; }
input[aria-invalid=true], select[aria-invalid=true], textarea[aria-invalid=true] { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.check input { width: 22px; height: 22px; margin: 2px 0 0; flex: none; accent-color: var(--brand); }

/* choice tiles (services, payment) */
.choices { display: grid; gap: 8px; }
.choices.cols { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.choice { text-align: left; border: 2px solid var(--line); background: var(--surface); border-radius: var(--radius-sm); padding: 12px 14px; cursor: pointer; display: grid; gap: 2px; min-height: 44px; }
.choice[aria-pressed=true] { border-color: var(--brand); background: var(--surface-2); }
.choice .t { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; }
.choice .p { font-variant-numeric: tabular-nums; color: var(--brand); white-space: nowrap; }
.choice small { color: var(--ink-2); }
.choice .save { color: var(--good); font-size: .8rem; font-weight: 700; }

/* calendar */
.calnav { display: flex; justify-content: space-between; align-items: center; }
.calnav button { min-width: 44px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal .dow { font-size: .75rem; color: var(--muted); padding-bottom: 2px; }
.cal button { min-height: 44px; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 0; position: relative; cursor: pointer; font-variant-numeric: tabular-nums; }
.cal button.in { background: var(--surface-2); border-color: var(--brand); }
.cal button.sel { background: var(--brand); color: var(--on-brand); font-weight: 700; border-color: var(--brand); }
.cal button.today { box-shadow: inset 0 0 0 1px var(--accent); }
.cal button:disabled { opacity: .35; cursor: not-allowed; text-decoration: line-through; }
.cal button .dots { position: absolute; left: 0; right: 0; bottom: 4px; display: flex; justify-content: center; gap: 2px; }
.cal button .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--good); display: block; }
.cal button .dots i.req { background: var(--warn); }
.cal button.blk { background: repeating-linear-gradient(135deg, var(--surface-2) 0 4px, var(--surface) 4px 8px); }

/* totals */
.total { display: grid; gap: 4px; padding: 14px; border-radius: var(--radius-sm); background: var(--surface-2); }
.total .big { font: 700 1.6rem/1.1 var(--font-display); color: var(--brand); font-variant-numeric: tabular-nums; }
.callout { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--good-soft); color: var(--ink); border: 1px solid var(--good); font-size: .92rem; }
.callout.warn { background: var(--warn-soft); border-color: var(--warn); }
.callout.bad { background: var(--bad-soft); border-color: var(--bad); }
.msg { min-height: 1.4em; font-size: .92rem; }
.msg.err { color: var(--bad); }
.msg.ok { color: var(--good); }

/* status pills — shape + label, never color alone */
.pill { display: inline-flex; align-items: center; gap: 6px; font: 600 .75rem/1 var(--font-label); padding: 5px 9px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.requested, .pill.reported, .pill.warn { color: var(--warn); background: var(--warn-soft); }
.pill.confirmed, .pill.succeeded, .pill.done, .pill.good { color: var(--good); background: var(--good-soft); }
.pill.completed, .pill.scheduled { color: var(--accent); background: var(--accent-soft); }
.pill.declined, .pill.cancelled, .pill.failed, .pill.refunded, .pill.skipped { color: var(--muted); background: transparent; }
.pill.bad { color: var(--bad); background: var(--bad-soft); }

/* lists */
.list { display: grid; }
.item { padding: 14px 0; border-top: 1px solid var(--line); display: grid; gap: 6px; min-width: 0; }
.item:first-child { border-top: 0; }
.item .head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.item .meta { color: var(--ink-2); font-size: .9rem; overflow-wrap: anywhere; }
.item .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.empty { padding: 20px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius-sm); }

/* admin shell */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs button { border: 0; background: none; padding: 12px 14px; min-height: 44px; cursor: pointer; color: var(--ink-2); font-weight: 600; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button[aria-selected=true] { color: var(--ink); border-bottom-color: var(--brand); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 4px; }
.kpi .v { font: 600 1.5rem/1.1 var(--font-display); font-variant-numeric: tabular-nums; }
.kpi .s { font-size: .82rem; color: var(--muted); }
.kpi.attn { border-color: var(--warn); background: var(--warn-soft); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 16px; align-items: start; }

/* route / visit timeline */
.visit { display: grid; grid-template-columns: 64px 1fr; gap: 12px; padding: 14px 0; border-top: 1px solid var(--line); }
.visit:first-child { border-top: 0; }
.visit .time { font: 600 1rem/1.2 var(--font-display); font-variant-numeric: tabular-nums; }
.visit .time small { display: block; font: 400 .75rem var(--font-label); color: var(--muted); text-transform: var(--label-case); letter-spacing: var(--label-track); }
.visit.done .body { opacity: .65; }

/* charts */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font: 11px var(--font-label); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .bar { fill: var(--chart); }
.chart .bar.cur { fill: var(--chart); }
.chart .bar.past { fill: var(--chart-soft); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart g:hover .bar { filter: brightness(1.15); }
.tip { position: fixed; pointer-events: none; background: var(--ink); color: var(--bg); padding: 6px 9px; border-radius: 6px; font-size: .82rem; z-index: 20; white-space: nowrap; }
.hbar { display: grid; grid-template-columns: 90px 1fr auto; gap: 10px; align-items: center; font-size: .9rem; }
.hbar .track, .hbar .fill { display: block; }
.hbar .track { height: 12px; background: var(--surface-2); border-radius: 0 4px 4px 0; }
.hbar .fill { height: 100%; background: var(--chart); border-radius: 0 4px 4px 0; min-width: 2px; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.data td.r, table.data th.r { text-align: right; font-variant-numeric: tabular-nums; }
.scroll { overflow-x: auto; }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; min-height: 32px; }

.toast { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 30; max-width: calc(100% - 32px); }
.foot { text-align: center; color: var(--muted); font-size: .82rem; }

.terms { max-height: 180px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; font-size: .88rem; display: grid; gap: 8px; background: var(--bg); }
.preview { max-width: 100%; max-height: 220px; border-radius: var(--radius-sm); justify-self: start; }
