:root {
    --bg-color: #f0f2f5;
    --sidebar-bg: #ffffff;
    --card-bg: rgba(255, 255, 255, 0.9);
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --glass-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-y: auto;
}

.app-container {
    display: flex;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 1.5rem;
    flex-shrink: 0;
}

.logo-area {
    margin-bottom: 2rem;
}

.logo-area h2 {
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.country-selector {
    background: #f8fafc;
    padding: 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
}

.country-selector select {
    width: 100%;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    border-radius: 0.25rem;
    border: 1px solid #cbd5e1;
}

.country-selector button {
    width: 100%;
    padding: 0.5rem;
    background: var(--text-primary);
    color: white;
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
}

.inputs-scroll h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin: 1.5rem 0 0.75rem 0;
    font-weight: 600;
}

.input-group {
    margin-bottom: 0.75rem;
}

.input-group label {
    display: block;
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
}

.input-group input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    font-family: inherit;
}

.primary-btn {
    width: 100%;
    margin-top: 1.5rem;
    padding: 0.75rem;
    background: var(--primary-color);
    color: white;
    font-weight: 600;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background 0.2s;
}

.primary-btn:hover {
    background: var(--primary-hover);
}

/* Main Content */
.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 1.5rem 2rem;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.tabs {
    display: flex;
    gap: 1rem;
}

.tab-btn {
    background: transparent;
    border: none;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    font-weight: 600;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--glass-shadow);
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.kpi-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Charts */
.charts-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-card {
    background: var(--card-bg);
    min-width: 0;
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--glass-shadow);
    height: 400px;
}

.chart-card h3 {
    margin-bottom: 1rem;
    font-size: 1rem;
    color: var(--text-primary);
}

/* Stats Table */
.detailed-stats {
    background: var(--card-bg);
    min-width: 0;
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--glass-shadow);
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
}

.stats-table td {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}

.stats-table tr:last-child td {
    border-bottom: none;
}

.stats-table td:first-child {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.stats-table td:last-child {
    text-align: right;
    font-weight: 500;
}

/* Stakeholders */
.stakeholder-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: var(--glass-shadow);
}

.stakeholder-table th,
.stakeholder-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.stakeholder-table th {
    background: #f8fafc;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Tooltips */
.info-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    background: #e2e8f0;
    color: #64748b;
    border-radius: 50%;
    text-align: center;
    line-height: 16px;
    font-size: 11px;
    font-weight: bold;
    cursor: help;
    margin-left: 6px;
    position: relative;
}

.info-icon:hover {
    background: var(--primary-color);
    color: white;
}

.info-icon-inline {
    display: inline-block;
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    text-align: center;
    line-height: 18px;
    font-size: 12px;
    font-weight: bold;
}


/* Splash Screen */
.splash-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
}

.splash-card {
    background: white;
    padding: 3rem;
    border-radius: 1.5rem;
    max-width: 700px;
    text-align: center;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.splash-card h1 {
    font-size: 2rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.splash-card .subtitle {
    color: var(--text-secondary);
    margin-bottom: 2.5rem;
    font-size: 1.1rem;
}

.splash-steps {
    display: flex;
    justify-content: space-between;
    gap: 2rem;
    margin-bottom: 3rem;
    text-align: left;
}

.step {
    flex: 1;
}

.step-icon {
    width: 32px;
    height: 32px;
    background: #eff6ff;
    color: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    margin-bottom: 1rem;
}

.step p {
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.step strong {
    color: var(--text-primary);
    display: block;
    margin-bottom: 0.25rem;
}

.splash-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 1rem 3rem;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 3rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.splash-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.3);
}

/* Print */
@media print {

    .sidebar,
    .top-bar {
        display: none;
    }

    .app-container {
        display: block;
    }

    .main-content {
        padding: 0;
        overflow: visible;
    }

    .charts-container {
        grid-template-columns: 1fr;
        page-break-inside: avoid;
    }

    .chart-card {
        height: 300px;
        margin-bottom: 1rem;
        box-shadow: none;
        border: 1px solid #ccc;
    }

    .kpi-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 1rem;
    }
}

