/* ============================================
   FEDO CNCPS Calculator - Modern GUI Design
   ============================================ */

/* ============================================
   1. CSS VARIABLES & THEME
   ============================================ */

:root {
    /* Colors - Primary */
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --primary-dark: #1e40af;
    
    /* Colors - Accent */
    --accent-color: #10b981;
    --accent-hover: #059669;
    --accent-light: #d1fae5;
    
    /* Colors - Status */
    --success-color: #10b981;
    --success-light: #d1fae5;
    --warn-color: #f59e0b;
    --warn-light: #fef3c7;
    --error-color: #ef4444;
    --error-light: #fee2e2;
    --info-color: #3b82f6;
    --info-light: #dbeafe;
    
    /* Colors - Backgrounds */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-header: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --bg-overlay: rgba(0, 0, 0, 0.5);

    /* Colors - Text */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --text-inverse: #ffffff;
    --text-disabled: #94a3b8;

    /* Colors - Borders */
    --border-color: #e2e8f0;
    --border-hover: #cbd5e1;
    --border-focus: #3b82f6;
    --border-error: #ef4444;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    /* Transitions */
    --transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;

    /* Border Radius */
    --border-radius-sm: 0.375rem;
    --border-radius: 0.5rem;
    --border-radius-md: 0.75rem;
    --border-radius-lg: 1rem;
    --border-radius-xl: 1.5rem;
    --border-radius-full: 9999px;

    /* Z-index */
    --z-dropdown: 1000;
    --z-sticky: 1020;
    --z-fixed: 1030;
    --z-modal-backdrop: 1040;
    --z-modal: 1050;
    --z-popover: 1060;
    --z-tooltip: 1070;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-header: #1e293b;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --bg-overlay: rgba(0, 0, 0, 0.7);
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --text-inverse: #0f172a;
    --text-disabled: #64748b;
    --border-color: #334155;
    --border-hover: #475569;
    --border-focus: #60a5fa;
    --border-error: #f87171;
}

/* ============================================
   2. BASE & RESET
   ============================================ */

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

html {
    line-height: 1.15;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
}

[data-theme="dark"] body {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

/* ============================================
   3. LAYOUT
   ============================================ */

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 1.5rem;
    width: 100%;
}

.main-content {
    min-height: calc(100vh - 80px);
    padding: 2rem 0;
    width: 100%;
}

.calculator-grid {
    display: block;
    width: 100%;
    margin-bottom: 2rem;
}

/* Full width layout - results appear below form */
@media (min-width: 1400px) {
    .container {
        max-width: 98vw;
        display: block;
    }
    
    .container.has-results {
        max-width: 98vw;
        display: block;
    }
}

/* ============================================
   4. HEADER
   ============================================ */

.main-header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    width: 100%;
}

[data-theme="dark"] .main-header {
    background: rgba(30, 41, 59, 0.95);
}

.header-content {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.main-logo {
    height: 40px;
    width: auto;
    max-width: 150px;
    object-fit: contain;
    transition: var(--transition-fast);
}

/* ============================================
   5. WELCOME SECTION
   ============================================ */

.welcome-section {
    text-align: center;
    margin-bottom: 2.5rem;
    padding: 2.5rem;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
    border-radius: var(--border-radius-xl);
    box-shadow: var(--shadow-lg);
    color: white;
    position: relative;
    overflow: hidden;
}

.welcome-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><defs><pattern id="grid" width="100" height="100" patternUnits="userSpaceOnUse"><path d="M 100 0 L 0 0 0 100" fill="none" stroke="rgba(255,255,255,0.1)" stroke-width="1"/></pattern></defs><rect width="100%" height="100%" fill="url(%23grid)"/></svg>');
    opacity: 0.3;
}

.welcome-section h2 {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 700;
    margin-bottom: 0.75rem;
    line-height: 1.3;
    letter-spacing: -0.02em;
    position: relative;
    z-index: 1;
}

