/* AVM demo web app — Geomatic brand styling.
   Colours are the Klima design tokens reused by the Streamlit app
   (avm/app/lookup.py): brand blue #0089cf, ink #2d2d2d, divider #bbbdc0. */

:root {
  --brand-blue: #0089cf;
  --ink: #2d2d2d;
  --ink-soft: #3e3e3e;
  --divider: #bbbdc0;
  --muted: #57606a;
  --border: #e3e6ea;
  --surface: #ffffff;
  --page-bg: #f6f8fa;
  --green: #1a7f37;
  --amber: #9a6700;
  --red: #b42318;
  --neutral: #57606a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(27, 31, 36, 0.06), 0 3px 8px rgba(27, 31, 36, 0.04);
}

* { box-sizing: border-box; }

/* Class rules below set `display` on elements that are toggled with the
   `hidden` attribute (e.g. `.confidence-row { display: flex }`), and a class
   selector outranks the UA stylesheet's `[hidden]`. Restate it, once. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page-bg);
  color: var(--ink);
  font-family: 'Lato', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 0.9rem 0;
}

/* --- Accessibility helpers ------------------------------------------- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--surface);
  color: var(--ink);
  padding: 0.6rem 1rem;
  z-index: 1000;
  border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; }

:focus-visible {
  outline: 3px solid var(--brand-blue);
  outline-offset: 2px;
}

/* --- Masthead --------------------------------------------------------- */

.masthead {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.masthead-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.1rem 1.5rem 0.9rem 1.5rem;
  position: relative;
}

/* Session chip (#70529): who is signed in, and the way out. */
.session-chip {
  position: absolute;
  right: 1.5rem;
  top: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.session-name { font-weight: 600; color: var(--ink); }

.btn-primary,
.btn-outline {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
}
.btn-primary {
  color: #fff;
  background: var(--brand-blue);
  border: 1px solid var(--brand-blue);
}
.btn-primary:disabled { opacity: 0.6; cursor: progress; }
.btn-outline {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--divider);
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

/* Sign-in card (#70529): stands in for the search until a session exists. */
.auth-card { max-width: 440px; margin: 2.5rem auto 0; }
.auth-sub { margin: 0 0 1.1rem; font-size: 0.9rem; color: var(--muted); }
.auth-field-gap { margin-top: 0.85rem; }
.auth-error { margin: 0.6rem 0 0; }
.auth-submit { width: 100%; margin-top: 1rem; }

@media (max-width: 640px) {
  .session-chip { position: static; margin-top: 0.5rem; }
}

.wordmark {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.wordmark-brand {
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.1;
}
.brand-geo { color: var(--brand-blue); }
.brand-matic { color: var(--ink); }

.wordmark-pipe {
  color: var(--divider);
  font-size: 1.7rem;
  font-weight: 300;
}

.wordmark-product {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0.14em;
}

.masthead-caption {
  margin: 0.35rem 0 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* --- Page layout ------------------------------------------------------ */

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.1rem;
}

/* The answer sits across the top, full width, as a pair: the valuation on
   the left at a third, the map beside it at two thirds. Everything below —
   comparables, property facts, imagery, and the confidence grounding last —
   runs full width underneath.

   The two share a row rather than a column, so the map gets the width a map
   actually needs while the number stays beside it rather than under it. */
#summary-column {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 1.1rem;
  /* Stretch, not start: equal-height cards read as one unit, and the map
     sets the row height so the valuation card squares up beside it. */
  align-items: stretch;
  /* Their spacing is the grid gap; this margin separates the pair from the
     cards below (the children's own margin is dropped for that reason). */
  margin-bottom: 1.1rem;
}

#summary-column > .card {
  margin-bottom: 0;
}

/* Let the map fill its stretched card instead of sitting at a fixed height
   inside it — height:auto releases the 400px from .map so flex can grow. */
#panel-map {
  display: flex;
  flex-direction: column;
}

#panel-map .map {
  height: auto;
  flex: 1 1 auto;
  min-height: 340px;
}

.page-footer {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 1.5rem 2.5rem 1.5rem;
  color: var(--muted);
  font-size: 0.8rem;
}
.page-footer p { margin: 0; }

