/* ============================================================
   SUIVI PARCOURS PATIENT — PIXEL ART HOSPITAL TRACKER
   Stardew Valley meets Hospital — warm, reassuring, retro
   ============================================================ */

/* --- CSS Custom Properties (Design Tokens) --- */
:root {
    /* Palette */
    --bg-cream: #FFF8F0;
    --bg-warm: #FFF3E6;
    --primary: #4ECDC4;
    --primary-dark: #3BA89F;
    --primary-light: #A8E6CF;
    --secondary: #FF6B6B;
    --secondary-light: #FFB5B5;
    --accent-yellow: #FFE66D;
    --accent-purple: #C3A6FF;
    --text-dark: #2C3E50;
    --text-mid: #5D6D7E;
    --text-light: #95A5A6;
    --success: #27AE60;
    --success-light: #D5F5E3;
    --card-bg: #FFFFFF;
    --card-shadow: 0 4px 24px rgba(44, 62, 80, 0.08);
    --card-shadow-hover: 0 8px 32px rgba(44, 62, 80, 0.12);
    --border-light: #E8E0D8;
    --error-bg: #FDECEA;
    --error-text: #C0392B;
    --error-border: #E74C3C;

    /* Pixel Art Colors */
    --pixel-skin: #F5C5A3;
    --pixel-skin-shadow: #D4A574;
    --pixel-hair-dark: #4A3728;
    --pixel-hair-light: #8B6914;
    --pixel-gown: #A8D8EA;
    --pixel-gown-shadow: #7BB8D0;
    --pixel-white: #FAFAFA;
    --pixel-outline: #2C3E50;
    --pixel-nurse-pink: #FFB5C5;
    --pixel-nurse-white: #FFFFFF;

    /* Typography */
    --font-body: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-pixel: 'Courier New', monospace;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Borders */
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;

    /* Timeline */
    --timeline-line: #D5E8D4;
    --timeline-line-active: var(--primary);
    --station-size: 56px;
    --station-size-mobile: 48px;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-cream);
    color: var(--text-dark);
    line-height: 1.6;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Pixel tile background pattern */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    opacity: 0.03;
    background-image:
        linear-gradient(45deg, var(--primary) 25%, transparent 25%),
        linear-gradient(-45deg, var(--primary) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--primary) 75%),
        linear-gradient(-45deg, transparent 75%, var(--primary) 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
    image-rendering: pixelated;
}

/* --- View Management --- */
.view {
    display: none !important;
    animation: fadeIn 0.4s ease;
}

.view.active {
    display: block !important;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- PIXEL FONT STYLE --- */
.pixel-title {
    font-family: var(--font-pixel);
    font-weight: 700;
    font-size: 1.5rem;
    letter-spacing: 1px;
    color: var(--text-dark);
    text-transform: uppercase;
    image-rendering: pixelated;
    margin-bottom: var(--space-xs);
}

.subtitle {
    font-family: var(--font-pixel);
    font-size: 0.9rem;
    color: var(--primary-dark);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: var(--space-lg);
}

/* ============================================================
   VERIFICATION VIEW
   ============================================================ */
#view-verify {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: var(--space-md);
}

#view-verify.active {
    display: flex;
}

.verify-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--card-shadow);
    max-width: 420px;
    width: 100%;
    overflow: hidden;
    border: 3px solid var(--border-light);
}

.hospital-header {
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    padding: var(--space-lg) var(--space-md);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 80px;
    position: relative;
    overflow: hidden;
}

.verify-content {
    padding: var(--space-xl) var(--space-lg);
    text-align: center;
}

.welcome-text {
    margin-bottom: var(--space-xl);
    color: var(--text-mid);
    font-size: 0.95rem;
    line-height: 1.7;
}

.welcome-text p + p {
    margin-top: var(--space-sm);
}

/* --- Date of Birth Fields --- */
.field-label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-dark);
    margin-bottom: var(--space-sm);
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: var(--font-pixel);
}

.dob-fields {
    display: grid;
    grid-template-columns: 1fr 1.4fr 1.2fr;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
}