/* Additions for Wizard & Impact UI */
.wizard-card {
    max-width: 500px;
    text-align: left;
}

.wizard-card h1 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.wizard-card .input-group label {
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 600;
}

.wizard-card .input-group input,
.wizard-card .input-group select {
    padding: 0.75rem;
    font-size: 1rem;
    border: 2px solid #e2e8f0;
    transition: border-color 0.2s;
    width: 100%;
    border-radius: 0.5rem;
}

.wizard-card .input-group input:focus,
.wizard-card .input-group select:focus {
    border-color: var(--primary-color);
    outline: none;
}

.wizard-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 2rem;
    gap: 1rem;
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem;
    border-radius: 2rem;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-secondary);
}

.secondary-btn:hover {
    background: #f8fafc;
    color: var(--text-primary);
}

/* New Programme Summary Table Styles */
.summary-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    margin-top: 0.5rem;
}

.summary-table td {
    padding: 0.8rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.95rem;
    /* Consistent Size */
    color: var(--text-primary);
}

.summary-table tr:last-child td {
    border-bottom: none;
}

/* Label Column (First Child) */
.summary-table td:first-child {
    color: var(--text-secondary);
    width: 60%;
    font-weight: 500;
}

/* Value Column (Last Child) */
.summary-table td:last-child {
    text-align: right;
    font-weight: 600;
    font-feature-settings: "tnum";
    /* Tabular Numbers */
    color: var(--text-primary);
}

/* Sub-labels */
.summary-table .sub-label {
    padding-left: 1.5rem !important;
    font-size: 0.85rem !important;
    /* Slightly smaller hierarchy */
    color: #64748b !important;
    font-weight: 400 !important;
}

/* Separator Row */
.summary-table .separator {
    height: 1px;
    background-color: transparent;
    /* Cleaner than line, just space? or line? */
    border-bottom: 1px dashed var(--border-color) !important;
}

/* Card Headers */
.card h3 {
    font-size: 1.1rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #f1f5f9;
}

/* Specific highlight colors */
.text-green {
    color: #10b981 !important;
}

.text-sm {
    font-size: 0.85rem !important;
}

/* Programme controls synchronised by the UI (not country observations). */
.auto-filled {
    background-color: #fef3c7 !important;
    border-color: #fcd34d !important;
    transition: background-color 0.3s ease;
}

/* Model inputs loaded or derived from dated authoritative country APIs (ADR-0046/0049). */
.country-observation {
    background-color: #eff6ff !important;
    border: 2px solid #2563eb !important;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.14);
    color: #172554 !important;
}

/* Programme assumptions informed by, but never populated from, country context (ADR-0050). */
.programme-assumption {
    background-color: #fffbeb !important;
    border: 2px solid #d97706 !important;
    box-shadow: 0 0 0 2px rgba(217, 119, 6, 0.12);
    color: #78350f !important;
}

.country-source-key {
    display: flex;
    align-items: flex-start;
    gap: 0.45rem;
    margin-top: 0.6rem;
    color: #334155;
    line-height: 1.35;
}

.country-source-swatch {
    flex: 0 0 auto;
    width: 1rem;
    height: 1rem;
    margin-top: 0.08rem;
    border: 2px solid #2563eb;
    border-radius: 0.2rem;
    background: #eff6ff;
}

.programme-source-swatch {
    flex: 0 0 auto;
    width: 1rem;
    height: 1rem;
    margin-top: 0.08rem;
    border: 2px solid #d97706;
    border-radius: 0.2rem;
    background: #fffbeb;
}