.welcome-section p {
    font-size: clamp(1rem, 2vw, 1.125rem);
    opacity: 0.95;
    position: relative;
    z-index: 1;
    line-height: 1.6;
}

/* ============================================
   6. FORMS
   ============================================ */

.calculator-form {
    width: 100%;
}

.input-section,
.analysis-section {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--border-radius-xl);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    margin-bottom: 2rem;
    transition: var(--transition-normal);
    position: relative;
}

.input-section:hover,
.analysis-section:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.input-section h3,
.analysis-section h3 {
    color: var(--primary-color);
    font-size: clamp(1.25rem, 2.5vw, 1.5rem);
    font-weight: 700;
    margin-bottom: 1.75rem;
    padding-bottom: 1rem;
    border-bottom: 3px solid var(--primary-light);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    line-height: 1.4;
    letter-spacing: -0.01em;
}

.form-row {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

/* Ensure Chemical Analysis uses grid on wide screens - all form-groups flow into 3 columns */
@media (min-width: 1440px) {
    .analysis-section {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 1.5rem !important;
    }
    
    .analysis-section h3 {
        grid-column: 1 / -1;
    }
    
    .analysis-section .form-row {
        display: contents !important;
    }
    
    .analysis-section .form-group {
        min-width: 0 !important;
        max-width: none !important;
    }
}

.form-group {
    flex: 1;
    min-width: 200px;
    display: flex;
    flex-direction: column;
}

.form-group.single-field {
    max-width: 400px;
}

.form-group label {
    display: block;
    margin-bottom: 0.625rem;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.9375rem;
    line-height: 1.4;
    letter-spacing: 0.01em;
}

.form-control {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-md);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 500;
    line-height: 1.5;
    transition: var(--transition-fast);
    font-family: inherit;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px var(--primary-light);
}

.form-control:hover:not(:focus) {
    border-color: var(--border-hover);
}

.form-control:invalid:not(:placeholder-shown) {
    border-color: var(--error-color);
    box-shadow: 0 0 0 4px var(--error-light);
}

/* Input with unit */
.input-with-unit {
    position: relative;
    display: flex;
    align-items: center;
}

.unit-label {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-weight: 600;
    pointer-events: none;
    z-index: 2;
    background: var(--bg-input);
    padding: 0 4px;
    line-height: 1.4;
}

.input-with-unit .form-control {
    padding-right: 80px;
}

.form-control:focus + .unit-label {
    color: var(--primary-color);
}

/* ============================================
   7. BUTTONS
   ============================================ */

.calculate-section {
    text-align: center;
    margin: 3rem 0;
    padding: 2rem;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border-radius: var(--border-radius-xl);
    border: 2px dashed var(--border-color);
}

.calculate-btn {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
    color: white;
    border: none;
    border-radius: var(--border-radius-lg);
    padding: 1.125rem 3rem;
    font-size: clamp(1rem, 2vw, 1.125rem);
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-normal);
    box-shadow: var(--shadow-lg);
    min-width: 280px;
    letter-spacing: 0.03em;
    line-height: 1.4;
    position: relative;
    overflow: hidden;
}

.calculate-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.6s;
}

.calculate-btn:hover::before {
    left: 100%;
}

.calculate-btn:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-xl);
}

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

.calculate-btn.loading {
    position: relative;
    color: transparent;
}

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

/* Floating Save Button */
.floating-save-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    border: none;
    box-shadow: 0 10px 25px rgba(37, 99, 235, 0.4);
    cursor: pointer;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-normal);
    color: white;
    font-size: 1.75rem;
}

.floating-save-btn:hover {
    transform: scale(1.1) translateY(-3px);
    box-shadow: 0 15px 35px rgba(37, 99, 235, 0.5);
}

.floating-save-btn:active {
    transform: scale(0.95);
}

/* ============================================
   8. RESULTS SECTION
   ============================================ */

