:root {
    --bg-main: #f6f7f9;
    --bg-card: #ffffff;

    --text-main: #111827;
    --text-muted: #4b5563;
    --text-soft: #6b7280;

    --blue: #1f4e79;
    --blue-dark: #163b5c;
    --blue-soft: #e8f0f7;

    --border: #d9dee7;
    --border-soft: #e5e7eb;

    --shadow-card: 0 4px 14px rgba(17, 24, 39, 0.05);

    --radius-lg: 12px;
    --radius-md: 10px;
}

/* Dark mode variables */

body.dark-mode {
    --bg-main: #0f172a;
    --bg-card: #111827;

    --text-main: #f9fafb;
    --text-muted: #d1d5db;
    --text-soft: #9ca3af;

    --blue: #60a5fa;
    --blue-dark: #bfdbfe;
    --blue-soft: #1e3a5f;

    --border: #374151;
    --border-soft: #1f2937;

    --shadow-card: 0 4px 14px rgba(0, 0, 0, 0.25);
}

/* Base */

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    font-family: "Segoe UI", Roboto, Arial, sans-serif;
    margin: 0;
    min-height: 100vh;
    background: var(--bg-main);
    color: var(--text-main);
    overflow-x: hidden;
}

/* Visibility rules */

.language-section {
    display: none;
}

.language-section.active {
    display: block;
}

.tab-panel {
    display: none;
}

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

.profile-panel {
    display: none;
}

.profile-panel.active {
    display: block;
}

.metrics-panel {
    display: none;
}

.metrics-panel.active {
    display: block;
}

.data-panel {
    display: none;
}

.data-panel.active {
    display: block;
}

.comparison-panel,
.status-comparison-panel {
    display: none;
}

.comparison-panel.active,
.status-comparison-panel.active {
    display: block;
}

/* Header */

header {
    background: #102033;
    color: white;
    padding: 38px 56px 42px 56px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 28px;
    border-bottom: 4px solid var(--blue);
}

body.dark-mode header {
    background: #020617;
    border-bottom-color: #2563eb;
}

header h1 {
    margin: 0 0 10px 0;
    font-size: 42px;
    line-height: 1.05;
    letter-spacing: -0.03em;
    font-weight: 750;
}

header p {
    margin: 0;
    max-width: 760px;
    color: #dbe3ec;
    font-size: 17px;
    line-height: 1.5;
}

.author-line {
    margin-top: 12px;
    color: #b8c7d8;
    font-size: 14px;
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.language-toggle {
    border: 1px solid #8da4bc;
    background: transparent;
    color: white;
    border-radius: 6px;
    padding: 9px 14px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
}

.language-toggle:hover {
    background: rgba(255, 255, 255, 0.08);
}

.theme-toggle {
    width: 40px;
    height: 40px;
    border: 1px solid #8da4bc;
    background: transparent;
    color: white;
    border-radius: 999px;
    padding: 0;
    cursor: pointer;
    font-weight: 600;
    font-size: 18px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* Layout */

main {
    max-width: 1240px;
    margin: 28px auto 40px auto;
    padding: 0 28px;
}

section {
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    padding: 28px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-card);
    overflow: visible;
}

body.dark-mode section,
body.dark-mode .chart-card,
body.dark-mode .metric-card {
    background: #111827;
    border-color: #374151;
}

/* Typography */

h2 {
    margin-top: 0;
    margin-bottom: 16px;
    font-size: 24px;
    color: var(--text-main);
    letter-spacing: -0.02em;
    line-height: 1.2;
    font-weight: 720;
}

h3 {
    margin-top: 0;
    margin-bottom: 7px;
    font-size: 18px;
    color: var(--text-main);
    line-height: 1.3;
    font-weight: 680;
}

p {
    line-height: 1.6;
}

/* Badge and notes */

.badge {
    display: inline-block;
    background: var(--blue-soft);
    color: var(--blue-dark);
    padding: 6px 10px;
    border-radius: 5px;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 16px;
    border: 1px solid #c8d7e6;
}

body.dark-mode .badge {
    background: #1e3a5f;
    color: #dbeafe;
    border-color: #2563eb;
}

.method-box {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-left: 4px solid var(--blue);
    border-radius: 8px;
    padding: 16px 18px;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.6;
}

body.dark-mode .method-box {
    background: #0f172a;
    border-color: #374151;
}

/* Tabs */

.tabs {
    display: flex;
    gap: 0;
    flex-wrap: wrap;
    margin: 0 0 24px 0;
    padding: 6px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-card);
    width: fit-content;
    max-width: 100%;
}

