/* ===========================================
   COMPONENTS-CRITICAL.CSS - Render-blocking components
   ===========================================

   Minimal set needed for patient-mode first paint.
   Deferred components loaded non-blocking by app.js.

   TABLE OF CONTENTS
   -----------------
   1. Cards
   2. Summary Bar
   3. Buttons - Base
   4. Buttons - Variants
   5. Labels & Badges
   6. Step Badges
   7. Contact Components
   8. PDF Link Card

   =========================================== */

/* -------------------------------------------
   MODULE SKELETON - Loading placeholder
   Overwritten by module render(); pulsing bars
   give immediate visual feedback on cold start.
   ------------------------------------------- */
.module-skeleton {
    padding: 2rem;
    animation: skeleton-pulse 1.2s ease-in-out infinite;
}

.skeleton-line {
    height: 0.875rem;
    background: var(--border-subtle, rgba(0, 0, 0, 0.08));
    border-radius: 4px;
    margin-bottom: 0.75rem;
}

.skeleton-title {
    height: 1.25rem;
    width: 40%;
    margin-bottom: 1.25rem;
}

.skeleton-line:not(.skeleton-title):not(.skeleton-short) {
    width: 80%;
}

.skeleton-short {
    width: 55%;
}

@keyframes skeleton-pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

/* Hide skeleton in patient mode (patient-mode-init handles its own preloading) */
.patient-mode-pending .module-skeleton {
    display: none;
}

/* -------------------------------------------
   CARDS
   ------------------------------------------- */
.card {
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    padding: 1.75rem;                    /* Was 1.5rem - more breathing room */
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.75rem;              /* Was 1.5rem */
    border: 1px solid var(--border-subtle);  /* Added subtle border */
    position: relative;
    contain: layout style;
}

@media (min-width: 768px) {
    .card {
        padding: 2rem;                   /* Was 1.75rem */
    }
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 2rem;
    right: 2rem;
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent,
        var(--border-color) 20%,
        var(--border-color) 80%,
        transparent
    );
    opacity: 0.4;                        /* Was 0.6 - more subtle */
}

.card:first-child::before {
    display: none;
}

/* Clinician card overrides — compact cards for config layouts */
@media (min-width: 768px) {
    .clinician-layout .card,
    .biologics-clinician-layout .card,
    .clinician-grid .card {
        padding: 1.25rem;
        margin-bottom: 0;
    }
    .clinician-layout .card-header,
    .biologics-clinician-layout .card-header,
    .clinician-grid .card-header,
    .dmard-mobile-card .card-header,
    .monitoring-mobile-card .card-header,
    .biologics-mobile-card .card-header {
        margin-bottom: 1rem;
        padding-bottom: 0.75rem;
    }
    .clinician-layout .card-header h2,
    .biologics-clinician-layout .card-header h2,
    .clinician-grid .card-header h2,
    .dmard-mobile-card .card-header h2,
    .monitoring-mobile-card .card-header h2,
    .biologics-mobile-card .card-header h2 {
        font-size: var(--text-base);
    }
}

@media (max-width: 767px) {
    .clinician-layout .card,
    .biologics-clinician-layout .card,
    .clinician-grid .card {
        padding: 1rem;
        margin-bottom: 0.875rem;
    }
    .clinician-layout .card-header,
    .biologics-clinician-layout .card-header,
    .clinician-grid .card-header,
    .dmard-mobile-card .card-header,
    .monitoring-mobile-card .card-header,
    .biologics-mobile-card .card-header {
        margin-bottom: 0.75rem;
        padding-bottom: 0.625rem;
    }
    .clinician-layout .card-header h2,
    .biologics-clinician-layout .card-header h2,
    .clinician-grid .card-header h2,
    .dmard-mobile-card .card-header h2,
    .monitoring-mobile-card .card-header h2,
    .biologics-mobile-card .card-header h2 {
        font-size: var(--text-sm);
    }
}

/* Card Header */
.card-header {
    display: flex;
    align-items: center;
    gap: 0.875rem;                       /* Was 0.75rem */
    margin-bottom: 1.5rem;               /* Was 1.25rem */
    padding-bottom: 1.25rem;             /* Was 1rem */
    border-bottom: 1px solid var(--border-subtle);  /* Use subtle border */
}

.card-header h2 {
    margin: 0;
    font-size: var(--text-base);
    font-weight: var(--font-semibold);   /* Was bold - slightly lighter */
    letter-spacing: var(--tracking-normal);  /* Was tight */
    color: var(--text-primary);
}

