/* Consulta PDM · AI for Architects
   Layout: top bar, centred headline, large map with the search on it, results below in one column.
   Palette from the brand: graphite and brushed gold. */
:root {
  --bg: #f3efe6;
  --surface: #ffffff;
  --sunk: #eee9df;
  --fg: #1b1e21;
  --fg-2: #3b4045;
  --muted: #6a6e72;
  --line: #e1dbcf;
  --brand: #1c2023;
  --brand-2: #262b2f;
  --on-brand: #efe8da;
  --gold: #8b6b2f;          /* gold for text and lines on light surfaces */
  --gold-bright: #c9a464;   /* gold on the graphite brand band */
  --gold-soft: #f3ead6;
  --ok: #2f7d4f;
  --warn: #9a6a00;
  --bad: #b3382c;
  --plot: #e0b04f;
  --display: "Barlow", "Inter", system-ui, sans-serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a; --surface: #1c2023; --sunk: #22272b; --fg: #ece7dc; --fg-2: #cbc5b9; --muted: #9b968c;
    --line: #333a3f; --gold: #d2b072; --gold-soft: #2b2619; --ok: #6cc08e; --warn: #e2b54a; --bad: #ec7a6c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 400 14px/1.55 var(--body); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: -0.01em; text-wrap: balance; margin: 0; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
a { color: var(--gold); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--fg); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
p { margin: 0; }

/* ---------- layout ---------- */
.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding-left: 20px; padding-right: 20px; }
.content { max-width: 1180px; display: flex; flex-direction: column; gap: 28px; padding-top: 8px; padding-bottom: 40px; }
.content > * { max-width: 900px; width: 100%; }

