/* WIS — World Information Service */
/* Light Newspaper / Economist-inspired theme */

/* ============================================================
   TYPOGRAPHY
   ============================================================ */

:root {
    /* Fonts */
    --font-headline: 'Playfair Display', Georgia, 'Times New Roman', serif;
    --font-body: 'Source Serif 4', Georgia, 'Times New Roman', serif;
    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* Newspaper color scheme (Economist-inspired) */
    --paper: #f8f7f4;           /* Warm off-white newsprint */
    --paper-white: #ffffff;      /* Pure white for panels */
    --ink: #1a1a1a;              /* Near-black text */
    --ink-soft: #4a4a4a;         /* Secondary text */
    --ink-muted: #8a8578;        /* Muted text */
    --rule: #d8d4c8;             /* Hairline rules */
    --rule-dark: #1a1a1a;        /* Heavy rules */

    /* Economist red accent */
    --red: #E3120B;
    --red-dark: #b80e08;
    --red-light: #fef0ef;
    --red-tint: rgba(227, 18, 11, 0.08);

    /* Semantic colors */
    --success: #1a7f4b;
    --success-tint: rgba(26, 127, 75, 0.1);
    --warning: #b45309;
    --warning-tint: rgba(180, 83, 9, 0.1);
    --danger: #dc2626;
    --danger-tint: rgba(220, 38, 38, 0.1);

    /* Region colors (muted, editorial) */
    --region-europe: #3b5b7e;
    --region-asia: #5b7e3b;
    --region-africa: #8e6b3b;
    --region-mideast: #8e3b3b;
    --region-caribbean: #6b5b8e;

    /* Map colors */
    --map-bg: #0a0f1a;
    --map-country: #c9c4b4;
    --map-country-hover: #a8a394;
    --map-country-visited: #9db4c9;
    --map-country-selected: var(--red);

    /* UI */
    --shadow-sm: 0 1px 2px rgba(26, 26, 26, 0.06);
    --shadow: 0 2px 8px rgba(26, 26, 26, 0.08);
    --shadow-lg: 0 8px 24px rgba(26, 26, 26, 0.12);
    --radius: 2px;               /* Sharp, editorial corners */
    --tab-bar-height: 44px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    background: var(--paper);
    color: var(--ink);
    line-height: 1.6;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ============================================================
   WELCOME OVERLAY — Newspaper Masthead
   ============================================================ */

#welcome-overlay {
    position: fixed;
    inset: 0;
    background: var(--paper);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeOut 0.8s ease-in-out 2s forwards;
    pointer-events: none;
}

.welcome-content {
    text-align: center;
    max-width: 600px;
    padding: 40px;
}

.masthead-rule {
    height: 3px;
    background: var(--ink);
    margin: 0 auto;
}

.masthead-rule.top { width: 100%; margin-bottom: 8px; }
.masthead-rule.top::after {
    content: '';
    display: block;
    height: 1px;
    background: var(--ink);
    margin-top: 2px;
}

.masthead-rule.bottom { width: 100%; margin-top: 16px; }
.masthead-rule.bottom::before {
    content: '';
    display: block;
    height: 1px;
    background: var(--ink);
    margin-bottom: 2px;
}

.masthead-date {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--ink-soft);
    margin-bottom: 24px;
}

.welcome-title {
    font-family: var(--font-headline);
    font-size: 6rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    color: var(--ink);
    line-height: 1;
    animation: fadeInUp 0.8s ease-out;
    margin-bottom: 4px;
}

.masthead-subtitle {
    font-family: var(--font-ui);
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.25em;
    color: var(--red);
    animation: fadeInUp 0.8s ease-out 0.15s both;
    margin-bottom: 16px;
}

.masthead-tagline {
    font-family: var(--font-body);
    font-style: italic;
    font-size: 1rem;
    color: var(--ink-muted);
    animation: fadeInUp 0.8s ease-out 0.3s both;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
        visibility: hidden;
    }
}

/* ============================================================
   Main layout — Panel LEFT, Map RIGHT
   ============================================================ */

#main {
    display: flex;
    flex-direction: row-reverse;
    flex: 1;
    overflow: hidden;
    height: 100vh;
}

/* Full-screen panel mode — panel covers whole screen, map hidden */
#main.panel-fullscreen {
    flex-direction: row;
}

#main.panel-fullscreen #info-panel {
    flex: 1 1 100%;
    max-width: none;
    border-right: none;
}

#main.panel-fullscreen #map-container {
    display: none;
}

/* Map */
#map-container {
    flex: 1;
    position: relative;
    min-width: 0;
    border-left: 1px solid var(--ink);
}

