/* FundWatcher public site — design system (Phase 7.3).
   Light, data-dense financial look (cf. Yahoo Finance / YCharts). One stylesheet,
   no build step; small Alpine islands only. */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --text: #16202c;
  --muted: #5d6b7a;
  --faint: #8a97a6;
  --border: #e2e7ed;
  --border-strong: #cdd5de;
  --brand: #1463c4;
  --brand-dark: #0f4d99;
  --pos: #157347;
  --neg: #c4341f;
  --shadow: 0 1px 2px rgba(16, 32, 44, .06), 0 1px 8px rgba(16, 32, 44, .04);
  --radius: 10px;
  --maxw: 1180px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 15px;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 1.25rem; }

/* ---- Header ---- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.site-header__inner {
  display: flex; align-items: center; gap: 1.25rem;
  height: 60px;
}
.brand { font-weight: 800; font-size: 1.2rem; color: var(--text); letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand span { color: var(--brand); }
.site-header .search { flex: 1; max-width: 460px; }

/* ---- Search box (home + header) ---- */
.search { position: relative; }
.search input {
  width: 100%; padding: .6rem .9rem; font-size: 1rem;
  border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--surface); color: var(--text); outline: none;
}
.search input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(20, 99, 196, .15); }
.search__menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow-y: auto; max-height: min(60vh, 420px); z-index: 60;
}
.search__item { display: block; padding: .55rem .9rem; border-bottom: 1px solid var(--border); }
.search__item:last-child { border-bottom: 0; }
.search__item:hover, .search__item.is-active { background: var(--surface-alt); text-decoration: none; }
.search__ticker { font-weight: 700; color: var(--text); margin-right: .5rem; }
.search__name { color: var(--muted); }
.search__family { display: block; color: var(--faint); font-size: .8rem; }

/* ---- Home hero ---- */
.hero { text-align: center; padding: 7vh 1rem 4rem; max-width: 640px; margin: 0 auto; }
.hero__logo { font-size: 2.6rem; font-weight: 800; letter-spacing: -.03em; margin-bottom: .25rem; }
.hero__logo span { color: var(--brand); }
.hero__tag { color: var(--muted); margin-bottom: 2rem; font-size: 1.05rem; }
.hero .search input { padding: .85rem 1.2rem; font-size: 1.1rem; }
.hero__examples { margin-top: 1.5rem; color: var(--faint); font-size: .9rem; }
.hero__examples a { margin: 0 .35rem; }

/* ---- Layout ---- */
main { padding: 1.5rem 0 3rem; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.5rem; align-items: start; }
.content { min-width: 0; }
.sidebar { display: flex; flex-direction: column; gap: 1.25rem; position: sticky; top: 76px; }
@media (max-width: 900px) {
  /* minmax(0, 1fr), NOT 1fr: a plain 1fr column has an `auto` minimum that
     grows to its content's intrinsic width, so a wide table would blow the
     page out sideways instead of scrolling inside its .table-wrap. */
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; }
}

/* ---- Cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1.25rem;
}
.card__head { padding: .85rem 1.1rem; border-bottom: 1px solid var(--border); display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.card__head h2 { margin: 0; }
.card__body { padding: 1.1rem; }
.card__body.p0 { padding: 0; }
.cite { font-size: .78rem; color: var(--faint); }
.cite a { color: var(--faint); text-decoration: underline; }
.asof { font-size: .72rem; color: var(--faint); }
.asof a { color: var(--faint); text-decoration: underline; }

/* ---- Fund header ---- */
.fundhead { margin-bottom: 1rem; }
.fundhead__ticker { font-size: 2rem; font-weight: 800; letter-spacing: -.02em; }
.fundhead__name { color: var(--muted); font-size: 1.05rem; }
.fundhead__family { color: var(--faint); font-size: .9rem; margin-top: .15rem; }
.badges { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.badge {
  display: inline-block; padding: .15rem .55rem; font-size: .75rem; font-weight: 600;
  background: #eef4fc; color: var(--brand-dark); border-radius: 999px; border: 1px solid #d7e6f9;
}

/* ---- Tabs ---- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; overflow-x: auto; }
.tabs a {
  padding: .65rem .95rem; color: var(--muted); font-weight: 600; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.is-active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---- Stat strip ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.stat { background: var(--surface); padding: .85rem 1rem; }
.stat__label { font-size: .75rem; color: var(--faint); text-transform: uppercase; letter-spacing: .03em; }
.stat__value { font-size: 1.25rem; font-weight: 700; margin-top: .15rem; }

/* ---- Tables ---- */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: .6rem .9rem; text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; color: var(--faint); font-weight: 600; }
.table tbody tr:hover { background: var(--surface-alt); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.shared-dot { color: var(--brand); font-weight: 700; }

/* ---- Charts (Chart.js islands) ---- */
.chart-box { position: relative; width: 100%; }
.chart-box--bar { height: 300px; }
.chart-box--donut { height: 240px; }
.chart-box--cal { height: 280px; }
.donut-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 720px) { .donut-grid { grid-template-columns: 1fr; } }

