/* insights area styles (loaded after app.css): home dashboard analytics, SVG charts, savings report. */

:root {
  /* Chart tokens — mirrored in appui/lib/charts.js (VIZ). Categorical order validated for CVD on white. */
  --viz-1: #3550E0; --viz-2: #EB6834; --viz-3: #1BAF7A; --viz-4: #E0A100; --viz-5: #6A3FC9; --viz-6: #E87BA4;
  --viz-neg: #D2380F; --viz-total: #A3ABC4; --viz-final: #283253;
  --viz-grid: #EBEEF5; --viz-axis: #C9CFDF;
}

/* ---------- Toolbar: period + example switch (one row above everything it scopes) ---------- */
.ins-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ins-exbadge { font-size: 11.5px; }
.ins-exbadge::before { display: none; }
.ins-toolbar { display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap; margin: -4px 0 16px; }
.ins-toolbar .seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.ins-toolbar .seg button { white-space: nowrap; }
.ins-switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.ins-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.ins-switch .track { width: 34px; height: 20px; border-radius: 99px; background: var(--rule); position: relative; transition: background .15s; flex: none; }
.ins-switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(12,20,51,.25); transition: transform .15s; }
.ins-switch input:checked + .track { background: var(--violet); }
.ins-switch input:checked + .track::after { transform: translateX(14px); }
.ins-switch input:focus-visible + .track { outline: 2px solid var(--sky-ink); outline-offset: 2px; }
.ins-exbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--violet-soft); border-color: #DCCEF8; color: #3F2483; margin-bottom: 16px; }
.ins-exbar svg { color: var(--violet); }
.ins-body { transition: opacity .15s; }
.ins-body.busy { opacity: .55; pointer-events: none; }
.ins-note { font-size: 13px; }