/* --- Search ----------------------------------------------------------- */

.field-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
  color: var(--ink);
}

.combo { position: relative; }

.address-input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
}
.address-input::placeholder { color: #8b949e; }

.suggestions {
  position: absolute;
  z-index: 500;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(27, 31, 36, 0.12);
  max-height: 320px;
  overflow-y: auto;
}

.suggestion {
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
}
.suggestion[aria-selected="true"],
.suggestion:hover {
  background: #eaf5fb;
  color: #05506f;
}

.hint {
  margin: 0.4rem 0 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.status-line {
  margin: 0.5rem 0 0 0;
  font-size: 0.9rem;
  color: var(--muted);
  min-height: 1.2em;
}
.status-line.error { color: var(--red); font-weight: 600; }

.unit-picker { margin-top: 1rem; }

.unit-select {
  width: 100%;
  max-width: 420px;
  padding: 0.55rem 0.7rem;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
}


/* --- Valuation -------------------------------------------------------- */

.metric-label {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.metric-value {
  margin: 0.15rem 0 0 0;
  font-size: 2.35rem;
  font-weight: 800;
  line-height: 1.15;
  color: var(--ink);
}

.metric-small {
  margin: 0.1rem 0 0.8rem 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
}

.metric-interval {
  margin: 0.3rem 0 0 0;
  font-size: 1rem;
  color: var(--muted);
  font-weight: 600;
}

.confidence-row {
  margin: 0.9rem 0 0 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.confidence-label { font-size: 0.95rem; }

.pill {
  display: inline-block;
  color: #ffffff;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.9em;
  font-weight: 600;
  white-space: nowrap;
  cursor: help;
}
.pill--green { background: var(--green); }
.pill--amber { background: var(--amber); }
.pill--red { background: var(--red); }
.pill--neutral { background: var(--neutral); }

.advisory {
  margin: 0.9rem 0 0 0;
  padding: 0.6rem 0.8rem;
  border-left: 4px solid var(--amber);
  background: #fff8e6;
  color: #6b4b00;
  border-radius: 0 6px 6px 0;
  font-size: 0.92rem;
}

.stale-note {
  margin: 0.7rem 0 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.provenance {
  margin: 1rem 0 0 0;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
}

.notice {
  margin: 0;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #f2f5f7;
  color: var(--ink);
  font-size: 0.95rem;
}
.notice strong { display: block; margin-bottom: 0.25rem; }
.notice--decline { border-left: 4px solid var(--neutral); }
.notice--warning { border-left: 4px solid var(--amber); background: #fff8e6; color: #6b4b00; }
.notice--error { border-left: 4px solid var(--red); background: #fdf1f0; color: #7a1c14; }
.notice-detail { margin: 0.4rem 0 0 0; font-size: 0.85rem; color: inherit; opacity: 0.85; }

/* --- Key/value lists --------------------------------------------------- */

.kv-list { margin: 0; }

.kv-row {
  display: grid;
  grid-template-columns: minmax(140px, 220px) 1fr;
  gap: 0.75rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
}
.kv-row:last-child { border-bottom: 0; }

.kv-row dt { font-weight: 600; color: var(--muted); font-size: 0.9rem; }
.kv-row dd { margin: 0; color: var(--ink); overflow-wrap: anywhere; }

.kv-inline { margin-top: 0.9rem; }

/* --- Prisdrivere -------------------------------------------------------
   Split two-up, following MAO's mockup: what lifts the price on the left,
   what lowers it on the right. Proportional bars are the mockup's too; its
   HIGH/MEDIUM/LOW IMPACT tags are deliberately NOT copied, since that is a
   customer-facing classification whose thresholds nobody has ratified. */

.drivers-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem 2rem;
}

.col-header {
  margin: 0 0 0.7rem 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.col-header.pos { color: var(--green); }
.col-header.neg { color: var(--red); }

.driver-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.driver {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}
.driver:last-child { border-bottom: 0; }

.driver-main { min-width: 0; }

.driver-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
}

.driver-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.driver-pct {
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
}
.driver-pct.pos { color: var(--green); }
.driver-pct.neg { color: var(--red); }

/* A `?` on a draft label the packet itself is unsure of. */
.driver-unsure {
  color: var(--amber);
  font-weight: 800;
  cursor: help;
}

.driver-detail {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Scaled against the widest effect on this card, not against an absolute
   percentage — otherwise a property whose drivers are all small shows four
   invisible bars. */
.driver-bar-track {
  height: 4px;
  margin-top: 0.4rem;
  background: #f0f2f4;
  border-radius: 2px;
  overflow: hidden;
}
.driver-bar { height: 100%; border-radius: 2px; }
.driver-bar.pos { background: var(--green); }
.driver-bar.neg { background: var(--red); }

.driver-empty {
  padding: 0.55rem 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-style: italic;
}

/* Ruling 8 in one line, so the split grid does not cost the reconciliation. */
.drivers-recon {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem 0.6rem;
  margin-top: 1.1rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--muted);
}
.recon-aggregates { color: var(--muted); }
.recon-subject {
  font-weight: 800;
  font-size: 1rem;
  color: var(--ink);
}

/* Loud on purpose. While this shows, the labels are machine keys and have
   not been through gate 3b — it must not be mistaken for approved copy. */
.drivers-internal {
  margin: 0 0 0.9rem 0;
  padding: 0.5rem 0.75rem;
  border-left: 4px solid var(--red);
  background: #fdf2f0;
  color: #7a1c12;
  font-size: 0.82rem;
  font-weight: 600;
}

/* --- Property header --------------------------------------------------
   The address, with the register facts read straight underneath it. The
   shape is from MAO's "VERA — future" mockup: a flowing row of small
   label-over-value items rather than a list, so a whole property fits in
   two lines above the valuation instead of a panel further down. */

.property-header {
  padding-bottom: 1rem;
}

.property-address {
  margin: 0 0 0.75rem 0;
  font-size: 1.28rem;
  font-weight: 700;
  color: var(--ink);
}

.property-meta {
  display: flex;
  flex-wrap: wrap;
  /* Generous column gap, tight row gap: the items are short, and the eye
     should read across before it reads down. */
  gap: 0.7rem 2rem;
  margin: 0;
}

.property-meta .kv-row {
  display: block;
  grid-template-columns: none;
  padding: 0;
  border-bottom: 0;
}

.property-meta .kv-row dt {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.property-meta .kv-row dd {
  margin-top: 0.1rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
}

.caption {
  margin: 0.8rem 0 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}
.caption:empty { display: none; }

/* --- Comps table ------------------------------------------------------- */

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.data-table th,
.data-table td {
  padding: 0.55rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th {
  font-weight: 700;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  border-bottom: 2px solid var(--border);
}
.data-table td.num, .data-table th.num { text-align: right; }
.data-table td.addr { white-space: normal; min-width: 220px; }
.data-table tbody tr:hover { background: #f6f9fb; }

/* --- Photos ------------------------------------------------------------ */

.photo-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.2rem;
  align-items: start;
}

.ortho-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
}

.photo { margin: 0; }
.photo img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #eef1f4;
}

.photo-caption {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
  color: var(--ink);
}

.photo-meta { min-width: 0; }

/* --- Map --------------------------------------------------------------- */

.map {
  height: 400px;
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #eef1f4;
}

/* --- Responsive -------------------------------------------------------- */

@media (max-width: 900px) {
  .photo-layout { grid-template-columns: 1fr; }
  /* Not enough width to put a number and a map side by side — stack them,
     valuation first. */
  #summary-column { grid-template-columns: 1fr; }
  #summary-column > .card { margin-bottom: 1.1rem; }
  #summary-column { margin-bottom: 0; }
  #panel-map .map { min-height: 300px; }
}

@media (max-width: 700px) {
  .ortho-grid { grid-template-columns: 1fr; }
  .metric-value { font-size: 1.9rem; }
  .kv-row { grid-template-columns: 1fr; gap: 0.1rem; }
  .drivers-grid { grid-template-columns: 1fr; }
  /* The facts row wraps on its own, but tighten its gaps so a phone gets
     two or three per line instead of one. */
  .property-meta { gap: 0.6rem 1.2rem; }
  .property-address { font-size: 1.12rem; }
  .page { padding: 1rem; }
  .wordmark-brand { font-size: 1.7rem; }
}
