* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin: 0;
    padding: 15px;
    background: #f5f5f5;
    color: #333;
}

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

h1 {
    color: #2c3e50;
    margin: 0;
    font-size: 1.4em;
}

.subtitle {
    color: #7f8c8d;
    margin: 0;
    font-size: 0.9em;
}

.run-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.run-btn {
    padding: 8px 20px;
    border: none;
    background: #3498db;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: all 0.2s;
}

.run-btn:hover {
    background: #2980b9;
}

.run-btn:disabled {
    background: #95a5a6;
    cursor: not-allowed;
}

.progress-container {
    width: 200px;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: #27ae60;
    width: 0%;
    transition: width 0.1s;
}

.progress-text {
    font-size: 0.8em;
    color: #7f8c8d;
    min-width: 80px;
}

/* Main 2-column layout: settings take one third of the width, results two thirds */
.main-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    gap: 15px;
    height: calc(100vh - 80px);
    max-width: 100%;
    overflow: hidden;
}

/* Column styling */
.config-column, .results-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
}

/* Panel with trajectory column layout. minmax(0, 1fr) lets the projection charts shrink
   with a narrow settings column instead of holding it open at their drawn width. */
.panel-with-trajectories {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.panel-with-trajectories > h2 {
    grid-column: 1 / -1;
}

.panel-inputs {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.trajectory-column {
    background: #f8f9fa;
    border-radius: 6px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.trajectory-column-header {
    font-size: 0.75em;
    font-weight: 600;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 8px;
    margin-bottom: 4px;
}

.trajectory-status {
    font-size: 0.65em;
    font-weight: normal;
    text-transform: none;
    letter-spacing: 0;
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 8px;
}

.trajectory-status.theoretical {
    background: #ffeaa7;
    color: #856404;
}

.trajectory-status.simulated {
    background: #d4edda;
    color: #155724;
}

/* Trajectory chart items */
.trajectory-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.trajectory-chart-container {
    width: 100%;
    height: 240px;
    background: white;
    border-radius: 4px;
    padding: 4px;
}

.trajectory-label {
    font-size: 0.7em;
    font-weight: 500;
    color: #2c3e50;
    line-height: 1.3;
}

.trajectory-sublabel {
    font-size: 0.6em;
    color: #95a5a6;
    margin-top: 2px;
}

/* Legacy subsection support for panels without trajectory column */
.subsection .trajectory-preview {
    display: none;
}

/* Tooltips */
.tooltip {
    position: relative;
    display: inline-block;
    cursor: help;
    color: #7f8c8d;
    font-weight: normal;
    margin-left: 4px;
}

.tooltip::after {
    content: attr(data-tip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: #2c3e50;
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.75em;
    font-weight: normal;
    white-space: normal;
    width: 220px;
    text-align: left;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 100;
    line-height: 1.4;
}

.tooltip::before {
    content: '';
    position: absolute;
    bottom: 115%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #2c3e50;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 100;
}

.tooltip:hover::after,
.tooltip:hover::before {
    opacity: 1;
    visibility: visible;
}

.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #e0e0e0;
    font-size: 0.7em;
    font-weight: 600;
}

/* Subsection styling */
.subsection {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed #e0e0e0;
}

.subsection-label {
    font-size: 0.7em;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.subsection-content {
    display: block;
}

.subsection-inputs {
    width: 100%;
}

.panel {
    background: white;
    padding: 12px;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.panel h2 {
    margin: 0 0 10px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid #3498db;
    color: #2c3e50;
    font-size: 0.95em;
}

.panel h2.green-border {
    border-bottom-color: #27ae60;
}

.panel h2.purple-border {
    border-bottom-color: #9b59b6;
}

.input-group {
    margin-bottom: 12px;
}

.input-group:last-child {
    margin-bottom: 0;
}

.input-group label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
    font-size: 0.8em;
}

.input-group select, .input-group input[type="number"] {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.85em;
}

.input-group input[type="number"] {
    -moz-appearance: textfield;
}

.input-group input[type="number"]::-webkit-outer-spin-button,
.input-group input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Slider styling */
.slider-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.slider-container input[type="range"] {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: #e0e0e0;
    border-radius: 2px;
    outline: none;
}

.slider-container input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.slider-container input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
    border: 2px solid white;
}

.slider-container.green input[type="range"]::-webkit-slider-thumb {
    background: #27ae60;
}

.slider-container.green input[type="range"]::-moz-range-thumb {
    background: #27ae60;
}

.slider-container.purple input[type="range"]::-webkit-slider-thumb {
    background: #9b59b6;
}

.slider-container.purple input[type="range"]::-moz-range-thumb {
    background: #9b59b6;
}

.slider-value {
    min-width: 75px;
    text-align: right;
    font-weight: 600;
    font-size: 0.9em;
    color: #2c3e50;
}

.input-row {
    display: flex;
    gap: 10px;
}

.input-row .input-group {
    flex: 1;
}

/* Distribution type selector row */
.dist-type-row {
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.dist-type-row label {
    font-size: 0.7em;
    color: #7f8c8d;
    min-width: 65px;
}

.dist-type-row select {
    font-size: 0.75em;
    padding: 3px 6px;
    border: 1px solid #ddd;
    border-radius: 3px;
    background: white;
}

/* Distribution config */
.dist-config {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 6px;
}

.dist-config input {
    padding: 4px 6px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 0.75em;
    width: 100%;
}

.dist-config label {
    font-size: 0.7em;
    color: #7f8c8d;
    display: block;
    margin-bottom: 2px;
}

/* Events list */
.events-list {
    max-height: 150px;
    overflow-y: auto;
}

.event-row {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
    align-items: center;
}

.event-row input {
    flex: 1;
    min-width: 0;
    padding: 4px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 0.8em;
}

.event-row select {
    width: 80px;
    padding: 4px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 0.8em;
}

.event-row button {
    padding: 4px 8px;
    border: 1px solid #e74c3c;
    background: white;
    color: #e74c3c;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.75em;
}

.add-event-btn {
    padding: 4px 10px;
    border: 1px dashed #3498db;
    background: white;
    color: #3498db;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.75em;
    margin-top: 6px;
}

/* Percentile table */
.percentile-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75em;
}

.percentile-table th {
    background: #f8f9fa;
    padding: 6px 4px;
    text-align: right;
    font-weight: 600;
    border-bottom: 1px solid #ddd;
}

.percentile-table th:first-child {
    text-align: left;
}

.percentile-table td {
    padding: 4px;
    text-align: right;
    border-bottom: 1px solid #eee;
}

.percentile-table td:first-child {
    text-align: left;
    font-weight: 500;
}

.percentile-table .highlight-row {
    background: #e8f8e8;
}

.percentile-table .separator-row td {
    height: 8px;
    background: transparent;
    border: none;
}

.percentile-table .single-value {
    text-align: center;
    font-weight: 600;
}

/* Breakdown table (transposed: years as columns) */
.breakdown-table {
    border-collapse: collapse;
    font-size: 0.7em;
    margin-top: 10px;
}

/* Columns size to their figures; if the years do not fit, the container scrolls sideways
   rather than the figures overlapping. */
.breakdown-table.transposed {
    width: 100%;
    table-layout: auto;
}

.breakdown-table th {
    background: #f8f9fa;
    padding: 4px 6px;
    text-align: right;
    font-weight: 600;
    border-bottom: 2px solid #ddd;
    font-size: 0.85em;
    white-space: nowrap;
}

.breakdown-table th:first-child {
    text-align: left;
}

.breakdown-table td {
    padding: 4px 6px;
    text-align: right;
    border-bottom: 1px solid #eee;
    white-space: nowrap;
}

.breakdown-table td.row-label {
    text-align: left;
    font-weight: 500;
    background: #f8f9fa;
    position: sticky;
    left: 0;
    z-index: 1;
}

.breakdown-table .net-cf-row {
    background: #f0f7f0;
    font-weight: 600;
}

.breakdown-table .net-cf-row td.row-label {
    background: #e8f4e8;
}

.breakdown-table tbody tr:hover {
    background: #f8f9fa;
}

.breakdown-table .net-cf-row:hover {
    background: #e8f4e8;
}

/* Full width of the results column, below the four charts */
#breakdownTableContainer {
    max-height: none;
    overflow-x: auto;
    overflow-y: visible;
    margin-top: var(--space-section);
    padding: var(--space-section);
    background: var(--colour-card-background);
    border-radius: var(--radius-card);
}

#breakdownTableContainer h4 {
    margin: 0 0 2px 0;
    font-size: 0.85em;
    color: #2c3e50;
}

.breakdown-note {
    font-size: 0.7em;
    color: #666;
    margin-top: 6px;
    line-height: 1.4;
}

/* Charts grid - 2x2 layout for 4 cells, filling the visible height of the results column.
   The year-by-year table sits below it, reached by scrolling the column. */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 15px;
    flex: none;
    height: var(--charts-grid-height);
    min-height: var(--charts-grid-min-height);
}

