/* Eurostat Stats — Stylesheet
   Covers: layout, header, nav, cards, charts, explorer, toasts,
   data tables, export buttons, country picker, responsive. */

/* ── Design Tokens ──────────────────────────────────────── */
:root {
    --bs-primary: #0f766e;
    --bs-primary-rgb: 15,118,110;
    --bs-secondary: #4b5563;
    --bs-secondary-rgb: 75, 85, 99;
    --accent: #115e59;
    --accent-light: #d5f5f0;
    --hover-warm: #f97316;
    --bg: #f0f5f3;
    --card-shadow: 0 4px 16px rgba(15,118,110,0.07);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
}

/* ── Base ────────────────────────────────────────────────── */
body {
    font-family: 'Segoe UI', Arial, sans-serif;
    background: var(--bg);
    color: #1e293b;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Header ──────────────────────────────────────────────── */
header {
    background: linear-gradient(135deg, #134e4a 0%, #0f766e 50%, #14b8a6 100%);
    color: #fff;
    padding: 24px 0 16px 0;
    text-align: center;
    box-shadow: 0 2px 12px rgba(15,118,110,0.18);
    position: relative;
}

header h1 {
    margin: 0 0 12px 0;
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

header .subtitle {
    font-size: 1rem;
    opacity: 0.85;
    margin-bottom: 12px;
    font-weight: 400;
}

/* ── Navigation ──────────────────────────────────────────── */
nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}

nav a,
nav a.nav-link {
    --bs-nav-link-color: #a7f3d0;
    --bs-link-color: #a7f3d0;
    color: #a7f3d0;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all var(--transition);
    padding: 5px 14px;
    border-radius: 20px;
}

nav a:hover,
nav a.nav-link:hover {
    --bs-nav-link-hover-color: #d1fae5;
    color: #d1fae5;
    background: rgba(167,243,208,0.1);
}

nav a.active,
nav a.nav-link.active {
    color: #ecfdf5;
    background: rgba(167,243,208,0.15);
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
    padding: 28px 32px;
    margin-bottom: 24px;
    background: #fff;
    transition: box-shadow var(--transition);
}

.card:hover {
    box-shadow: 0 6px 24px rgba(15,118,110,0.12);
}

.card h2 {
    color: var(--accent);
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.card h3 {
    font-size: 1.25rem;
    font-weight: 700;
}

.card ul {
    padding-left: 20px;
    margin: 16px 0 0 0;
}

.card li {
    margin-bottom: 10px;
    font-size: 1.05rem;
}

.card strong {
    color: var(--accent);
}

/* ── Chart Sections ──────────────────────────────────────── */
.chart-section {
    position: relative;
}

.chart-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.chart-section .chart-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0;
}

.chart-section .chart-desc {
    font-size: 0.9rem;
    color: #6b7280;
    margin-bottom: 16px;
}

.chart-updated {
    font-size: 0.78rem;
    margin-bottom: 8px;
}

/* ── Chart Action Buttons (Table, CSV, PNG, Share) ──────── */
.chart-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.btn-action {
    background: var(--accent-light);
    color: var(--accent);
    border: 1px solid #b2ece4;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 10px;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-action:hover {
    background: var(--bs-primary);
    color: #fff;
    border-color: var(--bs-primary);
}

.chart-explain {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #f0faf8;
    border: 1px solid #d1fae5;
    color: #1f2937;
    font-size: 0.85rem;
}

/* ── Input Group & Fetch Button ──────────────────────────── */
.input-group .form-control {
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    border: 2px solid #d1d5db;
    font-size: 0.85rem;
    padding: 10px 14px;
    transition: border-color var(--transition);
}

.input-group .form-control:focus {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 3px rgba(15,118,110,0.15);
}

.btn-fetch {
    background: var(--bs-primary);
    color: #fff;
    border: 2px solid var(--bs-primary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-weight: 600;
    padding: 10px 20px;
    font-size: 0.85rem;
    transition: all var(--transition);
    white-space: nowrap;
    cursor: pointer;
}

.btn-fetch:hover {
    background: #0d5f59;
    border-color: #0d5f59;
    color: #fff;
}

/* ── Loading Spinner ─────────────────────────────────────── */
.loading-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e0e0e0;
    border-top-color: var(--bs-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ── Explorer Card ───────────────────────────────────────── */
.explorer-card {
    border-top: 3px solid var(--bs-primary);
}

.explorer-field {
    margin-bottom: 18px;
    position: relative;
}

.explorer-field > label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--accent);
    margin-bottom: 6px;
}

/* Dataset search dropdown */
.explorer-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 50;
    background: #fff;
    border: 2px solid #d1d5db;
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    max-height: 300px;
    overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}

.explorer-dropdown .dropdown-item {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid #f0f0f0;
}

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

.explorer-dropdown .dropdown-item:hover {
    background: #f0faf8;
}

.dropdown-code {
    font-family: monospace;
    font-weight: 600;
    color: var(--bs-primary);
    font-size: 0.85rem;
    min-width: 110px;
    flex-shrink: 0;
}

.dropdown-name {
    font-size: 0.88rem;
    color: #1e293b;
    flex: 1;
}

.dropdown-cat {
    font-size: 0.75rem;
    color: #9ca3af;
    white-space: nowrap;
}

.dropdown-empty {
    padding: 12px 14px;
    color: #9ca3af;
    font-size: 0.88rem;
}

/* Selected dataset badge */
.selected-dataset-badge {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 8px;
    padding: 10px 14px;
    background: var(--accent-light);
    border-radius: var(--radius-sm);
    border: 1px solid #b2ece4;
    font-size: 0.9rem;
}

.selected-dataset-badge code {
    font-weight: 700;
    color: var(--bs-primary);
}

.badge-remove {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: #6b7280;
    padding: 0 4px;
    line-height: 1;
}

.badge-remove:hover {
    color: #ef4444;
}

/* ── Country Presets ─────────────────────────────────────── */
.country-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.btn-preset {
    background: #fff;
    color: var(--accent);
    border: 2px solid #d1d5db;
    border-radius: 20px;
    padding: 5px 14px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-preset:hover {
    border-color: var(--bs-primary);
    background: var(--accent-light);
}

.btn-preset.active {
    background: var(--bs-primary);
    color: #fff;
    border-color: var(--bs-primary);
}

/* ── Country Picker (Custom) ─────────────────────────────── */
.country-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    padding: 12px;
    background: #f7faf9;
    border-radius: var(--radius-sm);
    border: 1px solid #e5e7eb;
}

.country-chip {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

.country-chip input {
    display: none;
}

.country-chip span {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 0.78rem;
    font-weight: 600;
    background: #fff;
    border: 1.5px solid #d1d5db;
    color: #374151;
    transition: all var(--transition);
}

.country-chip input:checked + span {
    background: var(--bs-primary);
    color: #fff;
    border-color: var(--bs-primary);
}

.country-chip:hover span {
    border-color: var(--bs-primary);
}

/* ── Visualize Button ────────────────────────────────────── */
.btn-visualize {
    background: linear-gradient(135deg, #0f766e 0%, #14b8a6 100%);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 12px 40px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: 0.3px;
}

.btn-visualize:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(15,118,110,0.3);
}

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

.event-pack-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.event-pack-controls .form-check {
    margin: 0;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid #d1d5db;
    background: #fff;
}

.signal-feed-list {
    margin: 0;
    padding-left: 18px;
}

.signal-feed-item {
    margin-bottom: 6px;
    font-size: 0.88rem;
}

.my-dashboard-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.my-dashboard-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
}

.my-dashboard-meta {
    font-size: 0.8rem;
    color: #6b7280;
}

/* ── Data Table ──────────────────────────────────────────── */
.data-table-wrapper {
    margin-top: 16px;
    max-height: 400px;
    overflow-y: auto;
    border-radius: var(--radius-sm);
    border: 1px solid #e5e7eb;
}

.eurostat-data-table {
    font-size: 0.85rem;
    margin-bottom: 0;
}

.eurostat-data-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f0faf8;
    font-size: 0.8rem;
}

