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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

.app-container {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    color: white;
    padding: 1rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.header-link {
    color: white;
    text-decoration: none;
    padding: 0.5rem;
    border-radius: 6px;
    transition: background-color 0.2s ease;
}

.header-link:hover {
    background: rgba(255, 255, 255, 0.1);
}

.app-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #e74c3c;
    animation: pulse 2s infinite;
}

.status-indicator.connected {
    background: #27ae60;
}

.status-indicator.connecting {
    background: #f39c12;
}

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

/* Direction Selection */
.direction-section {
    padding: 1rem 1rem 0.5rem 1rem;
    background: white;
    border-bottom: 1px solid #e1e8ed;
}

.direction-label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: #2c3e50;
    font-size: 0.875rem;
}

.direction-select {
    width: 100%;
    padding: 0.5rem;
    border: 2px solid #e1e8ed;
    border-radius: 6px;
    font-size: 0.875rem;
    background: white;
    transition: border-color 0.2s ease;
}

.direction-select:focus {
    outline: none;
    border-color: #3498db;
}

/* Station Selection */
.station-section {
    padding: 0.5rem 1rem 1rem 1rem;
    background: white;
    border-bottom: 1px solid #e1e8ed;
}

.station-label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: #2c3e50;
}

.station-select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e1e8ed;
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    transition: border-color 0.2s ease;
}

.station-select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}

.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: #2c3e50;
    border-bottom: 2px solid #e1e8ed;
    padding-bottom: 0.5rem;
}

.trains-section {
    margin-bottom: 2rem;
}

.trains-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Train Cards */
.train-card {
    background: white;
    border-radius: 8px;
    padding: 0.75rem;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    border-left: 3px solid #27ae60;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    margin-bottom: 0.5rem;
}

.train-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.train-card.delayed {
    border-left-color: #e74c3c;
}

.train-card.early {
    border-left-color: #f39c12;
}

.train-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.train-number {
    font-size: 1rem;
    font-weight: 600;
    color: #2c3e50;
}

.train-direction {
    font-size: 0.75rem;
    color: #7f8c8d;
    font-weight: 500;
}

.train-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.detail-item {
    display: flex;
    flex-direction: column;
}

.detail-label {
    font-size: 0.7rem;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}

.detail-value {
    font-weight: 500;
    color: #2c3e50;
}

.train-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.75rem;
    border-top: 1px solid #e1e8ed;
}

.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-badge.on-time {
    background: #d5f4e6;
    color: #27ae60;
}

.status-badge.delayed {
    background: #fadbd8;
    color: #e74c3c;
}

.status-badge.early {
    background: #fef9e7;
    color: #f39c12;
}

.delay-time {
    font-weight: 600;
    font-size: 1.125rem;
}

.delay-time.positive {
    color: #e74c3c;
}

.delay-time.negative {
    color: #f39c12;
}

.delay-time.zero {
    color: #27ae60;
}

/* Loading States */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: #7f8c8d;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e1e8ed;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Visualization Section */
.visualization-section {
    margin-bottom: 2rem;
}