/* Mobile Responsiveness */
@media screen and (max-width: 768px) {
    body {
        height: auto;
        overflow-y: auto;
        /* Enable page scroll */
    }

    .app-container {
        flex-direction: column;
        height: auto;
    }

    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 1rem;
    }

    .main-content {
        padding: 1rem;
        height: auto;
        overflow: visible;
    }

    .charts-container {
        grid-template-columns: 1fr !important;
        display: flex;
        /* Flexbox might be safer for simple stacking if Grid fails? No, Grid 1fr is standard. */
        display: grid;
    }

    .kpi-grid {
        grid-template-columns: 1fr;
        /* Stack KPI cards */
        gap: 1rem;
    }

    /* Adjust Tables */
    .summary-table td {
        padding: 0.5rem 0.25rem;
        font-size: 0.85rem;
    }

    .summary-table td:first-child {
        width: 50%;
        /* More balanced on small screens */
    }

    /* Splash Screen Mobile */
    .splash-card {
        padding: 1.5rem;
        max-width: 95%;
        margin: 1rem;
        max-height: 90vh;
        /* Prevent overflow */
        overflow-y: auto;
    }

    .splash-steps {
        flex-direction: column;
        gap: 1.5rem;
    }

    .splash-card h1 {
        font-size: 1.5rem;
    }

    .splash-btn {
        width: 100%;
        padding: 0.8rem;
    }

    /* Wizard Nav */
    .wizard-nav {
        flex-direction: column-reverse;
        gap: 0.5rem;
    }

    .secondary-btn {
        width: 100%;
        text-align: center;
    }

    /* Top Bar */
    .top-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .wb-indicators {
        width: 100%;
        overflow-x: auto;
        /* Allow horizontal scroll for pills */
        padding-bottom: 0.5rem;
        white-space: nowrap;
        display: block;
        /* Ensure scroll works */
    }

    /* Pills inside scrolling container */
    .wb-indicators>div {
        display: inline-flex !important;
        flex-wrap: nowrap !important;
    }

    .logo-area {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
    }

    color: var(--text-primary);
}

/* New Programme Summary Table Styles */
.summary-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.5rem;
}

.summary-table td {
    padding: 0.8rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.95rem;
    /* Consistent Size */
    color: var(--text-primary);
}

.summary-table tr:last-child td {
    border-bottom: none;
}

/* Label Column (Data Table Only) */
#monthlyDataTable td:first-child {
    color: var(--text-secondary);
    width: 140px;
    min-width: 140px;
    max-width: 140px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* Label Column (Summary Tables) */
.summary-table td:first-child {
    color: var(--text-secondary);
    width: 60%;
    /* Restore original width for other tables */
    font-weight: 500;
}

/* Value Column (Last Child) */
.summary-table td:last-child {
    text-align: right;
    font-weight: 600;
    font-feature-settings: "tnum";
    /* Tabular Numbers */
    color: var(--text-primary);
}

/* Sub-labels */
.summary-table .sub-label {
    padding-left: 1.5rem !important;
    font-size: 0.85rem !important;
    /* Slightly smaller hierarchy */
    color: #64748b !important;
    font-weight: 400 !important;
}

/* Separator Row */
.summary-table .separator {
    height: 1px;
    background-color: transparent;
    /* Cleaner than line, just space? or line? */
    border-bottom: 1px dashed var(--border-color) !important;
}

/* Card Headers */
.card h3 {
    font-size: 1.1rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #f1f5f9;
}

/* Specific highlight colors */
.text-green {
    color: #10b981 !important;
}

.text-sm {
    font-size: 0.85rem !important;
}

/* Mobile Responsiveness */
@media screen and (max-width: 768px) {
    body {
        height: auto;
        overflow-y: auto;
        /* Enable page scroll */
    }

    .app-container {
        flex-direction: column;
        height: auto;
    }

    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 1rem;
    }

    .main-content {
        padding: 1rem;
        height: auto;
        overflow: visible;
    }

    .charts-container {
        grid-template-columns: 1fr !important;
        display: flex;
        /* Flexbox might be safer for simple stacking if Grid fails? No, Grid 1fr is standard. */
        display: grid;
    }

    .kpi-grid {
        grid-template-columns: 1fr;
        /* Stack KPI cards */
        gap: 1rem;
    }

    /* Adjust Tables */
    .summary-table td {
        padding: 0.5rem 0.25rem;
        font-size: 0.85rem;
    }

    .summary-table td:first-child {
        width: 50%;
        /* More balanced on small screens */
    }

    /* Splash Screen Mobile */
    .splash-card {
        padding: 1.5rem;
        max-width: 95%;
        margin: 1rem;
        max-height: 90vh;
        /* Prevent overflow */
        overflow-y: auto;
    }

    .splash-steps {
        flex-direction: column;
        gap: 1.5rem;
    }

    .splash-card h1 {
        font-size: 1.5rem;
    }

    .splash-btn {
        width: 100%;
        padding: 0.8rem;
    }

    /* Wizard Nav */
    .wizard-nav {
        flex-direction: column-reverse;
        gap: 0.5rem;
    }

    .secondary-btn {
        width: 100%;
        text-align: center;
    }

    /* Top Bar */
    .top-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .wb-indicators {
        width: 100%;
        overflow-x: auto;
        /* Allow horizontal scroll for pills */
        padding-bottom: 0.5rem;
        white-space: nowrap;
        display: block;
        /* Ensure scroll works */
    }

    /* Pills inside scrolling container */
    .wb-indicators>div {
        display: inline-flex !important;
        flex-wrap: nowrap !important;
    }

    .logo-area {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
    }
}

