/* Main CSS - Core styles and variables */

:root {
    /* Brand Colors */
    --primary: #006494;
    --primary-dark: #003554;
    --primary-light: #0077b6;
    --success: #52b788;
    --danger: #d62828;
    --warning: #f77f00;
    --info: #0077b6;
    --light: #f8f9fa;
    --dark: #212529;

    /* Neutral Palette */
    --neutral-100: #f8f9fa;
    --neutral-200: #e9ecef;
    --neutral-300: #dee2e6;
    --neutral-400: #ced4da;
    --neutral-500: #adb5bd;
    --neutral-600: #6c757d;
    --neutral-700: #495057;
    --neutral-800: #343a40;
    --neutral-900: #212529;

    /* Elevation System (3 levels) */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.04), 0 4px 8px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.08), 0 16px 32px rgba(0, 0, 0, 0.08);

    /* Focus Ring */
    --focus-ring: 0 0 0 3px rgba(0, 100, 148, 0.2);

    /* Layout */
    --sidebar-width: 240px;
    --header-height: 70px;
    --content-max-width: 90rem;  /* in rem: scales with text size and zoom (~1440px at 16px) */

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.2s ease;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--neutral-900);
    line-height: 1.5;
}

/* App Container */
.app-container {
    display: flex;
    height: 100vh;
    background: white;
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.main-header {
    height: var(--header-height);
    padding: 0 30px;
    background: white;
    border-bottom: 1px solid var(--neutral-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.main-header h1 {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--neutral-900);
}

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

/* Content Wrapper */
.content-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    background: var(--neutral-100);
}

.content-wrapper > * {
    max-width: var(--content-max-width);
    margin-left: 0;   /* next to the sidebar, not centred */
    margin-right: 0;
    width: 100%;
}

/* Top bar: holds the user card, pinned to the content's right edge */
.top-bar {
    position: sticky;
    top: 0;
    height: 0;
    z-index: 20;
}

/* Content Sections */
.content-section {
    display: none;
}

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

/* Cards - Elevation System */
.card {
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    margin-bottom: 20px;
    overflow: hidden;
    transition: box-shadow var(--transition-normal), transform var(--transition-normal);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

.card.card-flat {
    box-shadow: var(--shadow-sm);
}

.card.card-flat:hover {
    box-shadow: var(--shadow-md);
}

.card.card-elevated {
    box-shadow: var(--shadow-lg);
}

.card-header {
    padding: 16px 20px;
    background: var(--neutral-100);
    border-bottom: 1px solid var(--neutral-200);
}

.card-header h3,
.card-header h4 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--neutral-800);
}

.card-body {
    padding: 20px;
}

.card h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--neutral-700);
    margin-bottom: 12px;
}

/* Forms - Enhanced Consistency */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 13px;
    color: var(--neutral-700);
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--neutral-300);
    border-radius: var(--radius-sm);
    font-size: 14px;
    line-height: 1.4;
    color: var(--neutral-800);
    background: white;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control::placeholder {
    color: var(--neutral-500);
}

.form-control:hover {
    border-color: var(--neutral-400);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}

.form-control:disabled {
    background: var(--neutral-100);
    color: var(--neutral-500);
    cursor: not-allowed;
}

/* Input with unit suffix */
.input-group {
    display: flex;
    align-items: stretch;
}

.input-group .form-control {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: none;
}

.input-group-text {
    display: flex;
    align-items: center;
    padding: 0 12px;
    background: var(--neutral-100);
    border: 1.5px solid var(--neutral-300);
    border-left: none;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 13px;
    color: var(--neutral-600);
}

/* Select styling */
select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236c757d' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-row {
    display: flex;
    gap: 15px;
    align-items: flex-end;
}

/* Form table styling */
.form-table td {
    padding: 8px 0;
    vertical-align: middle;
}

.form-table td:first-child {
    padding-right: 15px;
    font-size: 13px;
    color: var(--neutral-600);
    white-space: nowrap;
}

.form-table input,
.form-table select {
    height: 36px;
}

/* Buttons - Enhanced */
.btn {
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 1px 2px rgba(0, 100, 148, 0.2);
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 2px 4px rgba(0, 100, 148, 0.3);
}

.btn-secondary {
    background: var(--neutral-600);
    color: white;
}

.btn-secondary:hover {
    background: var(--neutral-700);
}

.btn-outline-secondary {
    background: white;
    color: var(--neutral-600);
    border: 1.5px solid var(--neutral-300);
}

.btn-outline-secondary:hover {
    background: var(--neutral-100);
    border-color: var(--neutral-400);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #3d9970;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #b52222;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-lg {
    padding: 12px 24px;
    font-size: 15px;
}

