/* ==========================================================================
   TIMETABLES STYLES - REDESIGNED FOR HIGH URGENCY, TASK-ORIENTED USE
   Focus: Speed, Clarity, Accessibility, Outdoor Readability
   ========================================================================== */

/* ==========================================================================
   TIMETABLE LINE SELECTOR
   ========================================================================== */

.line-selector-wrapper {
    margin-bottom: var(--space-6);
}

#line-select {
    width: 100%;
    max-width: 500px;
    padding: 14px 48px 14px 16px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    background-color: var(--surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%231a4d73' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
    transition:
        border-color var(--transition-fast),
        box-shadow var(--transition-fast);
}

#line-select:hover {
    border-color: var(--accent);
}

#line-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(43, 110, 168, 0.22);
}

#line-select option {
    padding: 12px;
    font-size: 16px;
}

#line-select optgroup {
    font-weight: 700;
    color: var(--color-primary);
}

/* ==========================================================================
   TIMETABLE CONTROLS - COMPACT LAYOUT
   ========================================================================== */

.timetable-controls {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
    margin-bottom: var(--space-8);
    max-width: 800px;
}

/* Control row - stacked vertically on all screen sizes to prevent shifting */
.timetable-control-row {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

/* ==========================================================================
   SEGMENTED CONTROLS - DIRECTION & DAY TOGGLES
   ========================================================================== */

.direction-toggle,
.day-toggle {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.direction-toggle p,
.day-toggle p,
.timetable-control-label {
    margin: 0;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Segmented control container */
.direction-buttons,
.day-buttons {
    display: inline-flex;
    background-color: var(--surface-2);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 4px;
    gap: 4px;
    position: relative;
}

/* Individual toggle buttons */
.direction-btn,
.day-btn {
    padding: 12px 20px;
    border: 1px solid transparent;
    background-color: transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: all 180ms ease;
    color: var(--text-secondary);
    min-height: 48px;
    text-align: center;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.direction-btn:hover,
.day-btn:hover {
    color: var(--text-primary);
    background-color: var(--surface-3);
    border-color: var(--border-subtle);
}

/* Active state - strong visual distinction */
.direction-btn.active,
.day-btn.active {
    background-color: var(--accent-soft);
    border-color: var(--accent);
    color: var(--text-primary);
    box-shadow: none;
    font-weight: 700;
}

.direction-btn.active:hover,
.day-btn.active:hover {
    background-color: var(--accent-soft);
    border-color: var(--accent-strong);
}

/* Focus states for accessibility */
.direction-btn:focus-visible,
.day-btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Swap direction button */
.direction-swap-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--border-subtle);
    background-color: var(--surface-2);
    border-radius: var(--radius-full);
    cursor: pointer;
    color: var(--color-primary);
    transition: all var(--transition-fast);
    flex-shrink: 0;
    align-self: center;
    margin: 0 4px;
}

.direction-swap-btn:hover {
    background-color: var(--accent-soft);
    color: var(--accent);
    border-color: var(--accent);
    transform: rotate(180deg);
}

.direction-swap-btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.direction-swap-btn i {
    font-size: 16px;
}

/* Direction buttons wrapper with swap */
.direction-buttons-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ==========================================================================
   TIMETABLE NOTES / WARNINGS
   ========================================================================== */

.timetable-notes {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    background-color: #fef3c7;
    border: 2px solid var(--color-warning);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    margin-bottom: var(--space-6);
    font-size: 15px;
    line-height: 1.6;
}

.notes-icon {
    color: var(--color-warning);
    font-size: 20px;
    margin-top: 2px;
    flex-shrink: 0;
}

.notes-content {
    flex: 1;
}

.notes-content strong {
    color: #92400e;
    display: block;
    margin-bottom: var(--space-1);
    font-weight: 700;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.notes-content p {
    margin: 0;
    color: #78350f;
    font-weight: 500;
}

/* ==========================================================================
   TIMETABLE TABLE - IMPROVED READABILITY
   ========================================================================== */

.timetable-container {
    max-width: 800px;
    margin: 0 auto;
}

.hours-minutes-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background-color: var(--surface-2);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: none;
    border: 1px solid var(--border-subtle);
}

/* Table header */
.hours-minutes-table thead th {
    background-color: var(--accent);
    color: var(--color-white);
    padding: 16px 20px;
    text-align: left;
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.hours-minutes-table thead th:first-child {
    width: 80px;
    text-align: center;
}

/* Table rows */
.hours-minutes-table tbody tr {
    transition: background-color var(--transition-fast);
}

.hours-minutes-table tbody tr:not(:last-child) {
    border-bottom: 1px solid var(--border-subtle);
}

/* Subtle row separators */
.hours-minutes-table tbody tr:nth-child(even) {
    background-color: var(--surface-1);
}

/* Current hour row highlight */
.hours-minutes-table tbody tr.current-hour {
    background-color: var(--accent-soft);
}

.hours-minutes-table tbody tr.current-hour td {
    border-top: 1px solid var(--accent);
    border-bottom: 1px solid var(--accent);
}

/* Hour cell - strong visual anchor */
.hour-cell {
    width: 80px;
    padding: 16px 12px;
    text-align: center;
    vertical-align: middle;
    background-color: var(--accent);
    color: var(--color-white);
    font-size: 20px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    position: relative;
}

/* Accent bar on hour cell */
.hour-cell::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background-color: var(--accent-strong);
}

/* Minutes cell */
.minutes-cell {
    padding: 12px 16px;
    vertical-align: middle;
}

.minutes-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

/* Minute pills - improved design */
.minute-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    min-width: 48px;
    min-height: 40px;
    background-color: var(--surface-1);
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    transition: all var(--transition-fast);
}

/* Past departures - faded */
.minute-box.past {
    background-color: var(--surface-2);
    color: var(--text-light);
    border-color: var(--border-color);
    opacity: 0.6;
}

/* Next departure - strong highlight */
.minute-box.next {
    background-color: #2f8a57;
    color: #ecfff4;
    border-color: #256b43;
    border-width: 2px;
    font-weight: 800;
    font-size: 18px;
    min-width: 52px;
    min-height: 44px;
    box-shadow: 0 4px 10px rgba(22, 64, 45, 0.32);
    animation: pulse-next 2s ease-in-out infinite;
}

@keyframes pulse-next {
    0%,
    100% {
        box-shadow: 0 4px 10px rgba(22, 64, 45, 0.32);
    }
    50% {
        box-shadow: 0 4px 16px rgba(22, 64, 45, 0.42);
    }
}

/* Upcoming departures */
.minute-box.upcoming {
    background-color: var(--accent-soft);
    color: var(--text-primary);
    border-color: var(--accent);
}

/* ==========================================================================
   NO SERVICE MESSAGE
   ========================================================================== */

.no-service-message {
    text-align: center;
    padding: var(--space-8);
    color: var(--text-secondary);
    font-size: 16px;
}

.no-service-message i {
    display: block;
    font-size: 48px;
    margin-bottom: var(--space-4);
    color: var(--text-light);
}

/* ==========================================================================
   RESPONSIVE STYLES - MOBILE FIRST
   ========================================================================== */

@media (max-width: 767px) {
    /* Prevent iOS zoom on focus */
    #line-select {
        font-size: 16px;
        padding: 16px 48px 16px 16px;
    }

    .timetable-controls {
        gap: var(--space-4);
        margin-bottom: var(--space-6);
    }

    /* Stack toggles vertically on mobile */
    .direction-toggle,
    .day-toggle {
        width: 100%;
    }

    /* Full-width segmented controls on mobile */
    .direction-buttons,
    .day-buttons {
        width: 100%;
        display: flex;
    }

    .direction-btn,
    .day-btn {
        flex: 1;
        padding: 14px 12px;
        font-size: 14px;
        min-height: 52px;
    }

    /* Direction buttons wrapper on mobile */
    .direction-buttons-wrapper {
        flex-wrap: wrap;
        gap: 12px;
    }

    .direction-buttons-wrapper .direction-buttons {
        order: 1;
        flex: 1 1 100%;
    }

    .direction-swap-btn {
        order: 2;
        width: 100%;
        height: 44px;
        border-radius: var(--radius-md);
        margin: 0;
    }

    .direction-swap-btn:hover {
        transform: none;
    }

    /* Table adjustments for mobile */
    .hours-minutes-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 calc(var(--space-4) * -1);
        width: calc(100% + var(--space-4) * 2);
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .hours-minutes-table thead th {
        padding: 14px 12px;
        font-size: 13px;
    }

    .hours-minutes-table thead th:first-child {
        width: 70px;
    }

    .hour-cell {
        width: 70px;
        padding: 14px 8px;
        font-size: 18px;
    }

    .minutes-cell {
        padding: 12px;
    }

    .minutes-wrapper {
        gap: 10px;
    }

    .minute-box {
        padding: 10px 14px;
        min-width: 48px;
        min-height: 48px;
        font-size: 17px;
        border-width: 1px;
    }

    .minute-box.next {
        min-width: 54px;
        min-height: 54px;
        font-size: 19px;
        border-width: 2px;
    }

    /* Notes on mobile */
    .timetable-notes {
        padding: var(--space-3);
        font-size: 14px;
        margin: 0 calc(var(--space-4) * -1) var(--space-4);
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    .direction-btn,
    .day-btn {
        padding: 14px 8px;
        font-size: 13px;
    }

    .hour-cell {
        width: 60px;
        font-size: 20px;
    }

    .minute-box {
        padding: 10px 12px;
        min-width: 50px;
        min-height: 50px;
        font-size: 18px;
    }

    .minute-box.next {
        min-width: 56px;
        min-height: 56px;
        font-size: 20px;
    }
}

/* Desktop enhancements */
@media (min-width: 768px) {
    .timetable-controls {
        max-width: 800px;
        margin: 0 auto var(--space-8);
    }

    .direction-btn,
    .day-btn {
        padding: 14px 24px;
        font-size: 15px;
        min-width: 140px;
    }

    .hour-cell {
        width: 90px;
        font-size: 22px;
    }

    .minute-box {
        padding: 10px 16px;
        min-width: 52px;
    }
}

@media (min-width: 1024px) {
    .direction-btn,
    .day-btn {
        padding: 14px 28px;
        font-size: 16px;
        min-width: 160px;
    }
}

/* ==========================================================================
   DARK MODE SUPPORT
   ========================================================================== */

[data-theme='dark'] #line-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%232f78b6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

[data-theme='dark'] #line-select:focus {
    box-shadow: 0 0 0 3px rgba(43, 110, 168, 0.24);
}

