/* Mobile-First Responsive Design */
* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f4f7f6;
    color: #333;
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    width: 100%;
    max-width: 600px;
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: box-shadow 0.3s ease;
}

@media (min-width: 768px) {
    .container {
        padding: 30px;
    }
}

header {
    text-align: center;
    border-bottom: 1px solid #eee;
    padding-bottom: 15px;
    margin-bottom: 20px;
}

header > div {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 15px;
    flex-wrap: wrap;
}

header > div > div:first-child {
    flex: 1;
    min-width: 0;
}

header h1 {
    margin: 0;
    font-size: 1.8em;
    color: #0078c3;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Language selector */
.language-selector {
    flex-shrink: 0;
}

.language-selector select {
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    font-size: 0.9em;
    color: #333;
    cursor: pointer;
    transition: all 0.2s ease;
}

.language-selector select:hover {
    border-color: #0078c3;
}

.language-selector select:focus {
    outline: none;
    border-color: #0078c3;
    box-shadow: 0 0 0 2px rgba(0, 120, 195, 0.1);
}

.logo {
    height: 40px;
    width: auto;
    object-fit: contain;
}

header p {
    margin: 5px 0 0;
    color: #666;
}

.selection-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#station-select {
    width: 100%;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 1em;
    background-color: #fff;
}

#results-container {
    margin-top: 25px;
    min-height: 50px;
}

.loading {
    text-align: center;
    color: #666;
    padding: 20px;
    font-style: italic;
    animation: pulse 1.5s ease-in-out infinite;
}

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

.line-info {
    margin-bottom: 20px;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
}

.line-header {
    padding: 10px 15px;
    font-weight: bold;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.train-list {
    padding: 15px;
    background-color: #f9f9f9;
}

.train {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #eee;
}

.train:last-child {
    border-bottom: none;
}

.train-destination {
    font-weight: 500;
}

.train-arrival {
    font-weight: bold;
    color: #d9534f;
    transition: color 0.3s ease;
}

.train-arrival .countdown {
    font-weight: normal;
    color: #666;
    font-size: 0.9em;
}

.train-arrival.arriving-now {
    color: #5cb85c;
    animation: blink 1s ease-in-out infinite;
}

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

.error {
    color: #d9534f;
    margin-top: 20px;
    padding: 12px;
    text-align: center;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    font-weight: 500;
    display: none;
}

.error:not(:empty) {
    display: block;
}

#timestamp-container {
    text-align: right;
    font-size: 0.9em;
    color: #666;
    margin-top: 15px;
    min-height: 20px;
}

#timestamp-container:empty {
    display: none;
}

.timestamp-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.line-indicators-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 4px;
}

.line-indicators-left {
    display: flex;
    align-items: center;
    flex: 1;
}

.buttons-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.line-indicators {
    display: flex;
    gap: 6px;
    justify-content: flex-start;
    flex-wrap: wrap;
}

.line-indicator {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    color: white;
    font-weight: 600;
    font-size: 0.85em;
    min-width: 32px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    outline: none;
}

.line-indicator:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.line-indicator:active {
    transform: scale(0.95);
}

.line-indicator.active {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.5), 0 2px 8px rgba(0, 0, 0, 0.4);
    transform: scale(1.15);
    font-weight: 700;
}

.line-indicator:focus {
    outline: 2px solid rgba(255, 255, 255, 0.8);
    outline-offset: 2px;
}

footer {
    text-align: center;
    margin-top: 30px;
    padding-top: 15px;
    border-top: 1px solid #eee;
    color: #999;
    font-size: 0.9em;
}

.version {
    margin-left: 8px;
    opacity: 0.7;
    font-weight: 500;
}

.copy-link-btn {
    background: transparent;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 8px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    transition: all 0.2s ease;
    min-width: 36px;
    height: 36px;
}

.copy-link-btn:hover {
    background-color: #f5f5f5;
    border-color: #0078c3;
    color: #0078c3;
}

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

