* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    background: white;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

h1 {
    color: #d71920;
    margin-bottom: 24px;
    text-align: center;
    font-size: 28px;
}

.tab-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}

.tab-btn {
    flex: 1;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: #666;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    margin-bottom: -2px;
}

.tab-btn:hover {
    color: #d71920;
    background: #f8f9fa;
}

.tab-btn.active {
    color: #d71920;
    border-bottom-color: #d71920;
    background: transparent;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

select, button {
    padding: 12px 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    background: white;
    cursor: pointer;
    transition: all 0.3s;
}

select:hover:not(:disabled), button:hover:not(:disabled) {
    border-color: #d71920;
}

select:disabled, button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button {
    background: #d71920;
    color: white;
    font-weight: 600;
    border: none;
}

button:hover:not(:disabled) {
    background: #b81519;
}

#status, #lrtStatus {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 16px;
    text-align: center;
    font-weight: 500;
}

#status.loading, #lrtStatus.loading {
    background: #fff3cd;
    color: #856404;
}

#status.success, #lrtStatus.success {
    background: #d4edda;
    color: #155724;
}

#status.error, #lrtStatus.error {
    background: #f8d7da;
    color: #721c24;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.section-header h2 {
    color: #d71920;
    font-size: 22px;
    margin: 0;
}

.refresh-all-btn {
    padding: 8px 16px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.refresh-all-btn:hover {
    background: #218838;
}

.favorites-section {
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 3px solid #e0e0e0;
}

.favorite-card {
    background: #f8f9fa;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 12px;
    transition: all 0.3s;
}

.favorite-card.collapsed {
    padding: 10px 12px;
}

.favorite-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    margin-bottom: 8px;
}

.favorite-card.collapsed .favorite-header {
    margin-bottom: 6px;
}

.favorite-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
}

.favorite-title h3 {
    color: #333;
    font-size: 16px;
    margin: 0;
    word-break: keep-all;
    overflow-wrap: break-word;
    line-height: 1.3;
}

.favorite-summary {
    display: none;
    margin-top: 4px;
}

.favorite-card.collapsed .favorite-summary {
    display: block;
}

.favorite-summary-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    background: white;
    border-radius: 6px;
    margin-bottom: 4px;
    font-size: 13px;
}

.favorite-summary-item:last-child {
    margin-bottom: 0;
}

.summary-destination {
    color: #666;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.summary-destination-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.summary-time {
    color: #28a745;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
    margin-left: 8px;
}

.summary-no-data {
    color: #999;
    font-size: 12px;
    padding: 6px 8px;
    text-align: center;
}

.favorite-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.expand-btn {
    background: transparent;
    border: none;
    color: #666;
    font-size: 20px;
    width: 32px;
    height: 32px;
    padding: 0;
    cursor: pointer;
    transition: transform 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.favorite-card.collapsed .expand-btn {
    transform: rotate(-90deg);
}

.remove-fav-btn {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 6px;
    width: 32px;
    height: 32px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.remove-fav-btn::before {
    content: '×';
    font-size: 24px;
    line-height: 1;
}

.remove-fav-btn:hover {
    background: #c82333;
    transform: scale(1.1);
}

/* Favorite card status - always visible */
.favorite-status {
    font-size: 11px;
    color: #888;
    margin-top: 8px;
    padding: 4px 0;
}

.favorite-status.loading {
    color: #856404;
}

.favorite-status.success {
    color: #155724;
}

.favorite-status.error {
    color: #721c24;
}

/* Show status even when collapsed */
.favorite-card.collapsed .favorite-status {
    display: block;
    border-top: 1px solid #eee;
    padding-top: 6px;
}

/* Hide detailed results when collapsed */
.favorite-card.collapsed .favorite-results {
    display: none;
}

.favorite-results {
    margin-top: 8px;
}

.favorite-results .direction {
    margin-bottom: 8px;
    padding: 10px;
    background: white;
    border: 1px solid #e0e0e0;
}

.favorite-results .direction h3 {
    font-size: 14px;
    margin-bottom: 8px;
    padding-bottom: 6px;
}

.favorite-results .train-item {
    padding: 8px;
    margin-bottom: 6px;
    font-size: 13px;
}

.favorite-results .train-number {
    font-size: 12px;
    min-width: 50px;
}

.favorite-results .train-details {
    font-size: 13px;
}

.favorite-results .time {
    font-size: 14px;
}

.favorite-results .countdown {
    font-size: 12px;
}

.line-badge {
    background: #d71920;
    color: white;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
}

.manual-section h2 {
    color: #d71920;
    font-size: 22px;
    margin-bottom: 16px;
}

.station-search-wrapper {
    position: relative;
    flex: 1;
}

#stationSearch, #lrtStationSearch {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    background: white;
    transition: all 0.3s;
}

#stationSearch:focus, #lrtStationSearch:focus {
    outline: none;
    border-color: #d71920;
}

