/* ===== fonts ======================================================= */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/static/vendor/Inter-Variable.woff2") format("woff2-variations"),
       url("/static/vendor/Inter-Variable.woff2") format("woff2");
}

/* ===== themes ======================================================
 *
 * Soft-black palette (was pure #000 — switched to #0b0b0c to avoid
 * OLED smearing and let the elevation system create depth via
 * progressively lighter surfaces).
 *
 * Light mode is opt-in via the ☀ button in the topbar (data-theme="light").
 * theme.js anchors that attribute on <html> and persists the choice in
 * localStorage so first paint matches.
 */

:root {
  /* Five-colour accent set. The lime is the primary accent (buttons,
   * focus rings); cyan/orange/purple/pink surface as chart-curve hues
   * and inline highlights. */
  --fg: #fafafa;
  --fg-muted: #a1a1aa;
  --fg-subtle: #71717a;
  /* Surfaces ~50% darker than the previous palette. The 3-tier
   * elevation system is preserved (bg < bg-card < bg-elev) so chips,
   * cards and hover states still pop off the page background — they
   * just sit closer to true black. Borders weren't darkened: keeping
   * them at the old contrast is what makes cards remain legible. */
  --bg: #040405;           /* near-black page background */
  --bg-card: #08080a;      /* elevated surface (legend, controls) */
  --bg-elev: #101013;      /* hover / focus / nested elements */
  --bg-overlay: rgba(8, 8, 10, 0.82); /* glass tooltips, scrim */
  --accent: #c3fc0d;       /* lime — primary action */
  --accent-fg: #000000;
  --accent-soft: #63ede0;  /* cyan — secondary highlight */
  --info: #38bdf8;         /* sky — hint/info states */
  --hot-pink: #f81d78;
  --hot-orange: #fd6c1d;
  --deep-violet: #470bf6;
  --border: #27272a;
  --border-strong: #3f3f46;
  --danger: #f81d78;
  --grid: #121215;
  --axis: #6b7280;
  --guide: #a1a1aa;
  --tooltip-bg: rgba(8, 8, 10, 0.9);
  --tooltip-fg: #fafafa;

  /* radius scale — 10px is the sweet spot for modern UI; the chart
   * frame uses the larger 14px to feel like a "card". */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  /* layered shadow tokens — combine in 1-3 strands for depth without
   * the muddy "single big shadow" look. */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 0 1px var(--accent), 0 0 16px rgba(195, 252, 13, 0.25);

  /* motion tokens — every interactive should reference these so the
   * vibe stays coherent and reduced-motion users can null them. */
  --t-fast: 120ms;
  --t-base: 180ms;
  --t-slow: 280ms;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "cv11", "ss01", "ss03", "calt";
  font-optical-sizing: auto;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --fg: #0a0a0b;
  --fg-muted: #52525b;
  --fg-subtle: #71717a;
  --bg: #f8f8f9;
  --bg-card: #ffffff;
  --bg-elev: #f1f2f4;
  --bg-overlay: rgba(255, 255, 255, 0.72);
  --accent: #c3fc0d;
  --accent-fg: #0a0a0a;
  --accent-soft: #470bf6;
  --info: #0284c7;
  --hot-pink: #f81d78;
  --hot-orange: #fd6c1d;
  --deep-violet: #470bf6;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --danger: #e11d48;
  --grid: #eef0f2;
  --axis: #71717a;
  --guide: #a1a1aa;
  --tooltip-bg: rgba(10, 10, 11, 0.92);
  --tooltip-fg: #fafafa;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 1px 2px rgba(0, 0, 0, 0.05), 0 8px 24px rgba(0, 0, 0, 0.12);
  --shadow-glow: 0 0 0 1px var(--accent), 0 0 16px rgba(195, 252, 13, 0.45);
  color-scheme: light;
}

/* Light-mode chart tuning. The chart is designed for a black canvas: the
   neon glow and the light "reads-on-black" text colours fall apart on
   white. So in light mode we kill the glow entirely and darken the
   lightest on-chart text. (Curve lines + their name labels still use the
   palette so each label matches its line — only the glow, the region
   captions, and the gray metadata change.) */