/* ---- Hover help (the "?" tooltips) ---- */
.tip { position: relative; display: inline-block; margin-left: .3rem; }
.tip__icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%; font-size: .68rem; font-weight: 700;
  background: var(--surface-alt); color: var(--muted); border: 1px solid var(--border-strong);
  cursor: help;
}
.tip__bubble {
  display: none; position: absolute; bottom: calc(100% + 8px); left: 50%;
  transform: translateX(-50%); width: min(240px, 90vw); max-width: 90vw; padding: .6rem .75rem;
  background: var(--text); color: #fff; font-size: .78rem; font-weight: 400;
  line-height: 1.4; border-radius: 8px; z-index: 80; text-transform: none;
  letter-spacing: normal; white-space: normal;
}
.tip:hover .tip__bubble, .tip:focus-within .tip__bubble { display: block; }

/* Teleported tooltip bubble (Alpine x-teleport to <body>): rendered at the top
   of the DOM so an ancestor's overflow:hidden (e.g. the .stats grid) can never
   clip it. Positioned with fixed coords from the trigger; visibility is driven
   by Alpine x-show, so it defaults to shown here (not display:none). */
.tip__bubble--float {
  display: block; position: fixed; bottom: auto;
  transform: translate(-50%, calc(-100% - 10px));
  z-index: 200; box-shadow: 0 6px 24px rgba(16, 32, 44, .28);
  pointer-events: none;
}

/* ---- Status pills (portfolio moves) ---- */
.pill {
  display: inline-block; padding: .1rem .5rem; border-radius: 999px;
  font-size: .72rem; font-weight: 600; border: 1px solid var(--border);
  background: var(--surface-alt); color: var(--muted);
}
.pill.new { background: #e7f4ec; color: var(--pos); border-color: #bfe3cd; }
.pill.exited { background: #fbeae7; color: var(--neg); border-color: #f0c9c1; }
.pill.increased { color: var(--pos); }
.pill.decreased { color: var(--neg); }

/* ---- Geography ---- */
#geo-map { height: 420px; border-radius: var(--radius); border: 1px solid var(--border); }
.contact-list { list-style: none; margin: 0; padding: 0; font-size: .92rem; }
.contact-list li { padding: .3rem 0; }
.contact-list .lbl { color: var(--faint); font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; display: block; }

/* ---- Family / list box ---- */
.linklist { list-style: none; margin: 0; padding: 0; }
.linklist li { border-bottom: 1px solid var(--border); }
.linklist li:last-child { border-bottom: 0; }
.linklist a { display: flex; justify-content: space-between; gap: .5rem; padding: .55rem 1.1rem; }
.linklist a:hover { background: var(--surface-alt); text-decoration: none; }
.linklist .tk { font-weight: 700; }
.linklist .sub { color: var(--muted); font-size: .85rem; }

/* ---- Prose ---- */
.prose { color: var(--text); }
.prose p { margin: 0 0 .8rem; }
.prose h3 { font-size: 1.05rem; margin: 1.6rem 0 .5rem; }
.prose h3:first-child { margin-top: 0; }
.prose ul { margin: 0 0 .8rem; padding-left: 1.25rem; }
.prose li { margin: 0 0 .35rem; }
.prose a { text-decoration: underline; }
.prose strong { font-weight: 700; }
.prose .legal-updated { color: var(--muted); font-size: .85rem; margin-bottom: 1.5rem; }
.prose .legal-lead { font-weight: 600; }

/* ---- Disclaimer / footer ---- */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); margin-top: 2rem; }
.site-footer__inner { padding: 1.5rem 0; font-size: .82rem; color: var(--muted); }
.site-footer a { color: var(--muted); text-decoration: underline; }
.site-footer__links { margin-top: .5rem; }

