/* Anachronistic Elegance - Life of Brian Aesthetic */
:root {
    /* Desert & Ancient Color Palette */
    --primary: #8B4513; /* Saddle brown - weathered wood */
    --secondary: #D2691E; /* Chocolate - desert dust */
    --accent: #B8860B; /* Dark goldenrod - tarnished gold */
    --success: #8FBC8F; /* Dark sea green - faded jade */
    --warning: #CD853F; /* Peru - clay pot */
    --error: #B22222; /* Fire brick - dried blood */
    /* Background Tones */
    --background: linear-gradient(135deg, #F5DEB3 0%, #DEB887 50%, #D2B48C 100%);
    --surface: #FAF0E6; /* Linen - papyrus */
    --surface-elevated: #FDF5E6; /* Old lace */    /* Text Colors */
    --text: #654321; /* Dark brown - ink */
    --text-light: #8B7765; /* Shadow */
    --text-accent: #4A4A4A; /* Charcoal */
    
    /* Border & Effects */
    --border: #CD853F; /* Peru */
    --shadow: rgba(101, 67, 33, 0.15);
    --shadow-heavy: rgba(101, 67, 33, 0.25);
    
    /* Chart Colors - Improved readability */
    --tank-temp-color: #8B4513; /* Saddle brown - better contrast */
    --target-temp-color: #DAA520; /* Goldenrod - more visible */
    --backup-heater-color: #DC143C; /* Crimson - clearer red */
    --reheat-color: #FF8C00; /* Dark orange - distinct from target */
    
    /* Responsive breakpoints */
    --mobile: 576px;
    --tablet: 768px;
    --desktop: 992px;
    --wide: 1200px;
}

/* CSS Feature Detection for graceful degradation */
@supports (backdrop-filter: blur(2px)) {
    .tooltip {
        backdrop-filter: blur(2px);
    }
}

@supports not (backdrop-filter: blur(2px)) {
    .tooltip {
        background: rgba(245, 222, 179, 0.8);
    }
}

/* Base Typography - Classical Serif with Modern Performance */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Preload critical fonts with fallbacks */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;500;600&family=Crimson+Text:ital,wght@0,400;0,600;1,400&display=swap');

/* Root font size for perfect rem scaling */
html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Crimson Text', 'Times New Roman', 'Times', serif;
    line-height: 1.7;
    color: var(--text);
    background: var(--background);
    background-attachment: fixed;
    min-height: 100vh;
    position: relative;
    /* Performance optimizations */
    will-change: scroll-position;
    -webkit-overflow-scrolling: touch;
}

/* Optimized textured background with reduced layers */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle at 25% 25%, rgba(139, 69, 19, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 75% 75%, rgba(205, 133, 63, 0.05) 0%, transparent 50%);
    background-size: 200px 200px, 300px 300px;
    background-position: 0 0, 100px 100px;
    pointer-events: none;
    z-index: -1;
    /* GPU acceleration */
    transform: translateZ(0);
    will-change: transform;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header Styles - Imperial Gravitas */
.hero {
    text-align: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 50%, var(--accent) 100%);
    color: var(--surface);
    padding: 50px 30px;
    border-radius: 20px;
    margin-bottom: 40px;
    box-shadow: 
        0 15px 35px var(--shadow-heavy),
        inset 0 2px 0 rgba(245, 222, 179, 0.2),
        inset 0 -2px 0 rgba(101, 67, 33, 0.3);
    border: 3px solid var(--border);
    position: relative;
    overflow: hidden;
}

.hero::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        repeating-linear-gradient(
            45deg,
            transparent 0px,
            transparent 2px,
            rgba(245, 222, 179, 0.1) 2px,
            rgba(245, 222, 179, 0.1) 4px
        );
    pointer-events: none;
}

.hero h1 {
    font-family: 'Cinzel', 'Times New Roman', serif;
    font-size: 3rem;
    font-weight: 600;
    margin-bottom: 15px;
    text-shadow: 
        3px 3px 6px rgba(101, 67, 33, 0.4),
        1px 1px 2px rgba(0, 0, 0, 0.3);
    letter-spacing: 2px;
    position: relative;
    z-index: 1;
}