#map {
    width: 100%;
    height: 100%;
    background: var(--map-bg);
}

#map-overlay {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: var(--paper-white);
    padding: 10px 18px;
    border: 1px solid var(--rule);
    border-top: 3px solid var(--red);
    box-shadow: var(--shadow);
    z-index: 1000;
}

#selected-country {
    font-family: var(--font-ui);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ink);
}

/* ============================================================
   Country Map Colors — Light editorial
   ============================================================ */

.country-base {
    transition: fill-opacity 0.2s, stroke 0.2s, stroke-width 0.2s;
}

.country-tooltip {
    background: var(--paper-white);
    border: none;
    border-bottom: 3px solid var(--red);
    border-radius: var(--radius);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 0.8125rem;
    font-weight: 600;
    padding: 8px 14px;
    box-shadow: var(--shadow-lg);
}

.country-tooltip::before {
    border-top-color: var(--paper-white);
}

/* ============================================================
   Info Panel — Newspaper column
   ============================================================ */

#info-panel {
    flex: 0 0 clamp(480px, 55vw, 1680px);
    background: var(--paper-white);
    border-right: 1px solid var(--rule);
    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* Content adapts to the panel's own width (works at 55vw, in
       fullscreen mode, and at any future width) */
    container: panel / inline-size;
}

/* Landing and Country views */
#landing-view,
#country-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

#landing-view.hidden,
#country-view.hidden {
    display: none;
}

/* Landing content */
#landing-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* Landing news wrapper */
#landing-news-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    padding: 0 20px;
}

#landing-news-stories {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

#landing-news-footer {
    padding: 14px 0;
    border-top: 1px solid var(--rule);
    font-family: var(--font-ui);
    font-size: 0.6875rem;
    color: var(--ink-muted);
    text-align: center;
    flex-shrink: 0;
}

#landing-news-footer a { color: var(--red); text-decoration: none; }
#landing-news-footer a:hover { text-decoration: underline; }

#landing-news-loading,
#landing-news-error {
    padding: 48px 32px;
    text-align: center;
    color: var(--ink-soft);
    font-family: var(--font-ui);
}

#landing-news-header {
    padding: 10px 0 8px;
    border-bottom: 2px solid var(--ink);
    flex-shrink: 0;
}

/* ============================================================
   Wide-panel adaptation — CSS container queries
   ============================================================
   Layout adapts to the PANEL's width, not the viewport's, so it
   stays correct at 55vw, in fullscreen (F), and on mobile.
   Reading measure: research puts comfortable reading at roughly
   45–75 characters per line (sweet spot ~65–70), so prose is
   capped while data-dense sections use the full panel width. */

/* Prose — reading measure */
.story-preview,
.story-summary,
.perspective-item {
    max-width: 70ch;
}

.story-list li {
    max-width: 66ch;
}

.story-quote {
    max-width: 62ch;
}

/* ============================================================
   News feed — horizontal never scrolls, vertical is natural
   ============================================================
   Nothing may overflow the panel width: prose keeps its reading
   measure and the collapsed feed fills the panel width in 2–3
   masonry columns. The columns are created and dealt by
   layoutStories() in news.js, which mirrors the 640px/1400px
   panel breakpoints (see storyColumnCount()). An expanded story
   stays in its column and extends downward — only the cards
   below it in that column shift; the rest of the grid stays in
   place. Scrolling down is natural and intended. */

/* Column wrapper + columns — dealt by layoutStories() in news.js */
.story-columns {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.story-col {
    flex: 1 1 0;
    min-width: 0;
}

@container panel (min-width: 640px) {
    /* Smaller thumbnails give the text room at two columns */
    .story-thumb { width: 72px; height: 48px; }
}

@container panel (min-width: 900px) {
    .story-thumb { width: 96px; height: 64px; }
}

/* ============================================================
   Quickfacts — dashboard grid (fits the panel height)
   ============================================================ */

@container panel (min-width: 640px) {
    #quickfacts-content {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 12px 16px;
        grid-template-areas:
            "identity identity identity"
            "stats stats stats"
            "leaders govgeo stock"
            "headlines headlines headlines";
        align-content: start;
    }

    #quickfacts-content > * { margin-bottom: 0; }

    .facts-identity { grid-area: identity; }
    .facts-grid { grid-area: stats; }
    #qf-leaders-block { grid-area: leaders; }
    #qf-govgeo-block { grid-area: govgeo; }
    #qf-stock-block { grid-area: stock; }
    #qf-headlines-block { grid-area: headlines; }

    /* Leader cards stack vertically inside their dashboard column */
    #qf-leaders-container { grid-template-columns: 1fr; }

    /* Headlines flow in two columns */
    #qf-headlines {
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: 16px;
    }
}