.results-section {
    background: var(--bg-card);
    border-radius: var(--border-radius-xl);
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
    margin-top: 3rem;
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
    width: 100%;
    max-width: 100%;
}

.results-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 5px;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
    flex-wrap: wrap;
    gap: 1rem;
    padding-bottom: 1.5rem;
    border-bottom: 3px solid var(--primary-light);
    position: relative;
}

.results-header::after {
    content: '';
    position: absolute;
    bottom: -3px;
    left: 0;
    width: 100px;
    height: 3px;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
}

.results-header h3 {
    color: var(--primary-color);
    font-size: clamp(1.5rem, 3vw, 1.75rem);
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.results-header h3::before {
    content: '📊';
    font-size: 1.5em;
}

.success-message {
    background: linear-gradient(135deg, var(--success-color), var(--accent-color));
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius-full);
    font-weight: 600;
    font-size: 0.875rem;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: fadeIn 0.5s ease-out;
}

.success-message::before {
    content: '✓';
    font-size: 1.2em;
    font-weight: 700;
}

.results-table-container {
    margin-top: 2rem;
    overflow-x: hidden;
    overflow-y: visible;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    max-width: 100%;
}

/* Optimize table for wide screens when below form */
@media (min-width: 1400px) {
    .results-table-container {
        max-width: 100%;
    }
    
    .results-table {
        font-size: 1rem;
    }
    
    .results-table th {
        padding: 1.5rem 2rem;
        font-size: 1rem;
    }
    
    .results-table td {
        padding: 1.375rem 2rem;
    }
    
    .results-table td.param-name {
        font-size: 1rem;
    }
    
    .results-table td.param-value {
        font-size: 1.1875rem;
    }
}

/* Better spacing between table sections */
.results-table-container table {
    margin-bottom: 0;
}

/* Add spacing between different thead sections */
.results-table thead + thead {
    margin-top: 2rem;
}

.results-table tbody + thead {
    margin-top: 2rem;
}

/* Better visual separation */
.results-table tbody:last-of-type {
    margin-bottom: 0;
}

.results-table {
    width: 100%;
    max-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--bg-card);
    font-size: 0.9375rem;
    line-height: 1.6;
    table-layout: fixed;
}

.results-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.results-table thead tr {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
}

.results-table thead tr:first-child th:first-child {
    border-top-left-radius: var(--border-radius-lg);
}

.results-table thead tr:first-child th:last-child {
    border-top-right-radius: var(--border-radius-lg);
}

.results-table th {
    padding: 1.5rem 2rem;
    text-align: center;
    font-weight: 700;
    font-size: 0.9375rem;
    letter-spacing: 0.05em;
    line-height: 1.4;
    text-transform: uppercase;
    position: relative;
}

/* Better section header styling */
.results-table thead th {
    position: relative;
}

.results-table tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition-fast);
    background: var(--bg-card);
}

.results-table tbody tr:last-child td {
    border-bottom: 2px solid var(--border-color);
}

.results-table tbody tr:hover {
    background: var(--bg-secondary);
    transform: translateX(2px);
    box-shadow: -2px 0 8px rgba(37, 99, 235, 0.1);
}

.results-table tbody tr:hover td {
    color: var(--primary-color);
}

.results-table tbody tr.highlight-row {
    background: linear-gradient(90deg, var(--primary-light), rgba(37, 99, 235, 0.05));
    font-weight: 700;
    border-left: 4px solid var(--primary-color);
}

.results-table tbody tr.highlight-row:hover {
    background: linear-gradient(90deg, rgba(37, 99, 235, 0.15), rgba(37, 99, 235, 0.08));
}