/* ── Toast Notifications ─────────────────────────────────── */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.eurostat-toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 500;
    color: #fff;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    opacity: 0;
    transform: translateX(30px);
    transition: all 0.3s ease;
    pointer-events: auto;
    max-width: 380px;
}

.eurostat-toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast-info    { background: #3b82f6; }
.toast-success { background: #22c55e; }
.toast-error   { background: #ef4444; }
.toast-warning { background: #f59e0b; color: #1e293b; }

/* ── Dataset Codes (Expandable Sections) ─────────────────── */
.dataset-codes-section {
    border: 2px solid var(--accent-light);
    border-radius: 10px;
    overflow: hidden;
}

.dataset-codes-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: var(--accent-light);
    cursor: pointer;
    transition: background var(--transition);
    border: none;
    width: 100%;
    text-align: left;
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent);
}

.dataset-codes-toggle:hover {
    background: #b2ece4;
}

.dataset-codes-toggle .toggle-icon {
    transition: transform 0.3s;
    font-size: 0.8rem;
}

.dataset-codes-toggle[aria-expanded="true"] .toggle-icon {
    transform: rotate(180deg);
}

.dataset-codes-list {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease;
}

.dataset-codes-list.expanded {
    max-height: 3000px;
}

.dataset-codes-list .code-item {
    display: flex;
    align-items: baseline;
    padding: 8px 20px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.9rem;
    transition: background 0.15s;
}

.dataset-codes-list .code-item:last-child {
    border-bottom: none;
}

.dataset-codes-list .code-item:hover {
    background: #f0faf8;
}

.dataset-codes-list .code-item code {
    font-weight: 600;
    color: var(--bs-primary);
    min-width: 140px;
    margin-right: 12px;
}

.dataset-codes-list .code-item .code-desc {
    color: #555;
    flex: 1;
}

.dataset-codes-count {
    font-size: 0.8rem;
    font-weight: 400;
    color: #888;
    margin-left: 8px;
}

/* ── Accordion ───────────────────────────────────────────── */
.accordion-button {
    font-weight: 600;
    font-size: 1.05rem;
}

.accordion-button:not(.collapsed) {
    background: var(--accent-light);
    color: var(--accent);
}

.accordion-button:focus {
    box-shadow: 0 0 0 3px rgba(15,118,110,0.15);
}

/* ── Tables ──────────────────────────────────────────────── */
.table th {
    background: #f0faf8;
    font-size: 0.9rem;
    font-weight: 600;
    color: #374151;
    white-space: nowrap;
}

.table td {
    font-size: 0.9rem;
    vertical-align: top;
}

.table code {
    font-weight: 600;
    color: var(--bs-primary);
}

/* ── Footer ──────────────────────────────────────────────── */
footer {
    background: #1a2e2b;
    color: rgba(255,255,255,0.7);
    padding: 24px 0;
    text-align: center;
    font-size: 0.85rem;
    margin-top: auto;
}

footer a {
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    transition: color var(--transition);
}

footer a:hover {
    color: var(--hover-warm);
}

/* ── Move Quiz Styles ────────────────────────────────────── */
.quiz-question {
    padding-bottom: 1rem;
    border-bottom: 1px solid #eee;
}

.quiz-question:last-of-type {
    border-bottom: none;
}

.quiz-slider-label {
    min-width: 100px;
}

.match-card {
    border: 1px solid #dee2e6;
    transition: transform 0.15s ease;
}

.match-card:hover {
    transform: translateX(4px);
}

/* ── Card Generator Modal ────────────────────────────────── */
#cardGenModal .card-template-option input:checked + div {
    box-shadow: 0 0 0 3px var(--bs-primary);
}

#cardGenModal .card-template-option.border-primary {
    border-color: var(--bs-primary) !important;
    border-width: 2px;
}