/* ---------- Top row: hero + savings stats ---------- */
.ins-top > .card { margin-top: 0; }
.ins-top { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 1000px) { .ins-top { grid-template-columns: minmax(0, 1fr); } }
.ins-hero { padding: 20px 22px 16px; display: flex; flex-direction: column; min-width: 0; }
.ins-kicker { color: var(--steel); font-size: 13px; font-weight: 620; }
.ins-hero-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.ins-hero-value { font-size: clamp(36px, 6.4vw, 54px); font-weight: 700; line-height: 1.05; letter-spacing: -.02em; font-stretch: 90%; color: var(--ink); overflow-wrap: anywhere; }
.ins-pill { display: inline-flex; align-items: center; height: 28px; padding: 0 11px; border-radius: 99px; background: var(--sky-soft); color: var(--sky-ink); font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.ins-pill.neg { background: var(--oxide-soft); color: var(--oxide-btn-h); }
.ins-hero-sub { color: var(--ink-2); margin: 8px 0 14px; max-width: 60ch; }
.ins-mini { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; border-top: 1px solid var(--rule-2); border-bottom: 1px solid var(--rule-2); }
.ins-mini .ins-metric { padding: 10px 12px 10px 0; }
.ins-mini .ins-metric + .ins-metric { padding-left: 12px; border-left: 1px solid var(--rule-2); }
.ins-mini .v { font-size: 18px; }
@media (max-width: 560px) {
  .ins-mini { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ins-mini .ins-metric:nth-child(3) { padding-left: 0; border-left: 0; }
  .ins-mini .ins-metric:nth-child(n+3) { border-top: 1px solid var(--rule-2); }
}
.ins-spark { margin-top: 12px; }
.ins-spark .viz { margin-top: 2px; }
.ins-hero-empty .ins-hero-value { color: var(--steel-2); }
.ins-hero-empty .row { margin-bottom: 4px; }

.ins-metric { min-width: 0; }
.ins-metric .k { font-size: 12px; color: var(--steel); font-weight: 500; }
.ins-metric .v { font-size: 22px; font-weight: 650; line-height: 1.2; font-stretch: 90%; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ins-metric .h { font-size: 11.5px; color: var(--steel); margin-top: 2px; line-height: 1.35; }
.ins-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.ins-stats.two { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--rule-2); }
.ins-stats.two .v { font-size: 17px; }
@media (max-width: 420px) { .ins-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.ins-range { margin-top: 16px; }
.ins-keys { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; }
.ins-keys span { display: inline-flex; align-items: center; gap: 6px; }
.ins-keys i { display: inline-block; flex: none; }
.ins-keys .k-mean { width: 9px; height: 9px; border-radius: 50%; background: var(--ink); }
.ins-keys .k-median { width: 3px; height: 12px; border-radius: 2px; background: var(--viz-2); }
.ins-keys .k-sd { width: 16px; height: 8px; border-radius: 4px; background: rgba(53, 80, 224, .18); }
.ins-keys .k-ends { width: 8px; height: 8px; border-radius: 50%; background: var(--steel); }

/* "How we calculate" disclosure */
.ins-how { margin-top: 12px; font-size: 12.5px; color: var(--ink-2); }
.ins-how summary { cursor: pointer; color: var(--sky-ink); font-weight: 600; list-style: none; display: inline-flex; align-items: center; gap: 4px; }
.ins-how summary::-webkit-details-marker { display: none; }
.ins-how summary::after { content: "›"; transition: transform .15s; display: inline-block; margin-left: 2px; }
.ins-how[open] summary::after { transform: rotate(90deg); }
.ins-how ul { margin: 8px 0 0; padding: 10px 14px 10px 28px; background: #F7F8FC; border: 1px solid var(--rule-2); border-radius: var(--r-md); }
.ins-how li + li { margin-top: 4px; }

/* ---------- Process metrics ---------- */
.ins-process { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ins-process .ins-metric { padding: 14px 18px; border-bottom: 1px solid var(--rule-2); }
.ins-process .ins-metric:not(:nth-child(4n+1)) { border-left: 1px solid var(--rule-2); }
.ins-process .ins-metric:nth-last-child(-n+4) { border-bottom: 0; }
.ins-process .v { font-size: 20px; }
.ins-meter { height: 6px; margin: 6px 0 2px; max-width: 160px; }
@media (max-width: 900px) {
  .ins-process { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ins-process .ins-metric { border-left: 0 !important; border-bottom: 1px solid var(--rule-2) !important; }
  .ins-process .ins-metric:nth-child(2n) { border-left: 1px solid var(--rule-2) !important; }
  .ins-process .ins-metric:nth-last-child(-n+2) { border-bottom: 0 !important; }
  .ins-process .ins-metric { padding: 12px 14px; }
}

/* ---------- Charts ---------- */
.viz { width: 100%; min-width: 0; position: relative; }
.viz svg { display: block; width: 100%; height: auto; overflow: visible; }
.viz text { font-family: var(--font); }
.viz text.num { font-variant-numeric: tabular-nums; }
.viz .hit { cursor: default; outline: none; }
.viz .hit:hover, .viz .hit.viz-on { fill: rgba(12, 20, 51, .045); }
.viz .hit:focus-visible { fill: rgba(53, 80, 224, .10); }
.viz-tip { position: fixed; z-index: 120; pointer-events: none; background: var(--white); color: var(--ink); border: 1px solid var(--rule); border-radius: 9px; box-shadow: 0 10px 28px -8px rgba(10, 18, 48, .28); padding: 8px 11px; font-size: 12.5px; min-width: 150px; max-width: 280px; }
.viz-tip[hidden] { display: none; }
.viz-tip-h { font-weight: 650; margin-bottom: 4px; color: var(--ink); }
.viz-tip-r { display: grid; grid-template-columns: 12px auto minmax(0, 1fr); align-items: center; gap: 7px; line-height: 1.55; }
.viz-tip-r i { width: 12px; height: 2.5px; border-radius: 2px; display: block; }
.viz-tip-r i.none { background: transparent; }
.viz-tip-r b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.viz-tip-r span { color: var(--steel); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ins-legend { margin-bottom: 8px; color: var(--ink-2); }
.ins-caption { margin: 8px 0 0; }
.ins-empty { display: flex; gap: 12px; align-items: flex-start; padding: 22px 4px; color: var(--ink); }
.ins-empty > svg { width: 28px; height: 28px; color: var(--steel-2); flex: none; }
.ins-empty b { display: block; margin-bottom: 2px; }
.ins-table { margin-top: 10px; font-size: 12.5px; }
.ins-table summary { cursor: pointer; color: var(--steel); font-weight: 600; width: max-content; }
.ins-table summary:hover { color: var(--ink); }
.ins-table .table-wrap { margin-top: 8px; border: 1px solid var(--rule-2); border-radius: var(--r-md); }

/* ---------- System activity ---------- */
.ins-split { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(0, 2fr); gap: 24px; align-items: start; }
@media (max-width: 900px) { .ins-split { grid-template-columns: minmax(0, 1fr); gap: 14px; } }
.ins-acts { list-style: none; margin: 0; padding: 0; }
.ins-acts li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--rule-2); font-size: 13px; }
.ins-acts li:last-child { border-bottom: 0; }
.ins-acts i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.ins-acts li.ai { color: var(--ink-2); }
.ins-acts li.ai i { background: transparent; border: 1.5px solid var(--steel-2); }
.ins-acts b { font-size: 15px; }
.ins-feed li { padding-bottom: 12px; }
.ins-feed .row.top { flex-wrap: nowrap; }

/* ---------- Operations ---------- */
.ins-opswrap { margin-top: 28px; }
.ins-section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; margin-bottom: 12px; padding-top: 18px; border-top: 1px solid var(--rule); }
.ins-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.ins-chip { display: inline-flex; align-items: baseline; gap: 6px; padding: 5px 11px; border: 1px solid var(--rule); background: var(--white); border-radius: 99px; color: var(--ink-2); font-size: 12.5px; }
.ins-chip:hover { text-decoration: none; border-color: var(--steel-2); }
.ins-chip b { color: var(--ink); font-size: 14px; }
.ins-ops { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.ins-ops-side > .card + .card { margin-top: 16px; }
@media (max-width: 900px) { .ins-ops { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 560px) { .ins-hide-sm, .rep-hide-sm { display: none; } }

/* ---------- Savings report (A4 sheet) ---------- */
.rep-tools { max-width: 860px; margin-left: auto; margin-right: auto; }
.rep-sheet { --brand: var(--oxide-btn); max-width: 860px; margin: 0 auto; background: var(--white); border: 1px solid var(--rule); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 0 40px 28px; overflow: hidden; }
.rep-cover { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px 24px; flex-wrap: wrap; padding: 30px 0 22px; border-top: 6px solid var(--brand); margin: 0 -40px; padding-left: 40px; padding-right: 40px; border-bottom: 1px solid var(--rule); }
.rep-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.rep-logo { max-height: 44px; max-width: 160px; object-fit: contain; }
.rep-mono { width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; background: var(--brand); color: #fff; font-weight: 750; font-size: 17px; letter-spacing: .02em; flex: none; }
.rep-org { font-weight: 700; font-size: 17px; }
.rep-title { text-align: right; }
.rep-kicker { font-size: 12px; font-weight: 700; color: var(--steel); display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.rep-title h1 { font-size: 26px; margin: 2px 0; }
.rep-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; margin: 22px 0 6px; border: 1px solid var(--rule-2); border-radius: var(--r-md); }
.rep-kpi { padding: 12px 14px; min-width: 0; border-bottom: 1px solid var(--rule-2); }
.rep-kpi:not(:nth-child(4n+1)) { border-left: 1px solid var(--rule-2); }
.rep-kpi:nth-last-child(-n+4) { border-bottom: 0; }
.rep-kpi .k { font-size: 11.5px; color: var(--steel); font-weight: 600; }
.rep-kpi .v { font-size: 20px; font-weight: 700; font-stretch: 90%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rep-kpi.big .v { font-size: 24px; color: var(--ink); }
.rep-kpi .s { font-size: 11px; color: var(--steel); }
.rep-sec { margin-top: 26px; break-inside: avoid; page-break-inside: avoid; }
.rep-sec h2 { font-size: 15px; margin-bottom: 2px; padding-left: 10px; border-left: 3px solid var(--brand); }
.rep-sec .rep-table { font-size: 12.5px; }
.rep-sec > .table-wrap { margin-top: 8px; }
.rep-kv { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 16px; margin: 10px 0 0; }
.rep-kv dt { font-size: 11.5px; color: var(--steel); }
.rep-kv dd { margin: 0; font-weight: 650; font-size: 15px; }
.rep-method ul { margin: 8px 0 0; padding-left: 18px; font-size: 12px; color: var(--ink-2); }
.rep-method li + li { margin-top: 3px; }
.rep-foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 28px; padding-top: 10px; border-top: 1px solid var(--rule); font-size: 11px; color: var(--steel); }
@media (max-width: 700px) {
  .rep-sheet { padding: 0 16px 20px; }
  .rep-cover { margin: 0 -16px; padding: 22px 16px 16px; }
  .rep-title { text-align: left; }
  .rep-kicker { justify-content: flex-start; }
  .rep-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rep-kpi { border-left: 0 !important; border-bottom: 1px solid var(--rule-2) !important; }
  .rep-kpi:nth-child(2n) { border-left: 1px solid var(--rule-2) !important; }
  .rep-kpi:nth-last-child(-n+2) { border-bottom: 0 !important; }
  .rep-kv { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Upgrade panel over a blurred preview */
.rep-upgrade { position: relative; max-width: 860px; margin: 0 auto; min-height: 560px; }
.rep-preview { filter: blur(3px) saturate(.9); opacity: .7; pointer-events: none; user-select: none; max-height: 820px; overflow: hidden; -webkit-mask-image: linear-gradient(#000 55%, transparent); mask-image: linear-gradient(#000 55%, transparent); }
.rep-lock { position: absolute; top: 70px; left: 50%; transform: translateX(-50%); width: min(460px, calc(100% - 24px)); padding: 24px 26px; box-shadow: var(--shadow-lg); }
.rep-lock h2 { font-size: 19px; margin: 10px 0 6px; }
.rep-lock .feat { margin-top: 10px; }
.rep-lock-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--night); color: #fff; display: grid; place-items: center; margin-bottom: 10px; }
.rep-lock-icon svg { width: 20px; height: 20px; }
@media (max-width: 560px) { .rep-lock { top: 24px; padding: 18px; } }

/* ---------- Print: A4, no app shell ---------- */
@media print {
  @page { size: A4; margin: 14mm; }
  html, body { background: #fff !important; }
  body { -webkit-print-color-adjust: exact; print-color-adjust: exact; font-size: 12px; }
  .side, .topbar, .scrim, .toasts, .viz-tip, .btn, .ins-noprint, .rep-tools, .ins-toolbar, .page-head, .ins-table, .ins-how { display: none !important; }
  .shell { display: block !important; }
  .main { display: block !important; }
  .page { padding: 0 !important; max-width: none !important; }
  .rep-sheet { border: 0; box-shadow: none; border-radius: 0; padding: 0; max-width: none; overflow: visible; }
  .rep-cover { margin: 0; padding: 0 0 14px; border-top: 0; box-shadow: inset 0 6px 0 var(--brand); padding-top: 22px; }
  .rep-sec { margin-top: 18px; }
  .rep-break { break-before: page; page-break-before: always; }
  .card { box-shadow: none !important; }
  .table-wrap { overflow: visible !important; }
  .rep-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
  .rep-kpi { border-left: 0 !important; border-bottom: 1px solid var(--rule-2) !important; }
  .rep-kpi:not(:nth-child(4n+1)) { border-left: 1px solid var(--rule-2) !important; }
  .rep-kpi:nth-last-child(-n+4) { border-bottom: 0 !important; }
  .rep-kv { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
  .rep-title { text-align: right; }
  .rep-hide-sm { display: table-cell !important; }
  a { color: inherit; text-decoration: none; }
}

/* ---------- Night hero for the savings headline (the dashboard's one bold surface) ---------- */
.ins-hero:not(.ins-hero-empty) { background: var(--night); border-color: var(--night); color: #E6EAFA; position: relative; overflow: hidden;
  background-image: radial-gradient(520px 260px at 100% 0%, rgba(124,149,255,.22), transparent 70%), radial-gradient(420px 240px at 0% 120%, rgba(52,214,158,.16), transparent 70%); }
.ins-hero:not(.ins-hero-empty)::after { content: ""; position: absolute; right: -120px; top: -150px; width: 360px; height: 360px; border-radius: 50%; border: 1px solid rgba(169,180,220,.12); box-shadow: 0 0 0 54px rgba(169,180,220,.03); pointer-events: none; }
.ins-hero:not(.ins-hero-empty) > * { position: relative; z-index: 1; }
.ins-hero:not(.ins-hero-empty) .ins-kicker { color: var(--mist); }
.ins-hero:not(.ins-hero-empty) .ins-hero-value { color: #fff; font-variation-settings: "wdth" 84; font-size: clamp(42px, 6.6vw, 64px); animation: hero-in .7s cubic-bezier(.2,.8,.2,1) both; }
.ins-hero:not(.ins-hero-empty) .ins-hero-sub { color: var(--mist); }
.ins-hero:not(.ins-hero-empty) .ins-pill { background: rgba(52,214,158,.16); color: #7EEBC4; }
.ins-hero:not(.ins-hero-empty) .ins-pill.neg { background: rgba(255,90,46,.16); color: #FF9A7C; }
.ins-hero:not(.ins-hero-empty) .ins-mini { border-color: rgba(169,180,220,.18); }
.ins-hero:not(.ins-hero-empty) .ins-mini .ins-metric + .ins-metric { border-left-color: rgba(169,180,220,.18); }
.ins-hero:not(.ins-hero-empty) .ins-metric .k, .ins-hero:not(.ins-hero-empty) .ins-metric .h, .ins-hero:not(.ins-hero-empty) .tiny.muted { color: var(--mist-2); }
.ins-hero:not(.ins-hero-empty) .ins-metric .v { color: #fff; }
.ins-hero:not(.ins-hero-empty) a, .ins-hero:not(.ins-hero-empty) .linkish, .ins-hero:not(.ins-hero-empty) summary { color: #C3CEFF; }
.ins-hero:not(.ins-hero-empty) svg path[stroke] { stroke: #7EEBC4; }
@keyframes hero-in { from { opacity: 0; transform: translateY(8px); filter: blur(4px); } }
