/* ============================================
   Blood Test Visualizer — Styles
   Midnight Ocean palette with glassmorphism
   ============================================ */

/* --- Custom Properties --- */
:root {
    --primary: #0EA5E9;
    --primary-light: #38BDF8;
    --accent: #F59E0B;
    --accent-light: #FBBF24;
    --bg: #0C1222;
    --bg-elevated: #111827;
    --bg-card: rgba(17, 24, 39, 0.7);
    --surface: #1E293B;
    --surface-hover: #263348;
    --text: #F1F5F9;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;
    --border: rgba(148, 163, 184, 0.12);
    --border-hover: rgba(14, 165, 233, 0.3);
    --success: #22C55E;
    --success-bg: rgba(34, 197, 94, 0.1);
    --danger: #EF4444;
    --danger-bg: rgba(239, 68, 68, 0.1);
    --warning: #F59E0B;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
    --transition: 0.2s ease;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="light"] {
    --bg: #F8FAFC;
    --bg-elevated: #FFFFFF;
    --bg-card: rgba(255, 255, 255, 0.8);
    --surface: #E2E8F0;
    --surface-hover: #CBD5E1;
    --text: #0F172A;
    --text-secondary: #475569;
    --text-muted: #94A3B8;
    --border: rgba(0, 0, 0, 0.08);
    --border-hover: rgba(14, 165, 233, 0.3);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.12);
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Utility --- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --- Glass Card --- */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.glass-card:hover {
    border-color: var(--border-hover);
}

/* --- Header --- */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(12, 18, 34, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
}

[data-theme="light"] .header {
    background: rgba(248, 250, 252, 0.85);
}

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

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

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff;
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 4px 16px rgba(14, 165, 233, 0.5);
    transform: translateY(-1px);
}

.btn-accent {
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    color: #1a1a2e;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.btn-accent:hover {
    box-shadow: 0 4px 16px rgba(245, 158, 11, 0.5);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 0.5rem;
}

.btn-ghost:hover {
    background: var(--surface);
    color: var(--text);
}

.btn-full {
    width: 100%;
    justify-content: center;
    padding: 0.75rem 1.5rem;
}

/* --- Main Content --- */
.main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* --- Section --- */
.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: var(--text);
}

/* --- Tabs --- */
.input-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.25rem;
    background: var(--surface);
    padding: 0.25rem;
    border-radius: var(--radius-sm);
}

.tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.tab.active {
    background: var(--bg-elevated);
    color: var(--primary);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.tab:hover:not(.active) {
    color: var(--text);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

/* --- Dropzone --- */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg-card);
}

.dropzone:hover,
.dropzone.dragover {
    border-color: var(--primary);
    background: rgba(14, 165, 233, 0.05);
}

.dropzone.dragover {
    transform: scale(1.01);
}

.dropzone-icon {
    color: var(--primary);
    margin-bottom: 1rem;
    opacity: 0.6;
}

.dropzone-text {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.dropzone-sub {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.csv-info {
    margin-top: 1rem;
    padding: 1rem 1.25rem;
}

.csv-info h4 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.csv-info code {
    display: block;
    font-size: 0.8rem;
    color: var(--primary-light);
    line-height: 1.8;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

/* --- Manual Form --- */
.manual-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-group input,
.form-group select {
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.9rem;
    transition: border-color var(--transition);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

.biomarker-fields {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
}

.biomarker-fields .hint {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
    padding: 1rem;
}

.biomarker-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.biomarker-field label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.biomarker-field .field-row {
    display: flex;
    gap: 0.25rem;
}

.biomarker-field input {
    flex: 1;
    padding: 0.5rem 0.625rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
    transition: border-color var(--transition);
}

.biomarker-field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

.biomarker-field .unit-tag {
    display: inline-flex;
    align-items: center;
    padding: 0 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* --- Results Section --- */
.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.results-header .section-title {
    margin-bottom: 0;
}

.date-selector select {
    padding: 0.5rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
}

/* --- Summary Cards --- */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.summary-card {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 1.25rem;
}

.summary-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.summary-icon.normal {
    background: rgba(14, 165, 233, 0.12);
    color: var(--primary);
}

.summary-icon.high {
    background: var(--danger-bg);
    color: var(--danger);
}

.summary-icon.low {
    background: var(--warning-bg);
    color: var(--warning);
}

.summary-info {
    display: flex;
    flex-direction: column;
}

.summary-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
}

.summary-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* --- Chart --- */
.chart-section {
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.chart-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.chart-header select {
    padding: 0.5rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
}

.chart-container {
    position: relative;
    width: 100%;
    height: 300px;
}

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

.chart-empty {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* --- Table --- */
.table-section {
    padding: 1.5rem;
}

.table-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

thead th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

tbody tr {
    transition: background var(--transition);
}

tbody tr:hover {
    background: rgba(14, 165, 233, 0.04);
}

tbody tr:last-child td {
    border-bottom: none;
}

/* Status badge */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-badge.normal {
    background: var(--success-bg);
    color: var(--success);
}

.status-badge.high {
    background: var(--danger-bg);
    color: var(--danger);
}

.status-badge.low {
    background: var(--warning-bg);
    color: var(--warning);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* --- Biomarker Info --- */
.info-section {
    padding: 1.5rem;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.info-card {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border-left: 3px solid var(--primary);
    transition: transform var(--transition);
}

.info-card:hover {
    transform: translateY(-2px);
}

.info-card h4 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.375rem;
    color: var(--primary-light);
}

.info-card p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.info-card .ref-range {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* --- Toast --- */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 1000;
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    color: var(--text);
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
    max-width: 360px;
}

.toast.success {
    border-left: 3px solid var(--success);
}

.toast.error {
    border-left: 3px solid var(--danger);
}

.toast.info {
    border-left: 3px solid var(--primary);
}

/* --- Footer --- */
.footer {
    text-align: center;
    padding: 2rem 1.5rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
    margin-top: 2rem;
}

/* --- Animations --- */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

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

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100px);
    }

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

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

/* --- Print Styles --- */
@media print {

    .header,
    .input-section,
    .footer,
    .btn,
    .toast-container,
    .date-selector,
    .chart-header select {
        display: none !important;
    }

    body {
        background: #fff;
        color: #000;
    }

    .glass-card {
        background: #fff;
        backdrop-filter: none;
        border: 1px solid #ddd;
        box-shadow: none;
    }

    .results-section,
    .info-section,
    .biomarkerInfo {
        display: block !important;
    }

    .summary-cards {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
    }

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

@media (max-width: 640px) {
    .header-inner {
        padding: 0.625rem 1rem;
    }

    .logo h1 {
        font-size: 1rem;
    }

    .main {
        padding: 1.25rem 1rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .summary-cards {
        grid-template-columns: 1fr 1fr;
    }

    .chart-container {
        height: 220px;
    }

    .btn-accent span {
        display: none;
    }

    table {
        font-size: 0.8rem;
    }

    thead th,
    tbody td {
        padding: 0.5rem 0.625rem;
    }

    .biomarker-fields {
        grid-template-columns: 1fr;
    }
}