#cardGenModal .card-size-option.active {
    background-color: var(--bs-primary);
    color: white;
    border-color: var(--bs-primary);
}

#cardPreview img {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.5rem;
    }

    header .subtitle {
        font-size: 0.88rem;
    }

    .card {
        padding: 20px 16px;
    }

    nav ul {
        gap: 4px;
    }

    nav a, nav a.nav-link {
        padding: 4px 10px;
        font-size: 0.78rem;
    }

    .chart-header {
        flex-direction: column;
    }

    .chart-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .dataset-codes-list .code-item {
        flex-direction: column;
    }

    .dataset-codes-list .code-item code {
        margin-bottom: 2px;
    }

    .explorer-dropdown .dropdown-item {
        flex-wrap: wrap;
    }

    .dropdown-code {
        min-width: 80px;
    }

    .dropdown-cat {
        width: 100%;
        margin-top: 2px;
    }

    .btn-visualize {
        width: 100%;
    }

    .country-presets {
        gap: 4px;
    }

    .btn-preset {
        font-size: 0.76rem;
        padding: 4px 10px;
    }

    #toast-container {
        top: 10px;
        right: 10px;
        left: 10px;
    }

    .eurostat-toast {
        max-width: 100%;
    }
}

/* ── Superpower Cards ────────────────────────────────────── */