:root[data-theme="light"] .chart-svg .curve {
  /* !important beats the inline drop-shadow filter set in chart.js. With
     it removed the computed filter is `none`, so the PNG export (which
     inlines computed styles) is glow-free too. */
  filter: none !important;
}
:root[data-theme="light"] .chart-svg .freq-region-label {
  filter: none;        /* drop the lime neon halo */
  fill: #3f6212;       /* dark lime — readable on white, keeps the green identity */
}
:root[data-theme="light"] .chart-svg .chart-rig {
  /* inline fill is the light TARGET_COLOR (#d1d5db) → invisible on white */
  fill: var(--fg-muted) !important;
}
:root[data-theme="light"] .chart-svg .target-curve {
  stroke: var(--fg-muted) !important; /* same light gray as the rig */
}

/* Honor users who opted out of motion in their OS settings. We zero
 * every animation/transition rather than reduce — anything less can
 * still trigger vestibular issues. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ===== layout ====================================================== */

* { box-sizing: border-box; }
body {
  margin: 0; color: var(--fg); background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.005em;
}
a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease);
}
a:hover { opacity: 0.85; }
code { font-family: ui-monospace, "Cascadia Code", Menlo, monospace; font-size: 0.92em; }

/* Focus ring — single source of truth so every interactive matches. */
:where(button, a, input, select, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0.85rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  /* Subtle backdrop blur if the user scrolls under it; the page itself
     is short today but Compare grows beyond viewport on small screens. */
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
}
.topbar .brand {
  font-weight: 800;
  font-size: 2.25rem;
  line-height: 1;
  letter-spacing: -0.04em;
  background: linear-gradient(90deg, #22d3ee 0%, #3b82f6 22%, #a855f7 42%, #ec4899 60%, #f97316 80%, #facc15 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  text-decoration: none;
  transition: filter var(--t-base) var(--ease);
}
.topbar .brand:hover { filter: brightness(1.15) saturate(1.1); text-decoration: none; }
/* Light theme: amarelo/ciano claros somem no branco — uso versões mais escuras
   e saturadas, e troco a ponta amarela por âmbar/laranja escuro. */
:root[data-theme="light"] .topbar .brand {
  background: linear-gradient(90deg, #0891b2 0%, #2563eb 22%, #7c3aed 42%, #db2777 60%, #ea580c 80%, #b45309 100%);
  -webkit-background-clip: text;
  background-clip: text;
}
.topbar nav { flex: 1; }
.topbar nav a { color: var(--fg-muted); margin-right: 1rem; }
.topbar nav a:hover { color: var(--fg); opacity: 1; }
.topbar-meta { color: var(--fg-muted); font-size: 0.875rem; }
.topbar-meta a { color: var(--accent); }
.topbar .theme-toggle {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--fg);
  font-size: 1rem;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.topbar .theme-toggle:hover {
  background: var(--bg-card);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}
.topbar .theme-toggle:active { transform: translateY(0); }

main   { max-width: 100%; margin: 1rem auto; padding: 0 1rem; }
footer { max-width: 100%; margin: 1.5rem auto 1rem; padding: 0 1rem; color: var(--fg-muted); font-size: 0.875rem; }

/* ===== home ======================================================== */

.hero { text-align: center; padding: 2rem 0; }
.hero h1 { font-size: 2.5rem; margin: 0 0 0.5rem; color: var(--fg); }
.hero .stats { color: var(--fg-muted); margin: 1.5rem 0; }
.hero .stats strong { color: var(--fg); }
.hero .cta { display: inline-block; padding: 0.6rem 1.2rem; background: var(--accent); color: var(--accent-fg); border-radius: var(--radius); font-weight: 500; }
.hero .cta:hover { text-decoration: none; opacity: 0.9; }

/* ===== filters, tables, detail ===================================== */

.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0 1.5rem; }
.filters input, .filters select, .filters button {
  padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-card); color: var(--fg); font: inherit;
}
.filters button { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); cursor: pointer; font-weight: 500; }
.filters button:hover { opacity: 0.9; }

.measurements-wrap { overflow-x: auto; }
table.measurements { width: 100%; border-collapse: collapse; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; min-width: 480px; }
table.measurements th, table.measurements td { padding: 0.6rem 0.85rem; text-align: left; border-bottom: 1px solid var(--border); }
table.measurements th { background: var(--bg-elev); font-weight: 600; font-size: 0.875rem; color: var(--fg-muted); }
table.measurements tr:last-child td { border-bottom: 0; }
table.measurements tr:hover td { background: var(--bg-elev); }

