/* ===================================================================
   ICS Chronostratigraphic Chart - Final Styles
   =================================================================== */

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

body {
    font-family: 'Open Sans', 'Segoe UI', Arial, sans-serif;
    background: #f5f6fa;
    color: #1f2933;
    line-height: 1.4;
}

.page-container {
    width: 100%;
    margin: 0 auto;
    padding: 16px 24px 60px 24px;
    max-width: 1920px;
}

/* ===================================================================
   Header & Controls
   =================================================================== */

.header {
    background: linear-gradient(135deg, #1a5490 0%, #2b6bb3 100%);
    color: #ffffff;
    padding: 24px 30px;
    border-radius: 6px;
    box-shadow: 0 12px 24px rgba(26, 84, 144, 0.25);
}

.header h1 {
    font-size: 2em;
    letter-spacing: 0.4px;
    margin-bottom: 6px;
}

.header p {
    font-size: 0.95em;
    opacity: 0.92;
}

.controls-panel {
    margin-top: 20px;
    background: #ffffff;
    border: 1px solid #d0d7e2;
    border-radius: 6px;
    padding: 16px 20px;
    box-shadow: 0 8px 16px rgba(15, 23, 42, 0.08);
}

.controls-row {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    align-items: center;
}

.controls-panel .controls-row + .controls-row {
    margin-top: 14px;
}

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

.control-group label {
    font-weight: 600;
    color: #1f2933;
    font-size: 0.92em;
}

.control-title {
    font-weight: 700;
    font-size: 0.95em;
    color: #1f2933;
}

.control-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.control-group select {
    padding: 6px 12px;
    border: 1px solid #c5ccd8;
    border-radius: 4px;
    background: #ffffff;
    font-size: 0.9em;
    cursor: pointer;
    transition: border 0.2s ease;
}

.control-group select:focus {
    border-color: #1a5490;
    outline: none;
}

.custom-range-input {
    width: 110px;
    padding: 6px 8px;
    border: 1px solid #c5ccd8;
    border-radius: 4px;
    font-size: 0.9em;
}

.btn {
    padding: 8px 16px;
    background: #2b6bb3;
    border: none;
    border-radius: 4px;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
}

.btn:hover {
    background: #1a5490;
    transform: translateY(-1px);
}

/* ===================================================================
   Loading & Error States
   =================================================================== */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    background: #ffffff;
    padding: 28px 36px;
    border-radius: 10px;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.25);
}

.loading-text {
    font-size: 1.05em;
    color: #1a5490;
    font-weight: 700;
}

.error-message {
    margin-top: 16px;
    padding: 14px 18px;
    border-radius: 6px;
    border: 1px solid #f5d2d5;
    background: #fdebec;
    color: #9f1c2d;
}

/* ===================================================================
   Chart Container & Layout
   =================================================================== */

.chart-wrapper {
    margin-top: 24px;
    background: #ffffff;
    border-radius: 8px;
    border: 2px solid #1f3d69;
    box-shadow: 0 18px 36px rgba(34, 51, 84, 0.18);
    overflow: auto;
}

.chart-container {
    min-width: 1400px;
    position: relative;
}

.chart-header {
    position: sticky;
    top: 0;
    z-index: 200;
    background: linear-gradient(180deg, #1f3d69 0%, #1a5490 70%, #134b7a 100%);
    border-bottom: 2px solid #09294d;
    box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.25);
    height: 52px;
}