/* ============================================================
   History — multi-column timeline (fits the panel height)
   ============================================================ */

@container panel (min-width: 640px) {
    .history-timeline {
        column-count: 2;
        column-gap: 24px;
    }

    .history-timeline::before { content: none; }

    .history-timeline-item { break-inside: avoid; }
}

@container panel (min-width: 1000px) {
    .history-timeline { column-count: 3; }
}

/* Data-dense sections — use the width on wide panels */
@container panel (min-width: 900px) {
    .facts-grid { grid-template-columns: repeat(6, 1fr); }
    .history-stats-grid { grid-template-columns: repeat(6, 1fr); }
}

/* ============================================================
   Tab bar — Newspaper section headers
   ============================================================ */

#tab-bar-landing,
#tab-bar-country {
    display: flex;
    height: var(--tab-bar-height);
    background: var(--paper-white);
    border-bottom: 2px solid var(--ink);
    flex-shrink: 0;
}

.tab-bar-tabs {
    display: flex;
    flex: 1;
}

.tab-btn,
.landing-tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    color: var(--ink-soft);
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0 12px;
}

/* Panel expand button */
.panel-expand-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    background: transparent;
    border: none;
    border-left: 1px solid var(--rule);
    color: var(--ink-muted);
    font-size: 1.125rem;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.panel-expand-btn:hover {
    background: var(--red-tint);
    color: var(--red);
}

#main.panel-fullscreen .panel-expand-btn .expand-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.tab-btn:hover,
.landing-tab-btn:hover {
    background: var(--red-tint);
    color: var(--ink);
}

.tab-btn.active,
.landing-tab-btn.active {
    color: var(--red);
    border-bottom-color: var(--red);
    background: transparent;
}

@media (max-width: 500px) {
    .tab-label { display: none; }
}

/* Tab content */
#tab-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.tab-pane {
    display: none;
    height: 100%;
    overflow-y: auto;
    padding: 16px 20px;
}

.tab-pane.active { display: block; }

/* Tab placeholder — typographic empty state */
.tab-placeholder {
    padding: 48px 32px;
    text-align: center;
    color: var(--ink-soft);
    max-width: 340px;
    margin: 0 auto;
}

.tab-placeholder::before,
.tab-placeholder::after {
    content: '';
    display: block;
    height: 1px;
    background: var(--rule);
    margin-bottom: 20px;
}

.tab-placeholder::after {
    margin-bottom: 0;
    margin-top: 20px;
}

.tab-placeholder p {
    font-family: var(--font-body);
    font-style: italic;
    font-size: 0.9375rem;
    line-height: 1.5;
}

/* Data status */
#data-status {
    padding: 8px 20px;
    border-top: 1px solid var(--rule);
    font-family: var(--font-ui);
    font-size: 0.6875rem;
    color: var(--ink-muted);
    text-align: center;
    flex-shrink: 0;
}

/* ============================================================
   QUICKFACTS TAB
   ============================================================ */

/* Facts Identity — Newspaper headline style */
.facts-identity {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--rule);
}

.facts-flag {
    height: 26px;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

.facts-flag img {
    display: block;
    height: 26px;
    width: auto;
    border: 1px solid var(--rule);
}

.facts-name {
    font-family: var(--font-headline);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.15;
}

.facts-capital {
    font-family: var(--font-ui);
    font-size: 0.8125rem;
    color: var(--ink-soft);
    margin-top: 2px;
}

/* Facts Grid */
.facts-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: var(--rule);
    border: 1px solid var(--rule);
    margin-bottom: 20px;
}

.fact-card {
    background: var(--paper-white);
    padding: 10px 12px;
    text-align: left;
}

.fact-value {
    font-family: var(--font-headline);
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.25;
    word-break: break-word;
}

.fact-label {
    font-family: var(--font-ui);
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 2px;
}

.fact-value.positive { color: var(--success); }
.fact-value.negative { color: var(--danger); }

/* Facts Section Blocks — Newspaper sections */
.facts-section-block { margin-bottom: 18px; }

.facts-block-title {
    font-family: var(--font-ui);
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--red);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--rule);
}

.facts-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding: 6px 0;
    font-size: 0.875rem;
    border-bottom: 1px solid rgba(216, 212, 200, 0.5);
}

