/* CasaHunter design system — "Aurora Glass"
 *
 * One stylesheet for every page. New pages are written against the classes
 * below; the older pages keep their own inline CSS and pick up the new look
 * through the token remap and the bridge rules at the end of this file (it is
 * linked AFTER their inline <style>, so it wins on equal specificity).
 *
 * Chart colours are not chosen by eye: the categorical order below passed the
 * colour-blind / contrast validator against --surface-1 (worst adjacent CVD
 * ΔE 8.4, normal-vision ΔE 19.3, all ≥ 3:1 on the surface). Keep the order.
 */
@import url("https://fonts.googleapis.com/css2?family=Geist:wght@300..700&family=Geist+Mono:wght@400;500&display=swap");

:root {
  color-scheme: dark;

  /* surfaces */
  --canvas: #070b14;
  --surface-1: #111723;                 /* what a glass panel resolves to; charts are validated against it */
  --glass: rgba(255, 255, 255, 0.045);
  --glass-strong: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.09);
  --glass-edge: rgba(255, 255, 255, 0.16);

  /* ink */
  --text-1: #eef2f8;
  --text-2: #aab4c5;
  --text-3: #727d92;

  /* brand accent — interface chrome only, never a data series */
  --accent: #2ee6a6;
  --accent-ink: #04130d;
  --accent-soft: rgba(46, 230, 166, 0.13);
  --accent-glow: rgba(46, 230, 166, 0.35);

  /* data: categorical slots, fixed order */
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #0ca30c;
  --series-7: #9085e9;
  --series-8: #e66767;
  --series-muted: #4a556b;              /* de-emphasis grey */
  /* data: one-hue ordinal ramp (brighter = more / fresher on a dark surface) */
  --ramp-1: #86b6ef;
  --ramp-2: #3987e5;
  --ramp-3: #1c5cab;
  --ramp-track: #18263d;

  /* status — reserved, always shown with an icon and a label */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;

  /* chart chrome */
  --grid: #222a3a;
  --axis: #36415a;

  --r-lg: 22px;
  --r-md: 14px;
  --r-sm: 9px;
  --gap: 16px;
  --shadow: 0 18px 50px -24px rgba(0, 0, 0, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  --blur: blur(22px) saturate(150%);
  --font: "Geist", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);

  /* ── tokens the older pages were written against ── */
  --bg: var(--canvas);
  --bg-card: var(--glass);
  --bg-hover: var(--glass-strong);
  --border: var(--glass-border);
  --text: var(--text-1);
  --dim: var(--text-2);
  --muted: var(--text-3);
  --accent-h: #5cf0bd;
  --gold: #e6c27a;
  --red: #f0706f;
  --purple: #a78bfa;
  --r: var(--r-md);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* a display rule on a class must never un-hide an element */

html { scrollbar-color: rgba(255, 255, 255, 0.18) transparent; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--text-1);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ── Canvas: slow aurora behind everything, plus a whisper of grain ── */
body::before {
  content: "";
  position: fixed;
  inset: -25%;
  z-index: -2;
  pointer-events: none;
  /* The aurora is artwork generated locally (FLUX.2 klein), 12 KB as WebP. The
     gradients underneath are the fallback if the image is missing or still loading. */
  background:
    url("/assets/art/canvas.webp") center / cover no-repeat,
    radial-gradient(38% 34% at 16% 12%, rgba(46, 230, 166, 0.22), transparent 70%),
    radial-gradient(34% 38% at 86% 10%, rgba(57, 135, 229, 0.26), transparent 70%),
    radial-gradient(44% 40% at 72% 92%, rgba(144, 133, 233, 0.20), transparent 70%);
  opacity: 0.8;
  animation: aurora 60s var(--ease) infinite alternate;
  will-change: transform;
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
@keyframes aurora {
  0% { transform: translate3d(-2%, -1%, 0) scale(1); }
  50% { transform: translate3d(3%, 2%, 0) scale(1.08); }
  100% { transform: translate3d(-1%, 3%, 0) scale(1.03); }
}

a { color: inherit; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ── Glass ─────────────────────────────────────────────────────────── */
.glass {
  position: relative;
  /* a light sheen over a dark tint: the canvas colours glow through, but text
     always sits on something close to --surface-1 */
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.085), rgba(255, 255, 255, 0.025) 60%, rgba(255, 255, 255, 0.045)),
    rgba(9, 13, 23, 0.58);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}