.column-header {
    position: absolute;
    top: 0;
    height: 52px;
    background: linear-gradient(180deg, #1f3d69 0%, #09294d 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
    text-align: center;
    font-weight: 700;
    color: #f7fafc;
    font-size: 0.92em;
    letter-spacing: 0.3px;
    border-right: 1px solid rgba(255, 255, 255, 0.35);
    text-transform: uppercase;
    -webkit-user-select: none; /* Safari */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* IE/Edge */
    user-select: none; /* Prevent text selection during resize */
}

.column-header:last-of-type {
    border-right: none;
}

/* Column resize handle */
.column-resize-handle {
    position: absolute;
    right: -4px;
    top: 0;
    bottom: 0;
    width: 8px;
    cursor: col-resize;
    z-index: 10;
    transition: background-color 0.2s ease;
}

.column-resize-handle:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

.column-resize-handle:active {
    background-color: rgba(255, 255, 255, 0.5);
}

.chart-body {
    position: relative;
    background: #ffffff;
    /* Leave space at the top so sticky header does not overlap the top-most time labels/boxes */
    padding-top: 16px; /* additional safety padding (header is 52px tall) */
}

.chart-column {
    position: absolute;
    top: 0;
    bottom: 0;
    border-right: 1px solid #d0d7e2;
}

.chart-column:last-child {
    border-right: none;
}

/* ===================================================================
   Time Column
   =================================================================== */

.time-column {
    background: linear-gradient(180deg, #ecf1f8 0%, #d9e2f3 100%);
    border-right: 2px solid #1f3d69;
}

.time-line {
    position: absolute;
    left: 0;
    width: 100%;
    height: 1px;
    background: rgba(31, 61, 105, 0.25);
}

.time-axis-border {
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    background: #1f3d69;
}

.time-label {
    position: absolute;
    left: 8px;
    transform: translateY(-50%);
    font-size: 11px;
    font-weight: 700;
    color: #1f2933;
    background: rgba(255, 255, 255, 0.98);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid rgba(26, 84, 144, 0.3);
    box-shadow: 0 2px 4px rgba(15, 23, 42, 0.1);
    z-index: 220; /* appear above header when scrolling */
}

/* ===================================================================
   ICS Columns & Cells
   =================================================================== */

.ics-column {
    background: #ffffff;
}

.ics-box {
    position: absolute;
    left: 0;
    right: 0;
    border: 1px solid rgba(15, 23, 42, 0.25);
    border-radius: 4px;
    padding: 4px 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-weight: 600;
    font-size: 12px;
    letter-spacing: 0.2px;
    box-shadow: inset 0 -2px 0 rgba(15, 23, 42, 0.15);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.ics-box:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.25);
}

.ics-label {
    line-height: 1.25;
    pointer-events: none;
}

.rank-eon {
    font-size: 14px;
    text-transform: uppercase;
}

.rank-era {
    font-size: 13px;
}

.rank-period {
    font-size: 12.5px;
}

.rank-epoch {
    font-size: 12px;
}

.rank-age {
    font-size: 11.5px;
}

/* ===================================================================
   Biozone Columns & Cells
   =================================================================== */

.biozone-column {
    background: #fdfdfd;
}

.biozone-box {
    position: absolute;
    left: 0;
    right: 0;
    border: 1px solid rgba(15, 23, 42, 0.2);
    border-left: 6px solid #1a1a1a;
    border-radius: 4px;
    padding: 3px 8px 3px 10px;
    display: flex;
    align-items: center;
    font-weight: 600;
    font-size: 11.5px;
    letter-spacing: 0.1px;
    box-shadow: inset 0 -1px 0 rgba(15, 23, 42, 0.12);
    transition: background 0.15s ease, transform 0.15s ease;
}

.biozone-box:hover {
    transform: translateX(2px);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.18);
}

.biozone-label {
    pointer-events: none;
}