.results-table td {
    padding: 1.375rem 2rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    transition: var(--transition-fast);
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.results-table td.param-name {
    font-weight: 600;
    color: var(--text-primary);
    width: 65%;
    font-size: 0.9375rem;
    line-height: 1.6;
    letter-spacing: 0.01em;
    padding-right: 1rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.results-table td.param-value {
    font-family: 'Courier New', 'Monaco', 'Consolas', monospace;
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--primary-color);
    text-align: right;
    width: 35%;
    line-height: 1.6;
    letter-spacing: 0.02em;
    padding-left: 1rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: nowrap;
}

/* Special styling for Cost Analysis section - target by nth-of-type */
.results-table thead:nth-of-type(4) {
    background: linear-gradient(135deg, var(--accent-color), var(--accent-hover)) !important;
}

.results-table thead:nth-of-type(4) ~ tbody tr {
    background: linear-gradient(90deg, var(--accent-light), rgba(16, 185, 129, 0.05));
}

.results-table thead:nth-of-type(4) ~ tbody tr td.param-value {
    font-size: 1.1875rem;
    color: var(--accent-color);
    font-weight: 800;
}

.results-table thead:nth-of-type(4) ~ tbody tr:hover {
    background: linear-gradient(90deg, rgba(16, 185, 129, 0.15), rgba(16, 185, 129, 0.08));
}

/* Energy Values section - make it more prominent */
.results-table thead:nth-of-type(3) {
    background: linear-gradient(135deg, var(--warn-color), #d97706) !important;
}

.results-table thead:nth-of-type(3) ~ tbody tr td.param-value {
    font-size: 1.1875rem;
    color: var(--warn-color);
    font-weight: 800;
}

/* Section separators - add spacing between table sections */
.results-table thead {
    margin-bottom: 0.5rem;
}

.results-table thead + tbody {
    margin-top: 0.5rem;
}

/* Better visual grouping for table sections */
.results-table tbody {
    position: relative;
}

.results-table tbody::after {
    content: '';
    display: block;
    height: 1.5rem;
    background: transparent;
}

/* Improved table row spacing */
.results-table tbody tr:not(:last-child) {
    border-bottom: 1px solid var(--border-color);
}

.results-table tbody tr:last-child {
    border-bottom: 2px solid var(--border-color);
}

/* Export buttons in results */
.export-options {
    margin-top: 2.5rem;
    padding-top: 2.5rem;
    border-top: 3px solid var(--border-color);
    background: linear-gradient(135deg, var(--bg-secondary), var(--bg-tertiary));
    border-radius: var(--border-radius-lg);
    padding: 2.5rem;
    margin-left: -3rem;
    margin-right: -3rem;
    margin-bottom: -3rem;
    border-bottom-left-radius: var(--border-radius-xl);
    border-bottom-right-radius: var(--border-radius-xl);
}

.export-buttons {
    display: flex;
    gap: 1.25rem;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
}

.export-btn {
    padding: 1rem 2rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-weight: 700;
    font-size: 0.9375rem;
    cursor: pointer;
    transition: var(--transition-normal);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 160px;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.export-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s;
}

.export-btn:hover::before {
    left: 100%;
}

.export-btn:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-width: 2px;
}

.export-btn.pdf-btn {
    background: linear-gradient(135deg, #ffffff, #fef2f2);
    border-color: #dc2626;
    color: #dc2626;
}

.export-btn.pdf-btn:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: white;
    border-color: #dc2626;
    box-shadow: 0 8px 20px rgba(220, 38, 38, 0.3);
}

.export-btn.excel-btn {
    background: linear-gradient(135deg, #ffffff, #f0fdf4);
    border-color: #16a34a;
    color: #16a34a;
}

.export-btn.excel-btn:hover {
    background: linear-gradient(135deg, #16a34a, #15803d);
    color: white;
    border-color: #16a34a;
    box-shadow: 0 8px 20px rgba(22, 163, 74, 0.3);
}

/* ============================================
   9. DATA PANEL
   ============================================ */

.data-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 480px;
    max-width: 95vw;
    height: 100vh;
    background: var(--bg-card);
    border-left: 1px solid var(--border-color);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
    z-index: var(--z-modal);
    transform: translateX(100%);
    transition: var(--transition-normal);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.data-panel.show {
    transform: translateX(0);
}

.data-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 2px solid var(--border-color);
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
}

.data-panel-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
}

.close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: white;
    padding: 0.5rem;
    border-radius: var(--border-radius);
    transition: var(--transition-fast);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.data-panel-content {
    padding: 1.5rem;
}

.data-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.data-search {
    margin-bottom: 1.25rem;
}

.data-search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: var(--transition-fast);
}