.card-header .icon {
    width: 24px;                         /* Was 22px - slightly larger */
    height: 24px;
    color: var(--theme-primary);
    flex-shrink: 0;
}

.card-header-text {
    min-width: 0;
}

.card-header-text h2 {
    margin: 0;
}

.card-subtitle {
    margin: 0.125rem 0 0;
    font-size: var(--text-2xs);
    color: var(--text-muted);
    font-weight: normal;
}

/* First card accent */
.page-content > .card:first-child,
.page-content > .step-section:first-child .card,
.summary-bar + .card {
    border-top: 3px solid var(--theme-primary);
    border-radius: var(--radius-lg);
}

.summary-bar + .card {
    margin-top: 1rem;
}

.page-content > .step-section:first-child .card::before {
    display: none;
}

/* -------------------------------------------
   SUMMARY BAR - Patient view header
   ------------------------------------------- */
.summary-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.125rem 0;
    padding: 0.5rem 1rem;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.12);
}

/* Dark mode: more visible divider */
[data-theme="dark"] .summary-bar {
    border-bottom-color: rgba(255, 255, 255, 0.15);
}

.summary-bar .summary-item {
    white-space: nowrap;
}

.summary-bar .summary-item:not(:last-child)::after {
    content: '\00B7';
    margin: 0 0.5rem;
    opacity: 0.4;
}

.summary-bar strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* Patient mode: remove summary-bar top padding since page-content provides the gap */
body.patient-mode .summary-bar {
    padding-top: 0;
}

/* -------------------------------------------
   BUTTONS - Base
   ------------------------------------------- */
button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
    color: inherit;
}

button:focus-visible {
    outline: 2px solid var(--theme-primary);
    outline-offset: 2px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.9375rem;                /* Was 0.925rem - slightly larger */
    font-weight: var(--font-semibold);
    padding: 0.75rem 1.5rem;             /* Was 1.25rem horizontal - wider */
    border-radius: var(--radius-md);
    border: 1px solid transparent;       /* For consistent sizing */
    transition:
        background var(--transition-fast),
        transform var(--transition-fast),
        box-shadow var(--transition-fast),
        border-color var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.btn:active {
    transform: translateY(0) scale(0.98);
    box-shadow: var(--shadow-xs);
    transition: transform 80ms var(--ease-out-expo),
                box-shadow 80ms var(--ease-out-expo);
}

/* -------------------------------------------
   BUTTONS - Variants
   ------------------------------------------- */
.btn-primary {
    background: var(--theme-primary);
    color: var(--text-on-theme);
    border-color: var(--theme-primary);
}

@media (hover: hover) {
    .btn-primary:hover {
        background: var(--theme-dark);
        border-color: var(--theme-dark);
        transform: translateY(-2px);     /* Was -1px - more pronounced */
        box-shadow:
            var(--shadow-md),
            0 4px 12px rgba(0, 0, 0, 0.15);  /* Glow effect */
    }
}
.hover-capable .btn-primary:hover {
    background: var(--theme-dark);
    border-color: var(--theme-dark);
    transform: translateY(-2px);
    box-shadow:
        var(--shadow-md),
        0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-primary:active {
    transform: translateY(0) scale(0.98);
    box-shadow: var(--shadow-xs);
    transition: transform 80ms var(--ease-out-expo),
                box-shadow 80ms var(--ease-out-expo);
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-xs);
}

@media (hover: hover) {
    .btn-secondary:hover {
        background: var(--bg-surface, var(--bg-primary));
        border-color: var(--theme-primary);
        color: var(--theme-primary);
        box-shadow: var(--shadow-sm);
        transform: translateY(-1px);
    }
}
.hover-capable .btn-secondary:hover {
    background: var(--bg-surface, var(--bg-primary));
    border-color: var(--theme-primary);
    color: var(--theme-primary);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

/* Shared mobile clear button for calculator modules */
.calc-mobile-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    cursor: pointer;
    box-shadow: 0 0 0 1px var(--border-color), var(--shadow-xs);
    transition: background var(--transition-fast), box-shadow var(--transition-fast), color var(--transition-fast);
}

.calc-mobile-clear svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

@media (hover: hover) {
    .calc-mobile-clear:hover {
        background: rgba(220, 38, 38, 0.08);
        box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.4), var(--shadow-sm);
        color: var(--risk-high-text);
    }
}
.hover-capable .calc-mobile-clear:hover {
    background: rgba(220, 38, 38, 0.08);
    box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.4), var(--shadow-sm);
    color: var(--risk-high-text);
}

