:root {
  /* Canadian flag palette: red / off-white / black writing.
   * Background is a soft warm cream rather than pure white so the
   * page reads as designed rather than as a default browser blank.
   * Cards stay pure white for contrast — every card "lifts" off the
   * page background. */
  --ink: #1a1a1a;             /* near-black for body text — kinder on the eye than pure black */
  --muted: #5a5a5a;           /* secondary text */
  --bg: #f8f6f2;              /* warm cream page background */
  --bg-deeper: #efece5;       /* slightly deeper cream for footer / section bands */
  --panel: #ffffff;           /* card panels — pure white to contrast against bg */
  --line: #dcd9d2;            /* hairline tinted to match the cream palette */
  --line-soft: #ebe8e2;       /* fainter hairline for nested separators */
  --accent: #d52b1e;          /* Pantone 186 — Canadian flag red */
  --accent-2: #a4221a;        /* deeper red for hovers / strong emphasis */
  --accent-soft: #fbe9e7;     /* very pale red for chip backgrounds */
  --ok: #117a3c;              /* neutral green for confirmed/active */
  --warn: #b45309;            /* warning amber */
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.page-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  /* Subtle 2-tone bottom edge: soft cream-to-white gradient + a thin
   * accent line. Breaks the flat-white feel without being loud. */
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(248, 246, 242, 0.96) 100%);
  box-shadow: 0 1px 0 var(--line-soft), 0 4px 12px rgba(0, 0, 0, 0.04);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 4;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--ink);
  text-decoration: none;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.01em;
}

.brand-mark {
  width: 4.4rem;
  height: 4.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  flex-shrink: 0;
}

.brand-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* "PI" fallback is ONLY meant to show if the image fails to load.
 * The img has onerror="this.style.display='none'" which hides it on
 * 404. With image present, hide the fallback so it doesn't double-up
 * with the logo (which is what your screenshot showed). */
.brand-fallback {
  display: none;
}
.brand-mark:not(:has(img:not([style*="display: none"]))) .brand-fallback,
.brand-mark img[style*="display: none"] + .brand-fallback {
  display: block;
  line-height: 1;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent-2);
}

.brand-name {
  /* Slightly tighter line-height so it sits visually centered next to
   * the round logo. */
  line-height: 1.15;
}

/* Mobile — slightly smaller logo so the brand name has room. */
@media (max-width: 640px) {
  .brand { font-size: 1rem; gap: 0.55rem; }
  .brand-mark { width: 3.4rem; height: 3.4rem; }
}

.brand-name {
  display: block;
}

.topnav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.topnav a {
  text-decoration: none;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.45rem 0.75rem;
}

.topnav .pill {
  background: var(--accent);
  color: #fff;
}

.content {
  padding: 1.2rem;
}

.hero {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1.6fr 1fr;
}

.hero-copy,
.hero-panel,
.profile-card,
.result-card,
.timeline-card,
.riding-panel,
.prose-block,
.map-controls {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  /* Two-stage shadow: a soft red-tinged glow (brand) plus a closer
   * neutral shadow for crisp lift off the cream background. */
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.04),
    0 8px 24px rgba(165, 35, 28, 0.06);
  transition: box-shadow 0.18s ease, transform 0.18s ease;
}

/* Make result cards in lists feel interactive — small lift on hover. */
.list-stack .result-card:hover,
.card-grid .result-card:hover {
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.06),
    0 12px 32px rgba(165, 35, 28, 0.10);
  transform: translateY(-1px);
}

.hero-copy h1,
.section-head h1,
.section-head h2,
.profile-main h1 {
  font-family: "Space Grotesk", sans-serif;
  margin-top: 0;
}

.eyebrow {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--accent);
  font-weight: 600;
}

.search-band {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.8rem;
}

.search-band input,
.search-band select,
.stack-form input,
.stack-form select {
  width: 100%;
  min-width: 180px;
  border: 1px solid #e8b8bf;
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  font: inherit;
}

