/* Components. Every colour, font and size comes from tokens.css. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body); font-size: var(--step-0); line-height: 1.5;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: var(--step--1); }
.error { color: var(--danger); margin: 0; min-height: 0; }
.error:empty { display: none; }

.app, .gate { max-width: 560px; margin: 0 auto; padding-left: max(var(--space-4), env(safe-area-inset-left, 0px)); padding-right: max(var(--space-4), env(safe-area-inset-right, 0px)); }
.brand { font-family: var(--display); font-weight: 700; font-size: var(--step-1); margin: 0; letter-spacing: 0.01em; }

/* gate */
.gate { min-height: 100svh; display: grid; place-items: center; padding-block: var(--space-6); }
.gate-card { width: 100%; display: grid; gap: var(--space-3); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: var(--space-5); }
.gate-title { font-family: var(--display); font-size: var(--step-3); line-height: 1.15; margin: var(--space-2) 0 0; text-wrap: balance; font-weight: 600; }
.gate-card p { margin: 0; }

/* header */
.top { display: flex; align-items: center; gap: var(--space-3); padding-block: var(--space-4) var(--space-2); }
.badge, .quota { white-space: nowrap; }
.badge { font-family: var(--data); font-size: var(--step--1); color: var(--accent); border: 1px solid var(--accent); border-radius: var(--radius-pill); padding: 0 var(--space-2); }
.quota { margin-left: auto; font-family: var(--data); font-size: var(--step--1); background: transparent; border: 1px solid var(--line); border-radius: var(--radius-pill); padding: var(--space-1) var(--space-3); color: var(--muted); cursor: pointer; }
.quota[data-state="low"] { color: var(--accent); border-color: var(--accent); }
.quota[data-state="out"] { color: var(--danger); border-color: var(--danger); }

/* hero + globe */
.hero { position: relative; margin-inline: calc(-1 * var(--space-2)); }
.globe-box { position: relative; width: 100%; aspect-ratio: 1 / 1; max-width: 100%; max-height: 520px; margin: 0 auto; }
.globe-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.hero-text { position: relative; margin-top: calc(-1 * var(--space-5)); padding-inline: var(--space-2); display: grid; gap: var(--space-1); }
.kicker { margin: 0; font-family: var(--data); font-size: var(--step--1); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.headline { margin: 0; font-family: var(--display); font-weight: 600; font-size: var(--step-2); line-height: 1.2; text-wrap: balance; }

/* panels + forms */
.panel { margin-top: var(--space-5); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: var(--space-4); display: grid; gap: var(--space-4); }
.fields { border: 0; margin: 0; padding: 0; display: grid; gap: var(--space-3); min-width: 0; }
legend { font-family: var(--data); font-size: var(--step--1); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding: 0; margin-bottom: var(--space-2); }
.field { display: grid; gap: var(--space-1); min-width: 0; }
.field.grow { flex: 1 1 200px; }
label { font-size: var(--step--1); color: var(--muted); }
input, select { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 10px var(--space-3); min-height: 44px; }
input::placeholder { color: var(--muted); opacity: 0.8; }
input[type="date"] { color-scheme: dark; }
.row-2 { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.row-2 > .field { flex: 1 1 140px; }
.row-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-pill); padding: 3px; gap: 2px; justify-self: start; max-width: 100%; }
.seg button { border: 0; background: transparent; border-radius: var(--radius-pill); padding: var(--space-2) var(--space-4); cursor: pointer; color: var(--muted); min-height: 40px; }
.seg button[aria-pressed="true"] { background: var(--surface-raised); color: var(--ink); font-weight: 600; }
.seg button[aria-disabled="true"] { opacity: 0.55; text-decoration: line-through; text-decoration-thickness: 1px; cursor: not-allowed; }
.seg.small button { padding: var(--space-1) var(--space-3); min-height: 36px; font-size: var(--step--1); }

.button { border-radius: var(--radius-pill); padding: 10px var(--space-5); min-height: 44px; cursor: pointer; border: 1px solid var(--line); background: transparent; }
.button.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 600; }
.button.primary[disabled] { opacity: 0.6; cursor: progress; }
.button.ghost { color: var(--ink); }
.button.wide { width: 100%; }
.icon-button { margin-left: auto; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: transparent; font-size: var(--step-2); line-height: 1; cursor: pointer; }

/* group homes */
.homes { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-2); }
.homes:empty::before { content: "No homes yet. Add each person's city below."; color: var(--muted); font-size: var(--step--1); }
.home-chip { display: inline-flex; align-items: center; gap: var(--space-2); font-family: var(--data); font-size: var(--step--1); border: 1px solid var(--line); border-radius: var(--radius-pill); padding: 2px 2px 2px var(--space-3); background: var(--bg); }
.home-chip i { width: 9px; height: 9px; border-radius: 50%; display: block; flex: none; }
.home-chip button { border: 0; background: transparent; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; color: var(--muted); font-size: var(--step-1); line-height: 1; }

