/* ── Reset & Base ───────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    color: #2c3e50;
    background: #f0f4f8;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.container {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* ── Header ────────────────────────────────────── */
header {
    background: linear-gradient(135deg, #1a2a3a 0%, #2c3e50 100%);
    color: #fff;
    padding: 2rem 0 1.6rem;
    text-align: center;
}
header h1 { font-size: 1.75rem; font-weight: 700; }
.subtitle  { margin-top: .35rem; font-size: .95rem; opacity: .75; }

/* ── Card / Form ───────────────────────────────── */
.card {
    background: #fff;
    border-radius: 12px;
    padding: 1.8rem 2rem;
    margin-top: 2rem;
    box-shadow: 0 2px 12px rgba(0,0,0,.07);
}

.form-label {
    display: block;
    font-weight: 600;
    margin-bottom: .5rem;
    font-size: .95rem;
}

.form-group + .form-group { margin-top: 1.4rem; }

/* Mode panels — IDs so hiding works even if parent class changes; JS also sets style.display */
#geo-query-group.is-mode-hidden,
#twitter-fieldset.is-mode-hidden,
#direct-text-group.is-mode-hidden {
    display: none !important;
}

/* Twitter sub-panels: display + class (label clicks, cached CSS) */
.twitter-fieldset .is-twitter-panel-hidden {
    display: none !important;
}

.form-hint {
    font-size: 0.82rem;
    color: #64748b;
    line-height: 1.45;
    margin: 0.25rem 0 0.5rem;
}

.direct-text-input {
    width: 100%;
    max-width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font: inherit;
    font-size: 0.9rem;
    line-height: 1.45;
    resize: vertical;
    min-height: 6rem;
}

.direct-text-actions {
    margin-top: 0.75rem;
}

.direct-results {
    margin-bottom: 1rem;
}

.direct-results-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 0.65rem;
}

.direct-results-list {
    max-height: min(420px, 55vh);
    overflow-y: auto;
    padding: 0.15rem 0.05rem 0.35rem;
}

.mode-selector {
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
}
.mode-option {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: .4rem;
}
.mode-label { font-size: .95rem; }

.twitter-fieldset {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 1rem 1.1rem 1.15rem;
    margin: 0;
}
.twitter-fieldset legend { padding: 0 0.35rem; }
.twitter-live-controls {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0;
}
.twitter-mode-row-wrapper .twitter-mode-row {
    margin-top: 0;
}
.twitter-mode-row { margin-top: 0.35rem; }
.twitter-subopts {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}
.twitter-subopts .form-label { margin-top: 0.35rem; margin-bottom: 0.15rem; }
.twitter-subopts .form-label:first-child { margin-top: 0; }
.twitter-num-input,
.twitter-text-input {
    max-width: 12rem;
    padding: 0.45rem 0.65rem;
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.95rem;
}
.twitter-text-input { max-width: 100%; }
.twitter-fallback-label { margin-top: 0.35rem; }

.twitter-access-block {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e2e8f0;
}
.twitter-auth-row { margin-top: 0.35rem; margin-bottom: 0.65rem; }
.twitter-auth-panel { margin-top: 0.5rem; }

.input-row {
    display: flex;
    gap: .6rem;
}
.input-row input[type="text"] {
    flex: 1;
    padding: .6rem .9rem;
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color .2s;
}
.input-row input[type="text"]:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

button, .btn-secondary {
    cursor: pointer;
    font-size: .95rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    padding: .6rem 1.4rem;
    transition: background .2s, opacity .2s;
}
#generate-btn {
    background: #3b82f6;
    color: #fff;
}
#generate-btn:hover:not(:disabled) { background: #2563eb; }
#generate-btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-secondary {
    background: #e2e8f0;
    color: #334155;
}
.btn-secondary:hover { background: #cbd5e1; }

/* ── Stub warning ──────────────────────────────── */
.stub-warning {
    background: #fef3cd;
    color: #856404;
    border: 1px solid #ffc107;
    border-radius: 8px;
    padding: .7rem 1rem;
    margin-top: 1.2rem;
    text-align: center;
    font-size: .9rem;
}

/* ── Results / Map ─────────────────────────────── */
.results-section {
    margin-top: 2rem;
    margin-bottom: 2rem;
}

.results-map-row {
    display: flex;
    gap: 1rem;
    align-items: stretch;
}

.results-map-row .map-container {
    flex: 1;
    min-width: 0;
}

.map-container {
    width: 100%;
    height: 480px;
    border-radius: 12px;
    overflow: hidden;
    background: #b8d4e3;
    box-shadow: 0 2px 12px rgba(0,0,0,.07);
}

.country-panel {
    display: none;
    flex-direction: column;
    width: min(340px, 100%);
    flex-shrink: 0;
    max-height: 480px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,.07);
    overflow: hidden;
}