[data-theme='dark'] .direction-buttons,
[data-theme='dark'] .day-buttons {
    background-color: var(--surface-2);
    border-color: var(--border-subtle);
}

[data-theme='dark'] .direction-btn,
[data-theme='dark'] .day-btn {
    color: var(--text-secondary);
}

[data-theme='dark'] .direction-btn:hover,
[data-theme='dark'] .day-btn:hover {
    color: var(--text-primary);
    background-color: var(--surface-3);
    border-color: var(--border-subtle);
}

[data-theme='dark'] .direction-btn.active,
[data-theme='dark'] .day-btn.active {
    background-color: var(--accent-soft);
    border-color: rgba(43, 110, 168, 0.45);
    color: var(--text-primary);
    box-shadow: none;
}

[data-theme='dark'] .direction-swap-btn {
    background-color: var(--surface-2);
    border-color: var(--border-subtle);
    color: var(--accent);
}

[data-theme='dark'] .direction-swap-btn:hover {
    background-color: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

[data-theme='dark'] .timetable-notes {
    background-color: rgba(217, 119, 6, 0.15);
    border-color: var(--color-warning);
}

[data-theme='dark'] .notes-content strong {
    color: var(--color-alert-warning);
}

[data-theme='dark'] .notes-content p {
    color: var(--text-secondary);
}

[data-theme='dark'] .hours-minutes-table {
    background-color: var(--surface-2);
    border-color: var(--border-subtle);
}

[data-theme='dark'] .hours-minutes-table tbody tr:nth-child(even) {
    background-color: var(--surface-1);
}

[data-theme='dark'] .hours-minutes-table tbody tr.current-hour {
    background-color: var(--accent-soft);
}

[data-theme='dark'] .hours-minutes-table tbody tr.current-hour td {
    border-color: var(--accent);
}

[data-theme='dark'] .hour-cell {
    background-color: var(--accent);
}

[data-theme='dark'] .hour-cell::before {
    background-color: var(--accent-strong);
}

[data-theme='dark'] .minute-box {
    background-color: var(--surface-1);
    color: var(--text-primary);
    border-color: var(--border-subtle);
}

[data-theme='dark'] .minute-box.past {
    background-color: var(--surface-2);
    color: var(--text-light);
    opacity: 0.5;
}

[data-theme='dark'] .minute-box.upcoming {
    background-color: var(--accent-soft);
    border-color: var(--accent);
}

[data-theme='dark'] .minute-box.next {
    background-color: #2f8a57;
    color: #ecfff4;
    border-color: #256b43;
    box-shadow: 0 4px 10px rgba(22, 64, 45, 0.36);
}

/* ==========================================================================
   ACCESSIBILITY - VISUALLY HIDDEN
   ========================================================================== */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ==========================================================================
   SCROLL BEHAVIOR
   ========================================================================== */

.timetable-view {
    scroll-margin-top: 100px;
}

/* Smooth scroll to current hour */
.hours-minutes-table tbody tr.current-hour {
    scroll-margin-top: 120px;
}