/* combobox suggestions */
.combo { position: relative; }
.suggest { position: absolute; z-index: 5; top: 100%; left: 0; right: 0; margin: var(--space-1) 0 0; padding: var(--space-1); list-style: none; background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-m); max-height: 280px; overflow-y: auto; }
.suggest li { padding: var(--space-2) var(--space-3); border-radius: var(--radius-s); cursor: pointer; display: flex; gap: var(--space-3); align-items: baseline; }
.suggest li b { font-family: var(--data); color: var(--accent); font-weight: 500; flex: none; }
.suggest li span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--line); }

/* results */
.results-section { margin-top: var(--space-6); display: grid; gap: var(--space-3); }
.results-head { display: grid; gap: var(--space-1); }
.section-title { font-family: var(--display); font-weight: 600; font-size: var(--step-1); margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.filters .field { flex: 1 1 130px; }
.filters select, .filters input { min-height: 40px; padding-block: 6px; }
.check { display: flex; gap: var(--space-2); align-items: center; font-size: var(--step--1); color: var(--ink); flex: 1 1 100%; }
.check input { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
.results { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.result { width: 100%; text-align: left; cursor: pointer; background: transparent; border: 1px solid transparent; border-radius: var(--radius-m);
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "dot place price" "dot meta price"; column-gap: var(--space-3); align-items: center; padding: var(--space-3); }
.result:hover { background: var(--surface); }
.result[aria-current="true"] { background: var(--surface); border-color: var(--line); }
.r-dot { grid-area: dot; width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--arc); }
.result[aria-current="true"] .r-dot { background: var(--arc); }
.r-place { grid-area: place; min-width: 0; }
.r-city { font-weight: 600; }
.r-country { color: var(--muted); font-size: 0.875rem; }
.r-meta { grid-area: meta; font-family: var(--data); font-size: var(--step--1); color: var(--muted); font-variant-numeric: tabular-nums; }
.r-price { grid-area: price; font-family: var(--data); font-variant-numeric: tabular-nums; font-weight: 600; color: var(--accent); font-size: var(--step-1); text-align: right; display: grid; justify-items: end; }
.r-price small { font-size: 0.6875rem; font-weight: 400; color: var(--muted); }
.bars { display: flex; gap: 2px; margin-top: 6px; height: 16px; align-items: flex-end; }
.bars i { width: 7px; border-radius: 2px 2px 0 0; display: block; }
.empty { margin: 0; padding: var(--space-5); border: 1px dashed var(--line); border-radius: var(--radius-m); color: var(--muted); text-align: center; }
.notice { margin: 0; padding: var(--space-3); border: 1px solid var(--accent); border-radius: var(--radius-m); color: var(--ink); background: var(--surface-raised); }
.foot { color: var(--muted); font-size: var(--step--1); padding-block: var(--space-6) var(--space-5); margin: 0; }

/* dialogs as bottom sheets on phones */
.sheet { width: min(560px, 100%); max-height: 88svh; margin: auto auto 0; border: 1px solid var(--line); border-bottom: 0; border-radius: var(--radius-l) var(--radius-l) 0 0; background: var(--surface); color: var(--ink); padding: var(--space-4) max(var(--space-4), env(safe-area-inset-right, 0px)) calc(var(--space-5) + env(safe-area-inset-bottom, 0px)) max(var(--space-4), env(safe-area-inset-left, 0px)); overflow-y: auto; }
@media (min-width: 640px) { .sheet { margin: auto; border-radius: var(--radius-l); border-bottom: 1px solid var(--line); } }
.sheet::backdrop { background: var(--bg); opacity: 0.75; }
.sheet-head { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.key-form { display: grid; gap: var(--space-3); }
.key-form p { margin: 0; }
.stats { display: grid; grid-template-columns: auto 1fr; gap: var(--space-1) var(--space-4); margin: 0; font-size: var(--step--1); }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-family: var(--data); font-variant-numeric: tabular-nums; }

/* detail */
.fare-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.fare-table th, .fare-table td { text-align: left; padding: var(--space-2) var(--space-2) var(--space-2) 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
.fare-table th { font-family: var(--data); font-size: var(--step--1); color: var(--muted); font-weight: 400; text-transform: uppercase; letter-spacing: 0.06em; }
.fare-table td.num { font-family: var(--data); text-align: right; }
.fare-table i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: var(--space-2); }
.table-wrap { overflow-x: auto; }
.options { list-style: none; padding: 0; margin: var(--space-3) 0; display: grid; gap: var(--space-2); }
.option { border: 1px solid var(--line); border-radius: var(--radius-m); padding: var(--space-3); display: grid; gap: var(--space-1); }
.option-top { display: flex; justify-content: space-between; gap: var(--space-3); font-weight: 600; }
.option-top span:last-child { font-family: var(--data); color: var(--accent); }
.detail-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }
.link-button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

/* home colours as classes (inline style attributes are blocked by the CSP) */
.hc-1 { background: var(--h1); }
.hc-2 { background: var(--h2); }
.hc-3 { background: var(--h3); }
.hc-4 { background: var(--h4); }
.hc-5 { background: var(--h5); }
.hc-6 { background: var(--h6); }
.hc-7 { background: var(--h7); }
.hc-8 { background: var(--h8); }
.hc-9 { background: var(--h9); }
.hc-10 { background: var(--h10); }
.hc-11 { background: var(--h11); }
.hc-12 { background: var(--h12); }
.bars i.none { background: var(--line); }