button.tab-button {
    appearance: none;
    -webkit-appearance: none;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 7px;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    line-height: 1;
    transition: background 0.15s ease, color 0.15s ease;
}

button.tab-button:hover {
    background: #f3f4f6;
    color: var(--text-main);
}

button.tab-button.active {
    background: var(--blue);
    color: #ffffff;
}

body.dark-mode .tabs {
    background: #111827;
    border-color: #374151;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

body.dark-mode button.tab-button {
    color: #d1d5db;
}

body.dark-mode button.tab-button:hover {
    background: #1f2937;
    color: #f9fafb;
}

body.dark-mode button.tab-button.active {
    background: #2563eb;
    color: #ffffff;
}

/* Profile selector */

.profile-selector {
    margin-top: 22px;
    background: #f9fafb;
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 8px;
    max-width: 100%;
}

body.dark-mode .profile-selector {
    background: #0f172a;
    border-color: #374151;
}

.profile-selector-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(220px, 1fr));
    gap: 14px;
    width: 100%;
}

.selector-field {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.selector-field label,
.profile-selector label {
    font-weight: 700;
    color: var(--text-main);
    font-size: 13px;
}

.selector-field select,
.profile-selector select {
    width: 100%;
    min-width: 0;
    border: 1px solid #c7ced8;
    border-radius: 6px;
    padding: 9px 11px;
    background: white;
    color: var(--text-main);
    font-weight: 600;
    outline: none;
}

.selector-field select:focus,
.profile-selector select:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(31, 78, 121, 0.12);
}

body.dark-mode .selector-field select,
body.dark-mode .profile-selector select {
    background: #111827;
    color: #f9fafb;
    border-color: #4b5563;
}

/* Methodology */

.methodology-list {
    margin: 16px 0 0 0;
    padding-left: 22px;
    color: var(--text-muted);
    line-height: 1.65;
}

.methodology-list li {
    margin-bottom: 8px;
}

/* Metrics */

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.metric-card {
    background: #ffffff;
    border: 1px solid var(--border);
    border-top: 4px solid var(--blue);
    border-radius: 10px;
    padding: 17px 16px;
}

.metric-label {
    color: var(--text-soft);
    font-size: 13px;
    font-weight: 650;
    margin-bottom: 8px;
    line-height: 1.35;
}

.metric-value {
    color: var(--text-main);
    font-size: 26px;
    font-weight: 760;
    letter-spacing: -0.025em;
}

/* Tables */

.table-wrapper {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
}

body.dark-mode .table-wrapper {
    background: #111827;
    border-color: #374151;
}

.data-table {
    width: 100%;
    min-width: 1180px;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th,
.data-table td {
    border-bottom: 1px solid #e5e7eb;
    padding: 10px 11px;
    text-align: right;
    white-space: nowrap;
}

.data-table th {
    background: #f3f4f6;
    font-weight: 700;
    color: var(--text-main);
}

.data-table tbody tr:nth-child(even) {
    background: #fafafa;
}

.data-table tbody tr:hover {
    background: #eef4fa;
}

body.dark-mode .data-table th {
    background: #1f2937;
    color: #f9fafb;
}

body.dark-mode .data-table td {
    color: #e5e7eb;
    border-bottom-color: #374151;
}

body.dark-mode .data-table tbody tr:nth-child(even) {
    background: #151f2e;
}

body.dark-mode .data-table tbody tr:hover {
    background: #1e293b;
}

.table-wrapper-full {
    max-height: 620px;
    overflow: auto;
}

.data-table-full {
    min-width: 1280px;
}

.table-wrapper-full .data-table th {
    position: sticky;
    top: 0;
    z-index: 2;
}

.data-profile-selector {
    margin-top: 18px;
}

/* Charts */

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 22px;
}

