/* =====================================================================
   Analytics page (colours come from the tokens in app.css)
   ===================================================================== */

/* date range picker: one row above everything it scopes */
.an-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin-bottom: 0.9rem; }
.an-presets { margin: 0; }
.an-custom { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.an-custom label { display: inline-flex; align-items: center; gap: 0.4rem; }
.an-custom input { padding: 0.35rem 0.55rem; font-size: 0.85rem; color-scheme: dark; }

/* while new numbers load, the old ones stay on screen, faded */
.an-body { transition: opacity 0.15s; }
.an-body.is-loading { opacity: 0.55; pointer-events: none; }
.an-body > * + * { margin-top: 1rem; }

.an-range p { margin: 0; color: var(--text-soft); font-size: 0.88rem; }
.an-range .an-note { margin-top: 0.3rem; }
.an-note { margin: 0.35rem 0 0; font-size: 0.8rem; color: var(--muted); max-width: 72ch; }
.an-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* "too few to trust": muted figure + a small tag (and stripes on bars) */
.thin-tag {
  display: inline-block; margin-left: 0.35rem; padding: 0.02rem 0.4rem; border-radius: 999px;
  font-size: 0.66rem; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; vertical-align: 0.08em;
  color: var(--text-soft); border: 1px dashed var(--border-strong); cursor: help;
}
.an-range .thin-tag { margin-left: 0; }
.an-pct { font-weight: 700; font-variant-numeric: tabular-nums; }
.an-pct.is-thin { color: var(--muted); font-weight: 600; }
.an-stripe-key {
  display: inline-block; width: 1.6rem; height: 0.55rem; border-radius: 3px; vertical-align: 0.05em;
  background: repeating-linear-gradient(135deg, var(--teal) 0 2px, transparent 2px 5px); opacity: 0.8;
}

/* ---------- headline + funnel ---------- */
.an-top { display: grid; grid-template-columns: minmax(200px, 1fr) minmax(0, 3.2fr); gap: 1rem; align-items: stretch; }
.an-hero { display: flex; flex-direction: column; justify-content: center; }
.an-hero-value { font-size: 3.4rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; margin: 0.2rem 0 0.3rem; }
.an-hero .stat-sub { font-size: 0.84rem; line-height: 1.45; }
.an-hero .stat-sub b { color: #fff; }
.an-hero .thin-tag { color: #fff; border-color: rgba(255, 255, 255, 0.6); }

.an-funnel h2, .an-section h2, .an-time h2 { margin-bottom: 0.4rem; }
.an-steps { list-style: none; margin: 0.6rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0.6rem; }
.an-step { position: relative; padding: 0.75rem 0.8rem 0.7rem; border-radius: var(--radius-sm);
           background: rgba(5, 10, 28, 0.35); border: 1px solid var(--border); min-width: 0; }
.an-step + .an-step::before {  /* the arrow between steps */
  content: ""; position: absolute; left: -0.5rem; top: 1.45rem; width: 0.4rem; height: 0.4rem;
  border-top: 2px solid var(--border-strong); border-right: 2px solid var(--border-strong); transform: rotate(45deg);
}
.an-step-label { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.an-step-value { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
.an-step-bar { height: 6px; margin: 0.35rem 0 0.45rem; border-radius: 99px; background: rgba(255, 255, 255, 0.06); overflow: hidden; }
.an-step-bar i { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--accent-bright); }
.an-step-signed .an-step-bar i { background: var(--green); }
.an-step-signed { border-color: rgba(47, 214, 123, 0.35); }
.an-step-rate { font-size: 0.78rem; color: var(--text-soft); line-height: 1.35; }
.an-step-rate .thin-tag { margin-left: 0.2rem; }
.an-funnel .an-note:first-of-type { margin-top: 0.8rem; }

/* ---------- by hour / by day ---------- */
.an-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: start; }
.an-callout { margin: 0 0 0.8rem !important; font-size: 0.86rem; }
.an-bars { display: flex; flex-direction: column; gap: 2px; }
.an-row { display: grid; grid-template-columns: 3.4rem minmax(0, 1fr) minmax(0, 1fr); align-items: center; gap: 0.8rem;
          padding: 0.22rem 0.35rem; border-radius: 6px; font-size: 0.82rem; }
.an-row:not(.an-bars-head):hover { background: rgba(255, 255, 255, 0.04); }
.an-bars-head { font-size: 0.66rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted);
                padding-bottom: 0.35rem; }
.an-bars-head small { font-size: inherit; font-weight: 600; letter-spacing: 0; text-transform: none; opacity: 0.8; }
.an-row-label { color: var(--text-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.an-row.is-best .an-row-label { color: var(--text); font-weight: 800; }
.an-cell { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.an-cell b { flex: none; min-width: 2.6rem; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.an-track { flex: 1; min-width: 0; height: 12px; border-radius: 0 4px 4px 0; background: rgba(255, 255, 255, 0.045); overflow: hidden; }
.an-fill { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.an-fill.calls { background: var(--accent); opacity: 0.75; }
.an-fill.rate { background: var(--teal); }
.an-row.is-best .an-fill.rate { background: var(--green); }
.an-row.is-thin .an-fill.rate { background: repeating-linear-gradient(135deg, var(--teal) 0 2px, transparent 2px 5px); opacity: 0.8; }
.an-row.is-thin .an-cell:last-child b { color: var(--muted); font-weight: 600; }

/* ---------- tables ---------- */
.an-card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; }
.an-card-head .chip-group { margin: 0; }
.an-section .table-wrap { margin-top: 0.8rem; background: rgba(5, 10, 28, 0.25); }
.an-table { min-width: 640px; }
.an-table td { padding: 0.6rem 0.9rem; }
.an-name b { font-weight: 700; }
.an-name small { display: block; color: var(--muted); font-size: 0.74rem; }
.an-n { white-space: nowrap; font-variant-numeric: tabular-nums; }
.an-n .an-pct { margin-left: 0.25rem; color: var(--text-soft); }
.an-n .an-pct.is-thin { color: var(--muted); }
.an-lately small { display: block; color: var(--muted); font-size: 0.72rem; }
.an-lately .an-pct { margin-left: 0; }
.an-mono { font-family: var(--mono); font-size: 0.84rem; }
.an-zero td { color: var(--muted); }
.an-latest { min-width: 150px; width: 26%; }
.an-stack { display: flex; gap: 2px; height: 12px; border-radius: 4px; overflow: hidden; background: rgba(255, 255, 255, 0.04); }
.an-stack i { display: block; min-width: 3px; height: 100%; }
.an-legend { display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; margin-top: 0.6rem; font-size: 0.76rem; color: var(--text-soft); }
.seg-amber { background: var(--amber); }
.seg-red { background: var(--red); }
.seg-purple { background: var(--purple); }
.seg-blue { background: var(--blue); }
.seg-green { background: var(--green); }
.seg-teal { background: var(--teal); }
.seg-grey { background: var(--grey); }
tr.an-warn td { background: rgba(255, 95, 120, 0.06); }
.an-warn-pill { display: flex; width: fit-content; max-width: 22rem; margin-top: 0.3rem; padding: 0.2rem 0.5rem;
                border-radius: 7px; white-space: normal; font-size: 0.72rem; line-height: 1.3; }

/* ---------- empty states ---------- */
.an-empty { max-width: 640px; }
.an-empty .btn { margin-top: 0.6rem; }

/* ---------- smaller screens ---------- */
@media (max-width: 1100px) {
  .an-top { grid-template-columns: 1fr; }
  .an-hero-value { font-size: 2.8rem; }
}

@media (max-width: 960px) {
  .an-pair { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  /* the funnel becomes a list, one step per line */
  .an-steps { grid-template-columns: 1fr; gap: 0.4rem; }
  .an-step { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 0.8rem; align-items: baseline; padding: 0.6rem 0.75rem; }
  .an-step + .an-step::before { display: none; }
  .an-step-label { grid-column: 1; grid-row: 1; }
  .an-step-value { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-size: 1.45rem; }
  .an-step-rate { grid-column: 1; grid-row: 2; }
  .an-step-bar { grid-column: 1 / -1; grid-row: 3; margin: 0.4rem 0 0; }
  .an-filters { gap: 0.5rem; }
  .an-custom { width: 100%; }
}

/* phones: keep the row's name in view while the rest of the table scrolls sideways */
@media (max-width: 600px) {
  .an-table { min-width: 600px; }
  .an-table th:first-child, .an-table td:first-child {
    position: sticky; left: 0; z-index: 1; background: var(--panel-solid);
    min-width: 9.5rem; max-width: 12rem; box-shadow: 1px 0 0 var(--border);
  }
  tr.an-warn td:first-child { background: linear-gradient(rgba(255, 95, 120, 0.06), rgba(255, 95, 120, 0.06)), var(--panel-solid); }
}

@media (max-width: 480px) {
  .an-row { grid-template-columns: 2.9rem minmax(0, 1fr) minmax(0, 1fr); gap: 0.5rem; padding: 0.2rem 0.1rem; }
  .an-cell { gap: 0.35rem; }
  .an-cell b { min-width: 2.2rem; font-size: 0.78rem; }
  .an-hero-value { font-size: 2.6rem; }
  .an-custom label { flex: 1 1 calc(50% - 0.5rem); }
  .an-custom input { flex: 1; min-width: 0; }
  .an-custom .btn { flex: 1 1 100%; }
}
