/* =========================================================
   INTELLIGENCE
   Ranked post list (left rail) + post detail (right panel).
   Colours come only from css/base/tokens.css.
   Type scale (§12.1): body 14px, secondary 13px, labels 12px,
   nothing under 12px.
========================================================= */

/* Shared icon size. intelIcon() emits this class; specific slots
   (.intel-thumb, .intel-permalink) override it as needed. Without it the
   inline SVG falls back to its 300x150 default and flexbox shrinks it into
   a wrapping blob. */
.intel-ico {
    width: 1em;
    height: 1em;
    flex: none;
}

.intel-sync-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.intel-synced {
    font-size: 13px;
    color: var(--text-3);
}

/* ---------- toolbar ---------- */

.intel-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
}

.intel-switch {
    display: inline-flex;
    padding: 4px;
    gap: 4px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.intel-switch-btn {
    min-height: 40px;
    padding: 0 18px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-2);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.intel-switch-btn[aria-pressed="true"][data-platform="facebook"] {
    background: var(--surface);
    border-color: var(--facebook);
    color: var(--text);
    box-shadow: inset 0 -3px 0 var(--facebook);
}

.intel-switch-btn[aria-pressed="true"][data-platform="instagram"] {
    background: var(--surface);
    border-color: var(--instagram);
    color: var(--text);
    box-shadow: inset 0 -3px 0 var(--instagram);
}

.intel-sort {
    display: inline-flex;
    gap: 8px;
}

.intel-chip {
    min-height: 40px;
    padding: 0 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-2);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.intel-chip[aria-pressed="true"] {
    background: var(--primary-soft-2);
    border-color: var(--border-strong);
    color: var(--primary-dark);
}

.intel-select {
    min-height: 40px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 13px;
}

.intel-range {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.intel-range-label {
    font-size: 13px;
    color: var(--text-3);
}

.intel-sort-select {
    display: none;
}

/* ---------- banners ---------- */

.intel-banner {
    margin: 0 0 16px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    background: var(--warning-soft);
    color: var(--warning);
    font-size: 13px;
    line-height: 1.5;
}

.intel-link {
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    font-weight: 700;
    text-decoration: underline;
    cursor: pointer;
}

/* ---------- master-detail ---------- */

.intel-layout {
    display: grid;
    grid-template-columns: 380px minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

.intel-list-pane,
.intel-detail-pane {
    min-width: 0;
}

.intel-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-right: 4px;
}

.intel-excluded {
    margin: 12px 2px 0;
    font-size: 13px;
    color: var(--text-3);
}

/* ---------- list rows ---------- */

.intel-row {
    display: grid;
    grid-template-columns: 22px 56px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    width: 100%;
    /* Never shrink below content: the list scrolls, rows do not compress. */
    flex: none;
    min-height: 120px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    text-align: left;
    font: inherit;
    color: var(--text);
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
}

.intel-row:hover {
    background: var(--surface-soft);
}

.intel-row[aria-current="true"] {
    border-color: var(--primary);
    background: var(--primary-soft-2);
}

.intel-rank {
    font-family: "JetBrains Mono", monospace;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-3);
    text-align: center;
}

.intel-thumb {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--surface-soft);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.intel-thumb svg,
.intel-post-media svg {
    width: 22px;
    height: 22px;
    color: var(--text-3);
}

.intel-row-body {
    min-width: 0;
}

.intel-row-top {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.intel-media-type {
    font-size: 12px;
    font-weight: 800;
    color: var(--text-2);
}

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

.intel-trend {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--success-soft);
    color: var(--success);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.intel-trend.is-down {
    background: var(--danger-soft);
    color: var(--danger);
}

.intel-caption {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 14px;
    line-height: 1.45;
    color: var(--text);
}

.intel-row-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-2);
}

.intel-row-meta b {
    font-family: "JetBrains Mono", monospace;
    color: var(--text);
}

.intel-sentiment-ratio {
    color: var(--text-3);
}

/* ---------- list states ---------- */

.intel-skeleton {
    /* Same as .intel-row: skeletons must not shrink below their height. */
    flex: none;
    min-height: 120px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: linear-gradient(90deg, var(--surface-soft), var(--surface), var(--surface-soft));
    background-size: 200% 100%;
    animation: intel-shimmer 1.4s ease-in-out infinite;
}

@keyframes intel-shimmer {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
}

.intel-empty,
.intel-hint {
    margin: 0;
    padding: 20px 4px;
    font-size: 14px;
    color: var(--text-3);
    line-height: 1.55;
}

/* Message and its action stack, so the button never lands mid-sentence. */
.intel-empty,
.intel-error {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
}

