/* ---------------------------------------------------------------------------
 * Analytics page styles
 * ---------------------------------------------------------------------------
 * Extracted from templates/analytics.ts inline <style> during the html``
 * migration (App-Building Bible principle 5). Loaded via the layout headExtra
 * <link> resolved through asset("analytics.css").
 * ------------------------------------------------------------------------- */

.analytics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 1024px) { .analytics-grid { grid-template-columns: 1fr; } }

.analytics-grid .card.full-width { grid-column: 1 / -1; }

.connect-notice {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  font-size: 13px;
  border: 1px dashed var(--border);
  padding: 24px;
  gap: 12px;
}
.connect-notice a { color: var(--primary); text-decoration: underline; }

.trend-placeholder {
  height: 200px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  font-size: 13px;
  border: 1px dashed var(--border);
}

.trend-placeholder svg {
  width: 48px;
  height: 48px;
  stroke: var(--text-3);
  margin-right: 12px;
  opacity: .5;
}

.mini-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.mini-table th {
  padding: 6px 10px;
  text-align: left;
  font-weight: 500;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.mini-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.mini-table tbody tr:last-child td { border-bottom: none; }
.mini-table tbody tr:hover { background: var(--bg-surface); }
.mini-table .num { text-align: right; font-variant-numeric: tabular-nums; }

.mini-table .title-cell {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mini-table .title-cell a { color: var(--primary); text-decoration: none; font-weight: 500; }
.mini-table .title-cell a:hover { text-decoration: underline; }

.stage-bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.stage-bar-label { width: 120px; text-align: right; font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 0; }
.stage-bar-track { flex: 1; height: 14px; background: var(--bg-muted); border-radius: 3px; overflow: hidden; position: relative; }
.stage-bar-fill { height: 100%; border-radius: 3px; }
.stage-bar-value { width: 40px; font-size: 11px; color: var(--text-2); font-variant-numeric: tabular-nums; flex-shrink: 0; }

.roi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
@media (max-width: 640px) { .roi-grid { grid-template-columns: 1fr; } }

.roi-stat {
  padding: 14px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  text-align: center;
}
.roi-stat .roi-value {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.roi-stat .roi-label { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.roi-stat.savings .roi-value { color: var(--success); }

.efficiency-pills {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
@media (max-width: 768px) { .efficiency-pills { grid-template-columns: repeat(2, 1fr); } }

.efficiency-pill {
  padding: 10px 12px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
}
.efficiency-pill .eff-label { font-size: 11px; color: var(--text-2); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.efficiency-pill .eff-value { font-size: 18px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }

.roi-assumptions {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
}
.roi-assumptions h4 { font-size: 12px; font-weight: 600; color: var(--text-2); margin: 0 0 8px; text-transform: uppercase; letter-spacing: 0.04em; }
.roi-input-row { display: flex; gap: 12px; align-items: center; margin-bottom: 6px; font-size: 13px; }
.roi-input-row label { width: 180px; color: var(--text-2); flex-shrink: 0; }
.roi-input-row input { width: 120px; }

/* --- Rules replacing former inline style= attributes (principle 17) --------- */
.trend-placeholder-title { font-weight: 500; color: var(--text-2); }
.trend-placeholder-sub { margin-top: 4px; }

.analytics-card-flush { padding: 0; }
.connect-notice[data-pad="32"] { padding: 32px; }

.analytics-count-chip { font-size: 11px; }

.analytics-empty { padding: 32px; text-align: center; color: var(--text-3); font-size: 13px; }
.analytics-empty-title { font-weight: 500; color: var(--text-2); margin-bottom: 4px; }

.analytics-neg { color: var(--error); }

.analytics-note { font-size: 13px; color: var(--text-3); text-align: center; padding: 12px; }
.analytics-bars-title { font-size: 12px; margin-bottom: 10px; margin-top: 8px; }
.analytics-bar-fill { background: var(--primary); }

.roi-recalc-row { margin-top: 8px; }

/* ---------------------------------------------------------------------------
 * Charts (CHART-1..4) — canvases, empty states, fullscreen lightbox, reveal.
 * Loaded via the layout headExtra <link>; strict CSP (style-src 'self') holds.
 * ------------------------------------------------------------------------- */

/* A chart canvas sits in a positioned frame so the expand affordance can float
   in the corner. The canvas is tappable (opens the lightbox). */
.chart-frame {
  position: relative;
  height: 260px;
}
.analytics-chart {
  display: block;
  width: 100%;
  height: 100%;
  cursor: zoom-in;
  border-radius: var(--radius-md);
}
.analytics-chart:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.chart-expand {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  border-radius: 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s, border-color .15s, color .15s;
}
.chart-frame:hover .chart-expand,
.chart-expand:focus-visible {
  opacity: 1;
}
.chart-expand:hover { border-color: var(--primary); color: var(--primary); }
.chart-expand:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Tasteful placeholder for charts with no real data (no fabricated numbers). */
.chart-empty {
  height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 24px;
  background: var(--bg-surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--text-3);
}
.chart-empty-icon svg { width: 44px; height: 44px; stroke: var(--text-3); opacity: .55; }
.chart-empty-title { font-weight: 500; color: var(--text-2); font-size: 13px; }
.chart-empty-sub { font-size: 12px; margin-top: 2px; }
.chart-empty-sub a { color: var(--primary); text-decoration: underline; }

/* --- Fullscreen lightbox (CHART-2) --------------------------------------- */
.chart-lightbox {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.chart-lightbox[hidden] { display: none; }

.chart-lightbox-scrim {
  position: absolute;
  inset: 0;
  background: rgba(9, 9, 11, .55);
}
.chart-lightbox-panel {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .18), 0 2px 8px rgba(0, 0, 0, .08);
  width: min(920px, 100%);
  max-height: min(720px, 92vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chart-lightbox-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
}
.chart-lightbox-title { font-size: 15px; font-weight: 600; color: var(--ink); }
.chart-lightbox-close {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-2);
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.chart-lightbox-close:hover { background: var(--border-light); color: var(--ink); }
.chart-lightbox-close:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.chart-lightbox-body {
  flex: 1;
  padding: 20px;
  min-height: 0;
}
.analytics-chart-full {
  width: 100% !important;
  height: 100% !important;
  cursor: default;
}

/* --- Progressive reveal (CHART-4) ---------------------------------------- */
.reveal-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.reveal-controls .btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
}
.reveal-controls .btn:hover { border-color: var(--primary); color: var(--primary); }
.reveal-controls .btn[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .chart-expand { transition: none; }
  .chart-lightbox-close { transition: none; }
}