/* Alerts */
.alert {
    padding: 15px;
    border-radius: 4px;
    margin-bottom: 20px;
}

.alert-info {
    background: #d1ecf1;
    border: 1px solid #bee5eb;
    color: #0c5460;
}

/* Utilities */
.mb-3 { margin-bottom: 1rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.text-muted { color: var(--neutral-600); font-size: 0.9em; }
.text-small { font-size: 0.85em; }

/* Placeholder */
.placeholder-message {
    text-align: center;
    padding: 60px 20px;
    color: var(--neutral-600);
}

.placeholder-message h3 {
    color: var(--neutral-800);
    margin-bottom: 10px;
}

/* Loading */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(0,0,0,.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Inline Edit */
.inline-edit {
    padding: 4px 8px;
    border: 1px solid transparent;
    border-radius: 3px;
    background: transparent;
    font-size: 13px;
    width: 100%;
}

.inline-edit:hover {
    border-color: var(--neutral-300);
    background: var(--neutral-100);
}

.inline-edit:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
}

select.inline-edit {
    width: auto;
    min-width: 80px;
}

input[type="date"].inline-edit {
    width: auto;
}

/* Modal Overlay - Enhanced */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: white;
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0, 0, 0, 0.05);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.25s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-content h3 {
    margin-bottom: 20px;
    color: var(--neutral-800);
    font-size: 1.2rem;
}

/* Dashboard/Project Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.dashboard-grid .card {
    padding: 20px;
}

.dashboard-grid .card h3 {
    margin-bottom: 15px;
    font-size: 1rem;
    color: var(--neutral-700);
}

/* ========================================
   Loading States (V65)
   ======================================== */

/* Skeleton loader animation */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
}

.skeleton-text.short {
    width: 60%;
}

.skeleton-title {
    height: 20px;
    width: 40%;
    margin-bottom: 12px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Button loading state */
.btn.loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Chart loading overlay */
.chart-loading {
    position: relative;
}

.chart-loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.8);
    z-index: 10;
}

.chart-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 32px;
    height: 32px;
    margin: -16px 0 0 -16px;
    border: 3px solid var(--neutral-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    z-index: 11;
}

/* ========================================
   Status Badges (V65)
   ======================================== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    gap: 5px;
    white-space: nowrap;
}

.badge-success {
    background: #d4edda;
    color: #155724;
}

.badge-danger {
    background: #f8d7da;
    color: #721c24;
}

.badge-warning {
    background: #fff3cd;
    color: #856404;
}

.badge-info {
    background: #cce5ff;
    color: #004085;
}

.badge-secondary {
    background: var(--neutral-200);
    color: var(--neutral-700);
}

.badge-running {
    background: #cce5ff;
    color: #004085;
    animation: pulse-badge 2s infinite;
}

@keyframes pulse-badge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Badge icons */
.badge .icon {
    font-size: 10px;
}

/* ========================================
   Run Button State Indicator (V65)
   ======================================== */

.btn-run {
    min-width: 160px;
    transition: all var(--transition-normal);
}

.btn-run.current {
    background: var(--success);
    box-shadow: 0 2px 4px rgba(82, 183, 136, 0.3);
}

.btn-run.current:hover {
    background: #3d9970;
}

.btn-run.stale {
    background: var(--warning);
    box-shadow: 0 2px 4px rgba(247, 127, 0, 0.3);
    animation: pulse-attention 2s infinite;
}

.btn-run.stale:hover {
    background: #e06c00;
    animation: none;
}

@keyframes pulse-attention {
    0%, 100% { box-shadow: 0 2px 4px rgba(247, 127, 0, 0.3); }
    50% { box-shadow: 0 2px 12px rgba(247, 127, 0, 0.5); }
}

/* Results status text */
.results-status {
    font-size: 12px;
    margin-top: 8px;
}

.results-status.current {
    color: var(--success);
}

.results-status.stale {
    color: var(--warning);
}

/* ========================================
   Site Cards (V65)
   ======================================== */

.site-card {
    padding: 0;
    overflow: hidden;
}

.site-card .site-header {
    padding: 16px 20px;
    background: var(--neutral-100);
    border-bottom: 1px solid var(--neutral-200);
}

.site-card .site-header h4 {
    margin: 0;
    font-size: 1rem;
    color: var(--neutral-800);
}

.site-card .site-location {
    font-size: 13px;
    color: var(--neutral-600);
}

.site-card .site-map {
    height: 150px;
    background: var(--neutral-200);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.site-card .site-map img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.site-card .site-map-placeholder {
    color: var(--neutral-500);
    font-size: 13px;
    text-align: center;
}

.site-card .site-details {
    padding: 16px 20px;
    border-bottom: 1px solid var(--neutral-200);
}

.site-card .detail-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 13px;
}