.dob-field select {
    width: 100%;
    padding: 12px 8px;
    border: 2px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 1rem;
    color: var(--text-dark);
    background-color: var(--bg-cream);
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%235D6D7E'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
}

.dob-field select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(78, 205, 196, 0.2);
}

.dob-field select:invalid {
    color: var(--text-light);
}

/* --- Verify Button --- */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    width: 100%;
    padding: 14px var(--space-lg);
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-pixel);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, background 0.2s;
    box-shadow: 0 4px 0 var(--primary-dark), 0 6px 12px rgba(78, 205, 196, 0.3);
    position: relative;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 var(--primary-dark), 0 8px 16px rgba(78, 205, 196, 0.4);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(2px);
    box-shadow: 0 2px 0 var(--primary-dark), 0 3px 8px rgba(78, 205, 196, 0.2);
}

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

.btn-primary:focus-visible {
    outline: 3px solid var(--accent-yellow);
    outline-offset: 2px;
}

/* --- Pixel Spinner --- */
.pixel-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 0;
    animation: pixelSpin 0.8s steps(8) infinite;
    image-rendering: pixelated;
}

@keyframes pixelSpin {
    to { transform: rotate(360deg); }
}

/* --- Error Message --- */
.error-msg {
    background: var(--error-bg);
    border: 2px solid var(--error-border);
    border-radius: var(--radius-sm);
    padding: var(--space-sm) var(--space-md);
    margin-bottom: var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.9rem;
    color: var(--error-text);
    animation: shakeIn 0.4s ease;
}

.error-msg[hidden] {
    display: none;
}

.error-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
}

