.hidden {
    display: none !important;
}

#fs-table .form-control,
#scenario-table input,
#scenario-table select {
    width: 100%;
    box-sizing: border-box;
    /* Crucial for padding/borders within width */
    min-width: 0;
    /* Prevents flex/grid items from overflowing */
    font-size: 0.9em;
    padding: 4px;
}


.calculator-layout {
    display: flex;
    flex-direction: column;
    gap: 30px;
    width: 100%;
}

.header-section {
    background: #f9f9f9;
    padding: 25px;
    border: 1px solid #e0e0e0;
    border-left: 4px solid #1a1a1a;
}

.header-section h2 {

    font-size: 1.8em;
    margin-bottom: 20px;
}

.global-settings {
    display: flex;
    gap: 30px;
    align-items: center;
}

/* Ensure scenario table can scroll horizontally */
.scenario-table-container {
    overflow-x: auto;
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

.setting-group {
    display: flex;
    align-items: center;
    gap: 20px;
}

.setting-group label {
    font-weight: 600;
    text-transform: uppercase;
}

.fractile-select {
    padding: 8px;
    border: 1px solid #ddd;

    font-size: 1em;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Button & Control Styles */
.table-controls {
    margin: 20px 0;
    display: flex;
    gap: 10px;
}

#add-fs-row,
#reset-fs-btn,
#add-scenario-btn {
    padding: 10px 20px;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 0;
    font-size: 0.85em;
    letter-spacing: 0.5px;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#add-fs-row,
#add-scenario-btn {
    background: #1a1a1a;
    color: white;
}

#add-fs-row:hover,
#add-scenario-btn:hover {
    background: #333;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

#reset-fs-btn {
    background: #ff4444;
    color: white;
}

#reset-fs-btn:hover {
    background: #cc0000;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

#fs-table,
#scenario-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

#fs-table th,
#fs-table td,
#scenario-table th,
#scenario-table td {
    padding: 2px 4px;
    /* Compact padding */
    text-align: left;
    border: 1px solid #eee;
    font-size: 0.9em;
}

#fs-table th,
#scenario-table th {
    background: #f5f5f5;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.85em;
    color: #1a1a1a;
    letter-spacing: 0.5px;
    position: relative;
    cursor: grab;
    user-select: none;
}

#fs-table th:active,
#scenario-table th:active {
    cursor: grabbing;
}

#fs-table th.dragging,
#scenario-table th.dragging {
    opacity: 0.5;
    background: #e0e0e0;
}

#fs-table th.over,
#scenario-table th.over {
    border-left: 2px solid #ff4444;
}

/* Validation Styles */
.result-cell.pass {
    background-color: #e8f5e9 !important;
    /* Accessible Light Green */
    color: #1b5e20 !important;
    /* Dark Green Text for Contrast > 4.5:1 */
}

.result-cell.fail {
    background-color: #ffebee !important;
    /* Accessible Light Red */
    color: #b71c1c !important;
    /* Dark Red Text for Contrast > 4.5:1 */
}

/* Delete Icon */
.btn-delete-icon {
    font-size: 12px;
    /* Small fixed size */
    color: #e57373;
    /* Soft Red */
    background: transparent;
    border: none;
    cursor: pointer;
    font-weight: bold;
    padding: 4px;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.btn-delete-icon:hover {
    opacity: 1;
    color: #ef5350;
    /* Slightly darker on hover */
    background: transparent;
}

.scenario-name {
    font-style: italic;
    color: #555;
    background: #f9f9f9;
}

/* Loading Indicator Styles */
.calculating-indicator {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: white;
    padding: 15px 25px;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 9999;
    animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
    from {
        transform: translateX(400px);
        opacity: 0;
    }

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

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

.calculating-indicator .spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #1a1a1a;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.calculating-indicator .text {
    font-size: 0.95em;
    font-weight: 600;
    color: #1a1a1a;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Draggable & Resizable Table Columns */
#fs-table th {
    position: relative;
    cursor: grab;
    user-select: none;
}

#fs-table th:active {
    cursor: grabbing;
}

#fs-table th.dragging {
    opacity: 0.5;
    background: #e0e0e0;
}

#fs-table th.over {
    border-left: 2px solid #ff4444;
}

.resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 1;
}

.resize-handle:hover,
.resize-handle.resizing {
    background: #0099cc;
}

/* Compact Data Set Switch for Table Header */
.data-set-switch {
    display: inline-flex;
    background: #e0e0e0;
    border-radius: 3px;
    padding: 2px;
    margin-top: 4px;
    font-size: 0.75em;
    font-weight: normal;
}

.data-set-switch input[type="radio"] {
    display: none;
}

.data-set-switch label {
    padding: 2px 6px;
    cursor: pointer;
    border-radius: 2px;
    color: #555;
    transition: all 0.2s;
}

.data-set-switch input[type="radio"]:checked+label {
    background: #fff;
    color: #1a1a1a;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    font-weight: bold;
}

/* Responsive Table */
.results-section {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    border: 1px solid #e0e0e0;
    /* Border around scrollable area */
}

/* Ensure table has minimum width so it doesn't crush content */
#fs-table,
#scenario-table {
    min-width: 100%;
    /* min-width: 800px; - Removed to prevent forced scrolling */
    table-layout: fixed;
    /* Optional: enforce column widths if set */
}

@media (max-width: 768px) {
    .calculator-layout {
        gap: 15px;
    }

    .header-section {
        padding: 15px;
    }

    /* Stack global settings inputs vertically on mobile */
    .global-settings {
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
    }

    /* Make sure table controls are accessible */
    .table-controls {
        flex-direction: column;
    }

    #add-fs-row,
    #reset-fs-btn {
        width: 100%;
    }
}