.site-card .detail-row .label {
    color: var(--neutral-600);
}

.site-card .detail-row .value {
    color: var(--neutral-800);
    font-weight: 500;
}

.site-card .site-pools {
    padding: 16px 20px;
}

.site-card .site-pools h5 {
    margin: 0 0 10px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--neutral-600);
}

.site-card .pool-list {
    list-style: none;
    padding: 0;
    margin: 0 0 12px;
}

.site-card .pool-list li {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--neutral-100);
}

.site-card .pool-list li:last-child {
    border-bottom: none;
}

.site-card .pool-volume {
    color: var(--neutral-600);
}

/* Add site card (dashed border) */
.site-card.add-site {
    border: 2px dashed var(--neutral-300);
    background: transparent;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.site-card.add-site:hover {
    border-color: var(--primary);
    background: rgba(0, 100, 148, 0.02);
}

.site-card.add-site .add-content {
    text-align: center;
    color: var(--neutral-500);
}

.site-card.add-site .add-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

/* Sites grid */
.sites-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

/* Responsive */
@media (max-width: 768px) {
    .content-wrapper {
        padding: 20px;
    }

    .form-row {
        flex-direction: column;
    }

    .sites-grid {
        grid-template-columns: 1fr;
    }
}
/* Debug Mode - hide detail cards when debug mode is off */
.debug-only {
    display: none !important;
}
body.debug-mode-on .debug-only {
    display: block !important;
}

/* Station map (Admin -> Weather): weight labels of the forecast grid points */
.leaflet-tooltip.grid-point-label {
    font-size: 11px;
    padding: 0 4px;
    box-shadow: none;
}
.leaflet-tooltip.grid-point-label::before {
    display: none;
}

/* Simulate -> Sensitivity Analysis: low | base | high per parameter */
.sens-params {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 15px;
    padding: 15px;
    background: #f5f5f5;
    border-radius: 8px;
    margin-bottom: 12px;
}
.sens-label {
    /* starts where the first box starts (after the sign column) */
    padding-left: 16px;
    /* as the result cards' titles (h4) */
    font-size: 1.1rem;
    font-weight: 700;
    color: #495057;
    margin-bottom: 6px;
}
.sens-boxes, .sens-captions {
    display: grid;
    grid-template-columns: 12px 64px 64px 12px 64px;
    column-gap: 4px;
    align-items: center;
}
.sens-boxes .sens-base { grid-column: 3; }
.sens-sign { text-align: right; color: #666; font-size: 13px; }
.sens-input {
    width: 64px;
    height: 30px;
    padding: 2px 4px;
    text-align: center;
    font-size: 13px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
}
/* The base comes from the Simulate tab: shown, not edited here */
.sens-input.sens-base {
    background: #e9ecef;
    border-style: dashed;
    color: #555;
    font-weight: 600;
    cursor: default;
}
.sens-input.sens-base:focus { outline: none; }
.sens-captions { margin-top: 2px; font-size: 10px; color: #999; }
.sens-captions span { text-align: center; }
.sens-captions span:nth-child(1) { grid-column: 2; }
.sens-captions span:nth-child(2) { grid-column: 3; }
.sens-captions span:nth-child(3) { grid-column: 5; }
.sens-results-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 15px;
}
@media (max-width: 900px) {
    .sens-results-grid { grid-template-columns: 1fr; }
}
.sens-results-grid tr.sens-total td {
    font-weight: 700;
    border-top: 2px solid #999;
    border-bottom: 2px solid #999;
}
.sens-results-grid tr.sens-net td {
    font-weight: 700;
    border-top: 2px solid #999;
    border-bottom: 2px solid #999;
    cursor: pointer;
}
.sens-results-grid tr.sens-net td:first-child { user-select: none; }
.sens-results-grid tr.sens-net:hover td { background: #eef4fb; }
/* Fold/unfold the loss parts: a boxed + / − as in spreadsheet row groups */
.sens-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin-right: 6px;
    border: 1px solid #888;
    border-radius: 3px;
    background: #fff;
    color: #333;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    vertical-align: -2px;
}

/* Unsaved changes: Save / Don't save / Cancel (assets/js/modules/unsaved.js) */
.unsaved-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    padding: 16px;
}
.unsaved-dialog {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    padding: 20px 22px 16px;
    width: 100%;
    max-width: 420px;
}
.unsaved-dialog h3 { margin: 0 0 8px; font-size: 1.1rem; }
.unsaved-dialog p { margin: 0 0 16px; color: #555; font-size: 14px; }
.unsaved-buttons { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