.subtitle {
    font-family: 'Crimson Text', serif;
    font-size: 1.4rem;
    font-style: italic;
    margin-bottom: 12px;
    opacity: 0.95;
    position: relative;
    z-index: 1;
}

.tagline {
    font-family: 'Crimson Text', serif;
    font-style: italic;
    opacity: 0.85;
    font-size: 1.1rem;
    font-weight: 400;
    position: relative;
    z-index: 1;
}

/* Input Panel Styles - Papyrus Scroll Aesthetic */
.input-panel {
    background: var(--surface);
    border-radius: 20px;
    padding: 40px;
    margin-bottom: 40px;
    box-shadow: 
        0 8px 25px var(--shadow-heavy),
        inset 0 1px 0 rgba(245, 222, 179, 0.8),
        inset 0 -1px 0 rgba(139, 69, 19, 0.3);
    border: 2px solid var(--border);
    position: relative;
    background-image: 
        linear-gradient(90deg, transparent 98%, rgba(139, 69, 19, 0.1) 100%),
        linear-gradient(0deg, transparent 98%, rgba(139, 69, 19, 0.1) 100%);
    background-size: 20px 20px;
}

.input-panel::before {
    content: '';
    position: absolute;
    top: 15px;
    left: 15px;
    right: 15px;
    bottom: 15px;
    border: 1px solid rgba(139, 69, 19, 0.2);
    border-radius: 15px;
    pointer-events: none;
}

.input-panel h2 {
    font-family: 'Cinzel', serif;
    color: var(--primary);
    margin-bottom: 12px;
    font-size: 2rem;
    font-weight: 500;
    text-shadow: 2px 2px 4px var(--shadow);
    letter-spacing: 1px;
}

.intro {
    color: var(--text-light);
    margin-bottom: 35px;
    font-style: italic;
    font-size: 1.1rem;
    line-height: 1.6;
}

.input-group {
    margin-bottom: 35px;
    padding: 25px;
    border: 2px solid var(--border);
    border-radius: 15px;
    background: var(--surface-elevated);
    box-shadow: 
        inset 0 2px 4px rgba(139, 69, 19, 0.1),
        0 2px 8px rgba(139, 69, 19, 0.05);
    position: relative;
}

.input-group::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 20px;
    right: 20px;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, var(--accent) 20%, var(--accent) 80%, transparent 100%);
    border-radius: 1px;
}

.input-group h3 {
    font-family: 'Cinzel', serif;
    color: var(--secondary);
    margin-bottom: 25px;
    font-size: 1.5rem;
    font-weight: 500;
    border-bottom: 3px solid var(--secondary);
    padding-bottom: 8px;
    letter-spacing: 1px;
    text-shadow: 1px 1px 2px var(--shadow);
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.field {
    position: relative;
}

.field label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text);
    font-family: 'Crimson Text', serif;
    font-size: 1.05rem;
    text-shadow: 1px 1px 2px rgba(139, 69, 19, 0.1);
}

.field input,
.field select {
    width: 100%;
    padding: 15px 18px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 1rem;
    font-family: 'Crimson Text', serif;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--surface);
    color: var(--text);
    box-shadow: 
        inset 0 2px 4px rgba(139, 69, 19, 0.1),
        0 1px 3px rgba(139, 69, 19, 0.1);
}

.field input:focus,
.field select:focus {
    outline: none;
    border-color: var(--accent);
    background: #FFFEF7;
    box-shadow: 
        inset 0 2px 4px rgba(184, 134, 11, 0.1),
        0 0 0 3px rgba(184, 134, 11, 0.15),
        0 2px 8px rgba(139, 69, 19, 0.2);
    transform: translateY(-1px);
}

.field input:hover,
.field select:hover {
    border-color: var(--secondary);
    box-shadow: 
        inset 0 2px 4px rgba(139, 69, 19, 0.1),
        0 2px 6px rgba(139, 69, 19, 0.15);
}

