/* CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Light theme colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f7fafc;
    --bg-tertiary: #edf2f7;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --accent-primary: #1a365d;
    --accent-secondary: #2c5282;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Dark theme */
[data-theme="dark"] {
    --bg-primary: #1a202c;
    --bg-secondary: #2d3748;
    --bg-tertiary: #4a5568;
    --text-primary: #f7fafc;
    --text-secondary: #e2e8f0;
    --text-muted: #a0aec0;
    --accent-primary: #63b3ed;
    --accent-secondary: #4299e1;
    --border-color: #4a5568;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3), 0 1px 2px 0 rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.app-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-primary);
}

.header-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.theme-toggle,
.install-btn {
    background: var(--accent-primary);
    color: white;
    border: none;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background-color 0.2s ease;
    white-space: nowrap;
}

.theme-toggle:hover,
.install-btn:hover {
    background: var(--accent-secondary);
}

.theme-icon {
    font-size: 1rem;
}

/* Main Layout */
.main {
    flex: 1;
    display: flex;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: 300px;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-primary);
    padding: 0.5rem;
    border-radius: 0.25rem;
    transition: background-color 0.2s ease;
    display: none; /* Hidden by default on desktop */
}

.sidebar-toggle:hover {
    background-color: var(--bg-tertiary);
}

.search-container {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

#station-search {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: border-color 0.2s ease;
}

#station-search:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(26, 54, 93, 0.1);
}

.stations-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.station-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-radius: 0.375rem;
    margin-bottom: 0.25rem;
    transition: background-color 0.2s ease;
    border: 1px solid transparent;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.station-info {
    flex: 1;
}

.station-item:hover {
    background-color: var(--bg-tertiary);
}

.station-item.selected {
    background-color: var(--accent-primary);
    color: white;
}

.station-name {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.station-code {
    font-size: 0.75rem;
    opacity: 0.8;
}

.favorite-btn {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.25rem;
    transition: all 0.2s ease;
    color: var(--text-muted);
}

.favorite-btn:hover {
    color: #fbbf24;
    background-color: var(--bg-tertiary);
}

.favorite-btn.favorited {
    color: #fbbf24;
}

.loading {
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
}

/* Arrivals Panel */
.arrivals-panel {
    flex: 1;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.arrivals-header {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.arrivals-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.last-updated {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.arrivals-content {
    flex: 1;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    text-align: center;
    color: var(--text-muted);
}

/* Arrivals Table */
.arrivals-table {
    width: 100%;
    border-collapse: collapse;
    background-color: var(--bg-primary);
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.arrivals-table th,
.arrivals-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.arrivals-table th {
    background-color: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-primary);
}

.arrivals-table tr:hover {
    background-color: var(--bg-secondary);
}

.line {
    font-weight: 600;
    text-align: center;
    min-width: 60px;
}

.line.red {
    background-color: #e53e3e;
    color: white;
    border-radius: 0.25rem;
    padding: 0.25rem 0.5rem;
}

.line.gold {
    background-color: #d69e2e;
    color: white;
    border-radius: 0.25rem;
    padding: 0.25rem 0.5rem;
}

.line.blue {
    background-color: #3182ce;
    color: white;
    border-radius: 0.25rem;
    padding: 0.25rem 0.5rem;
}

.line.green {
    background-color: #38a169;
    color: white;
    border-radius: 0.25rem;
    padding: 0.25rem 0.5rem;
}

.direction {
    font-weight: 500;
}

.direction.north {
    color: #3182ce;
}

.direction.south {
    color: #e53e3e;
}

.direction.east {
    color: #38a169;
}

.direction.west {
    color: #d69e2e;
}

.destination {
    font-weight: 500;
}

.minutes {
    font-weight: 600;
    color: var(--accent-primary);
}

.platform {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Mobile Styles */
@media (max-width: 768px) {
    .main {
        flex-direction: column;
    }
    
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 280px;
        z-index: 200;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar-toggle {
        display: block; /* Show on mobile */
    }
    
    .arrivals-panel {
        padding: 0.75rem;
    }
    
    .app-title {
        font-size: 1.25rem;
    }
    
    .header {
        padding: 0.75rem;
    }
    
    .arrivals-table {
        font-size: 0.875rem;
    }
    
    .arrivals-table th,
    .arrivals-table td {
        padding: 0.5rem;
    }
    
    .install-btn {
        font-size: 0.75rem;
        padding: 0.375rem 0.5rem;
    }
}

@media (max-width: 480px) {
    .arrivals-table th,
    .arrivals-table td {
        padding: 0.375rem;
        font-size: 0.75rem;
    }
    
    .station-item {
        padding: 0.5rem 0.75rem;
    }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 150;
    display: none;
}

.sidebar-overlay.active {
    display: block;
}

/* iOS Install Banner */
.ios-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--accent-primary);
    color: white;
    padding: 0.75rem;
    z-index: 300;
    box-shadow: var(--shadow-lg);
}

.banner-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.banner-dismiss {
    background: none;
    border: none;
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.25rem;
    transition: background-color 0.2s ease;
}

.banner-dismiss:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Error Toast */
.error-toast {
    position: fixed;
    top: 1rem;
    right: 1rem;
    background-color: #e53e3e;
    color: white;
    padding: 1rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    z-index: 400;
    max-width: 300px;
}

.toast-content {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
}

.toast-dismiss {
    background: none;
    border: none;
    color: white;
    font-size: 1rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.25rem;
    transition: background-color 0.2s ease;
}

.toast-dismiss:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Loading Animation */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--border-color);
    border-top: 2px solid var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Focus styles */
button:focus,
input:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Favorite Bar */
.favorite-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 0.75rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    z-index: 200;
    box-shadow: var(--shadow-lg);
}

.favorite-list {
    display: flex;
    gap: 0.5rem;
    flex: 1;
    overflow-x: auto;
}

.favorite-item {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 120px;
    flex-shrink: 0;
}

.favorite-item:hover {
    background-color: var(--bg-tertiary);
    border-color: var(--accent-primary);
}

.favorite-name {
    font-weight: 500;
    font-size: 0.875rem;
    margin-bottom: 0.125rem;
}

.favorite-code {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.favorite-refresh-btn {
    background: var(--accent-primary);
    color: white;
    border: none;
    padding: 0.5rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
}

.favorite-refresh-btn:hover {
    background: var(--accent-secondary);
}

/* Adjust main content to account for favorite bar */
.main {
    padding-bottom: 60px; /* Space for favorite bar */
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3);
    }
    
    [data-theme="dark"] {
        --border-color: #ffffff;
    }
}