.calc-mobile-clear:active {
    background: rgba(220, 38, 38, 0.12);
    box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.5), var(--shadow-sm);
    color: var(--risk-high-text);
}

[data-theme="dark"] .calc-mobile-clear {
    background: var(--bg-primary);
}

@media (hover: hover) {
    [data-theme="dark"] .calc-mobile-clear:hover {
        background: rgba(220, 38, 38, 0.15);
        box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.5), var(--shadow-sm);
        color: var(--risk-high-border);
    }
}
.hover-capable [data-theme="dark"] .calc-mobile-clear:hover {
    background: rgba(220, 38, 38, 0.15);
    box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.5), var(--shadow-sm);
    color: var(--risk-high-border);
}

[data-theme="dark"] .calc-mobile-clear:active {
    background: rgba(220, 38, 38, 0.15);
    box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.5), var(--shadow-sm);
    color: var(--risk-high-border);
}

/* -------------------------------------------
   LABELS & BADGES
   ------------------------------------------- */
.label {
    display: block;
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wider);
    color: var(--text-muted);
    margin-bottom: 0.625rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-pill);
    background: var(--bg-primary);
    color: var(--text-secondary);
}

/* -------------------------------------------
   STEP BADGES - Numbered progression indicators
   Shared across DMARD and Biologics modules
   ------------------------------------------- */
.step-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--border-color);
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: 700;
    margin-right: 0.5rem;
    transition:
        background var(--transition-fast),
        color var(--transition-fast),
        box-shadow var(--transition-fast);
}

/* -------------------------------------------
   CONTACT COMPONENTS
   ------------------------------------------- */
.contact-box h3 {
    font-size: var(--text-base);
    font-weight: var(--font-bold);
    margin: 0 0 0.75rem;
    color: var(--text-primary);
}

.contact-box .contact-row:last-of-type {
    margin-bottom: 0;
}

.contact-box .note-box {
    margin-top: 1rem;
}

.contact-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--theme-primary);
}

.contact-icon svg {
    width: 18px;
    height: 18px;
}

.contact-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.625rem;
}

.contact-row:last-child {
    margin-bottom: 0;
}

.contact-row svg {
    flex-shrink: 0;
    color: var(--theme-primary);
}

.note-box {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin-top: 0.875rem;
    padding: 0.75rem;
    background: var(--accent-warning);
    border-left: 3px solid var(--accent-warning-border);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    color: var(--accent-warning-dark);
    line-height: var(--leading-relaxed);
}

.note-icon {
    display: flex;
    flex-shrink: 0;
    color: var(--accent-warning-border);
    margin-top: 0.125rem;
}

.note-icon svg {
    width: 18px;
    height: 18px;
}

.contact-row a {
    color: var(--text-primary);
    text-decoration: none;
    border-bottom: 1px dotted var(--text-muted);
    transition:
        color var(--transition-fast),
        border-color var(--transition-fast);
}

@media (hover: hover) {
    .contact-row a:hover {
        color: var(--theme-primary);
        border-color: var(--theme-primary);
    }

    [data-theme="dark"] .contact-row a:hover {
        color: var(--nhs-light-blue);
        border-color: var(--nhs-light-blue);
    }
}
.hover-capable .contact-row a:hover {
    color: var(--theme-primary);
    border-color: var(--theme-primary);
}
.hover-capable [data-theme="dark"] .contact-row a:hover {
    color: var(--nhs-light-blue);
    border-color: var(--nhs-light-blue);
}

/* Save Contact Button - shared across patient views */
.btn-save-contact {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    margin-top: 1rem;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--text-sm);
    font-weight: 600;
    cursor: pointer;
}

@media (hover: hover) {
    .btn-save-contact:hover {
        border-color: var(--theme-primary);
        background: var(--theme-light);
    }
}
.hover-capable .btn-save-contact:hover {
    border-color: var(--theme-primary);
    background: var(--theme-light);
}

.btn-save-contact svg {
    width: 20px;
    height: 20px;
}

@media print {
    .btn-save-contact {
        display: none !important;
    }
}

/* -------------------------------------------
   MOBILE/DESKTOP BUTTON TEXT TOGGLE
   Shared across patient views (DMARD, Biologics, Prednisolone)
   ------------------------------------------- */
.btn-icon-mobile,
.btn-text-mobile {
    display: none;
}

.btn-icon-desktop,
.btn-text-desktop {
    display: inline;
}

@media (max-width: 767px) {
    .btn-icon-mobile,
    .btn-text-mobile {
        display: inline;
    }

    .btn-icon-desktop,
    .btn-text-desktop {
        display: none;
    }
}

