/* =====================================================
   SHARED HEADER, FOOTER & COMPONENT STYLES
   Clean, Accessible, Consistent Design
   ===================================================== */

/* =====================================================
   SKIP LINK (Accessibility)
   ===================================================== */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    z-index: 9999;
    padding: 0.75rem 1.25rem;
    background: var(--primary-600);
    color: #fff;
    font-weight: 700;
    font-size: var(--text-sm);
    border-radius: 0 0 var(--radius-lg) 0;
    transition: top 0.2s ease;
    text-decoration: none;
}

.skip-link:focus {
    top: 0;
}

/* =====================================================
   HEADER & NAVIGATION
   ===================================================== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height, 64px);
    z-index: 100;
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    transition: box-shadow 0.3s ease, background-color 0.3s ease;
}

.header.scrolled {
    box-shadow: var(--shadow-md);
    background-color: var(--header-bg);
    /* fallback for Chrome < 111 */
    background-color: color-mix(in srgb, var(--header-bg) 97%, transparent);
}

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

/* ── Logo ─────────────────────────────────────────── */
.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--header-text);
    flex-shrink: 0;
}

.logo-icon {
    width: 1.875rem;
    height: 1.875rem;
    color: var(--primary-600);
    flex-shrink: 0;
}

.logo-text {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.logo h1 {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 1.125rem;
    line-height: 1.2;
    margin: 0;
    color: var(--header-text);
}

.logo-subtitle {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.logo-developer {
    font-size: 0.65rem;
    color: var(--text-tertiary);
    margin-top: 1px;
}

.logo-developer strong {
    color: var(--primary-600);
}

/* ── Navigation ───────────────────────────────────── */
.nav {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-lg);
    position: relative;
    transition: color 0.15s ease, background-color 0.15s ease;
    min-height: 44px;
}

.nav-link:hover {
    color: var(--primary-600);
    background-color: var(--primary-50);
}

[data-theme="dark"] .nav-link:hover {
    background-color: rgba(96, 165, 250, 0.1);
}

.nav-link.active {
    color: var(--primary-600);
    font-weight: 600;
}

.nav-link.active::after {
    content: '';
    position: absolute;
    bottom: 4px;
    left: 0.75rem;
    right: 0.75rem;
    height: 2px;
    background-color: var(--primary-600);
    border-radius: 1px;
}

/* ── Header Actions ───────────────────────────────── */
.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.theme-toggle {
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.theme-toggle svg {
    width: 1rem;
    height: 1rem;
}

.theme-toggle:hover {
    background-color: var(--neutral-100);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

[data-theme="dark"] .theme-toggle:hover {
    background-color: var(--secondary-800);
}

/* ── Mobile Menu Button ───────────────────────────── */
.mobile-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-lg);
    cursor: pointer;
    padding: 0.5rem;
    transition: background-color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.mobile-menu-btn svg {
    width: 1.25rem;
    height: 1.25rem;
}

.mobile-menu-btn:hover {
    background-color: var(--neutral-100);
}

[data-theme="dark"] .mobile-menu-btn:hover {
    background-color: var(--secondary-800);
}

/* ── Mobile Navigation Dropdown ───────────────────── */
@media (max-width: 768px) {
    .nav {
        display: none;
        position: absolute;
        top: var(--header-height, 64px);
        left: 0;
        right: 0;
        flex-direction: column;
        background: var(--bg-surface);
        padding: 0.75rem;
        border-bottom: 1px solid var(--border-color);
        box-shadow: var(--shadow-lg);
        gap: 0.25rem;
        align-items: stretch;
        z-index: 99;
    }

    .nav.active {
        display: flex;
    }

    .nav-link {
        width: 100%;
        padding: 0.875rem 1rem;
        border-radius: var(--radius-lg);
        font-size: 1rem;
    }

    .nav-link.active::after {
        display: none;
    }

    .nav-link.active {
        background-color: var(--primary-50);
        font-weight: 600;
    }

    [data-theme="dark"] .nav-link.active {
        background-color: rgba(96, 165, 250, 0.1);
    }

    .mobile-menu-btn {
        display: flex;
    }
}

/* =====================================================
   BOTTOM TAB BAR (mobile only)
   ===================================================== */
.bottom-tab-bar {
    display: none;
    /* hidden on desktop */
}

@media (max-width: 768px) {
    .bottom-tab-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 64px;
        z-index: 100;
        background: var(--bg-surface);
        border-top: 1px solid var(--border-subtle);
        /* Safe area for iPhone home indicator */
        padding-bottom: env(safe-area-inset-bottom, 0px);
        align-items: stretch;
        box-shadow: 0 -4px 12px rgb(0 0 0 / 0.08);
    }

    .tab-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        color: var(--text-tertiary);
        text-decoration: none;
        font-size: 0.625rem;
        font-weight: 500;
        letter-spacing: 0.03em;
        text-transform: uppercase;
        border: none;
        background: none;
        cursor: pointer;
        min-height: 44px;
        transition: color 0.15s ease;
        -webkit-tap-highlight-color: transparent;
        -webkit-user-select: none;
        user-select: none;
        position: relative;
    }

    .tab-item svg {
        width: 1.375rem;
        height: 1.375rem;
        stroke-width: 1.75;
        transition: stroke-width 0.15s ease;
    }

    .tab-item.active {
        color: var(--primary-600);
    }

    .tab-item.active svg {
        stroke-width: 2.25;
    }

    /* Active indicator line above tab */
    .tab-item.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 25%;
        right: 25%;
        height: 2px;
        background: var(--primary-600);
        border-radius: 0 0 2px 2px;
    }

    /* Main content needs bottom padding to avoid tab bar overlap */
    main {
        padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    }
}