.facts-detail-row:last-child { border-bottom: none; }
.facts-detail-label {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    color: var(--ink-muted);
    flex-shrink: 0;
    min-width: 90px;
}
.facts-detail-value {
    font-family: var(--font-body);
    color: var(--ink);
    text-align: right;
    line-height: 1.4;
}

/* ============================================================
   Leaders Container
   ============================================================ */

.leaders-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.leader-card {
    background: var(--paper);
    border: 1px solid var(--rule);
    border-top: 3px solid var(--ink);
    padding: 10px 14px;
    display: flex;
    flex-direction: row;
    align-items: center;
    text-align: left;
    gap: 12px;
}

.leader-photo {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--rule);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--ink);
    flex-shrink: 0;
}

.leader-photo img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: grayscale(20%);
}

/* Initials fallback — visible whenever no photo loads */
.leader-initials {
    font-family: var(--font-ui);
    font-size: 0.9375rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--ink-soft);
    text-transform: uppercase;
}

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

.leader-name {
    font-family: var(--font-headline);
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.2;
}

.leader-title {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    color: var(--ink-soft);
    margin-top: 2px;
}

.leader-role {
    font-family: var(--font-ui);
    font-size: 0.5625rem;
    font-weight: 600;
    color: var(--red);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 2px;
}

/* Single leader */
.leaders-container.single {
    grid-template-columns: 1fr;
}

/* ============================================================
   Stock Card
   ============================================================ */

.stock-card {
    background: var(--paper);
    border: 1px solid var(--rule);
    border-left: 3px solid var(--ink);
    padding: 12px 14px;
}

.stock-card.compact { padding: 10px 12px; }

.stock-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.stock-card.compact .stock-header { margin-bottom: 4px; }

.stock-name {
    font-family: var(--font-headline);
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
}
.stock-exchange {
    font-family: var(--font-ui);
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stock-price-row { display: flex; align-items: baseline; gap: 12px; }

.stock-price {
    font-family: var(--font-headline);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.stock-card.compact .stock-price { font-size: 1.25rem; }

.stock-change {
    font-family: var(--font-ui);
    font-size: 0.875rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.stock-change.positive { color: var(--success); }
.stock-change.negative { color: var(--danger); }

.stock-52w {
    font-family: var(--font-ui);
    font-size: 0.6875rem;
    color: var(--ink-muted);
    margin-top: 8px;
}

/* ============================================================
   Headlines List
   ============================================================ */

.headlines-list { display: flex; flex-direction: column; }

.headline-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--rule);
    cursor: pointer;
    transition: all 0.15s;
}

.headline-item:last-child { border-bottom: none; }

.headline-item:hover { background: var(--red-tint); margin: 0 -8px; padding: 10px 8px; }

/* Article thumbnail for the headline list (decorative — title is adjacent) */
.headline-thumb {
    width: 48px;
    height: 32px;
    object-fit: cover;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--paper);
    flex-shrink: 0;
}

.headline-text {
    font-family: var(--font-body);
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.4;
    /* Even rows: cap headlines at two lines */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.headline-item:hover .headline-text { color: var(--red); }

.see-all-btn {
    width: 100%;
    margin-top: 8px;
    padding: 8px;
    background: transparent;
    border: 1px solid var(--ink);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    transition: all 0.2s;
}

.see-all-btn:hover {
    background: var(--ink);
    color: var(--paper-white);
}

/* ============================================================
   NEWS TAB
   ============================================================ */

#news-content-wrapper {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Region buttons — wrap instead of scrolling horizontally */
#region-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 8px;
    padding: 8px 20px;
    border-bottom: 1px solid var(--rule);
    flex-shrink: 0;
    background: var(--paper);
}

.region-label {
    font-family: var(--font-ui);
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    white-space: nowrap;
    flex-shrink: 0;
    margin-right: 4px;
}

.region-btn {
    padding: 6px 14px;
    background: transparent;
    border: 1px solid var(--rule);
    color: var(--ink-soft);
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
}

.region-btn:hover {
    border-color: var(--ink);
    color: var(--ink);
}

.region-btn.active {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--paper-white);
}

#news-header {
    padding-bottom: 8px;
    border-bottom: 2px solid var(--ink);
    margin-bottom: 0;
    flex-shrink: 0;
}

/* One-row section header: title + inline dateline + actions on a baseline */
.news-header-row {
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
}

.news-header-row h2 {
    flex-shrink: 0;
}

#news-title {
    font-family: var(--font-headline);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.2;
}
#landing-news-title {
    font-family: var(--font-headline);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.2;
}
/* Dateline — inline with the section title, truncated when narrow */
.news-meta {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--font-ui);
    font-size: 0.75rem;
    color: var(--ink-soft);
}