.meta { color: var(--fg-muted); font-size: 0.875rem; margin-top: 0.75rem; }
.empty { color: var(--fg-muted); padding: 2rem; text-align: center; background: var(--bg-card); border: 1px dashed var(--border); border-radius: var(--radius); }

.crumbs { color: var(--fg-muted); font-size: 0.875rem; margin-bottom: 0.5rem; }
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1.5rem; background: var(--bg-card); padding: 1rem 1.25rem; border: 1px solid var(--border); border-radius: var(--radius); }
dl.props dt { color: var(--fg-muted); font-size: 0.875rem; }
dl.props dd { margin: 0; }

.chart-placeholder { margin-top: 1.5rem; padding: 2rem; text-align: center; background: var(--bg-card); border: 1px dashed var(--border); border-radius: var(--radius); color: var(--fg-muted); }

/* ===== chart ======================================================= */

.chart-frame {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  /* Only the outer (right) corner is rounded — the left edge butts
     up against .compare-left and the bottom edge against
     .chart-controls inside the same column. */
  border-radius: 0 var(--radius-lg) 0 0;
  box-shadow: var(--shadow-sm);
  padding: 1rem;
  margin: 1rem 0;
  /* Fluid height: fills the viewport minus topbar / footer / chart-
     controls / gaps. Clamps so it never collapses on small screens
     and doesn't grow absurdly tall on giant monitors. */
  min-height: clamp(420px, calc(100vh - 220px), 1200px);
}
.chart-svg   { width: 100%; height: auto; display: block; font: 11px ui-sans-serif, system-ui, sans-serif; }
.chart-svg .domain      { stroke: var(--axis); }
.chart-svg text         { fill: var(--fg-muted); }
.chart-svg .grid        { stroke: var(--grid); }
.chart-svg .axis-label  { font-size: 12px; fill: var(--fg-muted); font-weight: 500; }
/* Axis numbers drawn INSIDE the plot (mobile, squig.link-style): faint so
   they read as a subtle scale under the curves, not as chart data. */
.chart-svg .axis-inside { font-size: 10px; opacity: 0.4; }
.chart-svg .guide       { stroke: var(--guide); stroke-dasharray: 3 3; pointer-events: none; }
/* Hover-isolate: when a label is hovered, chart.js adds .isolating to the
   <svg> and .is-hover to the matching path. Every other line fades to a
   ghost so the focused response stands out. The opacity transition lives
   on the curves themselves so entering/leaving isolation is smooth. */
.chart-svg .curve, .chart-svg .target-curve { transition: opacity var(--t-base) var(--ease); }
.chart-svg.isolating .curve:not(.is-hover),
.chart-svg.isolating .target-curve:not(.is-hover) { opacity: 0.12; }
.chart-svg .chart-label { cursor: default; }
.chart-svg .tooltip-dot { stroke: var(--bg-card); stroke-width: 1.5; pointer-events: none; }
.chart-svg .zero-line   { stroke: var(--guide); stroke-dasharray: 2 4; stroke-width: 1; }
/* Frequency-region hover highlight (squig.link-style): a subtle band shaded
   over the hovered region's frequency range. Theme-aware via --fg-muted
   (light band on the dark canvas, dark band on white); JS toggles opacity. */
.chart-svg .region-highlight { fill: var(--fg-muted); pointer-events: none; transition: opacity var(--t-fast) var(--ease); }
.chart-svg .chart-label {
  font-size: 40px;
  /* 490 = 700 thinned 30 % (Inter Variable handles the non-standard
     weight); 0.8 = 0.7 made 15 % more opaque. Both per user request. */
  font-weight: 490;
  letter-spacing: 0.005em;
  opacity: 0.8;
}
/* Rig caption inherits opacity from .chart-label per user request,
   but the 40 px main-label size would be too dominant for metadata. */