.superpower-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.superpower-card {
    position: relative;
    height: 360px;
    perspective: 1000px;
    cursor: pointer;
}

.superpower-card-front,
.superpower-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: transform 0.6s;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.superpower-card-front {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #fff;
}

.superpower-card-back {
    background: linear-gradient(135deg, #0f3460 0%, #1a1a2e 100%);
    color: #fff;
    transform: rotateY(180deg);
}

.superpower-card:hover .superpower-card-front {
    transform: rotateY(-180deg);
}

.superpower-card:hover .superpower-card-back {
    transform: rotateY(0deg);
}

.superpower-flag {
    font-size: 4rem;
    margin-bottom: 0.5rem;
}

.superpower-country {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.superpower-title {
    font-size: 0.875rem;
    color: #e94560;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.25rem;
}

.superpower-metric {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.superpower-value {
    font-size: 2rem;
    font-weight: 700;
    color: #00d4ff;
    margin-bottom: 0.5rem;
}

.superpower-source {
    font-size: 0.75rem;
    color: #888;
}

.superpower-funfact {
    font-size: 1.1rem;
    line-height: 1.5;
    margin-bottom: 1.5rem;
    font-style: italic;
}

.superpower-actions {
    display: flex;
    gap: 0.75rem;
}

.superpower-card-highlight {
    animation: superpower-pulse 2s ease-in-out;
}

@keyframes superpower-pulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3); }
    50% { box-shadow: 0 0 30px rgba(233, 69, 96, 0.6); }
}

@media (max-width: 576px) {
    .superpower-card {
        height: 320px;
    }
    .superpower-flag {
        font-size: 3rem;
    }
    .superpower-country {
        font-size: 1.25rem;
    }
    .superpower-value {
        font-size: 1.5rem;
    }
}

/* ── Perception Quiz ─────────────────────────────────────── */

.perception-stats-card {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 12px;
    padding: 2rem;
    color: #fff;
}

.perception-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.perception-stat {
    text-align: center;
}

.perception-stat-label {
    font-size: 0.875rem;
    color: #888;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.perception-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #00d4ff;
}

.perception-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.perception-option {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    border: 2px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    transition: all 0.2s;
}

.perception-option:hover {
    border-color: var(--bs-primary);
    transform: translateY(-2px);
}

.perception-option-flag {
    font-size: 2rem;
}

.perception-option-name {
    font-size: 1.1rem;
    font-weight: 600;
}

.perception-result {
    font-size: 1.5rem;
    font-weight: 700;
    padding: 1rem 2rem;
    border-radius: 8px;
    display: inline-block;
}

.perception-correct {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.perception-incorrect {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.perception-result-icon {
    margin-right: 0.5rem;
}

.perception-reveal-flag {
    font-size: 5rem;
    margin-bottom: 0.5rem;
}

.perception-reveal-country {
    font-size: 2rem;
    font-weight: 700;
}

.perception-explanation {
    background: #f0faf8;
    border-left: 4px solid var(--bs-primary);
    padding: 1rem 1.5rem;
    border-radius: 0 8px 8px 0;
}

.perception-final-score {
    padding: 2rem;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 12px;
    color: #fff;
}

.perception-score-number {
    font-size: 4rem;
    font-weight: 700;
    color: #00d4ff;
}

.perception-score-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.perception-score-message {
    color: #ccc;
}

.perception-breakdown {
    background: #f8fafc;
    border-radius: 8px;
    padding: 1.5rem;
}

.perception-breakdown h4 {
    margin-bottom: 1rem;
}

.perception-answer-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid #e5e7eb;
}

.perception-answer-row:last-child {
    border-bottom: none;
}

.perception-answer-icon {
    width: 24px;
    text-align: center;
}

.perception-answer-correct .perception-answer-icon {
    color: #22c55e;
}

.perception-answer-incorrect .perception-answer-icon {
    color: #ef4444;
}

@media (max-width: 576px) {
    .perception-options {
        grid-template-columns: 1fr;
    }

    .perception-stats-grid {
        grid-template-columns: 1fr;
    }

    .perception-score-number {
        font-size: 3rem;
    }

    .perception-reveal-flag {
        font-size: 4rem;
    }
}