/* =====================================================
   LAYOUT UTILITIES
   ===================================================== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

@media (max-width: 480px) {
    .container {
        padding: 0 1rem;
    }
}

.grid {
    display: grid;
    gap: 1.5rem;
}

@media (min-width: 640px) {
    .grid-2 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .grid-3 {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1024px) {
    .grid-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Spacing utilities */
.mt-4 {
    margin-top: 1rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.py-4 {
    padding-top: 1rem;
    padding-bottom: 1rem;
}

.pt-24 {
    padding-top: 6rem;
}

.pb-16 {
    padding-bottom: 4rem;
}

.text-center {
    text-align: center;
}

/* Visual utilities */
.bg-surface {
    background-color: var(--bg-surface);
}

.border {
    border-width: 1px;
    border-style: solid;
}

.border-subtle {
    border-color: var(--border-subtle);
}

.rounded-3xl {
    border-radius: 1.5rem;
}

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

.overflow-hidden {
    overflow: hidden;
}

.min-h-600 {
    min-height: 600px;
}

/* Text utilities */
.text-safe {
    color: var(--success);
}

.text-caution {
    color: var(--warning);
}

.text-avoid {
    color: var(--error);
}

.text-neutral {
    color: var(--text-secondary);
}

.text-primary {
    color: var(--primary-600);
}

.text-secondary {
    color: var(--text-secondary);
}

.font-bold {
    font-weight: 700;
}

.font-semibold {
    font-weight: 600;
}

/* =====================================================
   CARD COMPONENT
   ===================================================== */
.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-200);
}

[data-theme="dark"] .card:hover {
    border-color: var(--primary-700);
}

@media (hover: none) {
    .card:hover {
        transform: none;
        box-shadow: var(--shadow-sm);
    }

    .card:active {
        transform: scale(0.98);
    }
}

/* =====================================================
   BUTTON COMPONENT
   ===================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 44px;
    padding: 0.625rem 1.375rem;
    border-radius: var(--radius-full);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: all 0.15s ease;
    white-space: nowrap;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-primary {
    background-color: var(--primary-600);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    background-color: var(--primary-700);
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
}

.btn-primary:focus-visible {
    box-shadow: var(--shadow-focus-primary);
}

.btn-secondary {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    border: 1.5px solid var(--border-subtle);
    box-shadow: var(--shadow-sm);
}

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

[data-theme="dark"] .btn-secondary {
    background-color: var(--secondary-800);
    border-color: var(--secondary-700);
}

[data-theme="dark"] .btn-secondary:hover {
    background-color: var(--secondary-700);
}

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

.btn-danger:hover {
    background-color: var(--error-700);
}

.btn-sm {
    min-height: 36px;
    padding: 0.375rem 0.875rem;
    font-size: 0.8rem;
}

.btn-lg {
    min-height: 52px;
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
}

/* =====================================================
   FORM ELEMENTS
   ===================================================== */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 1rem;
}