.chart-svg .chart-rig {
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* Frequency-region captions under the x-axis. Plain text only — same
   muted color and font as the x-axis tick labels (.chart-svg text). */
.chart-svg .freq-region-label {
  /* Lime accent (the theme's signature colour) per user request. */
  fill: var(--accent);
  /* 50% larger than the x-axis tick labels (~11 px). MARGIN.bottom
     in chart.js was bumped in lockstep so the text isn't clipped. */
  font-size: 16px;
  /* Lime neon glow to match the curves' colored halo. */
  filter: drop-shadow(0 0 6px rgba(195, 252, 13, 0.45));
  pointer-events: none;
}

/* 2-column compare layout:
   left  = brand/model picker (chips + filters + product list)
   right = chart on top, chart-controls below (the "customs" strip). */
.compare-layout {
  display: grid;
  /* Unified card holds both panes (picker + legend) side-by-side, so
     it needs ~40% to give each pane breathing room. */
  grid-template-columns: minmax(360px, 40%) 1fr;
  /* No gap — left card and chart frame share their adjacent edge.
     The touching corners are flattened below so the join is clean. */
  gap: 0;
  /* Both columns share the same vertical reach (the row height comes
     from the left column's max-height below). align-items: stretch
     makes the right column fill the same row, so the chart-controls
     can flex: 1 to occupy any gap below the chart. */
  align-items: stretch;
}
.compare-right { min-width: 0; display: flex; flex-direction: column; gap: 0; }
.compare-right .chart-frame {
  margin: 0;
  /* Fill the height left after the controls (natural height) and allow
     shrinking, so the whole compare view fits the viewport with no page
     scroll. min-height:0 lets flex shrink it below the base clamp; the
     chart SVG (height:auto) re-flows to whatever height it gets. The
     layout's overall height is pinned to the viewport in JS
     (fitLayoutHeight). */
  flex: 1 1 0;
  min-height: 0;
  /* Drop the bottom border at the chart→controls join to avoid the
     double-border seam. */
  border-bottom: none;
}
/* Take whatever vertical space is left over after the chart. With
   align-items: stretch the right column equals the left column's
   height, so this flex:1 closes the gap that used to sit below the
   "customs" strip. */
.compare-right .chart-controls { margin: 0; flex: 0 0 auto; align-content: flex-start; }

/* Unified card: .compare-left wraps both the picker (Lista de IEMs)
   and the legend (IEMs selecionados) inside a single visual surface.
   The two panes share one background, one border, one radius — only
   a 1px vertical divider (border-right on the picker) separates them.
   Individual card styling on #legend and .add-curve-panel is null'd
   below to avoid double-borders / double-backgrounds. */
.compare-left {
  min-width: 0;
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  /* Only the outer (left) corners are rounded — the right edge butts
     up against .chart-frame / .chart-controls, so those corners are
     flattened for a flush join. */
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
  /* Right border doubles up with the chart's left border at the join;
     dropping it here avoids a 2px visual seam. */
  border-right: none;
  box-shadow: var(--shadow-sm);
  overflow: hidden; /* clip child radii to parent's corner radius */
  /* Loose pre-JS guard ONLY: stops the (tall) product list from inflating
     the layout for one frame before fitLayoutHeight() pins .compare-layout
     to the viewport height. It must stay LARGER than that pinned height so
     it never binds — otherwise the card's bottom wouldn't line up with the
     controls (the old calc(100vh-100px) cap caused exactly that). Once the
     layout has a definite height, align-items:stretch sizes this card and
     the list scrolls inside it. */
  max-height: 100vh;
}

/* Both panes flex 1 = split the card 50/50. The chain `compare-left
   → pane → list` all need `min-height: 0` so the inner scroll works
   when the catalogue overflows. */
.compare-left > #legend {
  flex: 1; display: flex; flex-direction: column;
  min-height: 0;
  padding: 1rem 1.15rem;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
}
.compare-left .add-curve-panel {
  flex: 1; display: flex; flex-direction: column;
  min-height: 0;
  padding: 1rem 1.15rem;
  /* Thin divider between the picker and the legend column. */
  border-right: 1px solid var(--border);
}
.compare-left .add-curve-list {
  max-height: none; flex: 1; min-height: 120px;
  background: transparent;
  border: none;
  border-radius: 0;
}