#news-meta .badge {
    display: inline-block;
    padding: 3px 10px;
    font-family: var(--font-ui);
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-right: 8px;
}

.badge-country { background: var(--red-tint); color: var(--red); }
.badge-region { background: rgba(26, 26, 26, 0.06); color: var(--ink); }

/* News header actions */
.news-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Translate Button */
.translate-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: transparent;
    border: 1px solid var(--rule);
    color: var(--ink-soft);
    font-family: var(--font-ui);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: all 0.15s;
}

.translate-btn:hover {
    border-color: var(--ink);
    color: var(--ink);
}

.translate-btn.active {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--paper-white);
}

.translate-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* News stories */
/* News stories (pane already provides the 20px side padding) */
#news-stories { flex: 1; overflow-y: auto; }

/* Source links */
.source-ref,
.source-link {
    color: var(--red);
    font-family: var(--font-ui);
    font-size: 0.65em;
    vertical-align: super;
    text-decoration: none;
    margin: 0 1px;
    font-weight: 600;
    white-space: nowrap;
}

.source-ref:hover,
.source-link:hover {
    text-decoration: underline;
}

/* Perspective sources */
.perspective-source {
    font-family: var(--font-ui);
    font-size: 0.625rem;
    color: var(--ink-muted);
    margin-top: 6px;
}

.perspective-source .source-link {
    font-size: 0.9em;
    vertical-align: baseline;
    margin: 0 2px;
}

/* Story cards — Newspaper article style (collapsible) */
.story-card {
    position: relative;
    padding: 8px 8px 8px 16px;
    border-bottom: 1px solid var(--rule);
    scroll-margin-top: 20px;
}

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

.story-card.highlighted {
    background: var(--red-tint);
    padding: 16px 16px;
    margin: 0 -16px;
    border-bottom: none;
    animation: highlight-pulse 2s ease-out;
}

@keyframes highlight-pulse {
    0% { background: rgba(227, 18, 11, 0.15); }
    100% { background: var(--red-tint); }
}

/* Story header — clickable to toggle.
   Grid: thumbnail left; title + clamped preview form the column beside it.
   Expanded cards drop the preview to full card width below the header row. */
.story-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
        "thumb title toggle"
        "thumb preview preview";
    row-gap: 8px;
    align-items: start;
    cursor: pointer;
    user-select: none;
    padding: 4px 8px;
    margin: -4px -8px 10px 0;
    border-radius: var(--radius);
    transition: background 0.15s;
}

/* Column gutter only when a thumbnail exists — without one the empty
   auto column collapses to zero and the title stays flush left */
.story-header:has(.story-thumb) {
    column-gap: 12px;
}

.story-header:hover {
    background: var(--red-tint);
}

.story-header:focus-visible {
    outline: 2px solid var(--red);
    outline-offset: -2px;
}

/* Article thumbnail — always visible in the story header; removal on
   error lets the title reclaim the full width via the empty grid column */
.story-thumb {
    grid-area: thumb;
    width: 96px;
    height: 64px;
    object-fit: cover;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--paper);
}

.story-headline {
    grid-area: title;
    min-width: 0;
}

/* Kicker — cluster category as a red label above every headline */
.story-kicker {
    font-family: var(--font-ui);
    font-size: 0.5625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--red);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.story-title {
    font-family: var(--font-headline);
    font-size: 1.1875rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.25;
}

/* Toggle indicator */
.story-toggle {
    grid-area: toggle;
    display: inline-flex;
    align-items: center;
    margin-top: 4px;
    color: var(--ink-muted);
    transition: transform 0.2s;
}

.story-card.collapsed .story-toggle {
    transform: rotate(-90deg);
}

.story-card.collapsed .story-title {
    color: var(--ink-soft);
    /* Uniform two-line title block — every collapsed card has the same
       height, so grid rows align like a printed page */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.5em;
}

/* Story preview — teaser paragraph beside the thumbnail (grid area),
   clamped when collapsed */
.story-preview {
    grid-area: preview;
    font-family: var(--font-body);
    font-size: 0.9375rem;
    color: var(--ink-soft);
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Expanded: the preview spans the full card width under the header row
   and becomes the main reading text — darker and larger */
.story-card:not(.collapsed) .story-header {
    grid-template-areas:
        "thumb title toggle"
        "preview preview preview";
}

.story-card:not(.collapsed) .story-preview {
    display: block;
    -webkit-line-clamp: unset;
    color: var(--ink);
    font-size: 1rem;
    line-height: 1.65;
}

/* Story body — hidden when collapsed */
.story-body {
    overflow: hidden;
}

.story-card.collapsed .story-body {
    display: none;
}

/* Reddit-style collapse line — thin vertical rule along the left edge of
   every card, always visible (short handle when collapsed, full-height when
   expanded); click to toggle. 2px visible line inside a 14px hit area. */
.story-collapse-line {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 14px;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.story-collapse-line::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--rule);
    transition: background 0.15s;
}