.data-search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(11, 111, 164, 0.15);
}

.action-btn {
    padding: 0.75rem 1.25rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    transition: var(--transition-fast);
}

.action-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.action-btn.save-btn {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.action-btn.save-btn:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.saved-calculations {
    max-height: 60vh;
    overflow-y: auto;
}

.calculation-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-md);
    margin-bottom: 0.75rem;
    background: var(--bg-primary);
    transition: var(--transition-fast);
    cursor: pointer;
}

.calculation-item:hover {
    border-color: var(--primary-color);
    background: var(--bg-secondary);
    transform: translateX(-4px);
}

.calculation-info {
    flex: 1;
}

.calculation-name {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.calculation-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.calculation-actions {
    display: flex;
    gap: 0.5rem;
}

.calculation-btn {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition-fast);
    font-weight: 600;
}

.calculation-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.calculation-btn.delete:hover {
    background: var(--error-color);
    color: white;
    border-color: var(--error-color);
}

/* Pagination */
.pagination-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-top: 2px solid var(--border-color);
    margin-top: 1.5rem;
    background: var(--bg-secondary);
}

.pagination-btn {
    padding: 0.625rem 1.25rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    transition: var(--transition-fast);
}

.pagination-btn:hover:not(:disabled) {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-info {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 600;
}

/* ============================================
   10. MODALS
   ============================================ */

.password-modal,
.delete-password-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition-normal);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    opacity: 1;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--border-radius-xl);
    box-shadow: var(--shadow-xl);
    width: min(520px, 92vw);
    max-height: 90vh;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.modal-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    width: 36px;
    height: 36px;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem 2rem;
}

.modal-footer {
    padding: 1.25rem 2rem 1.75rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.save-modal .form-group {
    margin: 0;
}

.save-modal .form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.save-modal .form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: var(--transition-fast);
    background: var(--bg-primary);
    color: var(--text-primary);
}

.save-modal .form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.name-warning {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 193, 7, 0.1);
    border: 1px solid rgba(255, 193, 7, 0.3);
    border-radius: var(--border-radius);
    color: #856404;
    font-size: 0.875rem;
}

.name-warning .warning-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.name-warning .warning-text {
    flex: 1;
    line-height: 1.4;
}

.save-modal .modal-header {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    border-bottom: none;
}

.save-modal .modal-header h3 {
    color: white;
}

.save-modal .modal-close {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
    color: white;
}

.save-modal .modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
    color: white;
}

.save-modal .btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    border: none;
    font-weight: 600;
    padding: 0.75rem 1.5rem;
    transition: var(--transition-fast);
}

.save-modal .btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.save-modal .btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.save-modal .btn-secondary {
    padding: 0.75rem 1.5rem;
    font-weight: 500;
}

.password-modal.show,
.delete-password-modal.show {
    opacity: 1;
    visibility: visible;
    display: flex;
}

.password-modal-content,
.delete-password-modal-content {
    background: var(--bg-card);
    border-radius: var(--border-radius-xl);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
    max-width: 420px;
    width: 90%;
    padding: 0;
    border: 2px solid var(--primary-color);
    animation: slideIn 0.3s ease-out;
}