.intel-error {
    padding: 16px;
    border: 1px solid var(--danger-soft);
    border-radius: var(--radius-md);
    background: var(--danger-soft);
    color: var(--danger);
    font-size: 14px;
}

/* ---------- detail ---------- */

.intel-detail {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    padding: 20px;
    min-height: 320px;
}

.intel-detail:focus {
    outline: none;
}

.intel-back {
    display: none;
}

.intel-post-head {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.intel-post-media {
    flex: 0 0 200px;
    max-height: 320px;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--surface-soft);
}

.intel-post-media img {
    width: 100%;
    max-height: 320px;
    object-fit: cover;
    display: block;
}

.intel-post-info {
    min-width: 0;
    flex: 1;
}

.intel-caption-full {
    margin: 8px 0 0;
    font-size: 14px;
    line-height: 1.55;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.intel-caption-full.is-expanded {
    -webkit-line-clamp: unset;
    display: block;
}

.intel-more {
    margin-top: 6px;
    font-size: 13px;
}

.intel-permalink {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--primary-dark);
    text-decoration: none;
    font-weight: 700;
}

.intel-permalink svg {
    width: 14px;
    height: 14px;
}

.intel-section {
    padding: 20px 0;
    border-bottom: 1px solid var(--border);
}

.intel-section:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.intel-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.intel-section-title {
    margin: 0;
    font-size: 16px;
    font-weight: 800;
    color: var(--text);
}

.intel-subtitle {
    margin: 20px 0 10px;
    font-size: 13px;
    font-weight: 800;
    color: var(--text-2);
}

.intel-as-of {
    font-size: 12px;
    color: var(--text-3);
}

.intel-metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 14px;
}

.intel-metric {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-soft);
}

.intel-metric-label {
    font-size: 12px;
    color: var(--text-2);
    font-weight: 700;
}

.intel-metric-value {
    margin-top: 6px;
    font-family: "JetBrains Mono", monospace;
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
}

.intel-chart {
    position: relative;
    min-height: 120px;
}

.intel-chart-summary {
    margin: 8px 0 0;
    font-size: 12px;
    color: var(--text-3);
}

/* The shared chart module draws axis/label text at 9-10px. This page's spec
   floors chart text at 12px, so lift it here rather than change chart.css
   (other pages keep their denser charts). The edge label is centred on the
   last point and sits just past the plot, so let the SVG paint it out. */
#page-intelligence .chart-axis,
#page-intelligence .chart-label,
#page-intelligence .chart-tooltip {
    font-size: 12px;
}

#page-intelligence .intel-chart svg {
    overflow: visible;
}

/* ---------- narrative + insights ---------- */

.intel-narrative {
    padding: 16px;
    border-radius: var(--radius-md);
    background: var(--surface-soft);
}

.intel-narrative-text {
    margin: 0;
    font-size: 14px;
    line-height: 1.55;
    color: var(--text);
}

.intel-highlights {
    margin: 12px 0 0;
    padding-left: 20px;
    font-size: 13.5px;
    line-height: 1.5;
    color: var(--text-2);
}

.intel-narrative-meta {
    margin: 12px 0 0;
    font-size: 12px;
    color: var(--text-3);
}

.intel-stale-note {
    margin: 10px 0 0;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--warning-soft);
    color: var(--warning);
    font-size: 12px;
}

.intel-donut {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-top: 16px;
}

.intel-donut-legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 12px;
    color: var(--text-2);
}

.intel-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 14px;
    margin-top: 16px;
}