.story-collapse-line:hover::before {
    background: var(--ink-muted);
}

.story-collapse-line:focus-visible {
    outline: none;
}

.story-collapse-line:focus-visible::before {
    background: var(--red);
}

.story-summary {
    font-family: var(--font-body);
    font-size: 1rem;
    color: var(--ink-soft);
    line-height: 1.7;
    margin-bottom: 12px;
    white-space: pre-line;
}

/* Photo caption — newspaper credit line under the story preview */
.story-caption {
    font-family: var(--font-body);
    font-style: italic;
    font-size: 0.8125rem;
    color: var(--ink-muted);
    line-height: 1.4;
    margin-bottom: 12px;
}

.story-section { margin-top: 10px; }

.story-section-title {
    font-family: var(--font-ui);
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--red);
    margin-bottom: 6px;
}

.story-quote {
    background: var(--paper);
    border-left: 3px solid var(--red);
    padding: 12px 16px;
    font-family: var(--font-body);
    font-style: italic;
    font-size: 1rem;
    color: var(--ink-soft);
    line-height: 1.6;
}

.story-quote-author {
    font-style: normal;
    font-family: var(--font-ui);
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--ink);
    margin-top: 8px;
}

.story-list { list-style: none; }

.story-list li {
    font-family: var(--font-body);
    font-size: 0.9375rem;
    color: var(--ink-soft);
    padding: 6px 0 6px 20px;
    position: relative;
    line-height: 1.6;
}

.story-list li::before {
    content: '▪';
    position: absolute;
    left: 0;
    color: var(--red);
    font-size: 0.75em;
    top: 10px;
}

.perspective-item {
    background: var(--paper);
    padding: 10px 14px;
    border-left: 2px solid var(--rule);
    margin-bottom: 8px;
    font-family: var(--font-body);
    font-size: 0.9375rem;
    color: var(--ink-soft);
    line-height: 1.6;
}

/* Timeline */
.story-timeline { position: relative; padding-left: 24px; }

.story-timeline::before {
    content: '';
    position: absolute;
    left: 5px;
    top: 8px;
    bottom: 8px;
    width: 2px;
    background: var(--rule);
}

.timeline-item {
    position: relative;
    padding: 6px 0;
    font-family: var(--font-body);
    font-size: 0.9375rem;
    color: var(--ink-soft);
    line-height: 1.5;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -24px;
    top: 14px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--red);
    border: 2px solid var(--paper-white);
}

.timeline-date {
    font-family: var(--font-ui);
    font-weight: 600;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--red);
}

/* News footer */
#news-footer {
    padding: 14px 0;
    border-top: 2px solid var(--ink);
    font-family: var(--font-ui);
    font-size: 0.6875rem;
    color: var(--ink-muted);
    text-align: center;
    flex-shrink: 0;
}

#news-footer a { color: var(--red); text-decoration: none; }
#news-footer a:hover { text-decoration: underline; }

/* Loading states */
#news-loading {
    padding: 48px 32px;
    text-align: center;
    color: var(--ink-soft);
    font-family: var(--font-ui);
}

/* Translation progress — slim inline bar pinned above the story list
   while stories are translated progressively */
#translation-loading,
#landing-translation-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    margin: 10px 0;
    border: 1px solid var(--rule);
    border-left: 3px solid var(--red);
    background: var(--red-light);
    color: var(--ink-soft);
    font-family: var(--font-ui);
    font-size: 0.8125rem;
    flex-shrink: 0;
}

#translation-loading .spinner.small,
#landing-translation-loading .spinner.small {
    margin: 0;
    flex-shrink: 0;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--rule);
    border-top-color: var(--red);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

.spinner.small { width: 20px; height: 20px; border-width: 2px; margin-bottom: 10px; }

@keyframes spin { to { transform: rotate(360deg); } }

#news-error {
    padding: 48px 32px;
    text-align: center;
    color: var(--danger);
    font-family: var(--font-ui);
}

/* ============================================================
   ECONOMY TAB
   ============================================================ */

.econ-section { margin-bottom: 16px; }