.password-modal-header,
.delete-password-modal-header {
    padding: 2rem;
    text-align: center;
    border-bottom: 2px solid var(--border-color);
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    border-radius: var(--border-radius-xl) var(--border-radius-xl) 0 0;
}

.password-modal-header h2,
.delete-password-modal-header h2 {
    margin: 0 0 0.5rem 0;
    font-size: 1.75rem;
    font-weight: 700;
}

.password-modal-body,
.delete-password-modal-body {
    padding: 2rem;
}

.password-modal-footer,
.delete-password-modal-footer {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    padding: 1.5rem 2rem;
    border-top: 2px solid var(--border-color);
}

.password-modal-footer .btn,
.delete-password-modal-footer .btn {
    min-width: 140px;
    height: 44px;
    border-radius: var(--border-radius-md);
    font-weight: 600;
}

.password-modal-footer .btn-secondary,
.delete-password-modal-footer .btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.password-modal-footer .btn-primary,
.delete-password-modal-footer .btn-primary {
    background: var(--primary-color);
    color: white;
    border: 1px solid var(--primary-color);
}

.password-modal-footer .btn-secondary:hover,
.delete-password-modal-footer .btn-secondary:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary-color);
}

.password-modal-footer .btn-primary:hover,
.delete-password-modal-footer .btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.unlock-btn,
.delete-confirm-btn {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    color: white;
    border: none;
    border-radius: var(--border-radius-md);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-fast);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.unlock-btn:hover,
.delete-confirm-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.error-message,
.password-error,
.delete-password-error {
    color: var(--error-color);
    font-size: 0.875rem;
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--error-light);
    border-radius: var(--border-radius);
    border-left: 4px solid var(--error-color);
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-overlay);
    z-index: var(--z-modal-backdrop);
    opacity: 0;
    transition: var(--transition-normal);
}

.overlay.show {
    opacity: 1;
}

/* ============================================
   11. NOTIFICATIONS
   ============================================ */

.notification {
    position: fixed;
    top: 24px;
    right: 24px;
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-xl);
    z-index: var(--z-tooltip);
    transform: translateX(120%);
    opacity: 0;
    transition: var(--transition-normal);
    border-left: 4px solid var(--info-color);
    max-width: 400px;
    word-wrap: break-word;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.notification.show {
    transform: translateX(0);
    opacity: 1;
}

.notification-success {
    border-left-color: var(--success-color);
    background: var(--success-light);
}

.notification-error {
    border-left-color: var(--error-color);
    background: var(--error-light);
}

.notification-warning {
    border-left-color: var(--warn-color);
    background: var(--warn-light);
}

/* ============================================
   12. FOOTER
   ============================================ */

.main-footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    margin-top: 3rem;
    width: 100%;
}

.footer-content {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1.5rem;
    text-align: center;
    width: 100%;
}

.footer-content p {
    color: var(--text-muted);
    font-size: 0.875rem;
    line-height: 1.5;
}

/* ============================================
   13. ANIMATIONS
   ============================================ */

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

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

@keyframes slideIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

/* ============================================
   14. RESPONSIVE DESIGN
   ============================================ */

/* Tablet (768px - 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    .container {
        max-width: 100%;
        padding: 0 1.5rem;
    }

    .form-row {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 1.25rem;
    }

    .form-group {
        min-width: 0;
        max-width: none;
    }
}

/* Medium Desktop (1024px - 1439px) */
@media (min-width: 1024px) and (max-width: 1439px) {
    .container {
        max-width: 95vw;
        padding: 0 2rem;
    }

    .form-row {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }

    .form-group {
        min-width: 0;
        max-width: none;
    }
}