/* a hairline of light along the top edge */
.glass::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  pointer-events: none;
  background: linear-gradient(160deg, var(--glass-edge), transparent 34%, transparent 70%, rgba(255, 255, 255, 0.05));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
}
/* pointer-following sheen; --mx/--my are set by ui.js */
.glass.spot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s var(--ease);
  background: radial-gradient(380px circle at var(--mx, 50%) var(--my, 0%), rgba(255, 255, 255, 0.07), transparent 60%);
}
.glass.spot:hover::after { opacity: 1; }

/* ── Shell: floating navigation ────────────────────────────────────── */
.ch-nav {
  position: sticky;
  top: 12px;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 12px auto 0;
  padding: 8px 10px 8px 16px;
  width: min(1480px, calc(100% - 32px));
  border-radius: 999px;
}
.ch-brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; letter-spacing: -0.01em; text-decoration: none; white-space: nowrap; }
.ch-brand-mark { width: 28px; height: 28px; border-radius: 8px; display: block; flex: none;
  box-shadow: 0 0 20px -4px var(--accent-glow), 0 0 0 1px rgba(255, 255, 255, 0.1); }
.ch-nav > nav { min-width: 0; flex: 1; display: flex; }
.ch-links { display: flex; gap: 2px; margin: 0 auto; padding: 0; list-style: none; overflow-x: auto; scrollbar-width: none; }
.ch-links::-webkit-scrollbar { display: none; }
.ch-links a { display: flex; align-items: center; gap: 7px; padding: 8px 13px; border-radius: 999px; font-size: 13px; font-weight: 500;
  color: var(--text-2); text-decoration: none; white-space: nowrap; transition: color 0.2s, background 0.2s; }
.ch-links a:hover { color: var(--text-1); background: rgba(255, 255, 255, 0.06); }
.ch-links a[aria-current="page"] { color: var(--text-1); background: rgba(255, 255, 255, 0.1); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1); }
.ch-links a[aria-current="page"] svg { color: var(--accent); }
.ch-links svg, .ch-side svg { width: 16px; height: 16px; flex: none; }
.ch-side { display: flex; align-items: center; gap: 6px; }
.ch-icon-btn { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 999px; color: var(--text-2);
  background: transparent; border: 0; cursor: pointer; text-decoration: none; transition: color 0.2s, background 0.2s; }
.ch-icon-btn:hover { color: var(--text-1); background: rgba(255, 255, 255, 0.07); }

.ch-page { width: min(1480px, calc(100% - 32px)); margin: 0 auto; padding: 26px 0 64px; }
.ch-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px 24px; margin-bottom: 20px; }
.ch-head h1 { margin: 0; font-size: 26px; font-weight: 600; letter-spacing: -0.025em; }
.ch-head p { margin: 4px 0 0; color: var(--text-2); font-size: 13.5px; }
.ch-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 1180px) {
  .ch-links a span { display: none; } .ch-links a { padding: 9px 11px; }
}
/* Phone tab bar + "Mais" sheet (built by ui.js mountTabbar) */
.ch-tabbar, .ch-more { display: none; }
@media (max-width: 720px) {
  .ch-nav { display: none; }
  .ch-page { width: calc(100% - 24px); padding: 16px 0 calc(96px + env(safe-area-inset-bottom)); }
  .ch-head h1 { font-size: 22px; }
  body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

  .ch-tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000; display: grid; grid-template-columns: repeat(5, 1fr);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: rgba(8, 11, 19, 0.9);
    -webkit-backdrop-filter: blur(18px) saturate(1.4); backdrop-filter: blur(18px) saturate(1.4);
    border-top: 1px solid rgba(255, 255, 255, 0.08); }
  .ch-tabbar > a, .ch-tabbar > button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 52px; padding: 4px 0; border: 0; border-radius: 14px; background: none; color: var(--text-2);
    font: 500 10.5px var(--font); text-decoration: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .ch-tabbar svg { width: 22px; height: 22px; }
  .ch-tabbar [aria-current="page"] { color: var(--text-1); }
  .ch-tabbar [aria-current="page"] svg { color: var(--accent); filter: drop-shadow(0 0 8px var(--accent-glow)); }
  .ch-tabbar > :active { background: rgba(255, 255, 255, 0.06); }

  .ch-more { display: block; }
  .ch-more-backdrop { position: fixed; inset: 0; z-index: 990; background: rgba(0, 0, 0, 0.5); opacity: 0; pointer-events: none; transition: opacity 0.25s; }
  .ch-more-panel { position: fixed; left: 10px; right: 10px; bottom: calc(74px + env(safe-area-inset-bottom)); z-index: 995;
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 10px; border-radius: 20px;
    transform: translateY(16px); opacity: 0; pointer-events: none; transition: transform 0.25s var(--ease), opacity 0.2s; }
  .ch-more-panel a { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 14px; border-radius: 14px;
    color: var(--text-1); font-size: 14px; font-weight: 500; text-decoration: none; background: rgba(255, 255, 255, 0.04); }
  .ch-more-panel a[aria-current="page"] { background: rgba(255, 255, 255, 0.1); }
  .ch-more-panel a[aria-current="page"] svg { color: var(--accent); }
  .ch-more-panel svg { width: 20px; height: 20px; flex: none; color: var(--text-2); }
  .ch-more-panel .ch-more-out { grid-column: 1 / -1; color: var(--text-2); }
  body.ch-more-open .ch-more-backdrop { opacity: 1; pointer-events: auto; }
  body.ch-more-open .ch-more-panel { transform: none; opacity: 1; pointer-events: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ══ Bridge: the older pages ═══════════════════════════════════════════
 * They define their own layout; these rules only swap the surface language.
 */
body { font-family: var(--font) !important; }
.nav { display: none !important; }                          /* replaced by the injected .ch-nav */
:is(.card, .chart-card, .info-card, .desc-card, .notes-card, .timeline-card, .cross-card, .gallery, .header,
    .vtable, .sys-item, .preset, .custom-filters, .cycle-bar):not(.glass) {
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.026)), rgba(9, 13, 23, 0.58);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}
input, select, textarea, button { font-family: inherit; }
.leaflet-container { font-family: var(--font) !important; }