.tooltip {
    display: block;
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 8px;
    line-height: 1.5;
    font-style: italic;
    padding: 8px 12px;
    background: rgba(245, 222, 179, 0.3);
    border-left: 3px solid var(--accent);
    border-radius: 0 8px 8px 0;
    backdrop-filter: blur(2px);
}

.calculate-btn {
    width: 100%;
    padding: 18px 40px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--primary) 50%, #8B4513 100%);
    color: var(--surface);
    border: 3px solid var(--primary);
    border-radius: 12px;
    font-family: 'Cinzel', serif;
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    margin-top: 30px;
    box-shadow: 
        0 8px 20px var(--shadow-heavy),
        inset 0 1px 0 rgba(245, 222, 179, 0.3),
        inset 0 -1px 0 rgba(101, 67, 33, 0.4);
    text-shadow: 2px 2px 4px rgba(101, 67, 33, 0.6);
    position: relative;
    overflow: hidden;
}

.calculate-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent 0%, rgba(245, 222, 179, 0.2) 50%, transparent 100%);
    transition: left 0.6s ease;
}

.calculate-btn:hover {
    transform: translateY(-3px);
    box-shadow: 
        0 12px 30px var(--shadow-heavy),
        inset 0 1px 0 rgba(245, 222, 179, 0.4),
        inset 0 -1px 0 rgba(101, 67, 33, 0.5);
    background: linear-gradient(135deg, #DAA520 0%, var(--primary) 50%, #654321 100%);
}

.calculate-btn:hover::before {
    left: 100%;
}

.calculate-btn:active {
    transform: translateY(-1px);
    box-shadow: 
        0 4px 12px var(--shadow-heavy),
        inset 0 2px 4px rgba(101, 67, 33, 0.3);
}

/* Results Panel Styles */
.results-panel {
    background: var(--surface);
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 5px 20px var(--shadow);
}

.results-panel h2 {
    color: var(--primary);
    margin-bottom: 30px;
    font-size: 1.8rem;
    text-align: center;
}

.diagnosis-section,
.comparison-section,
.graph-section,
.legionella-section {
    margin-bottom: 40px;
    padding: 20px;
    border-radius: 10px;
    background: #f8f9fa;
}

.diagnosis-section h3,
.comparison-section h3,
.graph-section h3,
.legionella-section h3 {
    color: var(--secondary);
    margin-bottom: 15px;
    font-size: 1.4rem;
}

.diagnosis-content {
    background: white;
    padding: 20px;
    border-radius: 8px;
    border-left: 5px solid var(--secondary);
}

.warning {
    background: #fff3cd;
    border-left-color: var(--warning) !important;
    color: #856404;
}

.critical {
    background: #ffe6e6;
    border-left-color: var(--accent) !important;
    color: #721c24;
}

.success {
    background: #d4edda;
    border-left-color: var(--success) !important;
    color: #155724;
}

/* Table Styles */
.table-container {
    overflow-x: auto;
}

.comparison-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px var(--shadow);
}

.comparison-table th,
.comparison-table td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

/* Hover explanation styling for comparison table */
.tooltip-cell {
    position: relative;
    cursor: help;
}
.hover-explanation {
    display: none;
    position: absolute;
    left: 100%;
    top: 0;
    width: 320px;
    background: #fffbe6;
    color: #333;
    border: 1px solid var(--warning);
    border-radius: 8px;
    padding: 12px;
    font-size: 0.95em;
    box-shadow: 0 2px 8px var(--shadow);
    z-index: 10;
}
.tooltip-cell:hover .hover-explanation {
    display: block;
}

.comparison-table th {
    background: var(--primary);
    color: white;
    font-weight: 600;
}

.comparison-table tbody tr:hover {
    background: #f8f9fa;
}

.risk-low {
    color: var(--success);
    font-weight: 600;
}

.risk-medium {
    color: var(--warning);
    font-weight: 600;
}

.risk-high {
    color: var(--accent);
    font-weight: 600;
}

/* Recommendation row styling */
.recommendation-row {
    background: #f8f9fa;
    border-top: 2px solid var(--secondary);
}