/* Large Desktop (1440px - 1919px) */
@media (min-width: 1440px) and (max-width: 1919px) {
    .container {
        max-width: 96vw;
        padding: 0 2.5rem;
    }

    .form-row {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 1.5rem;
    }

    /* Chemical Analysis: 3 columns on large desktop - all form-groups flow into 3 columns */
    .analysis-section {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 1.5rem !important;
    }
    
    .analysis-section h3 {
        grid-column: 1 / -1;
    }
    
    .analysis-section .form-row {
        display: contents !important;
    }
    
    .analysis-section .form-group {
        min-width: 0 !important;
        max-width: none !important;
    }

    .form-group {
        min-width: 0;
        max-width: none;
    }
}

/* Ultra-wide (1920px - 2559px) */
@media (min-width: 1920px) and (max-width: 2559px) {
    .container {
        max-width: 98vw;
        padding: 0 3.5rem;
    }

    .calculator-form {
        padding: 0;
    }

    .form-row {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 1.75rem;
    }

    /* Chemical Analysis: 3 columns on ultra-wide - all form-groups flow into 3 columns */
    .analysis-section {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 1.75rem !important;
    }
    
    .analysis-section h3 {
        grid-column: 1 / -1;
    }
    
    .analysis-section .form-row {
        display: contents !important;
    }
    
    .analysis-section .form-group {
        min-width: 0 !important;
        max-width: none !important;
    }

    .form-group {
        min-width: 0;
        max-width: none;
    }

    .form-group.single-field {
        grid-column: span 1;
    }

    .welcome-section {
        padding: 3rem;
    }

    .welcome-section h2 {
        font-size: clamp(2.25rem, 4vw, 3rem);
    }

    .results-section {
        margin-top: 4rem;
        padding: 3.5rem;
    }
}

/* Ultra-ultra-wide (2560px+) */
@media (min-width: 2560px) {
    .container {
        max-width: 98vw;
        padding: 0 4rem;
    }

    .calculator-form {
        padding: 0;
    }

    .form-row {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        gap: 2rem;
    }

    /* Chemical Analysis: 3 columns on ultra-ultra-wide - all form-groups flow into 3 columns */
    .analysis-section {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 2rem !important;
    }
    
    .analysis-section h3 {
        grid-column: 1 / -1;
    }
    
    .analysis-section .form-row {
        display: contents !important;
    }
    
    .analysis-section .form-group {
        min-width: 0 !important;
        max-width: none !important;
    }

    .form-group {
        min-width: 0;
        max-width: none;
    }

    .form-group.single-field {
        grid-column: span 2;
    }

    .welcome-section {
        padding: 3.5rem;
    }

    .welcome-section h2 {
        font-size: 3.5rem;
    }

    .results-table {
        font-size: 1.1rem;
    }

    .results-table th,
    .results-table td {
        padding: 1.5rem 2rem;
    }
}

/* Mobile (< 768px) */
@media (max-width: 767px) {
    .container {
        padding: 0 1rem;
        max-width: 100%;
    }

    .main-content {
        padding: 1.5rem 0;
        min-height: calc(100vh - 100px);
    }

    .header-content {
        padding: 0.75rem 1rem;
    }

    .main-logo {
        height: 32px;
        max-width: 120px;
    }

.welcome-section {
    padding: 1.5rem;
        margin-bottom: 2rem;
}

.welcome-section h2 {
        font-size: 1.75rem;
        line-height: 1.3;
}

.welcome-section p {
    font-size: 1rem;
}

    .input-section,
    .analysis-section {
        padding: 1.5rem;
        margin-bottom: 1.5rem;
    }

    .input-section h3,
    .analysis-section h3 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    }

    .form-group label {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
    }

    .form-control {
        font-size: 16px;
    }

.form-row {
    display: flex;
        flex-direction: column;
    gap: 1rem;
        align-items: stretch;
}

.form-group {
        min-width: 100%;
        max-width: 100%;
        width: 100%;
}

.form-control {
        height: 48px;
        font-size: 16px;
}

.calculate-btn {
        width: 100%;
    padding: 1rem 2rem;
        font-size: 1rem;
        min-width: auto;
        line-height: 1.4;
    }

