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

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-glow: rgba(59, 130, 246, 0.3);
    --background: #f1f5f9;
    --card-bg: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #22c55e;
    --success-glow: rgba(34, 197, 94, 0.3);
    --warning: #f59e0b;
    --warning-glow: rgba(245, 158, 11, 0.3);
    --danger: #ef4444;
    --info: #0ea5e9;
}

@media (prefers-color-scheme: dark) {
    :root {
        --background: #0f172a;
        --card-bg: #1e293b;
        --text: #f1f5f9;
        --text-muted: #94a3b8;
        --border: #334155;
        --primary-glow: rgba(59, 130, 246, 0.2);
        --success-glow: rgba(34, 197, 94, 0.2);
        --warning-glow: rgba(245, 158, 11, 0.2);
    }
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--background);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
}

.app {
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: 80px;
}

/* ==================== HEADER ==================== */
.header {
    background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
    color: white;
    padding: 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    overflow: hidden;
}

/* Animated background particles */
.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        radial-gradient(circle at 20% 50%, rgba(96, 165, 250, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(96, 165, 250, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 40% 80%, rgba(96, 165, 250, 0.05) 0%, transparent 30%);
    animation: headerPulse 8s ease-in-out infinite;
}

@keyframes headerPulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    position: relative;
    z-index: 1;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.plane-icon {
    width: 40px;
    height: 40px;
    color: #60a5fa;
    filter: drop-shadow(0 0 8px rgba(96, 165, 250, 0.5));
    animation: planeFloat 3s ease-in-out infinite;
}

@keyframes planeFloat {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-4px) rotate(2deg); }
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: 0.75rem;
    color: #94a3b8;
}

.refresh-btn {
    background: rgba(255,255,255,0.1);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(4px);
}

.refresh-btn:hover {
    background: rgba(255,255,255,0.2);
    transform: scale(1.05);
}

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

.refresh-icon {
    width: 22px;
    height: 22px;
    color: white;
    transition: transform 0.3s;
}

.refresh-btn.spinning .refresh-icon {
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.last-updated {
    font-size: 0.75rem;
    color: #94a3b8;
    position: relative;
    z-index: 1;
}

/* ==================== TABS ==================== */
.tabs {
    display: flex;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 92px;
    z-index: 99;
    overflow: hidden;
}

.tab {
    flex: 1;
    padding: 14px;
    border: none;
    background: none;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-bottom: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.tab::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, var(--primary-glow) 0%, transparent 100%);
    opacity: 0;
    transition: opacity 0.3s;
}

.tab.active::before {
    opacity: 1;
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-icon {
    width: 20px;
    height: 20px;
    transition: transform 0.3s;
    position: relative;
    z-index: 1;
}

/* Arrival tab - plane landing animation */
.tab[data-tab="arrivals"].active .tab-icon {
    animation: planeLanding 2s ease-in-out infinite;
}

@keyframes planeLanding {
    0% { transform: translateX(-8px) translateY(-8px) rotate(-15deg); }
    50% { transform: translateX(0) translateY(0) rotate(0deg); }
    100% { transform: translateX(-8px) translateY(-8px) rotate(-15deg); }
}

/* Departure tab - plane takeoff animation */
.tab[data-tab="departures"].active .tab-icon {
    animation: planeTakeoff 2s ease-in-out infinite;
}

@keyframes planeTakeoff {
    0% { transform: translateX(0) translateY(0) rotate(0deg); }
    50% { transform: translateX(8px) translateY(-8px) rotate(15deg); }
    100% { transform: translateX(0) translateY(0) rotate(0deg); }
}

/* ==================== FLIGHTS CONTAINER ==================== */
.flights-container {
    padding: 16px;
    min-height: 60vh;
}

/* ==================== LOADING ==================== */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.spinner {
    width: 50px;
    height: 50px;
    position: relative;
    margin-bottom: 20px;
}

.spinner::before {
    content: '';
    position: absolute;
    inset: 0;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Plane in center of spinner */
.spinner::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    transform: translate(-50%, -50%);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%233b82f6' stroke-width='2'%3E%3Cpath d='M17.8 19.2L16 11l3.5-3.5C21 6 21.5 4 21 3c-1-.5-3 0-4.5 1.5L13 8 4.8 6.2c-.5-.1-.9.1-1.1.5l-.3.5c-.2.4-.1.9.3 1.1l4.8 3.8-2.5 3-2.6-.5c-.5-.1-1 .1-1.2.5l-.2.4c-.2.4-.1.9.3 1.1l3.2 1.2 1.2 3.2c.2.4.7.5 1.1.3l.4-.2c.4-.2.6-.7.5-1.2l-.5-2.6 3-2.5 3.8 4.8c.2.4.7.5 1.1.3l.5-.3c.4-.2.6-.6.5-1.1z'/%3E%3C/svg%3E");
    background-size: contain;
    animation: planeWobble 1.5s ease-in-out infinite;
}

@keyframes planeWobble {
    0%, 100% { transform: translate(-50%, -50%) rotate(-5deg); }
    50% { transform: translate(-50%, -50%) rotate(5deg); }
}

/* ==================== FLIGHT CARD ==================== */
.flight-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 18px;
    margin-bottom: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.05);
    border: 1px solid var(--border);
    opacity: 0;
    transform: translateY(20px);
    animation: cardSlideIn 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    transition: transform 0.3s, box-shadow 0.3s;
    position: relative;
    overflow: hidden;
}