/* Buttons. Scoped to pages not yet rebuilt on components.css (they set <body class="ch">). */
body:not(.ch) :is(.btn, .tab, .pagination button) {
  border-radius: 11px;
  font-family: var(--font);
  transition: transform 0.18s var(--ease), box-shadow 0.25s, background 0.2s, border-color 0.2s, color 0.2s;
}
body:not(.ch) :is(.btn, .tab, .pagination button):hover { transform: translateY(-1px); }
body:not(.ch) :is(.btn, .tab, .pagination button):active { transform: translateY(1px) scale(0.99); }
/* primary: lit from above, glows on hover */
body:not(.ch) :is(.btn-primary, .btn-row > .btn:not(.btn-outline), .pagination button.current) {
  color: var(--accent-ink) !important;
  border: 0 !important;
  font-weight: 600;
  background: linear-gradient(180deg, #7af7cf 0%, var(--accent) 48%, #1fca92 100%) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), inset 0 -1px 0 rgba(0, 0, 0, 0.18), 0 10px 26px -12px var(--accent-glow);
}
body:not(.ch) :is(.btn-primary, .btn-row > .btn:not(.btn-outline)):hover {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), inset 0 -1px 0 rgba(0, 0, 0, 0.18), 0 16px 34px -12px var(--accent-glow);
}
/* neutral and selected states: glass */
body:not(.ch) :is(.btn-outline, .tab, .pagination button:not(.current)) { background: rgba(255, 255, 255, 0.05); border-color: var(--glass-border); }
body:not(.ch) .tab.active { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.2); color: var(--text-1); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1); }
body:not(.ch) .tabs { top: 70px !important; background: transparent !important; border-bottom-color: var(--glass-border) !important; }
@media (max-width: 720px) {   /* no top bar on phones: stick to the top, opaque so content doesn't show through */
  body:not(.ch) .tabs { top: 0 !important; background: rgba(7, 11, 20, 0.92) !important; }
}

/* headings were set in a display serif */
.nav-logo, .page-title, .hero h1 { font-family: var(--font) !important; font-weight: 600; letter-spacing: -0.025em; }

/* form controls: translucent wells instead of opaque black boxes */
:is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea):not(.ch-input) {
  background-color: rgba(255, 255, 255, 0.045) !important;
  border-color: var(--glass-border) !important;
  color: var(--text-1) !important;
  border-radius: var(--r-sm);
}
:is(input, select, textarea):focus { border-color: rgba(46, 230, 166, 0.55) !important; outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
select option { background: #121826; color: var(--text-1); }
::placeholder { color: var(--text-3); }

/* the stat strip on the listings page: glass cells instead of a black band */
body:not(.ch) .stat { background: rgba(255, 255, 255, 0.035) !important; -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur); }

/* map: floating panels and popups */
body:not(.ch) :is(.filter-panel, .legend, .leaflet-popup-content-wrapper, .leaflet-popup-tip, .leaflet-control-zoom a) {
  background: rgba(13, 18, 30, 0.78) !important;
  border-color: var(--glass-border) !important;
  color: var(--text-1) !important;
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}
body:not(.ch) :is(.filter-panel, .legend, .leaflet-popup-content-wrapper) { border-radius: var(--r-md) !important; box-shadow: var(--shadow) !important; }
.gallery-hero { background: rgba(255, 255, 255, 0.03) !important; }