@media (max-width: 800px) {
  /* Single column. The four components live in two wrapper divs
     (.compare-left = picker + legend, .compare-right = chart + controls),
     so a plain stack would group by wrapper. display:contents unwraps
     both wrappers, making all four direct flex items of .compare-layout,
     so `order` can interleave them across the old column boundary into
     the mobile order:
       1. chart   2. on-chart legend   3. IEM picker   4. controls. */
  .compare-layout { display: flex; flex-direction: column; gap: 0.75rem; }
  .compare-left, .compare-right { display: contents; }

  /* Mobile order: chart first, then the on-chart legend ("IEMs
     selecionados") directly under it, then the IEM picker ("Lista de
     IEMs"), then the controls. The brand title sits above all this in
     the centered topbar. */
  .compare-right .chart-frame    { order: 1; }
  .compare-left > #legend        { order: 2; }
  .compare-left .add-curve-panel { order: 3; }
  .compare-right .chart-controls { order: 4; }

  /* Stacked, each component is its own card. The desktop "unified card"
     joins (clipped corners, dropped borders, shared edges, 50/50 flex)
     only make sense side-by-side — restore full borders/radius/bg here. */
  .compare-left .add-curve-panel,
  .compare-left > #legend,
  .compare-right .chart-frame,
  .compare-right .chart-controls {
    margin: 0;
    flex: initial;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    box-shadow: var(--shadow-sm);
  }
  .compare-left .add-curve-list { max-height: 360px; flex: 1 1 auto; min-height: 120px; }

  /* squig.link-style full-bleed chart: drop the tall min-height clamp (the
     frame wraps the short wide chart), kill the padding, and cancel main's
     1rem side padding with negative margins so the plot reaches the window
     edges. Side borders/radius off so it reads as a clean full-width band;
     keep the top/bottom border to divide it from the brand + picker. */
  .compare-right .chart-frame {
    min-height: 0;
    padding: 0;
    margin-left: -1rem;
    margin-right: -1rem;
    border-left: none;
    border-right: none;
    border-radius: 0;
  }

  /* squig.link-style header: brand name centered at the very top; the
     theme toggle tucks into the corner so it doesn't break the centering.
     .topbar keeps position:sticky (which is also the positioning context
     the absolute toggle anchors to — don't override it). */
  .topbar { flex-direction: column; align-items: center; text-align: center; gap: 0.2rem; }
  .topbar nav { display: none; }
  .topbar .brand { font-size: 2rem; }
  .topbar-meta { font-size: 0.78rem; }
  .topbar .theme-toggle { position: absolute; top: 0.55rem; right: 0.85rem; }
}

/* Lives inside .chart-controls now — pushed to the far right via
   margin-left: auto, aligned vertically with the <label> stacks. */
.chart-toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0 0 0 auto; align-self: flex-end; }
.chart-toolbar button {
  padding: 0.5rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--fg);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease);
}
.chart-toolbar button:hover {
  background: var(--bg-card);
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.chart-toolbar button:active { transform: translateY(0); box-shadow: none; }
/* Share-link button text picks up the same lime accent as the
   footer's "source" link (and other <a> tags). The 💾 export button
   stays neutral so the emoji color isn't overridden. */
.chart-toolbar #btn-copy-link { color: var(--accent); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }
.chart-toolbar #btn-copy-link svg { display: block; }
.chart-toolbar .toolbar-status { color: var(--fg-muted); font-size: 0.85rem; align-self: center; margin-left: auto; }

.chart-controls {
  display: flex; flex-wrap: wrap;
  gap: 0.85rem 1.5rem;
  padding: 1rem 1.15rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  /* Only the outer (bottom-right) corner is rounded — touches
     .compare-left on the left and .chart-frame on top. */
  border-radius: 0 0 var(--radius-lg) 0;
  box-shadow: var(--shadow-sm);
  margin: 0 0 1rem;
}
.chart-controls label {
  display: flex; flex-direction: column; gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Custom-styled select — strip the browser appearance, draw a chevron
   via SVG background. Same treatment as inputs so the controls strip
   reads as one cohesive surface. */
.chart-controls select,
.chart-controls input[type="number"],
#filter-brand,
#filter-search {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--fg);
  font: inherit;
  font-size: 0.9rem;
  letter-spacing: -0.005em;
  transition: border-color var(--t-fast) var(--ease),
              background var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease);
}
.chart-controls select,
#filter-brand {
  padding-right: 2.25rem;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M3 4.5l3 3 3-3' stroke='%23a1a1aa' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 12px;
  cursor: pointer;
  min-width: 140px;
}
.chart-controls input[type="number"] { width: 140px; }
.chart-controls select:hover,
.chart-controls input[type="number"]:hover,
#filter-brand:hover,
#filter-search:hover {
  border-color: var(--border-strong);
  background-color: var(--bg-card);
}
.chart-controls select:focus,
.chart-controls input[type="number"]:focus,
#filter-brand:focus,
#filter-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(195, 252, 13, 0.15);
}

/* Glassmorphism tooltip — fits the soft-black palette, reads cleanly
   over both dark surfaces and the chart's light grid. */