.copy-link-btn.copied {
    background-color: #5cb85c;
    border-color: #5cb85c;
    color: white;
}

/* Refresh Button */
.refresh-btn {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 8px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #495057;
    transition: all 0.2s ease;
    min-width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.refresh-btn:hover {
    background-color: #e9ecef;
    border-color: #0078c3;
    color: #0078c3;
    transform: scale(1.05);
}

.refresh-btn:active {
    transform: rotate(180deg) scale(0.95);
    transition: transform 0.3s ease;
}

.refresh-btn svg {
    width: 18px;
    height: 18px;
}

/* Favorites Section */
.favorites-section {
    margin-bottom: 20px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.favorites-header {
    font-size: 0.9em;
    font-weight: 600;
    color: #495057;
    margin-bottom: 10px;
}

.favorites-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.favorite-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 0 0 auto;
}

.favorite-item:hover {
    background: #f8f9fa;
    border-color: #0078c3;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

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

.favorite-name {
    font-size: 0.9em;
    font-weight: 500;
    color: #212529;
}

.favorite-lines {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.favorite-line-indicator {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    color: white;
    font-weight: 600;
    font-size: 0.75em;
}

.favorite-remove {
    background: transparent;
    border: none;
    color: #6c757d;
    font-size: 1.2em;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.favorite-remove:hover {
    background: #dc3545;
    color: white;
}

.favorite-btn {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 8px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    transition: all 0.2s ease;
    min-width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.favorite-btn:hover {
    background-color: #e9ecef;
    border-color: #0078c3;
    color: #0078c3;
}

.favorite-btn.active {
    background-color: #fff3cd;
    border-color: #ffc107;
    color: #856404;
}

.favorite-btn.active:hover {
    background-color: #ffe69c;
    border-color: #ffc107;
}

.favorite-btn svg {
    width: 18px;
    height: 18px;
}

/* Dropdown line indicators */
.choices__item--choice {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
}

.choices-station-name {
    flex: 1;
    min-width: 0; /* Allow text truncation */
}

.choices-line-indicators {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    flex-shrink: 0;
    margin-left: 8px;
}

.dropdown-line-indicator {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    color: white;
    font-weight: 600;
    font-size: 0.7em;
    line-height: 1.3;
    white-space: nowrap;
}

/* Dropdown list styling - fixed height and scrollable */
.choices__list--dropdown {
    max-height: 320px; /* Show ~8 items, rest scrollable */
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    margin-top: 4px !important; /* Add spacing between input and dropdown */
}

/* Force dropdown to always be below (override Choices.js auto positioning) */
.choices[data-type*="select-one"] .choices__list--dropdown,
.choices[data-type*="select-multiple"] .choices__list--dropdown {
    top: 100% !important;
    bottom: auto !important;
    margin-top: 4px !important;
}

.choices__list--dropdown .choices__item--choice {
    padding: 10px 12px;
}

/* Search box styling */
.choices__inner {
    position: relative;
}

.choices__input--cloned {
    margin: 0;
    padding: 8px 10px;
}

/* Hide line indicators in selected display */
.choices__list--single .choices__item .choices-line-indicators {
    display: none;
}

.choices__list--single .choices__item {
    display: block;
}

/* Search input styling - make it clearly visible */
.choices__list--dropdown .choices__input {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #f8f9fa;
    border: 2px solid #0078c3;
    border-radius: 4px;
    margin: 8px;
    padding: 10px 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    font-size: 0.95em;
    outline: none;
}

.choices__list--dropdown .choices__input:focus {
    border-color: #005a8f;
    box-shadow: 0 0 0 3px rgba(0, 120, 195, 0.1);
}

/* Add a visual indicator that this is the search field */
.choices__list--dropdown .choices__input::placeholder {
    color: #6c757d;
    font-style: italic;
}

/* Responsive adjustments */
@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    .container {
        padding: 12px;
        max-width: 100%;
    }
    
    header {
        padding-bottom: 12px;
        margin-bottom: 15px;
    }
    
    header h1 {
        font-size: 1.4em;
        gap: 8px;
    }
    
    .logo {
        height: 30px;
    }
    
    header p {
        font-size: 0.9em;
        margin-top: 4px;
    }
    
    .selection-form {
        gap: 12px;
    }
    
    #station-select {
        padding: 10px;
        font-size: 0.95em;
    }
    
    #results-container {
        margin-top: 20px;
    }
    
    .line-info {
        margin-bottom: 15px;
    }
    
    .line-header {
        padding: 8px 12px;
        font-size: 0.9em;
        flex-wrap: wrap;
        gap: 4px;
    }
    
    .line-header span:first-child {
        font-size: 1em;
    }
    
    .line-header span:last-child {
        font-size: 0.85em;
        opacity: 0.95;
    }
    
    .train-list {
        padding: 12px;
    }
    
    .train {
        padding: 8px 0;
        font-size: 0.9em;
    }
    
    .train-destination {
        font-size: 0.9em;
    }
    
    .train-arrival {
        font-size: 0.95em;
    }
    
    .train-arrival .countdown {
        font-size: 0.8em;
    }
    
    #timestamp-container {
        font-size: 0.85em;
        margin-top: 12px;
        text-align: left;
    }
    
    .line-indicators-wrapper {
        justify-content: space-between;
        margin-top: 6px;
        gap: 8px;
    }
    
    .line-indicators-left {
        flex: 1;
    }
    
    .buttons-right {
        gap: 6px;
    }
    
    .line-indicators {
        justify-content: flex-start;
        gap: 5px;
    }
    
    .line-indicator {
        padding: 3px 6px;
        font-size: 0.8em;
        min-width: 28px;
        cursor: pointer;
    }
    
    .line-indicator:hover {
        transform: scale(1.05);
    }
    
    .line-indicator.active {
        transform: scale(1.1);
        font-weight: 700;
    }
    
    footer {
        margin-top: 20px;
        padding-top: 12px;
        font-size: 0.85em;
    }
    
    .error {
        margin-top: 15px;
        padding: 10px;
        font-size: 0.9em;
    }
    
    .loading {
        padding: 15px;
        font-size: 0.9em;
        animation: pulse 0.8s ease-in-out infinite;
    }
    
    .copy-link-btn {
        padding: 6px 8px;
        min-width: 32px;
        height: 32px;
    }
    
    .copy-link-btn svg {
        width: 14px;
        height: 14px;
    }
    
    .timestamp-content {
        gap: 6px;
    }
    
    .line-indicators-wrapper {
        gap: 8px;
        margin-top: 4px;
    }
    
    .refresh-btn {
        padding: 6px 8px;
        min-width: 32px;
        height: 32px;
    }
    
    .refresh-btn svg {
        width: 16px;
        height: 16px;
    }
    
    .favorite-btn {
        min-width: 32px;
        height: 32px;
        padding: 6px 8px;
    }
    
    .favorite-btn svg {
        width: 16px;
        height: 16px;
    }
    
    .favorites-section {
        padding: 10px;
        margin-bottom: 15px;
    }
    
    .favorite-item {
        padding: 6px 10px;
        font-size: 0.85em;
    }
    
    .favorite-name {
        font-size: 0.85em;
    }
    
    .favorite-line-indicator {
        padding: 2px 5px;
        font-size: 0.7em;
    }
    
    /* Mobile search input styling */
    .choices__list--dropdown .choices__input {
        margin: 6px;
        padding: 8px 10px;
        font-size: 0.9em;
    }
    
    /* Faster animations for mobile */
    .container {
        transition: box-shadow 0.15s ease;
    }
    
    .train-arrival {
        transition: color 0.15s ease;
    }
    
    .train-arrival.arriving-now {
        animation: blink 0.6s ease-in-out infinite;
    }
}

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

/* Focus styles for accessibility */
select:focus,
button:focus {
    outline: 2px solid #0078c3;
    outline-offset: 2px;
}