.biozone-nalma .biozone-box { border-left-color: #28a745; }
.biozone-salma .biozone-box { border-left-color: #ffc107; }
.biozone-elma .biozone-box { border-left-color: #17a2b8; }
.biozone-alma .biozone-box { border-left-color: #dc3545; }
.biozone-mp .biozone-box { border-left-color: #6f42c1; }

/* ===================================================================
   Legend & Footer
   =================================================================== */

/* Legend removed intentionally */

.footer {
    margin-top: 36px;
    text-align: center;
    font-size: 0.9em;
    color: #4a5568;
}

.footer a {
    color: #1a5490;
    font-weight: 600;
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

.footer p + p {
    margin-top: 10px;
}

.footer-meta {
    font-size: 0.9em;
}

/* ===================================================================
   Print adjustments
   Ensure background colors are preserved when printing / saving to PDF.
   Many browsers will still require the "Print background colors and images"
   option to be enabled in the print dialog, but these rules improve
   compatibility (WebKit/Chromium and modern browsers supporting
   print-color-adjust).
   =================================================================== */
@media print {
    /* Ask the browser to preserve colors exactly when printing */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    /* Hide resize handles in print */
    .column-resize-handle {
        display: none !important;
    }
    
    /* Preserve custom column widths in print using inline styles */
    /* The JavaScript sets inline styles which override default widths */

    /* Simplify appearance for print — remove shadows which may not render well */
    .header, .controls-panel, .chart-wrapper, .chart-header, .chart-body, .chart-column, .ics-box, .biozone-box, .time-label {
        box-shadow: none !important;
    }

    /* Force solid background for header (gradients may be ignored) */
    .chart-header {
        background: #1f3d69 !important;
        border-bottom: 2px solid #09294d !important;
    }

    /* Ensure chart areas keep their background colors */
    .chart-wrapper, .chart-body, .chart-column, .ics-column, .biozone-column {
        background-color: #ffffff !important;
    }

    /* Time labels should remain readable on print */
    .time-label {
        background-color: #ffffff !important;
        color: #1f2933 !important;
        border-color: rgba(26, 84, 144, 0.3) !important;
    }

    /* Remove rounded corners that can cause seams in some PDFs */
    .chart-wrapper, .chart-column, .ics-box, .biozone-box {
        border-radius: 0 !important;
    }

    /* Reduce visual noise */
    .header h1, .header p, .controls-panel, .footer {
        color: #000 !important;
    }

    /* Avoid page breaks inside boxes where possible */
    .ics-box, .biozone-box {
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }
    
    /* Ensure borders are visible in print for both ICS and biozone boxes */
    .ics-box {
        border: 1px solid #333 !important;
    }
    
    .biozone-box {
        border: 1px solid #333 !important;
        border-left-width: 6px !important;
    }
    
    /* Ensure biozone border colors are preserved in print */
    .biozone-nalma .biozone-box { 
        border-left-color: #28a745 !important; 
    }
    .biozone-salma .biozone-box { 
        border-left-color: #ffc107 !important; 
    }
    .biozone-elma .biozone-box { 
        border-left-color: #17a2b8 !important; 
    }
    .biozone-alma .biozone-box { 
        border-left-color: #dc3545 !important; 
    }
    .biozone-mp .biozone-box { 
        border-left-color: #6f42c1 !important; 
    }
}

/* When the JS print helper adds .printing to <body>, provide solid background fallbacks
   so the print dialog shows consistent colors even if gradients are disabled. */
body.printing .ics-box, body.printing .biozone-box {
    /* If inline styles set background-color they will be used; this rule ensures
       border-left and other properties look correct for print preview. */
    background-image: none !important;
    background-color: inherit !important;
}

body.printing .chart-header {
    background-image: none !important;
    background-color: #1f3d69 !important;
}

/* ===================================================================
   Responsive
   =================================================================== */

@media (max-width: 1200px) {
    .page-container {
        padding: 16px;
    }

    .header h1 {
        font-size: 1.65em;
    }

    .controls-row {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 768px) {
    .chart-wrapper {
        border-width: 1px;
    }

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

/* ===================================================================
   Print
   =================================================================== */

@media print {
    body {
        background: #ffffff;
    }

    .controls-panel,
    .legend-section,
    .footer,
    .btn {
        display: none !important;
    }

    .chart-wrapper {
        box-shadow: none;
        border: 1px solid #000;
    }
}