.summary-table th,
.summary-table td {
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    padding: 8px;
    border: 1px solid #ccc;
}

/* Programme summary cards fit the main panel instead of forcing a three-column
   minimum width. `min(100%, 20rem)` permits a single card to shrink on narrow
   screens while retaining useful card widths on larger ones. */
.stats-table-wrapper,
.results-grid,
.results-grid > .card {
    min-width: 0;
    max-width: 100%;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

/* The monthly audit table is deliberately wide. Keep its cells on one line,
   but contain that width in a local scroll area rather than widening the page. */
.monthly-table-scroll {
    display: block;
    width: 100%;
    max-width: 100%;
    max-height: min(60vh, 500px);
    overflow: auto;
    overscroll-behavior: contain;
}

.monthly-table-card {
    width: 100%;
    max-width: 100%;
    height: auto;
    min-height: 0;
    min-width: 0;
    margin-top: 2rem;
    padding: 1.5rem;
    background: var(--card-bg);
    border-radius: 1rem;
    box-shadow: var(--glass-shadow);
    overflow: hidden;
}

.monthly-table-card h3 {
    margin-bottom: 1rem;
    font-size: 1rem;
    color: var(--text-primary);
}

#monthlyDataTable {
    table-layout: auto;
}

#monthlyDataTable th,
#monthlyDataTable td {
    min-width: 100px;
    white-space: nowrap;
    overflow-wrap: normal;
}

#monthlyDataTable thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f8fafc;
}

/* Responsive Adjustments */
@media screen and (max-width: 1024px) {
    .sidebar {
        width: 280px;
    }
}

@media screen and (max-width: 768px) {
    .app-container {
        flex-direction: column;
        overflow-y: auto;
    }

    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 2px solid var(--border-color);
        max-height: 400px;
        padding: 1rem;
    }

    .main-content {
        height: auto;
        padding: 1rem;
    }

    .kpi-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .summary-table {
        font-size: 0.8rem;
    }
}
/* Inline hint under an input (e.g. the cost-of-capital provenance note). */
.help-text {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.7rem;
    line-height: 1.35;
    color: #64748b;
}

/* Country selector: flag a pending "Load Country Data" click after the
   selection changes, so the user is not left wondering why nothing moved. */
#fetchDataBtn.needs-attention {
    animation: pulse-attention 1.4s ease-in-out infinite;
    box-shadow: 0 0 0 2px rgba(180, 83, 9, 0.35);
}

@keyframes pulse-attention {

    0%,
    100% {
        box-shadow: 0 0 0 2px rgba(180, 83, 9, 0.35);
    }

    50% {
        box-shadow: 0 0 0 5px rgba(180, 83, 9, 0.12);
    }
}

.country-selector select {
    font-size: 0.9rem;
    cursor: pointer;
}

.country-selector small {
    display: block;
    margin-top: 0.4rem;
    font-size: 0.72rem;
    line-height: 1.4;
    color: #64748b;
}

/* F-73: no valid calculation backs the dashboard, so hide it rather than show stale numbers. */
#modelTab.no-results .charts-container,
#modelTab.no-results .detailed-stats {
    display: none;
}

.no-results-notice {
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid #d97706;
    border-radius: 0.5rem;
    background: #fef3c7;
    color: #92400e;
    font-size: 0.9rem;
    line-height: 1.5;
}