.chart-container {
    background: #fafafa;
    padding: 15px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    min-height: 200px;
    overflow: hidden;
}

.chart-container.full-width {
    grid-column: 1 / -1;
}

.chart-container h3 {
    margin: 0 0 2px 0;
    font-size: 0.8em;
    color: #2c3e50;
}

.chart-subtitle {
    margin: 0 0 8px 0;
    font-size: 0.7em;
    color: #7f8c8d;
    line-height: 1.3;
}

.chart-wrapper {
    flex: 1;
    min-height: 0;
}

/* Probability table */
.prob-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.7em;
}

.prob-table th, .prob-table td {
    padding: 3px 4px;
    text-align: center;
    border: 1px solid #eee;
}

.prob-table th {
    background: #f8f9fa;
    font-weight: 600;
}

.prob-cell-good { background: #d4edda; }
.prob-cell-ok { background: #fff3cd; }
.prob-cell-bad { background: #f8d7da; }

/* Toggle switch */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toggle-switch {
    position: relative;
    width: 40px;
    height: 20px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.3s;
    border-radius: 20px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: #3498db;
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

.toggle-label {
    font-size: 0.8em;
    font-weight: 500;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

.metric-positive { color: #27ae60; }
.metric-negative { color: #e74c3c; }

.note {
    font-size: 0.7em;
    color: #7f8c8d;
    margin-top: 8px;
    padding: 8px;
    background: #fafafa;
    border-radius: 4px;
}