.results-section {
    padding: 1.5rem;
        border-radius: var(--border-radius-lg);
}

.results-header {
        margin-bottom: 1.5rem;
        padding-bottom: 1rem;
}

.results-header h3 {
    font-size: 1.5rem;
}

.results-table-container {
    margin-top: 1.5rem;
    border-radius: var(--border-radius);
}

.results-table {
        font-size: 0.875rem;
        line-height: 1.5;
}

.results-table th {
        font-size: 0.8125rem;
        padding: 1rem 1.25rem;
}

.results-table td {
        padding: 0.875rem 1.25rem;
}

.results-table td.param-name {
        font-size: 0.875rem;
        width: 60%;
}

.results-table td.param-value {
        font-size: 0.9375rem;
        width: 40%;
    }

    .results-export {
        margin-top: 1.5rem;
        padding-top: 1.5rem;
        flex-direction: column;
    }

    .results-export-btn {
        width: 100%;
        justify-content: center;
    }

    .floating-save-btn {
        width: 56px;
        height: 56px;
        bottom: 1.5rem;
        right: 1.5rem;
        font-size: 1.5rem;
    }

    .data-panel {
        width: 100%;
        max-width: 100%;
        border-left: none;
    border-top: 1px solid var(--border-color);
    }

    .notification {
        left: 1rem;
        right: 1rem;
        max-width: none;
        top: 1rem;
    font-size: 0.875rem;
        padding: 0.875rem 1.25rem;
    }
}

/* Small Mobile (< 480px) */
@media (max-width: 479px) {
    .container {
        padding: 0 0.75rem;
    }

    .main-content {
        padding: 1rem 0;
    }

    .header-content {
        padding: 0.5rem 0.75rem;
    }

    .main-logo {
        height: 28px;
        max-width: 100px;
    }

    .welcome-section {
        padding: 1.25rem;
        margin-bottom: 1.5rem;
    }

    .welcome-section h2 {
        font-size: 1.5rem;
        line-height: 1.3;
    }

    .welcome-section p {
        font-size: 0.9375rem;
    }

    .input-section,
    .analysis-section {
        padding: 1.25rem;
        margin-bottom: 1.25rem;
    }

    .input-section h3,
    .analysis-section h3 {
        font-size: 1.25rem;
        margin-bottom: 1.25rem;
    }

    .form-control {
        height: 48px;
        font-size: 16px;
        padding: 0.75rem 0.875rem;
    }

    .results-section {
        padding: 1.25rem;
    }

    .results-header {
        margin-bottom: 1.25rem;
        padding-bottom: 0.875rem;
    }

    .results-header h3 {
        font-size: 1.25rem;
    }

    .results-table-container {
        margin-top: 1.25rem;
    }

    .results-table {
        font-size: 0.8125rem;
        line-height: 1.5;
    }

    .results-table th {
        padding: 0.875rem 1rem;
        font-size: 0.75rem;
    }

    .results-table td {
        padding: 0.75rem 1rem;
    }

    .results-table td.param-name {
        font-size: 0.8125rem;
        width: 60%;
    }

    .results-table td.param-value {
        font-size: 0.875rem;
        width: 40%;
    }

    .results-export {
        margin-top: 1.25rem;
        padding-top: 1.25rem;
        flex-direction: column;
    }

    .results-export-btn {
    width: 100%;
        justify-content: center;
        padding: 0.875rem 1.25rem;
    }
}

/* ============================================
   15. ACCESSIBILITY & UTILITIES
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

.calculate-btn:focus,
.form-control:focus,
.floating-save-btn:focus {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    .main-header,
    .floating-save-btn,
    .calculate-section {
        display: none;
    }

    .main-content {
        padding: 0;
    }

    .container {
        padding: 0;
    }

    body {
        background: white;
        color: black;
    }

    .results-section,
    .calculator-form {
        box-shadow: none;
        border: 1px solid #ccc;
    }
}
