/* =========================================================
   ANALYTICS PAGE
   Page-specific layout for the Analytics dashboard: hero band,
   split FB/IG KPI grids, trend/donut charts, top-posts spotlight.
   Shared card/list chrome (.kpi, .panel, .inbox-list) stays in
   their own component files — this file only holds what's unique
   to this page.
========================================================= */

/* One vertical rhythm for every top-level block on the page — gap does the
   spacing, so no block needs its own margin, and stacking two .panel
   siblings here never double-spaces against panels.css's own `.panel +
   .panel` rule. */
.analytics-stack {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.analytics-stack > .panel { margin-top: 0; }

.loading-note {
    font-size: 11px;
    color: var(--text-3);
    padding: 14px 18px;
}

/* A second, smaller panel-header used mid-panel (e.g. "Engagement per
   post" under the top-posts list) — same row, quieter title. */
.panel-subheader { padding-top: 4px; }
.panel-title-sub { font-size: 11px; color: var(--text-2); }

/* A chart-area sized for the shorter bar charts (chartGroupedBars: 150px,
   chartStackedBars: 190px) instead of the generic line-chart height, so
   the panel doesn't carry a band of dead space under a short chart. A
   floor, not a fixed height: chartFbPosts/chartIgPosts also carry a
   legend appended below the chart (see renderPostEngagementChart), which
   a fixed height would clip — min-height lets the box grow for that
   while still giving chartCompare's bare, legend-less chart a tidy size. */
.chart-area-compact { min-height: 224px; }

/* The comparison chart is shorter than the stacked ones (150 viewBox + its
   two-item legend) — a smaller floor so it doesn't carry the same band of
   dead space the fixed heights used to leave under it. */
.chart-area-slim { min-height: 186px; }

/* ---------- hero strip & platform stat panels ----------
   Same flat, divided-cell language for both: one panel, cells separated
   by a hairline rather than each cell getting its own bordered/shadowed
   card — keeps a labelled number reading as one thing everywhere it
   appears on this page instead of two competing card styles. */

.hero-strip {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
    padding: 4px 0;
}

.hero-card {
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.hero-card + .hero-card {
    border-left: 1px solid var(--border);
}

.hero-label {
    font-size: 10.5px;
    font-weight: 800;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.hero-value {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -.03em;
    color: var(--text);
    line-height: 1.2;
}

.hero-sub {
    font-size: 10.5px;
    color: var(--text-3);
}

.hero-delta {
    margin-top: 4px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-3);
    min-height: 14px;
}

.hero-delta.is-up { color: var(--success); }
.hero-delta.is-down { color: var(--danger); }

.hero-verdict .hero-value {
    font-size: 22px;
}

@media (max-width: 900px) {
    .hero-strip { grid-template-columns: 1fr 1fr; }
    .hero-card:nth-child(3) { border-left: none; }
    .hero-card:nth-child(n+3) { border-top: 1px solid var(--border); }
}

.kpi-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.platform-heading {
    display: flex;
    align-items: center;
    gap: 8px;
}

.platform-stats {
    display: grid;
    padding: 6px 0;
}

.platform-stats-3 { grid-template-columns: repeat(3, 1fr); }
.platform-stats-4 { grid-template-columns: repeat(4, 1fr); }

.platform-stat {
    padding: 14px 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.platform-stat + .platform-stat {
    border-left: 1px solid var(--border);
}

.platform-stat-label {
    font-size: 10.5px;
    font-weight: 800;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.platform-stat-value {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -.03em;
    color: var(--text);
    line-height: 1.2;
    margin-top: 2px;
}

.platform-stat-context {
    font-size: 10.5px;
    color: var(--text-3);
}

@media (max-width: 720px) {
    .platform-stats-3, .platform-stats-4 { grid-template-columns: 1fr 1fr; }
    .platform-stats-3 .platform-stat:nth-child(3n+1),
    .platform-stats-4 .platform-stat:nth-child(2n+1) { border-left: none; }
    .platform-stats-3 .platform-stat:nth-child(n+3),
    .platform-stats-4 .platform-stat:nth-child(n+3) { border-top: 1px solid var(--border); }
}

/* ---------- top posts ---------- */

.top-list {
    display: flex;
    flex-direction: column;
    padding: 4px 18px 8px;
}

.top-card {
    display: flex;
    gap: 14px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
    align-items: flex-start;
}

.top-card:last-child { border-bottom: none; }

.top-rank {
    flex: 0 0 24px;
    width: 24px;
    height: 24px;
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--text-2);
    font-size: 11px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
}

.top-card:nth-child(1) .top-rank {
    background: var(--primary);
    color: #fff;
}

/* Fixed box: expired CDN URLs or no image never shift the layout. */
.top-thumb {
    flex: 0 0 64px;
    width: 64px;
    height: 64px;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--surface-soft);
}

.top-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.top-body { min-width: 0; flex: 1 1 auto; }

.top-head {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.top-when {
    font-size: 10.5px;
    color: var(--text-3);
}

.top-open {
    margin-left: auto;
    font-size: 10.5px;
    font-weight: 700;
    color: var(--text-3);
    text-decoration: none;
    padding: 3px 8px;
    border-radius: 999px;
    flex: 0 0 auto;
    transition: background var(--transition), color var(--transition);
}

.top-open:hover { background: var(--surface-soft); color: var(--text); }

.top-caption {
    margin-top: 6px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.45;
}

.top-caption.is-clamped {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.top-more {
    margin-top: 2px;
    padding: 0;
    border: none;
    background: none;
    font-size: 10.5px;
    font-weight: 700;
    color: var(--primary);
    cursor: pointer;
}

.top-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.top-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10.5px;
    font-weight: 700;
    color: var(--text-2);
    background: var(--surface-soft);
    padding: 3px 9px;
    border-radius: 999px;
}

.top-chip svg { flex: 0 0 auto; opacity: .8; }

.top-chip-engagement {
    color: var(--primary);
    background: var(--primary-soft);
}

.top-themes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 7px;
}

.top-theme {
    font-size: 10px;
    color: var(--text-3);
    border: 1px solid var(--border);
    padding: 2px 8px;
    border-radius: 999px;
}

/* A complaint is a different signal from praise — same chip, danger tone. */
.top-theme-complaint {
    color: var(--danger);
    border-color: var(--danger-soft);
    background: var(--danger-soft);
}