/* ---------- top bar and headline ---------- */
.topbar { background: var(--brand); border-bottom: 1px solid #000; position: sticky; top: 0; z-index: 900; }
.topbar-in { display: flex; align-items: center; gap: 12px; height: 60px; }
.topbar .brand-link img { display: block; width: 38px; height: 38px; border-radius: 4px; box-shadow: 0 0 0 1px rgba(201, 164, 100, 0.4); }
.brand-text h1 { font-size: 1.15rem; font-weight: 700; line-height: 1.1; color: #fff; letter-spacing: 0.02em; }
.brand-text p { font-size: 0.72rem; color: #b9b2a3; }
.brand-text p a { color: var(--gold-bright); font-weight: 600; text-decoration: none; }
.brand-text p a:hover { text-decoration: underline; }
.topnav { margin-left: auto; display: flex; gap: 22px; font-size: 0.85rem; }
.topnav a { color: #d8d1c2; text-decoration: none; font-weight: 500; letter-spacing: 0.03em; }
.topnav a:hover { color: var(--gold-bright); }
.hero { background-color: var(--brand); color: var(--on-brand);
  background-image: linear-gradient(rgba(201, 164, 100, 0.07) 1px, transparent 1px), linear-gradient(90deg, rgba(201, 164, 100, 0.07) 1px, transparent 1px);
  background-size: 32px 32px; border-bottom: 3px solid var(--gold-bright); }
.hero-in { display: grid; gap: 14px; padding-top: 44px; padding-bottom: 36px; max-width: 1180px; }
.kicker { font: 600 0.72rem var(--body); letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold-bright); }
.hero h2 { font-size: clamp(2rem, 5vw, 3.4rem); font-weight: 700; line-height: 1.04; color: #fff; letter-spacing: -0.015em; }
.hero .lead { color: #c9c2b3; max-width: 560px; font-size: 1rem; }
.facts { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 26px; font-size: 0.82rem; color: #b9b2a3; }
.facts strong { color: var(--gold-bright); font-weight: 600; }

/* ---------- map ---------- */
.stage { display: grid; gap: 10px; padding-top: 24px; padding-bottom: 22px; scroll-margin-top: 66px; }
.map-card { position: relative; height: clamp(420px, 60vh, 660px); border: 1px solid var(--brand); border-top: 3px solid var(--gold-bright); border-radius: 4px; overflow: hidden; background: var(--sunk); box-shadow: 8px 8px 0 rgba(28, 32, 35, 0.08); }
.map-stack { position: absolute; inset: 0; }
#map { position: absolute; inset: 0; background: var(--sunk); }
.map-pill { position: absolute; z-index: 500; left: 12px; bottom: 12px; max-width: calc(100% - 24px); background: var(--brand); color: var(--on-brand); border-radius: 3px; padding: 6px 12px; font: 500 0.76rem var(--body); letter-spacing: 0.03em; pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.stage-bar strong { color: var(--fg); font-weight: 600; }
#results { scroll-margin-top: 76px; padding-top: 14px; }
.back-map { align-self: flex-start; font-size: 0.85rem; font-weight: 500; text-decoration: none; margin-bottom: 4px; }
.back-map:hover { text-decoration: underline; }

/* ---------- controls ---------- */
.label, .eyebrow, .sublabel { font: 600 0.7rem/1.3 var(--body); text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.eyebrow { color: var(--gold); }
.sublabel { margin-top: 4px; }
.hint { color: var(--muted); font-size: 0.82rem; }
input, textarea, select { font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 9px 11px; min-width: 0; width: 100%; }
input:focus, textarea:focus, select:focus { border-color: var(--gold); outline: none; box-shadow: 0 0 0 3px var(--gold-soft); }
textarea { resize: vertical; min-height: 80px; }
.btn { font: 600 0.8rem/1 var(--body); letter-spacing: 0.04em; cursor: pointer; white-space: nowrap; background: var(--brand); color: #fff; border: 1px solid var(--brand); border-radius: var(--r); padding: 10px 16px; transition: background 0.15s, border-color 0.15s; }
.btn:hover { background: #000; border-color: var(--gold-bright); }
.btn[disabled] { opacity: 0.5; cursor: progress; }
.btn.ghost { background: var(--surface); color: var(--fg); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--gold); }
.btn.small { padding: 7px 11px; font-size: 0.75rem; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.between { justify-content: space-between; }
.links-inline { gap: 16px; font-size: 0.85rem; }

.search { position: relative; z-index: 700; width: min(620px, 100%); display: flex; flex-direction: column; margin-top: 8px; }
.search-row { display: flex; gap: 0; background: #fff; border-radius: 3px; box-shadow: 6px 6px 0 rgba(201, 164, 100, 0.35); }
.search-row input { border: 0; border-radius: 3px 0 0 3px; box-shadow: none !important; background: transparent; padding: 15px 16px; font-size: 1rem; }
.search-row .btn { border-radius: 0 3px 3px 0; padding: 0 22px; background: var(--gold-bright); color: var(--brand); border-color: var(--gold-bright); font-size: 0.85rem; }
.search-row .btn:hover { background: #dbb678; border-color: #dbb678; }
.suggest { position: absolute; z-index: 1000; top: calc(100% + 6px); left: 0; right: 0; list-style: none; margin: 0; padding: 4px 0; background: var(--surface); color: var(--fg); border: 1px solid var(--line); border-radius: 3px; box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3); }
.suggest li { padding: 10px 14px; cursor: pointer; font-size: 0.88rem; }
.suggest li:hover { background: var(--sunk); }

.status { padding: 10px 12px; border: 1px solid var(--line); border-left: 3px solid var(--gold); border-radius: var(--r); background: var(--surface); font-size: 0.85rem; }
.status.error { border-left-color: var(--bad); }
.spinner { width: 13px; height: 13px; border: 2px solid var(--line); border-top-color: var(--gold); border-radius: 50%; display: inline-block; vertical-align: -2px; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* ---------- intro ---------- */
.intro { display: grid; gap: 14px; }
.idx { font: 600 0.8rem var(--mono); color: var(--gold); margin-right: 8px; letter-spacing: 0.04em; }
.content > section > h2, .intro > h2 { font-size: 1.3rem; border-bottom: 1px solid var(--brand); padding-bottom: 8px; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: step; display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); }
.steps li { counter-increment: step; display: grid; gap: 4px; align-content: start; padding: 14px; color: var(--fg-2); font-size: 0.85rem; border-right: 1px solid var(--line); }
.steps li:last-child { border-right: 0; }
.steps li::before { content: "0" counter(step); font: 600 0.78rem var(--mono); color: var(--gold); letter-spacing: 0.04em; }
.steps strong { color: var(--fg); font-size: 0.98rem; font-family: var(--display); }

/* ---------- concelhos ---------- */
.concelhos { display: grid; gap: 14px; scroll-margin-top: 70px; }
.concelhos .lead { color: var(--fg-2); }
.concelho-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); }
.concelho-list li + li { border-top: 1px solid var(--line); }
.concelho-list button { width: 100%; text-align: left; font: inherit; cursor: pointer; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 14px; background: transparent; color: var(--fg); border: 0; padding: 14px 16px; transition: background 0.15s; }
.concelho-list button:hover { background: var(--gold-soft); }
.concelho-list strong { font: 600 1.1rem var(--display); }
.concelho-list span { grid-column: 1; font-size: 0.78rem; color: var(--muted); }
.concelho-list em { grid-column: 2; grid-row: 1 / span 2; font-style: normal; font-size: 0.8rem; font-weight: 600; color: var(--gold); }
.request { margin-top: 6px; }

/* ---------- results ---------- */
.block { display: flex; flex-direction: column; gap: 12px; padding-top: 18px; border-top: 1px solid var(--line); }
.back-map + .block { border-top: 0; padding-top: 0; }
.sec-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.sec-head h2 { position: relative; padding-left: 12px; }
.sec-head h2::before { content: ""; position: absolute; left: 0; top: 0.2em; bottom: 0.2em; width: 3px; border-radius: 2px; background: var(--gold); }
.kv { display: grid; grid-template-columns: 112px 1fr; gap: 5px 12px; margin: 0; font-size: 0.86rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.num { font-family: var(--mono); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

.card { display: flex; flex-direction: column; gap: 9px; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 14px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04); }
.card p { color: var(--fg-2); }
.card ul { margin: 0; padding-left: 18px; color: var(--fg-2); }
.card.plan { border-color: color-mix(in srgb, var(--gold) 35%, var(--line)); }
.card.reserve { border-left: 3px solid var(--bad); }
.note { font-size: 0.84rem; color: var(--fg-2); background: var(--gold-soft); border: 1px solid color-mix(in srgb, var(--gold) 30%, transparent); border-radius: var(--r); padding: 10px 12px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.stat { display: grid; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.stat .v { font: 600 1.25rem/1.2 var(--display); font-variant-numeric: tabular-nums; }
.stat .k { font-size: 0.72rem; color: var(--muted); }
.stats.results .stat { background: var(--brand); border-color: var(--brand); }
.stats.results .stat .v { color: var(--gold-bright); }
.stats.results .stat .k { color: #b9b2a3; }
.inputs { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.field { display: grid; gap: 5px; min-width: 0; align-content: start; }

.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 0.74rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--sunk); color: var(--fg-2); white-space: nowrap; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.chip.ok::before { background: var(--ok); }
.chip.warn::before { background: var(--warn); }
.chip.bad::before { background: var(--bad); }
.tag { font: 600 0.68rem var(--body); letter-spacing: 0.06em; color: var(--gold); border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; margin-right: 4px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 7px; vertical-align: 0; }
.toggle { font-size: 0.8rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.toggle input { width: auto; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 0.8rem; }
th, td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); background: var(--sunk); }
th.r, td.r { text-align: right; }
tr:last-child td { border-bottom: 0; }
tr.total td { font-weight: 600; background: var(--sunk); }
.art-ref { color: var(--muted); white-space: nowrap; }

details { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
details > summary { cursor: pointer; padding: 10px 12px; font-weight: 500; list-style: none; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: "+"; color: var(--gold); font-weight: 600; }
details[open] > summary::after { content: "\2212"; }
details > .body { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 8px; color: var(--fg-2); font-size: 0.85rem; }
details > .body.art { display: block; }
details .body ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.page { margin-left: auto; color: var(--muted); font-size: 0.75rem; font-weight: 400; }
.art { font-size: 0.83rem; line-height: 1.65; }
.art mark { background: var(--gold-soft); color: inherit; padding: 0 2px; border-radius: 2px; box-shadow: inset 0 -1px 0 var(--gold); }
.art u { text-decoration-color: var(--gold); text-decoration-thickness: 2px; }

.links { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; font-size: 0.86rem; }
.links li { display: flex; flex-direction: column; }
.links small { color: var(--muted); }

.ai-form { display: grid; gap: 8px; }
.md { font-size: 0.875rem; color: var(--fg-2); overflow-wrap: anywhere; }
.md h2 { font-size: 1rem; margin: 16px 0 6px; color: var(--fg); }
.md table { display: block; overflow-x: auto; margin: 8px 0; }

/* ---------- services (AI for Architects) ---------- */
.services { background-color: var(--brand); color: var(--on-brand); border-top: 3px solid var(--gold-bright);
  background-image: linear-gradient(rgba(201, 164, 100, 0.06) 1px, transparent 1px), linear-gradient(90deg, rgba(201, 164, 100, 0.06) 1px, transparent 1px); background-size: 32px 32px; }
.services-in { display: grid; gap: 26px; padding-top: 46px; padding-bottom: 46px; }
.services-head { display: grid; gap: 10px; max-width: 700px; }
.services h2 { font-size: clamp(1.5rem, 3vw, 2.1rem); color: #fff; line-height: 1.1; }
.services .lead { color: #c9c2b3; }
.service-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); border: 1px solid rgba(201, 164, 100, 0.3); border-radius: 4px; background: rgba(0, 0, 0, 0.22); }
.service-list li { display: grid; gap: 6px; align-content: start; padding: 18px; font-size: 0.85rem; color: #b9b2a3; border-right: 1px solid rgba(201, 164, 100, 0.2); }
.service-list li:last-child { border-right: 0; }
.service-list .idx { color: var(--gold-bright); }
.service-list strong { color: #fff; font: 600 1.05rem/1.25 var(--display); }
.services-cta { display: grid; gap: 14px; }
.services-cta > p { color: #c9c2b3; max-width: 640px; }
.btn.gold { background: var(--gold-bright); color: var(--brand); border-color: var(--gold-bright); text-decoration: none; display: inline-block; }
.btn.gold:hover { background: #dbb678; border-color: #dbb678; color: var(--brand); }
.btn.ghost-light { background: transparent; color: var(--on-brand); border-color: rgba(239, 232, 218, 0.4); text-decoration: none; display: inline-block; }
.btn.ghost-light:hover { background: transparent; border-color: var(--gold-bright); color: var(--gold-bright); }

/* ---------- footer ---------- */
.foot { border-top: 1px solid var(--line); background: var(--sunk); font-size: 0.74rem; color: var(--muted); }
.foot-in { display: grid; gap: 6px; padding-top: 18px; padding-bottom: 22px; }
.foot-brand { display: inline-flex; align-items: center; gap: 8px; font: 600 0.8rem var(--body); color: var(--fg); text-decoration: none; }
.foot-brand:hover { color: var(--gold); }
.foot-brand img { border-radius: 4px; }

/* ---------- map ---------- */
.map-tools { position: absolute; z-index: 600; top: 12px; right: 12px; display: grid; gap: 6px; justify-items: end; max-width: calc(100% - 24px); pointer-events: none; }
.map-tools .btn { pointer-events: auto; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); }
.tools-row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.tools-hint { pointer-events: none; max-width: 320px; background: rgba(28, 32, 35, 0.92); color: var(--on-brand); border: 1px solid rgba(201, 164, 100, 0.4); border-radius: var(--r); padding: 8px 11px; font-size: 0.78rem; }
#map.drawing, #map.drawing .leaflet-interactive { cursor: crosshair; }
.vtx { background: #fff; border: 2px solid var(--plot); border-radius: 50%; }
.vtx.mid { background: var(--plot); opacity: 0.6; border-color: #fff; }
.vtx.mid:hover { opacity: 1; }
.leaflet-container { font-family: var(--body); }
.leaflet-control-layers { border-radius: var(--r) !important; border: 1px solid var(--line) !important; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2) !important; }
.leaflet-control-layers-expanded { padding: 6px 10px; }
.leaflet-control-layers label { display: flex; align-items: center; gap: 6px; margin: 2px 0; font-size: 0.8rem; }
.leaflet-control-layers label > span, .leaflet-control-layers label > div { display: flex; align-items: center; gap: 6px; }
.leaflet-control-layers-selector { margin: 0; width: auto; }

/* ---------- phones ---------- */
@media (max-width: 820px) {
  .wrap { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .hero-in { padding-top: 28px; padding-bottom: 26px; }
  .map-card { box-shadow: none; }
  .map-pill { display: none; }
  .tools-hint { max-width: 260px; }
  .kv { grid-template-columns: 96px 1fr; }
  .topbar-in { height: 54px; }
  .topnav { gap: 14px; }
  .service-list li { border-right: 0; border-bottom: 1px solid rgba(201, 164, 100, 0.2); }
  .service-list li:last-child { border-bottom: 0; }
  .btn.gold, .btn.ghost-light { text-align: center; white-space: normal; }
  .steps li { border-right: 0; border-bottom: 1px solid var(--line); }
  .steps li:last-child { border-bottom: 0; }
}

/* Request form for municípios not yet available */
.request form { display: grid; gap: 10px; }
.request h3 { margin: 0; font-family: "Barlow", sans-serif; font-size: 1.05rem; }
.request .hp { position: absolute; left: -9999px; }
.card.limit { border-left: 3px solid var(--gold); }
.quota { margin-top: -4px; }
.tipologias { border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 4px; }
.tipologias p { margin: 0; color: var(--fg); }
.tipologias .ref { color: var(--fg-2); font-size: 0.9em; }