.intel-stat {
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.intel-stat-value {
    display: block;
    font-family: "JetBrains Mono", monospace;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.intel-stat-label {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-3);
}

.intel-themes {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.intel-theme {
    display: grid;
    grid-template-columns: minmax(90px, 150px) minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    font: inherit;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.intel-theme:hover {
    background: var(--surface-soft);
}

.intel-theme[aria-pressed="true"] {
    border-color: var(--primary);
    background: var(--primary-soft-2);
}

.intel-theme-name {
    font-size: 13px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.intel-theme-bar {
    display: flex;
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    background: var(--surface-soft);
    min-width: 8px;
}

.intel-theme-seg {
    display: block;
    height: 100%;
}

.intel-theme-meta {
    font-size: 12px;
    color: var(--text-3);
    white-space: nowrap;
}

.intel-intents {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.intel-intent {
    display: grid;
    grid-template-columns: minmax(110px, 150px) minmax(0, 1fr) 34px;
    gap: 12px;
    align-items: center;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: none;
    font: inherit;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.intel-intent:hover:not(:disabled) {
    background: var(--surface-soft);
}

.intel-intent[aria-pressed="true"] {
    border-color: var(--primary);
    background: var(--primary-soft-2);
}

.intel-intent:disabled {
    cursor: default;
    color: var(--text-3);
}

.intel-intent-name {
    font-size: 13px;
    text-transform: capitalize;
}

.intel-intent-bar {
    height: 8px;
    border-radius: 999px;
    background: var(--primary-soft);
    min-width: 4px;
}

.intel-intent-count {
    font-family: "JetBrains Mono", monospace;
    font-size: 12px;
    color: var(--text-2);
    text-align: right;
}

.intel-gists {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.intel-gists li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.intel-gist {
    padding: 8px 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--surface-soft);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.intel-gist:hover {
    background: var(--surface-hover);
}

.intel-gist-likes {
    font-size: 12px;
    color: var(--text-3);
    white-space: nowrap;
}

/* ---------- comment filters + list ---------- */

.intel-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-bottom: 16px;
}

.intel-filters-toggle {
    display: none;
}

.intel-filter-group {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.intel-chip-sm {
    min-height: 32px;
    padding: 0 12px;
    font-size: 12px;
    text-transform: capitalize;
}

.intel-comment-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.intel-comment {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.intel-comment.is-reply {
    margin-left: 28px;
    background: var(--surface-soft);
}

.intel-comment.is-spam {
    opacity: .68;
}

.intel-comment-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--text-3);
}

.intel-comment-who {
    font-weight: 800;
    color: var(--text-2);
}

.intel-comment-text {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
}

.intel-comment-themes {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.intel-theme-tag,
.intel-intent-tag,
.intel-answered,
.intel-spam-tag,
.intel-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.intel-theme-tag {
    background: var(--surface-soft);
    color: var(--text-2);
}

.intel-intent-tag {
    background: var(--primary-soft-2);
    color: var(--primary-dark);
}

.intel-answered {
    background: var(--success-soft);
    color: var(--success);
}

.intel-spam-tag {
    background: var(--danger-soft);
    color: var(--danger);
}

.intel-badge-positive {
    background: var(--success-soft);
    color: var(--success);
}

.intel-badge-neutral {
    background: var(--surface-soft);
    color: var(--text-2);
}

.intel-badge-negative {
    background: var(--danger-soft);
    color: var(--danger);
}

.intel-pagination {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 16px;
}

.intel-page-label {
    font-size: 13px;
    color: var(--text-3);
}

/* ---------- >= 960px: two panes, each scrolls on its own ----------
   The page fills the viewport below the sticky topbar, so neither pane
   scrolls the document; the rail and the detail scroll independently. */

@media (min-width: 960px) {
    #page-intelligence.active {
        display: flex;
        flex-direction: column;
        height: calc(100vh - var(--topbar));
        padding-top: 24px;
        padding-bottom: 24px;
    }

    .intel-layout {
        flex: 1 1 auto;
        min-height: 0;
        align-items: stretch;
    }

    .intel-list-pane {
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .intel-list {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
    }

    .intel-detail-pane {
        min-height: 0;
        overflow-y: auto;
    }
}

/* ---------- responsive: single column, detail full-screen ---------- */

@media (max-width: 959px) {
    .intel-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .intel-sort {
        display: none;
    }

    .intel-sort-select {
        display: inline-block;
    }

    .intel-range {
        margin-left: 0;
    }

    .intel-filters-toggle {
        display: inline-flex;
        align-items: center;
    }

    .intel-filters {
        display: none;
    }

    .intel-filters.is-open {
        display: flex;
    }

    /* The detail takes the whole column, so the header stacks instead of
       squeezing the caption into a one-word-per-line sliver. */
    .intel-post-head {
        flex-direction: column;
        gap: 16px;
    }

    .intel-post-media {
        flex: none;
        width: 100%;
    }

    .intel-layout.intel-detail-open .intel-list-pane {
        display: none;
    }

    .intel-layout:not(.intel-detail-open) .intel-detail-pane {
        display: none;
    }

    .intel-back {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        min-height: 44px;
        margin-bottom: 10px;
        padding: 0 4px;
        border: 0;
        background: none;
        color: var(--text-2);
        font: inherit;
        font-size: 13px;
        font-weight: 700;
        white-space: nowrap;
        cursor: pointer;
    }
}

@media (prefers-reduced-motion: reduce) {
    .intel-skeleton {
        animation: none;
    }

    .intel-row,
    .intel-chip,
    .intel-switch-btn {
        transition: none;
    }
}

/* ---------- accessibility targets ----------
   Every operable control clears 44x44 (spec 12.7); the visual padding above
   stays, this only guarantees the hit area. */

.intel-switch-btn,
.intel-chip,
.intel-chip-sm,
.intel-select,
.intel-theme,
.intel-intent,
.intel-gist,
.intel-back {
    min-height: 44px;
}
