/* Sector Dashboard - mobile first: base rules target a phone screen,
   the media query at the end widens the layout on larger screens. */

:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #5d6b7c;
  --line: #dde2e8;
  --accent: #3b5b8c;          /* neutral blue: scores are not buy/sell signals */
  --track: #e6eaf0;
  --note-bg: #fff6dd;
  --note-line: #e8c96a;
  --alert-bg: #fde7e7;
  --alert-text: #a12a2a;
  /* Same colors as reports/growth.png, so the two can be compared at a glance. */
  --strategy: #2a6fdb;
  --spy: #f0642d;
  --equal: #16a37f;
  /* Moving averages on the price charts */
  --ma50: #3d7bd9;
  --ma200: #c27a1a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b;
    --card: #1a2029;
    --text: #e4e9ef;
    --muted: #9aa7b6;
    --line: #2c3541;
    --accent: #8fb0e0;
    --track: #2a323d;
    --note-bg: #3a3218;
    --note-line: #8a7530;
    --alert-bg: #4a1f1f;
    --alert-text: #ffb4b4;
    --ma50: #7aa7ec;
    --ma200: #e0a050;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 16px 32px;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

h1 { font-size: 1.4rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 8px; }

.page-header { padding: 16px 0 8px; }
.meta { margin: 0; color: var(--muted); font-size: 0.9rem; }
.meta strong { color: var(--text); }

.disclaimer {
  margin: 8px 0 16px;
  padding: 10px 12px;
  background: var(--note-bg);
  border: 1px solid var(--note-line);
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
}

.alert { color: var(--alert-text); font-weight: 600; }
.stale-banner {
  margin: 8px 0;
  padding: 10px 12px;
  background: var(--alert-bg);
  color: var(--alert-text);
  border: 1px solid var(--alert-text);
  border-radius: 8px;
  font-size: 0.9rem;
}
.alert-box p { margin: 0 0 10px; }
.retry {
  font: inherit;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--alert-text);
  background: var(--card);
  color: var(--alert-text);
  cursor: pointer;
}
.alert-box {
  padding: 12px;
  background: var(--alert-bg);
  color: var(--alert-text);
  border-radius: 8px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 16px;
}

.lead { margin: 0 0 12px; }
.small { font-size: 0.85rem; color: var(--muted); margin: 8px 0 0; }

/* Backtest: one row per portfolio, bar length = annual return */
.bt-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  margin-bottom: 8px;
}
.bt-label { font-size: 0.9rem; }
.bt-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.bt-bar { grid-column: 1 / -1; height: 8px; background: var(--track); border-radius: 4px; overflow: hidden; }
.bt-bar span { display: block; height: 100%; border-radius: 4px; }

details { margin-top: 10px; }
summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 4px 0; }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
th, td { padding: 4px 6px; text-align: right; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; }

.growth img { width: 100%; height: auto; border-radius: 6px; background: #fff; }

/* Product cards (sectors and comparison products) */
.section-title { margin: 24px 0 4px; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: 0.9rem; }

.product-list { list-style: none; margin: 0; padding: 0; }
.product {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 10px;
}
.product > summary {
  list-style: none;            /* hide the default triangle */
  cursor: pointer;
  padding: 12px 14px;
  color: inherit;
  font-weight: normal;
}
.product > summary::-webkit-details-marker { display: none; }
.product[open] > summary { border-bottom: 1px solid var(--line); }

.card-top { display: flex; align-items: baseline; gap: 8px; }
.rank { color: var(--muted); font-size: 0.85rem; min-width: 2em; }
.symbol { font-weight: 700; }
.name { color: var(--muted); font-size: 0.9rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score { font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.tag { font-size: 0.75rem; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; }
.as-of { margin: 4px 0 0; font-size: 0.8rem; color: var(--muted); }

.score-bar { height: 6px; background: var(--track); border-radius: 3px; margin: 8px 0; overflow: hidden; }
.score-bar span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

.facts { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 0.85rem; color: var(--muted); margin-top: 6px; }
.facts b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.facts .more { margin-left: auto; color: var(--accent); font-weight: 600; }
.facts .more::after { content: " \25BE"; }
.product[open] .facts .more::after { content: " \25B4"; }

/* Detail of an opened card */
.detail { padding: 4px 14px 14px; }
.detail-block { margin-top: 14px; }
.detail h3 { font-size: 0.95rem; margin: 0 0 6px; }
.detail p { margin: 4px 0; }

.component { display: grid; grid-template-columns: 1fr auto; gap: 0 8px; margin-top: 8px; }
.component-label { font-size: 0.9rem; }
.component-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.component .score-bar { grid-column: 1 / -1; margin: 4px 0 2px; }
.component-help { grid-column: 1 / -1; font-size: 0.8rem; color: var(--muted); margin: 0; }

.measures { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin: 0; }
.measures dt { font-size: 0.8rem; color: var(--muted); }
.measures dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Price chart */
.chart { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; font-family: inherit; }
.chart path { fill: none; stroke-width: 1.6; stroke-linejoin: round; }
.line-price { stroke: var(--text); }
.line-ma50 { stroke: var(--ma50); }
.line-ma200 { stroke: var(--ma200); stroke-dasharray: 5 3; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
.legend b { color: var(--text); font-weight: 600; }
.swatch { display: inline-block; width: 14px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 4px; }
.swatch.line-price { border-color: var(--text); }
.swatch.line-ma50 { border-color: var(--ma50); }
.swatch.line-ma200 { border-color: var(--ma200); border-top-style: dashed; }

.page-footer { margin-top: 24px; color: var(--muted); font-size: 0.85rem; }
.loading { color: var(--muted); }

/* Wider screens: same content, centered column */
@media (min-width: 720px) {
  body { max-width: 760px; margin: 0 auto; padding: 0 24px 40px; }
  h1 { font-size: 1.7rem; }
}