.econ-section-title {
    font-family: var(--font-ui);
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--red);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--rule);
}

/* Economy — height-fitted: charts fill exactly the vertical space that
   exists. The pane never scrolls on normal desktop sizes; on narrow
   panels charts wrap to more rows and scrolling degrades gracefully. */
#economy-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

#economy-content > .econ-data-source {
    flex-shrink: 0;
}

/* Charts grid — fills the leftover height, as many columns as fit */
.charts-grid {
    flex: 1 1 0;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    grid-auto-rows: 1fr;
    gap: 12px;
    align-content: stretch;
}

@media (max-width: 500px) {
    .charts-grid { grid-template-columns: 1fr; }
}

/* Each chart block stretches its grid cell; the canvas fills the rest */
.charts-grid .econ-section {
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chart-container {
    flex: 1 1 0;
    min-height: 140px;
    background: var(--paper-white);
    border: 1px solid var(--rule);
    padding: 12px;
    position: relative;
}

.chart-container canvas { max-height: 100%; }

/* Data source note */
.econ-data-source {
    padding: 12px 0;
    font-family: var(--font-ui);
    font-size: 0.6875rem;
    color: var(--ink-muted);
    text-align: center;
}

.econ-data-source a { color: var(--red); text-decoration: none; }
.econ-data-source a:hover { text-decoration: underline; }

/* ============================================================
   HISTORY TAB
   ============================================================ */

.history-section {
    margin-bottom: 20px;
}

.history-section-title {
    font-family: var(--font-ui);
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--red);
    margin-bottom: 10px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--rule);
}

/* Current leaders list */
.history-leaders-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-current-leader {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--paper);
    border: 1px solid var(--rule);
    border-left: 3px solid var(--ink);
    padding: 10px 12px;
}

.history-current-leader .leader-photo {
    width: 44px;
    height: 44px;
}

.history-current-leader .leader-initials {
    font-size: 0.8125rem;
}

.history-current-leader .leader-details {
    flex: 1;
    min-width: 0;
}

.history-current-leader .leader-name {
    font-family: var(--font-headline);
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--ink);
}

.history-current-leader .leader-meta {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    color: var(--ink-soft);
    margin-top: 2px;
}

.history-current-leader .leader-tenure {
    font-family: var(--font-ui);
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--red);
    margin-top: 2px;
}

/* Timeline */
.history-timeline {
    position: relative;
    padding-left: 28px;
}

.history-timeline::before {
    content: '';
    position: absolute;
    left: 9px;
    top: 8px;
    bottom: 8px;
    width: 2px;
    background: var(--rule);
}

.history-timeline-item {
    position: relative;
    padding: 10px 0;
    border-bottom: 1px solid rgba(216, 212, 200, 0.5);
}

.history-timeline-item:last-child {
    border-bottom: none;
}

.history-timeline-item::before {
    content: '';
    position: absolute;
    left: -23px;
    top: 18px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--paper-white);
    border: 2px solid var(--ink);
}

.history-timeline-item.died::before {
    background: var(--danger);
    border-color: var(--danger);
}

.timeline-leader-name {
    font-family: var(--font-headline);
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
}

.timeline-leader-title {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    color: var(--ink-soft);
}

.timeline-dates {
    font-family: var(--font-ui);
    font-size: 0.6875rem;
    color: var(--ink-muted);
    margin-top: 4px;
}

.timeline-tenure {
    font-family: var(--font-ui);
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--red);
}

.timeline-badge {
    display: inline-block;
    padding: 2px 8px;
    font-family: var(--font-ui);
    font-size: 0.5625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-left: 8px;
}

.timeline-badge.died {
    background: var(--danger-tint);
    color: var(--danger);
}

.timeline-badge.multi-stint {
    background: var(--warning-tint);
    color: var(--warning);
}

/* Stats grid */
.history-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: var(--rule);
    border: 1px solid var(--rule);
}

.history-stat-card {
    background: var(--paper-white);
    padding: 12px 10px;
    text-align: center;
}

.history-stat-value {
    font-family: var(--font-headline);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--red);
}

.history-stat-label {
    font-family: var(--font-ui);
    font-size: 0.5625rem;
    font-weight: 600;
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 6px;
}

/* Data source */
.history-data-source {
    padding: 14px 0;
    font-family: var(--font-ui);
    font-size: 0.6875rem;
    color: var(--ink-muted);
    text-align: center;
}

.history-data-source a {
    color: var(--red);
    text-decoration: none;
}

.history-data-source a:hover {
    text-decoration: underline;
}

/* ============================================================
   Utility
   ============================================================ */