.recommendation-row td {
    font-weight: 600;
}

.recommendation-row strong {
    color: var(--secondary);
}

/* Graph Styles */
.graph-description {
    color: var(--text-light);
    margin-bottom: 15px;
}

.tank-selector {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.tank-btn {
    padding: 10px 20px;
    border: 2px solid var(--secondary);
    background: white;
    color: var(--secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.tank-btn.active,
.tank-btn:hover {
    background: var(--secondary);
    color: white;
}

.chart-container {
    position: relative;
    height: 400px;
    background: white;
    border-radius: 8px;
    padding: 10px;
}

/* Cost Info Styles */
.cost-info {
    background: white;
    padding: 20px;
    border-radius: 8px;
    border-left: 5px solid var(--warning);
}

/* Scientific calculations section */
.science-section {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 20px;
    margin-top: 40px;
    box-shadow: 0 2px 8px var(--shadow);
}

.science-section h4 {
    color: var(--primary);
    margin: 20px 0 10px 0;
    font-size: 1.2rem;
    border-bottom: 2px solid var(--secondary);
    padding-bottom: 5px;
}

.science-section p {
    margin: 5px 0;
    line-height: 1.4;
}

.science-section strong {
    color: var(--accent);
    font-weight: 600;
}

/* Footer */
footer {
    text-align: center;
    padding: 30px;
    color: var(--text-light);
    font-style: italic;
}

footer p {
    margin-bottom: 5px;
}

/* Modern Responsive Design with Container Queries Support */
@media (max-width: 576px) {
    /* Mobile First - Small phones */
    .container {
        padding: 15px;
    }
    
    .hero h1 {
        font-size: 1.8rem;
        line-height: 1.2;
    }
    
    .hero {
        padding: 30px 20px;
    }
    
    .input-panel {
        padding: 20px;
    }
    
    .input-group {
        padding: 15px;
        margin-bottom: 25px;
    }
    
    .field input, .field select {
        padding: 12px 15px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    .calculate-btn {
        padding: 15px 30px;
        font-size: 1.1rem;
    }
    
    .chart-container {
        height: 250px;
        padding: 10px;
    }
    
    .legend-container {
        flex-direction: column;
        gap: 10px;
    }
}

@media (min-width: 577px) and (max-width: 768px) {
    /* Tablets */
    .container {
        padding: 20px;
    }
    
    .hero h1 {
        font-size: 2.2rem;
    }
    
    .grid {
        grid-template-columns: 1fr 1fr;
        gap: 20px;
    }
    
    .chart-container {
        height: 350px;
    }
}

@media (min-width: 769px) and (max-width: 1200px) {
    /* Desktop */
    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 25px;
    }
    
    .chart-container {
        height: 400px;
    }
}

@media (min-width: 1201px) {
    /* Wide screens */
    .container {
        max-width: 1400px;
    }
    
    .grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 30px;
    }
}

/* Improved animations with performance in mind */
.results-panel {
    animation: slideInUp 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    /* GPU acceleration for smooth animations */
    transform: translateZ(0);
    will-change: transform, opacity;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Performance optimized loading states */
.calculating {
    pointer-events: none;
    opacity: 0.7;
}

.calculating .calculate-btn {
    background: var(--text-light);
    cursor: not-allowed;
}

.calculating .calculate-btn::after {
    content: " 🔄";
    animation: spin 1s infinite linear;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Enhanced Chart Styling */
:root {
    --tank-temp-color: rgb(207, 142, 83);
    --target-temp-color: rgb(184, 134, 11);
    --backup-heater-color: rgb(178, 34, 34);
    --reheat-color: rgb(184, 134, 11);
}

.chart-container {
    position: relative;
    background: linear-gradient(135deg, rgb(245, 245, 220) 0%, rgb(250, 235, 215) 100%);
    border: 3px solid rgb(139, 69, 19);
    border-radius: 12px;
    padding: 15px;
    box-shadow: 
        inset 0 2px 4px rgba(139, 69, 19, 0.1),
        0 4px 8px rgba(0, 0, 0, 0.1);
}

.legend-container {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: center;
    margin-top: 15px;
    padding: 10px;
    background: rgba(245, 222, 179, 0.5);
    border-radius: 8px;
    border: 1px solid rgba(139, 69, 19, 0.3);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: rgb(101, 67, 33);
    font-weight: 500;
}

.legend-color {
    width: 24px;
    height: 4px;
    border-radius: 2px;
    border: 1px solid rgba(139, 69, 19, 0.3);
}

.legend-marker {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid rgba(139, 69, 19, 0.3);
}

.backup-marker {
    background: var(--backup-heater-color);
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
    border-radius: 0;
    width: 16px;
    height: 14px;
}

.reheat-marker {
    background: var(--reheat-color);
    transform: rotate(45deg);
    border-radius: 0;
}

.tank-selector {
    margin-bottom: 20px;
}

.tank-btn {
    background: linear-gradient(135deg, rgb(222, 184, 135) 0%, rgb(205, 133, 63) 100%);
    border: 2px solid rgb(139, 69, 19);
    color: rgb(101, 67, 33);
    font-weight: bold;
    font-family: serif;
    border-radius: 6px;
    transition: all 0.3s ease;
    text-shadow: 1px 1px 2px rgba(139, 69, 19, 0.2);
}

.tank-btn:hover {
    background: linear-gradient(135deg, rgb(240, 230, 140) 0%, rgb(218, 165, 32) 100%);
    border-color: rgb(184, 134, 11);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(139, 69, 19, 0.3);
}

.tank-btn.active {
    background: linear-gradient(135deg, rgb(184, 134, 11) 0%, rgb(139, 69, 19) 100%);
    color: rgb(245, 222, 179);
    border-color: rgb(139, 69, 19);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.graph-section h3 {
    color: rgb(139, 69, 19);
    font-family: serif;
    font-size: 1.4rem;
    text-shadow: 2px 2px 4px rgba(139, 69, 19, 0.2);
    margin-bottom: 10px;
}

.graph-description {
    color: rgb(101, 67, 33);
    font-style: italic;
    font-family: serif;
    margin-bottom: 15px;
}

/* Footer Styling - Ancient Gravitas */
footer {
    margin-top: 60px;
    padding: 30px;
    text-align: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: var(--surface);
    border-radius: 15px;
    border: 2px solid var(--border);
    box-shadow: 0 8px 20px var(--shadow-heavy);
    position: relative;
}

footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        repeating-linear-gradient(
            45deg,
            transparent 0px,
            transparent 3px,
            rgba(245, 222, 179, 0.05) 3px,
            rgba(245, 222, 179, 0.05) 6px
        );
    pointer-events: none;
}

footer p {
    font-family: 'Crimson Text', serif;
    font-style: italic;
    margin-bottom: 8px;
    font-size: 1.1rem;
    text-shadow: 2px 2px 4px rgba(101, 67, 33, 0.4);
    position: relative;
    z-index: 1;
}

footer p:last-child {
    margin-bottom: 0;
    font-size: 1rem;
    opacity: 0.9;
}

/* Enhanced Visual Effects */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 25px;
    position: relative;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 12px;
}

::-webkit-scrollbar-track {
    background: var(--surface);
    border-radius: 6px;
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, var(--secondary) 0%, var(--primary) 100%);
    border-radius: 6px;
    border: 2px solid var(--surface);
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, var(--accent) 0%, var(--primary) 100%);
}

/* Selection styling */
::selection {
    background: rgba(184, 134, 11, 0.3);
    color: var(--text);
}

::-moz-selection {
    background: rgba(184, 134, 11, 0.3);
    color: var(--text);
}

/* Enhanced loading animation */
.calculating .calculate-btn::after {
    content: " ⚗️";
    animation: spin 1.5s infinite linear, pulse 2s infinite ease-in-out;
}

@keyframes pulse {
    0%, 100% { 
        opacity: 1; 
        transform: scale(1);
    }
    50% { 
        opacity: 0.7;
        transform: scale(1.05);
    }
}