@keyframes shakeIn {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

/* --- Verify Footer --- */
.verify-footer {
    margin-top: var(--space-xl);
    padding-top: var(--space-md);
    border-top: 2px dashed var(--border-light);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    color: var(--text-light);
    font-size: 0.8rem;
}

.pixel-heart-small {
    width: 8px;
    height: 8px;
    background: var(--secondary);
    image-rendering: pixelated;
    flex-shrink: 0;
    clip-path: polygon(
        25% 0%, 50% 15%, 75% 0%, 100% 25%, 100% 50%,
        50% 100%, 0% 50%, 0% 25%
    );
}

/* ============================================================
   TIMELINE VIEW
   ============================================================ */

/* --- Timeline Header --- */
.timeline-header {
    background: var(--card-bg);
    border-bottom: 3px solid var(--border-light);
    padding: var(--space-md) var(--space-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(44, 62, 80, 0.05);
}

.patient-info {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.patient-avatar {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.patient-name {
    font-family: var(--font-pixel);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-dark);
}

.patient-service {
    font-size: 0.8rem;
    color: var(--primary-dark);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.patient-service::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
}

/* --- Refresh Indicator --- */
.refresh-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: 0.7rem;
    color: var(--text-light);
}

.refresh-dot {
    width: 6px;
    height: 6px;
    background: var(--success);
    border-radius: 50%;
    animation: pulse 2s ease infinite;
}

.refresh-dot.fetching {
    background: var(--accent-yellow);
    animation: blink 0.5s steps(2) infinite;
}

.refresh-dot.offline {
    background: var(--secondary);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

@keyframes blink {
    50% { opacity: 0; }
}

/* --- Timeline Container --- */
.timeline-container {
    padding: var(--space-lg) var(--space-md);
    max-width: 600px;
    margin: 0 auto;
}

.timeline-intro {
    text-align: center;
    margin-bottom: var(--space-xl);
    font-size: 0.95rem;
    color: var(--text-mid);
}

/* --- Timeline --- */
.timeline {
    position: relative;
    padding-left: 36px;
}

/* Vertical line */
.timeline::before {
    content: '';
    position: absolute;
    left: 18px;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--timeline-line);
    border-radius: 2px;
    image-rendering: pixelated;
}

/* --- Timeline Event/Station --- */
.timeline-event {
    position: relative;
    padding: 0 0 var(--space-xl) var(--space-lg);
    animation: eventFadeIn 0.5s ease both;
}

.timeline-event:last-child {
    padding-bottom: 0;
}

@keyframes eventFadeIn {
    from { opacity: 0; transform: translateX(-12px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Station dot */
.station-dot {
    position: absolute;
    left: -27px;
    top: 4px;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    image-rendering: pixelated;
    border: 3px solid var(--timeline-line);
    background: var(--card-bg);
    transition: all 0.3s ease;
}

.timeline-event.completed .station-dot {
    background: var(--success);
    border-color: var(--success);
}

.timeline-event.current .station-dot {
    background: var(--primary);
    border-color: var(--primary);
    animation: stationPulse 1.5s ease infinite;
    box-shadow: 0 0 0 4px rgba(78, 205, 196, 0.2);
}

@keyframes stationPulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(78, 205, 196, 0.2); }
    50% { box-shadow: 0 0 0 8px rgba(78, 205, 196, 0.1); }
}

.station-dot-inner {
    width: 6px;
    height: 6px;
    background: white;
    border-radius: 2px;
}

.timeline-event.completed .station-dot-inner {
    /* Checkmark via CSS */
    width: 5px;
    height: 9px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    margin-top: -2px;
    margin-left: 1px;
    background: transparent;
    border-radius: 0;
}

/* Active line segment */
.timeline-event.completed + .timeline-event::after {
    content: '';
    position: absolute;
    left: -12px;
    top: -100%;
    bottom: 50%;
    width: 4px;
    background: var(--success);
    z-index: 1;
}

/* --- Event Card --- */
.event-card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    border: 2px solid var(--border-light);
    transition: border-color 0.3s, box-shadow 0.3s;
    position: relative;
}

.timeline-event.current .event-card {
    border-color: var(--primary);
    box-shadow: 0 4px 16px rgba(78, 205, 196, 0.15);
}

.timeline-event.completed .event-card {
    opacity: 0.85;
}

.event-card-top {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
}

.event-icon {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    image-rendering: pixelated;
}

.event-info {
    flex: 1;
    min-width: 0;
}

.event-label {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-dark);
    line-height: 1.3;
}

.event-service {
    font-size: 0.8rem;
    color: var(--text-mid);
    margin-top: 2px;
}

.event-location {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 2px;
}

.event-time {
    font-family: var(--font-pixel);
    font-size: 0.8rem;
    color: var(--text-mid, #5a6b7b);
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
    padding-top: 2px;
}

/* --- Pixel Character on Timeline --- */
.timeline-character {
    position: absolute;
    left: -44px;
    top: 0;
    z-index: 10;
    transition: top 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

/* --- Current Station Badge --- */
.current-badge {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary-dark);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    margin-top: var(--space-xs);
    font-family: var(--font-pixel);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* --- Sparkle Animation --- */
.sparkle {
    position: absolute;
    pointer-events: none;
    animation: sparkleAnim 0.6s ease forwards;
}

@keyframes sparkleAnim {
    0% { opacity: 1; transform: scale(0) rotate(0deg); }
    50% { opacity: 1; transform: scale(1.2) rotate(180deg); }
    100% { opacity: 0; transform: scale(0.5) rotate(360deg); }
}

/* ============================================================
   JOURNEY END / SORTIE
   ============================================================ */
.journey-end {
    text-align: center;
    padding: var(--space-2xl) var(--space-md);
    position: relative;
}

.journey-end[hidden] {
    display: none;
}

.journey-end-content {
    position: relative;
    z-index: 2;
}

.journey-end h2 {
    font-family: var(--font-pixel);
    font-size: 1.3rem;
    color: var(--success);
    margin: var(--space-md) 0 var(--space-sm);
}

.journey-end p {
    color: var(--text-mid);
    font-size: 0.95rem;
}

/* --- Confetti --- */
.confetti-container {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.confetti-piece {
    position: absolute;
    width: 6px;
    height: 6px;
    image-rendering: pixelated;
    animation: confettiFall 3s linear forwards;
}

@keyframes confettiFall {
    0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(200px) rotate(720deg); opacity: 0; }
}

/* --- Pixel Star --- */
.pixel-star {
    display: inline-block;
    width: 32px;
    height: 32px;
    background: var(--accent-yellow);
    clip-path: polygon(
        50% 0%, 61% 35%, 98% 35%, 68% 57%,
        79% 91%, 50% 70%, 21% 91%, 32% 57%,
        2% 35%, 39% 35%
    );
    animation: starSpin 3s ease infinite;
}

@keyframes starSpin {
    0%, 100% { transform: rotate(0deg) scale(1); }
    25% { transform: rotate(10deg) scale(1.1); }
    75% { transform: rotate(-10deg) scale(1.05); }
}

/* ============================================================
   TIMELINE FOOTER
   ============================================================ */
.timeline-footer {
    text-align: center;
    padding: var(--space-md);
    font-size: 0.75rem;
    color: var(--text-light);
    border-top: 2px dashed var(--border-light);
    margin-top: var(--space-xl);
}

/* --- Offline Banner --- */
.offline-banner {
    background: var(--accent-yellow);
    color: var(--text-dark);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    margin-top: var(--space-sm);
    font-weight: 600;
    font-size: 0.8rem;
}

.offline-banner[hidden] {
    display: none;
}

/* ============================================================
   ERROR / LOCKOUT VIEWS
   ============================================================ */
.error-view-content {
    padding: var(--space-2xl) var(--space-lg);
    text-align: center;
}

.error-view-content .pixel-title {
    margin: var(--space-md) 0;
}

.error-view-content p {
    color: var(--text-mid);
    line-height: 1.7;
}

.pixel-sad, .pixel-lock {
    display: inline-block;
    width: 48px;
    height: 48px;
}

/* ============================================================
   PIXEL ART SPRITE CONTAINERS
   ============================================================ */
.pixel-sprite-container {
    display: inline-block;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* ============================================================
   ACCESSIBLE FOCUS STYLES
   ============================================================ */
*:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

/* Skip link for keyboard users */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 9999;
    padding: var(--space-sm) var(--space-md);
    background: var(--primary);
    color: white;
    font-weight: 700;
}

.skip-link:focus {
    left: var(--space-md);
}

/* Screen reader only 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-width: 0;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* Small phones */
@media (max-width: 380px) {
    .verify-content {
        padding: var(--space-lg) var(--space-md);
    }

    .dob-fields {
        grid-template-columns: 1fr;
        gap: var(--space-sm);
    }

    .pixel-title {
        font-size: 1.2rem;
    }

    .patient-avatar {
        width: 36px;
        height: 36px;
    }
}

/* Phones */
@media (max-width: 768px) {
    .timeline-header {
        padding: var(--space-sm) var(--space-md);
    }

    .timeline-container {
        padding: var(--space-md) var(--space-sm);
    }

    .timeline {
        padding-left: 32px;
    }

    .refresh-text {
        display: none;
    }
}

/* Tablets and up */
@media (min-width: 769px) {
    .verify-card {
        margin: var(--space-xl) auto;
    }

    .timeline-container {
        padding: var(--space-xl) var(--space-lg);
    }

    .event-card {
        padding: var(--space-lg);
    }

    .timeline-header {
        padding: var(--space-md) var(--space-xl);
    }
}

/* Large screens */
@media (min-width: 1024px) {
    .timeline-container {
        max-width: 700px;
    }
}

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

/* Dark mode support (optional, respects system preference) */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-cream: #1A1A2E;
        --bg-warm: #16213E;
        --card-bg: #222244;
        --text-dark: #E8E8E8;
        --text-mid: #B0B0C0;
        --text-light: #7878A0;
        --border-light: #333366;
        --card-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
        --timeline-line: #333366;
        --error-bg: #3D1515;
        --error-text: #FF8888;
    }

    body::before {
        opacity: 0.02;
    }

    .dob-field select {
        background-color: var(--bg-warm);
        color: var(--text-dark);
        border-color: var(--border-light);
    }
}