.flight-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1), 0 8px 24px rgba(0,0,0,0.08);
}

/* Staggered animation for cards */
.flight-card:nth-child(1) { animation-delay: 0.05s; }
.flight-card:nth-child(2) { animation-delay: 0.1s; }
.flight-card:nth-child(3) { animation-delay: 0.15s; }
.flight-card:nth-child(4) { animation-delay: 0.2s; }
.flight-card:nth-child(5) { animation-delay: 0.25s; }
.flight-card:nth-child(6) { animation-delay: 0.3s; }
.flight-card:nth-child(7) { animation-delay: 0.35s; }
.flight-card:nth-child(8) { animation-delay: 0.4s; }

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

/* Status indicator stripe */
.flight-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
    transition: background 0.3s;
}

.flight-card.status-active::before,
.flight-card.status-landed::before,
.flight-card.status-departed::before {
    background: var(--success);
    box-shadow: 0 0 8px var(--success-glow);
}

.flight-card.status-delayed::before {
    background: var(--warning);
    box-shadow: 0 0 8px var(--warning-glow);
    animation: pulseWarning 2s ease-in-out infinite;
}

.flight-card.status-cancelled::before {
    background: var(--danger);
}

@keyframes pulseWarning {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.flight-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 14px;
}

.flight-number {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.02em;
}