.search-band button,
.stack-form button,
.cta-link {
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  padding: 0.7rem 1rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.section-head {
  margin: 1.6rem 0 0.8rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  /* A thin red accent rule under each section header — defines page
   * rhythm without imposing a heavy underline. */
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--line-soft);
  position: relative;
}
.section-head::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 3.5rem;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 2px;
}
.section-head h1,
.section-head h2 {
  margin-bottom: 0;
}

.card-grid {
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.card-top,
.result-head,
.inline-tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.confidence,
.chip,
.asof-pill {
  border-radius: 999px;
  padding: 0.18rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid transparent;
}

.confidence-confirmed { background: #fde0dd; color: #a4221a; }
.confidence-supported { background: #fdeae8; color: #a4221a; }
.confidence-sourced { background: #efefef; color: #333333; }
.confidence-provisional { background: #fef3c7; color: #92400e; }
.confidence-disputed { background: #ffedd5; color: #9a3412; }

.chip { background: #fde0dd; color: var(--accent-2); }
.chip-warn { background: #fff7ed; color: var(--warn); }
.chip-ok { background: #fee2e2; color: var(--ok); }
.asof-pill { background: #eff6ff; color: #1d4ed8; }

/* Jurisdiction picker tiles on the landing page. Same shell as
 * .profile-card so the visual language matches the page below, but
 * styled as a link target — no internal layout, slightly lifted on
 * hover, accent stripe on the left to read as "tap me, pick a path". */
.jurisdiction-grid {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  margin-bottom: 1.4rem;
}
.pick-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  text-decoration: none;
  color: inherit;
  position: relative;
  padding-left: 1.4rem;
}
.pick-card::before {
  content: "";
  position: absolute;
  left: 0.6rem;
  top: 1.1rem;
  bottom: 1.1rem;
  width: 3px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-radius: 2px;
}
.pick-card:hover {
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.06),
    0 12px 32px rgba(165, 35, 28, 0.10);
  transform: translateY(-1px);
}
.pick-card h3 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
}
.pick-card p {
  margin: 0;
  font-size: 0.95rem;
}
.pick-card .cta-link {
  align-self: flex-start;
  margin-top: 0.5rem;
}
.muted {
  color: #8a6e6e;
  font-size: 0.85em;
}

/* Jurisdiction picker tiles on the landing page. Same shell as
 * .profile-card so the visual language matches the page below, but
 * styled as a link target — accent stripe on the left, lift on hover. */
.jurisdiction-grid {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  margin-bottom: 1.4rem;
}
.pick-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  text-decoration: none;
  color: inherit;
  position: relative;
  padding-left: 1.4rem;
}
.pick-card::before {
  content: "";
  position: absolute;
  left: 0.6rem;
  top: 1.1rem;
  bottom: 1.1rem;
  width: 3px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-radius: 2px;
}
.pick-card:hover {
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.06),
    0 12px 32px rgba(165, 35, 28, 0.10);
  transform: translateY(-1px);
}
.pick-card h3 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
}
.pick-card p {
  margin: 0;
  font-size: 0.95rem;
}
.pick-card .cta-link {
  align-self: flex-start;
  margin-top: 0.5rem;
}
.muted {
  color: #8a6e6e;
  font-size: 0.85em;
}

/* Biography block on the profile page. Blockquote needs structure or
 * it visually melts into the surrounding muted text. Accent rule on
 * the left echoes the picker tiles. Roles row reads as a chip series
 * (separators applied inline). */
.bio-block .bio-roles {
  font-weight: 600;
  letter-spacing: 0.01em;
  margin-bottom: 0.5rem;
}
.bio-block .bio-excerpt {
  margin: 0.5rem 0 0.8rem;
  padding: 0.6rem 0 0.6rem 0.95rem;
  border-left: 3px solid var(--accent);
  font-size: 1.02rem;
  line-height: 1.55;
  color: var(--ink);
}
.bio-block .bio-attribution,
.bio-block .bio-methodology {
  margin: 0.3rem 0;
}
.bio-block .bio-methodology {
  font-style: italic;
  margin-top: 0.7rem;
}

/* Headshot inside a Featured Politician card. Square thumbnail with the
 * same warm shadow as the profile-hero portrait so cards feel related to
 * the full profile page. We don't pad it — the parent .profile-card
 * already supplies the breathing room. */
.profile-card .card-headshot {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  object-position: center top;
  border-radius: 10px;
  border: 1px solid var(--line);
  margin: 0.6rem 0 0.4rem;
  background: #faeeec;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.06),
    0 6px 18px rgba(165, 35, 28, 0.07);
}

.map-layout,
.riding-layout,
.profile-hero {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: minmax(150px, 190px) 1fr;
}

.map-canvas-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 420px;
  background: #ffecef;
}

.map-canvas {
  width: 100%;
  min-height: 420px;
}

.profile-media img {
  /* Cap the headshot to a sensible portrait thumbnail. Previously the
   * image filled the column (up to 360px) and read ~3x too large. */
  width: 100%;
  max-width: 190px;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.06),
    0 12px 32px rgba(165, 35, 28, 0.08);
}

.photo-fail-closed {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  min-height: 220px;
  background: var(--panel);
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.06),
    0 12px 32px rgba(165, 35, 28, 0.08);
}

.photo-fail-closed {
  display: grid;
  place-items: center;
  text-align: center;
  padding: 1rem;
  background: #fff5f6;
}

.list-stack {
  display: grid;
  gap: 0.65rem;
}

.muted {
  color: var(--muted);
}

.footer-provenance {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.45rem;
  padding: 0.9rem 1.2rem;
  border-top: 1px solid var(--line);
  background: #fff0f2;
  color: #3f3f46;
  font-size: 0.92rem;
}

/* Affiliation disclosure spans the full footer width as its own row. */
.footer-disclosure {
  flex-basis: 100%;
  font-size: 0.85rem;
  color: #555;
  padding-bottom: 0.3rem;
  border-bottom: 1px dashed var(--line);
  margin-bottom: 0.3rem;
}

/* Legal nav links sit on their own row below the disclosure. */
.footer-links {
  flex-basis: 100%;
  font-size: 0.88rem;
}
.footer-links a {
  color: #3f3f46;
  text-decoration: none;
  padding: 0 0.15rem;
}
.footer-links a:hover {
  text-decoration: underline;
}

/* Inline error banner used on form-error redirects (e.g. AI Settings). */
.banner-error {
  padding: 1rem;
  border: 1px solid #c33;
  background: #fee;
  color: #900;
  border-radius: 6px;
  margin-bottom: 1rem;
}
.banner-success {
  padding: 0.75rem 1rem;
  border: 1px solid #3a7;
  background: #efe;
  color: #074;
  border-radius: 6px;
  margin-bottom: 1rem;
}
.banner-info {
  padding: 0.75rem 1rem;
  border: 1px solid #58a;
  background: #eef5fb;
  color: #235;
  border-radius: 6px;
  margin-bottom: 1rem;
}

/* Edmonton motion list — text excerpt and pagination. */
.motion-excerpt {
  font-size: 0.92em;
  color: #444;
  margin: 0.4rem 0;
  line-height: 1.5;
  max-height: 4.5em;
  overflow: hidden;
}
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin: 1.5rem 0;
  padding: 0.75rem 0;
  border-top: 1px solid var(--line);
}
.pagination a {
  text-decoration: none;
  font-weight: 500;
}