/* Expandable narrative (strategy "…" toggle) */
.expand-btn {
  background: none; border: 0; color: var(--brand); cursor: pointer;
  font: inherit; padding: 0; font-weight: 600;
}
.expand-btn:hover { text-decoration: underline; }

/* "View all" footer row inside a card */
.card__more { display: block; text-align: center; padding: .65rem 1rem; border-top: 1px solid var(--border); font-weight: 600; }
.card__more:hover { background: var(--surface-alt); text-decoration: none; }
.disclaimer { background: #fff8e6; border: 1px solid #f3e2b3; color: #6b5618; padding: .55rem .9rem; border-radius: 8px; font-size: .82rem; margin-bottom: 1.25rem; }

/* ---- Ad slots (AdSense placeholders) ---- */
.ad-wrap { display: flex; justify-content: center; margin: 0 0 1.25rem; }
.ad-slot {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  max-width: 100%; background: repeating-linear-gradient(45deg, #fbfcfd, #fbfcfd 10px, #f3f5f8 10px, #f3f5f8 20px);
  border: 1px dashed var(--border-strong); border-radius: 6px; color: var(--faint);
  font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; gap: .2rem;
}
.ad-slot__dims { font-size: .8rem; letter-spacing: 0; color: var(--muted); font-weight: 600; }
.ad-desktop { display: flex; }
.ad-mobile { display: none; }
@media (max-width: 720px) {
  .ad-desktop { display: none; }
  .ad-mobile { display: flex; }
}

.empty { color: var(--muted); padding: 1rem 0; }

/* ---- Pagination ---- */
.pager { display: flex; gap: .5rem; align-items: center; justify-content: center; padding: 1rem; }
.pager a, .pager span { padding: .4rem .8rem; border: 1px solid var(--border); border-radius: 6px; }
.pager .current { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---- Compare form ---- */
/* Bottom-align so the button sits level with the selects, not centered against
   the taller stacked label+select. */
.cmp-form { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.cmp-form input, .cmp-form select { padding: .55rem .8rem; border: 1px solid var(--border-strong); border-radius: 8px; font-size: 1rem; background: var(--surface); color: var(--text); }
.cmp-form label { display: flex; flex-direction: column; gap: .2rem; font-size: .8rem; color: var(--muted); font-weight: 600; }
.btn { display: inline-block; padding: .55rem 1rem; background: var(--brand); color: #fff; border: 0; border-radius: 8px; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.cmp-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 720px) { .cmp-cols { grid-template-columns: 1fr; } }
.coverage { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1rem; }

/* Compare page: shared positions carry a hover cue; hovering one cross-
   highlights the same security in both columns (.match-hover added by JS).
   Declared after .ov-shared so the hover colour wins over the shared tint. */
.cmp-cols tr.ov-shared { cursor: pointer; }
.cmp-cols tr.ov-shared td { background: #eef4fc; }
.cmp-cols tr.match-hover td { background: #ffe6b3; }

/* ---- Contact form ---- */
.contact-lead { color: var(--muted); margin: 0 0 1.1rem; }
.contact-form { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field__label { font-size: .82rem; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  padding: .6rem .8rem; border: 1px solid var(--border-strong); border-radius: 8px;
  font-size: 1rem; font-family: inherit; background: var(--surface); color: var(--text);
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(20, 99, 196, .15);
}
.field textarea { resize: vertical; min-height: 7rem; }
.field__err { font-size: .82rem; color: var(--neg); font-weight: 600; }
.contact-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
/* Honeypot: kept in the DOM but taken off-screen (not display:none, which some
   bots skip). A real visitor never sees or tabs to it. */
.contact-hp { position: absolute !important; left: -9999px !important;
  width: 1px; height: 1px; overflow: hidden; }

/* Inline notices (contact success / error banners). */
.notice { padding: .8rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.notice--ok { background: #e7f4ec; border: 1px solid #b6ddc6; color: #12633c; }
.notice--ok p { margin: .4rem 0 0; }
.notice--err { background: #fbeceb; border: 1px solid #f0bfba; color: #a32c1c; }

/* ============================================================================
   Responsive / mobile
   Breakpoints (shared across the site — reuse these, don't invent new ones):
     900px = content/sidebar layout collapses to one column
     720px = "phone": chart grids + ad slots swap to mobile, most tweaks live here
     480px = "narrow phone": tightest guard for the smallest screens
   Everything below is additive and mobile-scoped, so the >=901px desktop render
   is unchanged. New pages get mobile behaviour by adding .table-wrap around a
   wide table and reusing .hide-narrow / .only-narrow — no per-page media query.
   ========================================================================= */

/* Wrap any wide .table in <div class="table-wrap"> so it scrolls sideways on a
   phone instead of overflowing the page. Inert on desktop (the table never
   exceeds the wrapper there). The right-edge fade hints there's more to swipe;
   it only shows while the wrapper actually overflows. */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 720px) {
  .table-wrap {
    background:
      linear-gradient(to right, var(--surface) 30%, rgba(255, 255, 255, 0)) left center / 24px 100% no-repeat,
      linear-gradient(to left, var(--surface) 30%, rgba(255, 255, 255, 0)) right center / 24px 100% no-repeat,
      linear-gradient(to right, rgba(16, 32, 44, .10), rgba(255, 255, 255, 0)) right center / 14px 100% no-repeat;
    background-attachment: local, local, scroll;
  }
}

/* Reusable visibility utilities for the narrow-phone guard. */
.only-narrow { display: none; }
@media (max-width: 480px) {
  .hide-narrow { display: none !important; }
  .only-narrow { display: revert; }
}

/* Ads can never push the page wider than the viewport: cap every slot (live
   AdSense <ins> and the placeholder box) to the container. Which ads render is
   unchanged — only their max width is clamped. */
.ad-wrap { max-width: 100%; }
.ad-slot, .ad-wrap ins.adsbygoogle { max-width: 100%; }

/* ---- Phone (<=720px) ---- */
@media (max-width: 720px) {
  /* A touch more room for content/tables on small screens. */
  .container { padding: 0 1rem; }

  /* Header: let the search box use the full width and keep brand + search on
     the one 60px row comfortably. */
  .site-header__inner { gap: .75rem; }
  .brand { font-size: 1.05rem; }
  .site-header .search { max-width: none; }

  /* Tabs: keep the horizontal scroll, but hide the scrollbar chrome and add a
     right-edge fade so it reads as "more tabs, swipe". Navigation is unchanged. */
  .tabs { scrollbar-width: none; -webkit-overflow-scrolling: touch; position: relative; }
  .tabs::-webkit-scrollbar { display: none; }

  /* Comfortable ~44px tap targets. */
  .tabs a { padding: .7rem 1rem; }
  .pager a, .pager span { padding: .6rem 1rem; }
  .pager { gap: .4rem; }

  /* Stacked compare/moves forms: full-width controls read better than a wrapped
     inline row on a phone. */
  .cmp-form { gap: .5rem; }
  .cmp-form label, .cmp-form input, .cmp-form select { width: 100%; }
  .cmp-form .btn { width: 100%; text-align: center; }

  /* Leaflet map: the fixed 420px is too tall on a phone. */
  #geo-map { height: 320px; }
}

/* ---- Narrow phone (<=480px) ---- */
@media (max-width: 480px) {
  #geo-map { height: 260px; }
  .fundhead__ticker { font-size: 1.6rem; }
  h1 { font-size: 1.3rem; }
}

/* ============================================================================
   Highlighted stat strips, footnotes, SIC explorer, machine links
   ========================================================================= */

/* Global muted text (previously only scoped inside tables). */
.muted { color: var(--muted); }

/* "Machine-readable: JSON · Markdown" line under each data page. */
.machine-note { margin-top: 1rem; font-size: .82rem; }

/* Highlighted stat strip — key-stats boxes get a light brand-blue wash so they
   stand out from the plain white cards. */
.stats--hero { background: #dcebfb; border-color: #bcd4f0; }
.stats--hero .stat { background: linear-gradient(180deg, #f5faff 0%, #e7f1fc 100%); }
.stats--hero .stat__label { color: var(--brand-dark); }
.stats--hero .stat__value { letter-spacing: -.01em; }

/* Footnote superscript markers + the footnotes card. */
sup.fn { font-size: .72em; line-height: 0; }
sup.fn a { font-weight: 600; }
.footnotes { margin: 0; padding-left: 1.25rem; font-size: .85rem; color: var(--muted); }
.footnotes li { margin-bottom: .5rem; }
.footnotes li:last-child { margin-bottom: 0; }
.footnotes li:target { background: #fff8e6; }

/* ---- SIC industry explorer (portfolio breakdown) ---- */
.sec-group { border-bottom: 1px solid var(--border); }
.sec-group:last-child { border-bottom: 0; }
.sec-group__head {
  display: flex; align-items: center; gap: .6rem;
  width: 100%; padding: .7rem 1.1rem; cursor: pointer; border: 0;
  background: var(--surface-alt); font: inherit; font-weight: 700; color: var(--text);
  text-align: left;
}
.sec-group__head:hover { background: #eef4fc; }
.sec-group__chev { color: var(--faint); font-size: .8rem; transition: transform .15s ease; }
.sec-group__chev.is-open { transform: rotate(90deg); }
.sec-group__name { flex: 1; }
.sec-group__count { color: var(--faint); font-weight: 400; font-size: .8rem; }
.sec-group__weight { font-variant-numeric: tabular-nums; color: var(--brand-dark); white-space: nowrap; }

/* Clickable SIC-code chip: the visual cue that a code opens the drill-down. */
.sic-link {
  display: inline-flex; align-items: center; gap: .3rem;
  font-variant-numeric: tabular-nums; font-weight: 600; font-size: .85rem;
  color: var(--brand); background: #eef4fc; border: 1px solid #d7e6f9;
  border-radius: 6px; padding: .05rem .5rem; cursor: pointer;
}
.sic-link:hover { background: #dcebfb; border-color: #bcd4f0; }

/* Mini weight bar under a % figure. */
.wbar { display: block; height: 4px; background: #e8eef6; border-radius: 2px; margin-top: .3rem; overflow: hidden; }
.wbar span { display: block; height: 100%; background: var(--brand); }

/* ---- Modal (SIC drill-down) ---- */
.modal-backdrop {
  /* Above everything, including a Leaflet map (its panes/controls reach
     z-index ~1000) — otherwise the geography drill-down renders under the map. */
  position: fixed; inset: 0; background: rgba(16, 32, 44, .45); z-index: 2000;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(16, 32, 44, .25);
  width: min(640px, 96vw); max-height: min(80vh, 640px);
  display: flex; flex-direction: column;
}
.modal__head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  padding: .85rem 1.1rem; border-bottom: 1px solid var(--border);
}
.modal__title { margin: 0; font-size: 1.05rem; }
.modal__close {
  background: none; border: 0; font-size: 1.3rem; line-height: 1;
  color: var(--muted); cursor: pointer; padding: .2rem .4rem;
}
.modal__close:hover { color: var(--text); }
.modal__body { overflow-y: auto; }

/* Security pages: the security NAME is the headline (funds lead with the
   ticker; securities usually have none). */
.fundhead__ticker--name { font-size: 1.7rem; line-height: 1.2; }
.fundhead__symbol { color: var(--muted); font-weight: 600; font-size: 1.15rem; }