.chart-tooltip {
  position: absolute;
  background: var(--tooltip-bg);
  color: var(--tooltip-fg);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: -0.005em;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  pointer-events: none;
  line-height: 1.45;
  box-shadow: var(--shadow-lg);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
}

#legend {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.15rem;
}

.legend-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; margin: 0 0 0.85rem; flex-wrap: wrap; }
.legend-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0.4rem 0.5rem; flex: 1; min-width: 0; }

/* squig.link-style colored chip. The swatch becomes the left accent
   bar; chart.js sets the chip color via --curve-color on the <li>.
   The pop-in animation runs every time htmx swaps the legend, which
   is exactly when a chip is added — feels alive without being noisy. */
.legend-item {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.3rem 0.55rem 0.3rem 0.65rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--curve-color, var(--fg-muted));
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: -0.005em;
  transition: background var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
  animation: chip-in var(--t-base) var(--ease);
}
.legend-item:hover { background: var(--bg-card); border-color: var(--border-strong); transform: translateY(-1px); }
@keyframes chip-in {
  from { opacity: 0; transform: translateY(4px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

.swatch { display: none; }  /* legacy — chip's left border replaces it */
.legend-label { color: var(--curve-color, var(--fg)); }
.remove-btn {
  border: none; background: transparent;
  color: var(--fg-subtle);
  cursor: pointer; font-size: 1rem; line-height: 1;
  padding: 0 0.15rem;
  border-radius: var(--radius-sm);
  transition: color var(--t-fast) var(--ease);
}
.remove-btn:hover { color: var(--danger); }

.clear-all-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg-muted);
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.4rem 0.45rem;
  border-radius: var(--radius);
  cursor: pointer; flex-shrink: 0;
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.clear-all-btn svg { display: block; }
.clear-all-btn:hover { color: var(--danger); border-color: var(--danger); background: rgba(248, 29, 120, 0.08); }

.empty-legend {
  color: var(--fg-muted);
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  /* Empty-state row with the inline SVG hint added in compare_legend.html */
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.empty-legend svg { color: var(--accent-soft); flex-shrink: 0; }

.add-curve-panel { display: flex; flex-direction: column; gap: 0.65rem; min-height: 0; flex: 1; }
.add-curve-filters { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.filter-pills { display: inline-flex; gap: 0.3rem; padding: 0.2rem; background: var(--bg-elev); border-radius: var(--radius-pill); }
.filter-pills .pill {
  background: transparent;
  border: 1px solid transparent;
  color: var(--fg-muted);
  font: inherit; font-size: 0.78rem;
  font-weight: 500;
  padding: 0.3rem 0.8rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.filter-pills .pill:hover { color: var(--fg); }
.filter-pills .pill.is-active {
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

#filter-brand { min-width: 140px; font-size: 0.85rem; padding: 0.4rem 0.7rem; }
#filter-search { flex: 1; min-width: 160px; font-size: 0.85rem; padding: 0.4rem 0.7rem; }

/* Live-filtered product list. Scrolls vertically with a custom
   scrollbar; each row is a clickable button with a "+" affordance
   on the right. Max-height keeps the page from ballooning when the
   user clears all filters and 880 rows render. */
.add-curve-list {
  display: flex; flex-direction: column;
  max-height: 360px;
  overflow-y: auto; overflow-x: hidden;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.add-curve-list::-webkit-scrollbar { width: 10px; }
.add-curve-list::-webkit-scrollbar-track { background: transparent; }
.add-curve-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-pill);
  border: 2px solid var(--bg-elev);
}
.add-curve-list::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

.add-curve-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 0.95rem;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
  font: inherit; font-size: 0.9rem;
  letter-spacing: -0.005em;
  text-align: left;
  cursor: pointer;
  position: relative;
  transition: background var(--t-fast) var(--ease), padding-left var(--t-fast) var(--ease);
}
.add-curve-item:last-child { border-bottom: none; }
.add-curve-item:hover {
  background: var(--bg-card);
  padding-left: 1.15rem;
}
.add-curve-item:hover::before {
  content: "";
  position: absolute;
  left: 0; top: 20%; bottom: 20%;
  width: 3px;
  background: var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
/* `display: flex` above beats the user-agent `[hidden] { display: none }`
   rule by specificity, so without this override the JS filter that
   sets `row.hidden = true` would have zero visible effect. */
.add-curve-item[hidden] { display: none; }
.add-curve-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.add-curve-plus {
  color: var(--fg-subtle);
  font-size: 1.25rem;
  font-weight: 300;
  line-height: 1;
  flex-shrink: 0;
  margin-left: 0.75rem;
  transition: color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.add-curve-item:hover .add-curve-plus {
  color: var(--accent);
  transform: rotate(90deg) scale(1.15);
}

.add-curve-empty { color: var(--fg-muted); font-size: 0.85rem; margin: 0.5rem 0 0; text-align: center; }

.chart-frame .empty { padding: 4rem 2rem; color: var(--fg-muted); text-align: center; }

/* ===== admin ======================================================= */

.admin-section { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin: 0 0 1.25rem; }
.admin-section h2 { margin: 0 0 0.75rem; font-size: 1.1rem; color: var(--fg); }
.admin-status { margin-left: 0.75rem; font-size: 0.85rem; color: var(--fg-muted); }
.admin-status.error { color: var(--danger); }

#upload-form { display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: end; }
#upload-form label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; color: var(--fg-muted); }
#upload-form input[type="text"], #upload-form input[type="file"], #upload-form select {
  padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--fg); font: inherit; min-width: 160px;
}
#upload-form button { padding: 0.45rem 1rem; background: var(--accent); color: var(--accent-fg); border: 1px solid var(--accent); border-radius: var(--radius); font: inherit; cursor: pointer; font-weight: 500; }
#upload-form button:hover { opacity: 0.9; }

#admin-reindex button { padding: 0.45rem 1rem; background: var(--accent); color: var(--accent-fg); border: 1px solid var(--accent); border-radius: var(--radius); font: inherit; cursor: pointer; margin-right: 0.75rem; }
#admin-reindex label { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; color: var(--fg-muted); margin-right: 0.75rem; }

.admin-search { width: 100%; max-width: 320px; padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--fg); font: inherit; margin-bottom: 0.75rem; }
.admin-table-wrap { overflow-x: auto; }
table.admin-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; min-width: 720px; }
table.admin-table th, table.admin-table td { padding: 0.4rem 0.6rem; text-align: left; border-bottom: 1px solid var(--border); }
table.admin-table th { background: var(--bg-elev); font-weight: 600; color: var(--fg-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
table.admin-table tr.dragging { opacity: 0.4; }
table.admin-table input, table.admin-table select { background: transparent; color: var(--fg); border: 1px solid transparent; border-radius: 3px; padding: 0.25rem 0.4rem; font: inherit; width: 100%; min-width: 80px; }
table.admin-table input:hover, table.admin-table select:hover { border-color: var(--border); }
table.admin-table input:focus, table.admin-table select:focus { outline: none; border-color: var(--accent); background: var(--bg-elev); }
table.admin-table input.saved { background: var(--bg-elev); transition: background 0.5s; }
table.admin-table input.error-field { border-color: var(--danger); }

.fav-btn, .delete-btn, .delete-target-btn { background: transparent; border: none; color: var(--fg-muted); cursor: pointer; font-size: 1rem; padding: 0.2rem 0.4rem; }
.fav-btn[data-on="1"] { color: var(--accent); }
.delete-btn:hover, .delete-target-btn:hover { color: var(--danger); }
.drag-handle { color: var(--fg-muted); cursor: grab; user-select: none; text-align: center; }

.admin-targets { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.4rem; }
.admin-targets li { display: flex; align-items: center; gap: 1rem; padding: 0.4rem 0.6rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); }
.admin-targets li code { color: var(--fg-muted); font-size: 0.78rem; flex: 1; }

/* ===== mobile ====================================================== */

@media (max-width: 640px) {
  main { margin: 1rem auto; }
  .topbar { gap: 0.75rem; padding: 0.5rem 0.85rem; flex-wrap: wrap; }
  .topbar nav a { margin-right: 0.75rem; }
  .hero h1 { font-size: 2rem; }
  .filters { flex-direction: column; }
  .filters input, .filters select, .filters button { width: 100%; }
  dl.props { grid-template-columns: 1fr; }
  dl.props dt { margin-top: 0.5rem; }
  .chart-controls { flex-direction: column; gap: 0.5rem; }
  .chart-controls label { width: 100%; }
  .chart-controls select { width: 100%; }
  .chart-toolbar .toolbar-status { width: 100%; margin: 0; text-align: left; }
}