.airline {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.status {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    transition: all 0.3s;
}

.status.scheduled { background: #dbeafe; color: #1d4ed8; }
.status.active { 
    background: #dcfce7; 
    color: #16a34a; 
    animation: statusPulse 2s ease-in-out infinite;
}
.status.landed { background: #d1fae5; color: #059669; }
.status.departed { background: #dbeafe; color: #2563eb; }
.status.delayed { 
    background: #fef3c7; 
    color: #d97706;
    animation: statusPulse 1.5s ease-in-out infinite;
}
.status.cancelled { background: #fee2e2; color: #dc2626; }
.status.diverted { background: #fae8ff; color: #a855f7; }

@keyframes statusPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@media (prefers-color-scheme: dark) {
    .status.scheduled { background: #1e3a5f; color: #60a5fa; }
    .status.active { background: #14532d; color: #4ade80; }
    .status.landed { background: #064e3b; color: #34d399; }
    .status.departed { background: #1e3a5f; color: #60a5fa; }
    .status.delayed { background: #451a03; color: #fbbf24; }
    .status.cancelled { background: #450a0a; color: #f87171; }
    .status.diverted { background: #4a044e; color: #e879f9; }
}

/* ==================== ROUTE SECTION ==================== */
.route {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    position: relative;
}

.airport {
    flex: 1;
    min-width: 0;
}

.airport-code {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.airport-name {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.route-line {
    flex: 0 0 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    height: 40px;
}

/* Animated flight path line */
.route-line::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--border) 0%, var(--border) 100%);
    transform: translateY(-50%);
}

/* Dashed line animation */
.route-line::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 2px;
    transform: translateY(-50%);
    background: repeating-linear-gradient(
        90deg,
        var(--primary) 0px,
        var(--primary) 4px,
        transparent 4px,
        transparent 8px
    );
    background-size: 200% 100%;
    animation: dashMove 1s linear infinite;
}

@keyframes dashMove {
    from { background-position: 0% 0; }
    to { background-position: 100% 0; }
}

.route-plane {
    width: 28px;
    height: 28px;
    color: var(--primary);
    position: relative;
    z-index: 2;
    background: var(--card-bg);
    padding: 2px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

/* Plane animation for arrivals */
.flight-card.arrival .route-plane {
    animation: flyArrival 3s ease-in-out infinite;
}

@keyframes flyArrival {
    0% { transform: translateX(15px) rotate(0deg) scale(0.9); opacity: 0.7; }
    50% { transform: translateX(0) rotate(-5deg) scale(1); opacity: 1; }
    100% { transform: translateX(15px) rotate(0deg) scale(0.9); opacity: 0.7; }
}

/* Plane animation for departures */
.flight-card.departure .route-plane {
    animation: flyDeparture 3s ease-in-out infinite;
}

@keyframes flyDeparture {
    0% { transform: translateX(-15px) rotate(0deg) scale(0.9); opacity: 0.7; }
    50% { transform: translateX(0) rotate(5deg) scale(1); opacity: 1; }
    100% { transform: translateX(-15px) rotate(0deg) scale(0.9); opacity: 0.7; }
}

/* Active flight - continuous movement */
.flight-card.status-active .route-plane {
    animation: flyActive 1.5s ease-in-out infinite !important;
}

@keyframes flyActive {
    0%, 100% { 
        transform: translateX(-5px) translateY(2px) rotate(-3deg); 
    }
    50% { 
        transform: translateX(5px) translateY(-2px) rotate(3deg); 
    }
}

.airport.destination {
    text-align: right;
}

/* ==================== TIMES SECTION ==================== */
.times {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.time-block {
    text-align: center;
    padding: 8px 4px;
    border-radius: 8px;
    transition: background 0.2s;
}

.time-block:hover {
    background: rgba(59, 130, 246, 0.05);
}

.time-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 4px;
    letter-spacing: 0.05em;
}

.time-value {
    font-size: 1rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.time-value.delayed {
    color: var(--warning);
    animation: textPulse 2s ease-in-out infinite;
}

@keyframes textPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.time-value.actual {
    color: var(--success);
}

/* ==================== ERROR STATE ==================== */
.error {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    animation: fadeIn 0.5s ease-out;
}

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

.error-icon {
    width: 56px;
    height: 56px;
    margin-bottom: 16px;
    color: var(--danger);
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.error h3 {
    margin-bottom: 8px;
    color: var(--text);
    font-size: 1.1rem;
}

.retry-btn {
    margin-top: 16px;
    padding: 12px 28px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.retry-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--primary-glow);
}

.retry-btn:active {
    transform: translateY(0);
}

/* ==================== EMPTY STATE ==================== */
.empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    animation: fadeIn 0.5s ease-out;
}

.empty-icon {
    width: 72px;
    height: 72px;
    margin-bottom: 20px;
    opacity: 0.4;
    animation: emptyFloat 4s ease-in-out infinite;
}

@keyframes emptyFloat {
    0%, 100% { transform: translateY(0) rotate(-5deg); }
    50% { transform: translateY(-10px) rotate(5deg); }
}

.empty h3 {
    font-size: 1.1rem;
    color: var(--text);
    margin-bottom: 8px;
}

/* ==================== INSTALL PROMPT ==================== */
.install-prompt {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    padding: 16px 20px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    align-items: center;
    gap: 12px;
    z-index: 1000;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.install-prompt.show {
    display: flex;
    transform: translateY(0);
}

.install-prompt p {
    flex: 1;
    font-size: 0.9rem;
}

.install-btn {
    padding: 10px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
}

.install-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.02);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 8px;
    transition: color 0.2s;
}

.close-btn:hover {
    color: var(--text);
}

/* ==================== DATE HEADER ==================== */
.date-header {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 12px 0 8px;
    margin-top: 8px;
    text-transform: capitalize;
    display: flex;
    align-items: center;
    gap: 10px;
}

.date-header::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, var(--border) 0%, transparent 100%);
}

.date-header:first-child {
    margin-top: 0;
}

/* ==================== PULL TO REFRESH INDICATOR ==================== */
.pull-indicator {
    text-align: center;
    padding: 12px;
    color: var(--text-muted);
    font-size: 0.8rem;
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.3s;
}

.pull-indicator.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

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