.hidden { display: none !important; }

kbd {
    background: var(--paper);
    border: 1px solid var(--rule);
    padding: 2px 6px;
    font-family: var(--font-ui);
    font-size: 0.6875rem;
    color: var(--ink-soft);
}

/* Scrollbar — thin, editorial */
.tab-pane::-webkit-scrollbar,
#news-stories::-webkit-scrollbar,
#landing-news-stories::-webkit-scrollbar { width: 6px; }

.tab-pane::-webkit-scrollbar-track,
#news-stories::-webkit-scrollbar-track,
#landing-news-stories::-webkit-scrollbar-track { background: transparent; }

.tab-pane::-webkit-scrollbar-thumb,
#news-stories::-webkit-scrollbar-thumb,
#landing-news-stories::-webkit-scrollbar-thumb {
    background: var(--rule);
    border-radius: 3px;
}

.tab-pane::-webkit-scrollbar-thumb:hover,
#news-stories::-webkit-scrollbar-thumb:hover,
#landing-news-stories::-webkit-scrollbar-thumb:hover { background: var(--ink-muted); }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 900px) {
    #main { flex-direction: column; }

    #main.panel-fullscreen { flex-direction: column; }

    #map-container {
        height: 45vh;
        flex: none;
        border-left: none;
        border-bottom: 1px solid var(--rule);
    }

    #main.panel-fullscreen #map-container {
        display: none;
    }

    #info-panel {
        flex: 1;
        width: 100%;
        min-width: 0;
        border-right: none;
    }

    /* Hide expand button on mobile — panel is already full-width */
    .panel-expand-btn { display: none; }

    .facts-grid { grid-template-columns: repeat(3, 1fr); }
    .fact-card { padding: 10px 8px; }
    .fact-value { font-size: 1rem; }

    #map-overlay { bottom: 10px; right: 10px; padding: 8px 14px; }

    .welcome-title { font-size: 4rem; }
    .masthead-subtitle { font-size: 0.875rem; letter-spacing: 0.2em; }

    .tab-pane { padding: 16px; }
}

@media (max-width: 600px) {
    .facts-grid { grid-template-columns: repeat(2, 1fr); }
    .facts-identity { flex-direction: column; text-align: center; }
    .leaders-container { grid-template-columns: 1fr; }
    .charts-grid { grid-template-columns: 1fr; }
    .history-stats-grid { grid-template-columns: repeat(2, 1fr); }
    .story-title { font-size: 1rem; }
    .story-thumb { width: 72px; height: 48px; }
    #news-title, #landing-news-title { font-size: 1.25rem; }
}

/* ============================================================
   Leaflet custom styles — Light theme
   ============================================================ */

.leaflet-container {
    background: var(--map-bg);
    font-family: var(--font-ui);
}

.leaflet-popup-content-wrapper {
    background: var(--paper-white);
    color: var(--ink);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.leaflet-popup-tip { background: var(--paper-white); }

.leaflet-bar {
    border: none !important;
    box-shadow: var(--shadow) !important;
    border-radius: var(--radius) !important;
    overflow: hidden;
}

.leaflet-bar a {
    background: var(--paper-white);
    color: var(--ink);
    border: none !important;
    border-bottom: 1px solid var(--rule) !important;
    width: 32px;
    height: 32px;
    line-height: 32px;
    font-size: 1.125rem;
}

.leaflet-bar a:last-child { border-bottom: none !important; }

.leaflet-bar a:hover {
    background: var(--red-tint);
    color: var(--red);
}

.leaflet-control-layers {
    background: var(--paper-white);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    color: var(--ink);
}

.leaflet-control-layers-toggle {
    background-color: var(--paper-white);
    border-radius: var(--radius);
}

.leaflet-control-layers-toggle:hover { background-color: var(--paper); }

.leaflet-control-layers-expanded {
    background: var(--paper-white);
    color: var(--ink);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    padding: 10px 14px;
}

.leaflet-control-layers-list label {
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 0.8125rem;
    padding: 4px 0;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.leaflet-control-layers-list label:hover { color: var(--red); }
.leaflet-control-layers-selector { accent-color: var(--red); }
.leaflet-control-layers-separator { border-top: 1px solid var(--rule); margin: 8px 0; }

/* Attribution */
.leaflet-control-attribution {
    background: rgba(255, 255, 255, 0.8) !important;
    color: var(--ink-soft) !important;
    font-family: var(--font-ui) !important;
    font-size: 0.625rem !important;
}

.leaflet-control-attribution a { color: var(--red) !important; }