#stationSearch:disabled, #lrtStationSearch:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #f5f5f5;
}

.station-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 2px solid #d71920;
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 300px;
    overflow-y: auto;
    display: none;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.station-dropdown.show {
    display: block;
}

.station-option {
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid #f0f0f0;
}

.station-option:hover,
.station-option.highlighted {
    background: #f8f9fa;
}

.station-option:last-child {
    border-bottom: none;
}

.station-option-text {
    font-size: 15px;
    color: #333;
}

.no-results {
    padding: 12px 16px;
    color: #999;
    text-align: center;
    font-style: italic;
}

.star-btn {
    width: 60px;
    background: white;
    color: #ffc107;
    border: 2px solid #ffc107;
    font-size: 24px;
    padding: 8px;
    transition: all 0.3s;
}

.star-btn:hover:not(:disabled) {
    background: #ffc107;
    color: white;
    transform: scale(1.1);
}

.star-btn.starred {
    background: #ffc107;
    color: white;
    border-color: #ffc107;
}

.star-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.direction {
    margin-bottom: 24px;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    padding: 16px;
    background: #f8f9fa;
}

.direction h2, .direction h3 {
    color: #333;
    font-size: 18px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid #d71920;
    word-wrap: break-word;
    line-height: 1.4;
}

.train-item {
    background: white;
    padding: 12px;
    margin-bottom: 8px;
    border-radius: 8px;
    border-left: 4px solid #d71920;
    display: flex;
    align-items: center;
    gap: 12px;
}

.train-number {
    font-weight: 700;
    color: #d71920;
    font-size: 14px;
    min-width: 60px;
}

.train-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 14px;
}

.arrival-info {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.time {
    font-weight: 700;
    color: #28a745;
    font-size: 16px;
}

.countdown {
    font-weight: 600;
    color: #007bff;
    font-size: 14px;
}

.countdown.arriving {
    color: #ffc107;
    font-weight: 700;
    animation: pulse 1s infinite;
}

.countdown.departed {
    color: #6c757d;
    font-weight: 500;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

@media (min-width: 768px) {
    .controls {
        flex-direction: row;
    }
    
    select {
        flex: 1;
    }
    
    button {
        width: auto;
    }
    
    .star-btn {
        width: 60px;
    }
}

@media (max-width: 767px) {
    .container {
        padding: 12px;
    }
    
    h1 {
        font-size: 22px;
        margin-bottom: 16px;
    }
    
    .tab-btn {
        padding: 10px 12px;
        font-size: 15px;
    }
    
    .section-header h2 {
        font-size: 18px;
    }
    
    .manual-section h2 {
        font-size: 18px;
        margin-bottom: 12px;
    }
    
    .favorite-title h3 {
        font-size: 15px;
    }
    
    .controls {
        gap: 10px;
    }
    
    select, #stationSearch, #lrtStationSearch {
        padding: 10px 12px;
        font-size: 15px;
    }
    
    .station-dropdown {
        max-height: 200px;
    }
    
    .direction {
        padding: 12px;
        margin-bottom: 16px;
    }
    
    .train-item {
        padding: 10px;
        gap: 10px;
    }
}