.chart-container {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-placeholder {
    text-align: center;
    color: #7f8c8d;
}

/* Delay Visualization */
.delay-stats {
    width: 100%;
}

.delay-bars {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.delay-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.delay-label {
    min-width: 60px;
    font-size: 0.875rem;
    font-weight: 500;
    color: #2c3e50;
}

.delay-bar-container {
    flex: 1;
    height: 20px;
    background: #e1e8ed;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

.delay-bar-fill {
    height: 100%;
    border-radius: 10px;
    transition: width 0.3s ease;
    position: relative;
}

.delay-bar-fill.on-time {
    background: linear-gradient(90deg, #27ae60, #2ecc71);
}

.delay-bar-fill.delayed {
    background: linear-gradient(90deg, #e74c3c, #c0392b);
}

.delay-bar-fill.early {
    background: linear-gradient(90deg, #f39c12, #e67e22);
}

.delay-percent {
    min-width: 40px;
    text-align: right;
    font-size: 0.875rem;
    font-weight: 600;
    color: #2c3e50;
}

/* Footer */
.app-footer {
    background: white;
    border-top: 1px solid #e1e8ed;
    padding: 1rem;
    margin-top: auto;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.last-updated {
    font-size: 0.875rem;
    color: #7f8c8d;
}

.refresh-btn {
    background: #667eea;
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.refresh-btn:hover {
    background: #5a6fd8;
    transform: scale(1.05);
}

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

.refresh-icon {
    width: 20px;
    height: 20px;
}

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

/* Error States */
.error-state {
    background: #fadbd8;
    color: #e74c3c;
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
    margin: 1rem 0;
}

/* Empty States */
.empty-state {
    text-align: center;
    padding: 2rem;
    color: #7f8c8d;
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Responsive Design */
@media (max-width: 480px) {
    .app-container {
        margin: 0;
        border-radius: 0;
    }
    
    .main-content {
        padding: 0.75rem;
    }
    
    .train-details {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    
    .app-title {
        font-size: 1.25rem;
    }
}

/* Toast Notifications */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 280px;
    max-width: 400px;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.toast.toast-show {
    transform: translateX(0);
}

.toast-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
}

.toast-message {
    font-size: 0.875rem;
    color: #2c3e50;
    flex: 1;
}

.toast-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: #7f8c8d;
    cursor: pointer;
    padding: 0;
    margin-left: 12px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.toast-close:hover {
    background: #f1f2f6;
    color: #2c3e50;
}

.toast-success {
    border-left: 4px solid #27ae60;
}

.toast-warning {
    border-left: 4px solid #f39c12;
}

.toast-error {
    border-left: 4px solid #e74c3c;
}

.toast-info {
    border-left: 4px solid #3498db;
}

/* Enhanced Mobile Responsiveness */
@media (max-width: 480px) {
    .toast {
        top: 10px;
        right: 10px;
        left: 10px;
        min-width: auto;
        max-width: none;
    }
    
    .app-container {
        margin: 0;
        border-radius: 0;
    }
    
    .main-content {
        padding: 0.75rem;
    }
    
    .train-details {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    
    .app-title {
        font-size: 1.25rem;
    }
    
    .section-title {
        font-size: 1.125rem;
    }
    
    .train-card {
        padding: 0.875rem;
    }
    
    .station-select {
        font-size: 0.9rem;
        padding: 0.625rem;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    body {
        background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    }
    
    .app-container {
        background: rgba(30, 30, 46, 0.95);
        color: #e1e8ed;
    }
    
    .station-section,
    .app-footer {
        background: #2c3e50;
        border-color: #34495e;
    }
    
    .train-card,
    .chart-container {
        background: #34495e;
        color: #e1e8ed;
    }
    
    .section-title {
        color: #e1e8ed;
        border-color: #34495e;
    }
    
    .direction-select,
    .station-select {
        background: #34495e;
        border-color: #34495e;
        color: #e1e8ed;
    }
    
    .direction-select:focus,
    .station-select:focus {
        border-color: #667eea;
    }
    
    .toast {
        background: #34495e;
        color: #e1e8ed;
    }
    
    .toast-message {
        color: #e1e8ed;
    }
    
    .toast-close {
        color: #bdc3c7;
    }
    
    .toast-close:hover {
        background: #2c3e50;
        color: #e1e8ed;
    }
    
    .delay-label {
        color: #e1e8ed;
    }
    
    .delay-bar-container {
        background: #2c3e50;
    }
    
    .delay-percent {
        color: #e1e8ed;
    }
}

/* DOM Update Manager Animations */

/* Base transitions for smooth updates */
.train-card {
    transition: opacity 0.3s ease, transform 0.3s ease, background-color 0.2s ease;
}

.train-list-item {
    transition: opacity 0.3s ease, transform 0.3s ease, box-shadow 0.2s ease;
}

/* New element animation */
.train-card.new,
.train-list-item.new {
    animation: fadeInUp 0.5s ease;
}

/* Removing element animation */
.train-card.removing,
.train-list-item.removing {
    animation: fadeOutDown 0.3s ease forwards;
}

/* Updating element animation */
.train-card.updating,
.train-list-item.updating {
    opacity: 0.7;
    transform: scale(0.98);
}

/* Loading overlay styles */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: inherit;
}

.loading-overlay.visible {
    opacity: 1;
}

.loading-overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    text-align: center;
}

.loading-overlay-content p {
    color: #7f8c8d;
    font-size: 0.875rem;
    margin: 0;
}

/* Smooth scroll behavior */
.trains-container {
    scroll-behavior: smooth;
}

/* Animation keyframes */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOutDown {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-20px);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* Skeleton loading animation for better perceived performance */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Enhanced hover effects for better feedback */
.train-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.train-list-item:hover {
    transform: translateY(-1px);
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .train-card,
    .train-list-item,
    .loading-overlay {
        transition: none;
    }
    
    .train-card.new,
    .train-list-item.new,
    .train-card.removing,
    .train-list-item.removing {
        animation: none;
    }
    
    .skeleton {
        animation: none;
        background: #f0f0f0;
    }
}