.chart-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px 20px 10px 20px;
    background: #ffffff;
    min-width: 0;
}

.chart-card-full {
    width: 100%;
}

.chart-subtitle {
    margin: 0 0 12px 0;
    color: var(--text-soft);
    font-size: 14px;
    line-height: 1.5;
}

.plotly-chart {
    width: 100%;
    min-height: 420px;
    overflow: visible;
}

.js-plotly-plot,
.plot-container,
.svg-container {
    overflow: visible !important;
}

body.dark-mode .plotly-chart {
    background: #111827;
}

body.dark-mode .js-plotly-plot,
body.dark-mode .plot-container,
body.dark-mode .svg-container {
    background: #111827 !important;
    overflow: visible !important;
}

body.dark-mode .modebar {
    background: transparent !important;
}

/* Interpretation / generic text */

.interpretation {
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1.65;
    margin-bottom: 0;
}

/* CSV / PDF download button */

.download-row {
    margin-top: 18px;
}

.download-row a,
.download-row a:link,
.download-row a:visited,
a.download-link,
a.download-link:link,
a.download-link:visited {
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    padding: 10px 14px !important;
    border-radius: 6px !important;
    border: 1px solid var(--blue) !important;
    background: #ffffff !important;
    color: var(--blue-dark) !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    text-decoration: none !important;
}

.download-row a::before,
a.download-link::before {
    content: "⬇";
    font-size: 13px;
}

.download-row a:hover,
a.download-link:hover {
    background: var(--blue-soft) !important;
    color: var(--blue-dark) !important;
    text-decoration: none !important;
}

body.dark-mode .download-row a,
body.dark-mode .download-row a:link,
body.dark-mode .download-row a:visited,
body.dark-mode a.download-link,
body.dark-mode a.download-link:link,
body.dark-mode a.download-link:visited {
    background: #1f2937 !important;
    color: #f9fafb !important;
    border-color: #60a5fa !important;
    text-decoration: none !important;
}

body.dark-mode .download-row a:hover,
body.dark-mode a.download-link:hover {
    background: #263445 !important;
    color: #ffffff !important;
    border-color: #93c5fd !important;
}

/* Comparison panels */

#comparison-panels-fr .chart-card,
#comparison-panels-en .chart-card {
    min-width: 0;
}

/* Decomposition */

.decomposition-selector {
    width: fit-content;
    max-width: 100%;
}

.decomposition-chart-card {
    margin-top: 0;
}

/* Working paper */

.working-paper-section {
    padding: 28px;
}

.working-paper-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    margin-bottom: 24px;
}

.working-paper-header h2 {
    margin-top: 0;
    margin-bottom: 10px;
}

.working-paper-header .interpretation {
    max-width: 900px;
    margin-bottom: 0;
}

.working-paper-download {
    white-space: nowrap;
    margin-top: 4px;
}

.working-paper-card {
    width: 100%;
    border: 1px solid #d7dee8;
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
    overflow: hidden;
}

.pdf-viewer-wrapper {
    width: 100%;
    height: 82vh;
    min-height: 760px;
    background: #f8fafc;
}

.pdf-viewer {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

body.dark-mode .working-paper-card {
    background: #111827;
    border-color: #374151;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

body.dark-mode .pdf-viewer-wrapper {
    background: #0f172a;
}

/* Contact */

.contact-section {
    max-width: 820px;
    margin: 0 auto 24px auto;
}

.contact-form {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.contact-form label {
    font-weight: 700;
    color: var(--text-main);
    font-size: 14px;
}

.contact-form input,
.contact-form textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #ffffff;
    color: var(--text-main);
    font-family: inherit;
    font-size: 15px;
    line-height: 1.4;
    outline: none;
}

.contact-form input:focus,
.contact-form textarea:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(31, 78, 121, 0.12);
}

.contact-form textarea {
    min-height: 160px;
    resize: vertical;
}

.contact-form button {
    width: fit-content;
    margin-top: 8px;
    padding: 11px 18px;
    border: 1px solid var(--blue);
    border-radius: 8px;
    background: var(--blue);
    color: #ffffff;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.contact-form button:hover {
    background: var(--blue-dark);
}

body.dark-mode .contact-form input,
body.dark-mode .contact-form textarea {
    background: #0f172a;
    color: #f9fafb;
    border-color: #374151;
}

body.dark-mode .contact-form input:focus,
body.dark-mode .contact-form textarea:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.16);
}

