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

:root {
    --wkd-blue: #004982;
    --wkd-blue-light: #0066b3;
    --wkd-blue-dark: #003561;
    --wkd-red: #e02521;
    --wkd-red-glow: rgba(224, 37, 33, 0.25);

    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.85);
    --bg-card-alt: rgba(0, 73, 130, 0.08);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --border: rgba(148, 163, 184, 0.1);
    --border-active: rgba(0, 102, 179, 0.4);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;

    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-glow: 0 0 40px rgba(0, 73, 130, 0.15);

    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-medium: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    background-image:
        radial-gradient(ellipse at 20% 0%, rgba(0, 73, 130, 0.15) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 100%, rgba(224, 37, 33, 0.06) 0%, transparent 50%);
}

a {
    color: var(--wkd-blue-light);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--wkd-red);
}

/* ===== Layout ===== */
.app {
    max-width: 640px;
    margin: 0 auto;
    padding: 20px 16px 40px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.header {
    padding: 12px 0 24px;
}

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

.logo-icon {
    font-size: 2rem;
    filter: grayscale(0.2);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--wkd-blue-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-top: 2px;
}

/* ===== Direction Card ===== */
.direction-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-active);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-card), var(--shadow-glow);
    margin-bottom: 20px;
    position: relative;
    overflow: hidden;
}

.direction-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--wkd-blue), var(--wkd-red));
}

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

.station {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.station-to {
    text-align: right;
}

.station-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.station-name {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.swap-btn {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid var(--border-active);
    background: rgba(0, 73, 130, 0.15);
    color: var(--wkd-blue-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.swap-btn:hover {
    background: var(--wkd-blue);
    color: white;
    border-color: var(--wkd-blue);
    transform: rotate(180deg);
    box-shadow: 0 0 20px rgba(0, 73, 130, 0.3);
}

.swap-btn:active {
    transform: rotate(180deg) scale(0.92);
}

.meta-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.schedule-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-card);
    flex: 1;
}

/* ===== Closest Arrivals Card ===== */
.closest-card {
    background: var(--wkd-blue-dark);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--wkd-blue);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-card), var(--shadow-glow);
    margin-bottom: 20px;
    flex: none;
}

.closest-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.closest-train {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: transform var(--transition-fast), background var(--transition-fast);
}

.closest-train:hover {
    background: rgba(0, 0, 0, 0.3);
    transform: translateY(-2px);
}

.closest-train-time {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.closest-departure {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.05em;
    font-variant-numeric: tabular-nums;
}

.closest-arrival {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.closest-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.closest-duration {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.closest-empty {
    text-align: center;
    padding: 20px 0;
    color: var(--text-muted);
}


.schedule-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.schedule-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.refresh-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.refresh-btn:hover {
    background: rgba(0, 73, 130, 0.15);
    color: var(--wkd-blue-light);
    border-color: var(--border-active);
}

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

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

/* ===== Loading ===== */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 48px 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--wkd-blue-light);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ===== Error ===== */
.error-msg {
    text-align: center;
    padding: 36px 0;
}

.error-icon {
    font-size: 2rem;
    display: block;
    margin-bottom: 12px;
}

.error-msg p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.retry-btn {
    padding: 10px 24px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--wkd-red);
    background: rgba(224, 37, 33, 0.1);
    color: var(--wkd-red);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
}

.retry-btn:hover {
    background: var(--wkd-red);
    color: white;
}

/* ===== Table ===== */
.trains-table-wrap {
    overflow-x: auto;
    margin: 0 -8px;
    padding: 0 8px;
}

.trains-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.trains-table thead th {
    text-align: left;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 0 12px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.trains-table tbody tr {
    transition: background var(--transition-fast);
    cursor: default;
}

.trains-table tbody tr:hover {
    background: rgba(0, 73, 130, 0.06);
}

.trains-table tbody td {
    padding: 14px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

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

/* Time cells */
.time-departure {
    font-weight: 700;
    font-size: 1.05rem;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

.time-arrival {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
}

.time-duration {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Train type badges */
.train-type {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.train-type-a1 {
    background: rgba(0, 73, 130, 0.15);
    color: var(--wkd-blue-light);
    border: 1px solid rgba(0, 73, 130, 0.25);
}

.train-type-za1 {
    background: rgba(224, 37, 33, 0.12);
    color: #ff6b6b;
    border: 1px solid rgba(224, 37, 33, 0.2);
}

.train-type-bus {
    background: rgba(234, 179, 8, 0.12);
    color: #eab308;
    border: 1px solid rgba(234, 179, 8, 0.2);
}

/* Next train highlight */
.train-next {
    position: relative;
    background: rgba(0, 73, 130, 0.08) !important;
}

.train-next td:first-child::before {
    content: '';
    position: absolute;
    left: 0;
    top: 4px;
    bottom: 4px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--wkd-blue-light);
    box-shadow: 0 0 8px rgba(0, 102, 179, 0.4);
}

.train-next .time-departure {
    color: var(--wkd-blue-light);
}

/* Past trains */
.train-past {
    opacity: 0.38;
}

.trains-count {
    margin-top: 16px;
    font-size: 0.78rem;
    color: var(--text-muted);
    text-align: center;
}

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding: 24px 0 0;
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* ===== Row appear animation ===== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

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

.trains-table tbody tr {
    animation: fadeInUp 0.3s ease both;
}

.trains-table tbody tr:nth-child(1) {
    animation-delay: 0.02s;
}

.trains-table tbody tr:nth-child(2) {
    animation-delay: 0.05s;
}

.trains-table tbody tr:nth-child(3) {
    animation-delay: 0.08s;
}

.trains-table tbody tr:nth-child(4) {
    animation-delay: 0.11s;
}

.trains-table tbody tr:nth-child(5) {
    animation-delay: 0.14s;
}

.trains-table tbody tr:nth-child(6) {
    animation-delay: 0.17s;
}

.trains-table tbody tr:nth-child(7) {
    animation-delay: 0.20s;
}

.trains-table tbody tr:nth-child(8) {
    animation-delay: 0.23s;
}

.trains-table tbody tr:nth-child(9) {
    animation-delay: 0.26s;
}

.trains-table tbody tr:nth-child(10) {
    animation-delay: 0.29s;
}

.trains-table tbody tr:nth-child(n+11) {
    animation-delay: 0.32s;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
    .app {
        padding: 12px 12px 32px;
    }

    .direction-card,
    .schedule-card {
        padding: 18px;
        border-radius: var(--radius-md);
    }

    .station-name {
        font-size: 0.92rem;
    }

    .swap-btn {
        width: 38px;
        height: 38px;
    }

    .trains-table {
        font-size: 0.85rem;
    }

    .trains-table thead th,
    .trains-table tbody td {
        padding: 10px 8px;
    }

    .time-departure {
        font-size: 0.95rem;
    }
}