.country-panel.is-open {
    display: flex;
}

.country-panel-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.country-panel-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #1e293b;
    margin: 0;
    line-height: 1.35;
}

.country-panel-list {
    overflow-y: auto;
    flex: 1;
    padding: 0.6rem 0.75rem 0.75rem;
}

.country-panel-item {
    padding: 0.65rem 0.75rem;
    border-radius: 8px;
    background: #f1f5f9;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    line-height: 1.45;
    color: #334155;
}

.country-panel-item:last-child {
    margin-bottom: 0;
}

.country-panel-text {
    white-space: pre-wrap;
    word-break: break-word;
}

.country-panel-score {
    margin-top: 0.4rem;
    font-size: 0.8rem;
    color: #64748b;
    font-weight: 500;
}

.sentiment-compact {
    margin-top: 0.4rem;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}
.sentiment-compact.sentiment-neg { color: #b91c1c; }
.sentiment-compact.sentiment-neu { color: #475569; }
.sentiment-compact.sentiment-pos { color: #15803d; }

.sentiment-probs-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.45rem;
    align-items: center;
}
.sentiment-prob-pill {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.22rem 0.5rem;
    border-radius: 6px;
    line-height: 1.2;
}
.sentiment-prob-pill.sentiment-neg {
    color: #991b1b;
    background: #fef2f2;
}
.sentiment-prob-pill.sentiment-neu {
    color: #475569;
    background: #f1f5f9;
}
.sentiment-prob-pill.sentiment-pos {
    color: #166534;
    background: #f0fdf4;
}

.country-panel-empty {
    font-size: 0.875rem;
    color: #64748b;
    padding: 0.5rem 0.25rem;
    margin: 0;
}

.results-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.meta-info {
    font-size: .85rem;
    color: #64748b;
    line-height: 1.5;
}
.meta-info .meta-sep {
    user-select: none;
    color: #94a3b8;
}

.meta-hint {
    margin-top: 0.65rem;
    font-size: 0.8rem;
    color: #64748b;
    line-height: 1.45;
    max-width: 52rem;
}

/* ── Leaflet legend ────────────────────────────── */
.map-legend {
    background: #fff;
    padding: .6rem .8rem;
    border-radius: 6px;
    box-shadow: 0 1px 6px rgba(0,0,0,.15);
    font-size: .8rem;
    line-height: 1.4;
}
.map-legend h4 { margin: 0 0 .3rem; font-size: .8rem; }
.legend-gradient {
    height: 10px;
    border-radius: 3px;
    width: 140px;
}
.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: .7rem;
    color: #64748b;
    margin-top: 2px;
    width: 140px;
}

/* ── Footer ────────────────────────────────────── */
footer {
    margin-top: auto;
    background: #1a2a3a;
    color: #94a3b8;
    padding: 1.2rem 0;
    text-align: center;
    font-size: .85rem;
}
.footer-inner { display: flex; flex-direction: column; gap: .4rem; align-items: center; }
.language-switcher a { color: #93c5fd; text-decoration: none; }
.language-switcher a:hover { text-decoration: underline; }
.language-switcher strong { color: #fff; }
.copyright { opacity: .5; font-size: .75rem; }

/* ── Responsive ────────────────────────────────── */
@media (max-width: 900px) {
    .results-map-row {
        flex-direction: column;
    }
    .country-panel {
        width: 100%;
        max-height: 280px;
    }
    .map-container { height: 360px; }
}

@media (max-width: 600px) {
    header h1 { font-size: 1.3rem; }
    .card { padding: 1.2rem; }
    .input-row { flex-direction: column; }
    .map-container { height: 320px; }
}