body.dark-mode .contact-form button {
    background: #2563eb;
    border-color: #60a5fa;
    color: #ffffff;
}

body.dark-mode .contact-form button:hover {
    background: #1d4ed8;
}

/* Consistency checks */

.consistency-checks-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-top: 22px;
}

.consistency-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    background: #ffffff;
}

body.dark-mode .consistency-card {
    background: #111827;
    border-color: #374151;
}

.consistency-status {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    border-radius: 999px;
    padding: 4px 9px;
    margin-bottom: 10px;
    font-size: 12px;
    font-weight: 800;
}

.consistency-status.ok {
    background: #dcfce7;
    color: #166534;
}

.consistency-status.warning {
    background: #fee2e2;
    color: #991b1b;
}

.consistency-label {
    color: var(--text-main);
    font-weight: 700;
    line-height: 1.45;
    margin-bottom: 12px;
}

.consistency-values {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.consistency-values span {
    display: block;
    color: var(--text-soft);
    font-size: 12px;
    margin-bottom: 4px;
}

.consistency-values strong {
    color: var(--text-main);
    font-size: 15px;
}

/* Footer */

footer {
    text-align: center;
    color: var(--text-soft);
    padding: 30px;
    font-size: 13px;
}

/* Responsive */

@media (max-width: 980px) {
    header {
        padding: 32px 24px 36px 24px;
        flex-direction: column;
    }

    header h1 {
        font-size: 34px;
    }

    main {
        margin: 24px auto 32px auto;
        padding: 0 16px;
    }

    section {
        padding: 22px;
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .metrics-grid {
        grid-template-columns: 1fr 1fr;
    }

    .profile-selector-grid {
        grid-template-columns: 1fr;
    }

    .working-paper-section {
        padding: 18px;
    }

    .working-paper-header {
        flex-direction: column;
        align-items: stretch;
    }

    .working-paper-download {
        width: fit-content;
    }

    .pdf-viewer-wrapper {
        height: 72vh;
        min-height: 560px;
    }
}

@media (max-width: 760px) {
    .consistency-checks-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 620px) {
    header p {
        font-size: 16px;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
    }

    .profile-selector {
        width: 100%;
    }

    .profile-selector select {
        min-width: 100%;
        width: 100%;
    }

    section {
        padding: 18px;
    }

    .tabs {
        width: 100%;
    }

    button.tab-button {
        flex: 1 1 auto;
        text-align: center;
        padding: 10px 12px;
    }

    .contact-section {
        max-width: 100%;
    }

    .contact-form button {
        width: 100%;
        justify-content: center;
    }
}

.methodology-versioning {
    margin-top: 32px;
}

.methodology-versioning-card {
    margin-top: 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    background: #f8fafc;
}

.methodology-versioning-card p {
    margin-top: 0;
    margin-bottom: 12px;
}

body.dark-mode .methodology-versioning-card {
    background: #0f172a;
    border-color: #374151;
}

.chart-note {
    margin: 12px 0 18px 0;
    padding: 10px 14px;
    max-width: 900px;
    border-left: 4px solid #2563eb;
    background: rgba(37, 99, 235, 0.08);
    color: #475569;
    font-size: 0.95rem;
    line-height: 1.5;
    border-radius: 10px;
}

.chart-note strong {
    color: #0f172a;
}
.info-tooltip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 6px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid currentColor;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    opacity: 0.75;
    text-decoration: none;
    color: inherit;
}

.info-tooltip:hover {
    opacity: 1;
}
}