/* -------------------------------------------
   PDF LINK CARD
   ------------------------------------------- */
.pdf-link-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    text-decoration: none;
    color: inherit;
    border-left: 4px solid var(--theme-primary);
    background: var(--bg-elevated);
    transition:
        transform var(--transition-fast),
        box-shadow var(--transition-fast);
}

/* Condition leaflet — information language (top accent, not left) */
.condition-leaflet-card {
    border-left: 1px solid transparent;
    border-top: 2px solid var(--theme-primary);
}

/* When condition leaflet is first card, suppress accent on next card */
.page-content .condition-leaflet-card + .card,
.drawer-body .condition-leaflet-card + .card {
    border-top-color: transparent;
}

.pdf-link-card svg {
    flex-shrink: 0;
    color: var(--theme-primary);
}

.pdf-link-content {
    flex: 1;
}

.pdf-link-title {
    font-weight: 600;
    color: var(--text-primary);
}

.pdf-link-subtitle {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.pdf-link-source {
    font-size: var(--text-2xs);
    color: var(--text-muted);
    font-style: italic;
}

.pdf-link-note {
    font-size: var(--text-2xs);
    color: var(--text-secondary);
    font-style: italic;
}

.pdf-link-card .pdf-arrow {
    color: var(--text-muted);
    font-size: var(--text-xl);
    transition: transform var(--transition-fast);
}

@media (hover: hover) {
    .pdf-link-card:hover {
        transform: translateY(-2px);
        box-shadow: var(--shadow-md);
    }

    .pdf-link-card:hover .pdf-arrow {
        transform: translateX(4px);
    }
}
.hover-capable .pdf-link-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.hover-capable .pdf-link-card:hover .pdf-arrow {
    transform: translateX(4px);
}

.pdf-link-card:active {
    transform: translateY(0) scale(0.99);
}

/* -------------------------------------------
   READING SECTION — grouped leaflet links
   ------------------------------------------- */
.reading-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0;
    text-decoration: none;
    color: inherit;
}

.reading-link + .reading-link {
    border-top: 1px solid var(--border-subtle);
}

.reading-link svg {
    flex-shrink: 0;
    color: var(--theme-primary);
}

.reading-link .pdf-link-content {
    transform-origin: left center;
    transition: transform var(--transition-fast);
}

.reading-link .pdf-arrow {
    color: var(--text-muted);
    font-size: var(--text-xl);
    transition: transform var(--transition-fast);
}

@media (min-width: 768px) and (hover: hover) {
    .reading-link:hover .pdf-link-content {
        transform: scale(1.015);
    }

    .reading-link:hover .pdf-arrow {
        transform: translateX(4px);
    }
}
@media (min-width: 768px) {
    .hover-capable .reading-link:hover .pdf-link-content {
        transform: scale(1.015);
    }

    .hover-capable .reading-link:hover .pdf-arrow {
        transform: translateX(4px);
    }
}

/* -------------------------------------------
   ABOVE-FOLD LAYOUT HINTS
   Geometry-only rules to prevent CLS before
   components-deferred.css loads. Full visual
   styles (color, shadow, transitions) applied
   by the deferred bundle.
   ------------------------------------------- */
.page-header {
    margin-bottom: 2rem;
}

.page-title {
    font-size: var(--text-2xl);
    font-weight: 700;
    margin: 0 0 0.25rem 0;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.page-subtitle {
    font-size: var(--text-base);
    margin: 0;
}

.btn-grid {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: 1fr;
}

@media (min-width: 480px) {
    .btn-grid.two-col,
    .btn-grid.medications {
        grid-template-columns: 1fr 1fr;
    }
}

.select-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    font-size: 0.9375rem;
    font-weight: var(--font-semibold);
    border-radius: var(--radius-md);
    min-height: 72px;
    font-family: inherit;
    border: 1px solid var(--border-color);
    position: relative;
}

/* -------------------------------------------
   MOBILE QR PLACEHOLDER (CLS GUARD)
   Reserve placeholder geometry before
   calculator-shared.css is injected.
   ------------------------------------------- */
@media (max-width: 767px) {
    .qr-placeholder-mobile {
        min-height: 180px;
        padding: 2rem 1rem;
        border: 1px solid transparent;
        border-radius: var(--radius-lg);
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        position: relative;
        font-size: var(--text-2xs);
        line-height: 1.4;
    }

    .qr-placeholder-mobile .qr-placeholder-icon {
        margin-bottom: 0.5rem;
        min-height: 56px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .qr-placeholder-mobile .qr-placeholder-icon svg {
        width: 56px;
        height: 56px;
    }
}