.form-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-input,
.form-select {
    width: 100%;
    min-height: 44px;
    padding: 0.625rem 0.875rem;
    font-family: inherit;
    font-size: 1rem;
    /* ≥16px prevents iOS auto-zoom */
    color: var(--text-primary);
    background: var(--bg-surface);
    border: 1.5px solid var(--border-subtle);
    border-radius: var(--radius-md);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    appearance: none;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: var(--shadow-focus-primary);
}

[data-theme="dark"] .form-input:focus,
[data-theme="dark"] .form-select:focus {
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.25);
}

.form-input::placeholder {
    color: var(--text-tertiary);
}

.form-input[type="number"] {
    font-size: 1.125rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

/* Validation states */
.form-input.is-valid {
    border-color: var(--success-600);
}

.form-input.is-invalid {
    border-color: var(--error);
}

.form-helper {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.form-helper.is-error {
    color: var(--error);
}

/* Input group (legacy) */
.input-group {
    margin-bottom: 1rem;
}

/* =====================================================
   SKELETON / SHIMMER LOADER
   ===================================================== */
@keyframes shimmer {
    0% {
        background-position: -400px 0;
    }

    100% {
        background-position: 400px 0;
    }
}

.skeleton {
    background: linear-gradient(90deg,
            var(--neutral-200) 25%,
            var(--neutral-100) 50%,
            var(--neutral-200) 75%);
    background-size: 800px 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

[data-theme="dark"] .skeleton {
    background: linear-gradient(90deg,
            var(--secondary-700) 25%,
            var(--secondary-600) 50%,
            var(--secondary-700) 75%);
    background-size: 800px 100%;
}

/* =====================================================
   CLINICAL RESULT BOX
   ===================================================== */
.result-box {
    background: var(--primary-50);
    border: 1px solid var(--primary-200);
    border-left: 4px solid var(--primary-600);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    margin-top: 1.5rem;
}

.result-box[data-result="normal"] {
    border-left-color: var(--success);
    background: var(--success-bg);
    border-color: var(--success-200, #a7f3d0);
}

.result-box[data-result="warning"] {
    border-left-color: var(--warning);
    background: var(--warning-bg);
    border-color: var(--warning-200, #fde68a);
}

.result-box[data-result="critical"] {
    border-left-color: var(--error);
    background: var(--error-bg);
    border-color: var(--error-200, #fecaca);
}

.result-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 0.25rem;
}

.result-value strong {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.result-unit {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-left: 0.25rem;
}

.result-normal-range {
    display: block;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 0.25rem;
}

/* =====================================================
   FOOTER STYLES
   ===================================================== */
.footer {
    background-color: #0f172a;
    color: white;
    padding: 4rem 0 2rem;
    margin-top: auto;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 2.5rem;
}

.footer-col h3,
.footer-col h4 {
    color: white;
    margin-bottom: 1rem;
}

.footer-col h3 {
    font-size: 1.125rem;
    font-weight: 700;
}

.footer-col h4 {
    font-size: 1rem;
    font-weight: 600;
}

.footer-col p {
    color: #94a3b8;
    line-height: 1.6;
    font-size: 0.9rem;
}

.footer-links {
    list-style: none;
    padding: 0;
    margin: 0;
}

.footer-links li {
    margin-bottom: 0.625rem;
}

.footer-links a {
    color: #cbd5e1;
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.15s ease;
}

.footer-links a:hover {
    color: white;
}

.footer-bottom {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1.5rem 0;
    margin-top: 2.5rem;
    border-top: 1px solid #1e293b;
    text-align: center;
    color: #64748b;
    font-size: 0.85rem;
}

/* =====================================================
   RESPONSIVE ADJUSTMENTS
   ===================================================== */
@media (max-width: 480px) {
    .footer-content {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
}