/* Edmonton landing — feature card grid linking to live sections. */
.edmonton-feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin: 1rem 0 1.5rem;
}
.edmonton-feature-card {
  display: block;
  padding: 1rem 1.25rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.edmonton-feature-card:hover {
  border-color: var(--accent-2, #b42318);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
.edmonton-feature-card h3 {
  margin: 0 0 0.4rem;
  font-size: 1.05em;
  color: var(--accent-2, #b42318);
}
.edmonton-feature-card p {
  margin: 0;
  font-size: 0.92em;
  line-height: 1.45;
}

/* Riding-detail boundary map. Replaces the raw-GeoJSON download link
 * with an embedded polygon view + extracted human-readable metadata. */
.riding-boundary-map {
  width: 100%;
  height: 320px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #f4f4f4;
  margin: 0.5rem 0 0.75rem;
  overflow: hidden;
}
.riding-boundary-meta {
  font-size: 0.92em;
  line-height: 1.5;
  padding: 0.4rem 0;
}
.riding-boundary-meta strong {
  color: var(--text);
}

/* AI chat widget — used on bill/motion/profile pages.
 * Multi-turn conversation about page content using the user's own LLM
 * key (BYOK). Conversation state is browser-only (sessionStorage). */
.ai-chat-shell {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafafa;
  padding: 1rem;
}
.ai-chat-empty {
  padding: 0.75rem;
  background: #fff;
  border-radius: 6px;
  border: 1px dashed var(--line);
}
.ai-chat-transcript {
  max-height: 480px;
  overflow-y: auto;
  margin-bottom: 1rem;
  padding-right: 0.25rem;
}
.ai-chat-msg {
  margin-bottom: 0.75rem;
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  line-height: 1.4;
}
.ai-chat-msg-user {
  background: #eaf2fb;
  border-left: 3px solid #5a8ec6;
}
.ai-chat-msg-assistant {
  background: #fff;
  border-left: 3px solid #b0a07a;
}
.ai-chat-pending {
  opacity: 0.7;
}
.ai-chat-msg-label {
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #888;
  margin-bottom: 0.3rem;
  font-weight: 600;
}
.ai-chat-msg-body {
  white-space: pre-wrap;
  font-size: 0.95em;
  color: #222;
}
.ai-chat-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.ai-chat-form textarea {
  width: 100%;
  resize: vertical;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 0.95em;
}
.ai-chat-form textarea:focus {
  outline: 2px solid #5a8ec6;
  outline-offset: 1px;
}
.ai-chat-form textarea:disabled {
  background: #f0f0f0;
  cursor: not-allowed;
}
.ai-chat-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.ai-chat-actions .btn-primary,
.ai-chat-actions .btn-secondary {
  padding: 0.4rem 1rem;
}
.ai-chat-turn-count {
  margin-left: auto;
  font-size: 0.85em;
}
.ai-chat-meta {
  margin-bottom: 0.5rem;
  font-size: 0.8em;
}
.ai-chat-error {
  margin-top: 0.75rem;
  color: #900;
  font-size: 0.9em;
}
.ai-chat-error:empty {
  display: none;
}
.ai-chat-disclosure {
  margin-top: 1rem;
  font-size: 0.8em;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

/* Trial-countdown banner shown sitewide for users mid-trial. */
.trial-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1.25rem;
  background: linear-gradient(90deg, #fff4e0 0%, #ffe6c2 100%);
  border-bottom: 1px solid #d9a45e;
  color: #5a3a10;
  font-size: 0.92rem;
}
.trial-banner strong {
  font-weight: 600;
}
.trial-banner .pill {
  display: inline-block;
  padding: 0.3rem 0.85rem;
  background: #5a3a10;
  color: #fff7eb;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 500;
  font-size: 0.88rem;
}
.trial-banner .pill:hover {
  background: #794d18;
}

.dev-note {
  border: 1px solid #f0c7cc;
  background: #fff5f6;
  border-radius: 12px;
  padding: 0.75rem;
}

.stack-form {
  display: grid;
  gap: 0.55rem;
}

.map-legend {
  margin-top: 1rem;
  border-top: 1px solid var(--line);
  padding-top: 0.8rem;
}

.map-legend h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-family: "Space Grotesk", sans-serif;
}

.map-legend ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.map-legend li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.legend-swatch {
  width: 1.1rem;
  height: 0.55rem;
  border-radius: 999px;
  display: inline-block;
}

.legend-federal {
  background: #d51224;
}

.legend-provincial {
  background: #1f2937;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

@media (max-width: 1024px) {
  .hero,
  .map-layout,
  .riding-layout,
  .profile-hero {
    grid-template-columns: 1fr;
  }
}
