/* ==========================================================================
   1. CSS VARIABLES (THEMES)
   ========================================================================== */
:root {
    --bg-primary: #f5f5f5;
    --bg-secondary: white;
    --text-primary: #333;
    --text-secondary: #999;
    --border-color: #ddd;
    --header-bg: #333;
    --header-text: white;
    --hover-bg: #555;
    --row-hover: #f9f9f9;
    --radio-hover: #AAAAAA;
    --shadow: rgba(0, 0, 0, 0.1);
    --accent-colour: #002C49;
}

body.dark-mode {
    --bg-primary: #1e1e1e;
    --bg-secondary: #2d2d2d;
    --text-primary: #e0e0e0;
    --text-secondary: #999;
    --border-color: #444;
    --header-bg: #1a1a1a;
    --header-text: #e0e0e0;
    --hover-bg: #3a3a3a;
    --row-hover: #3a3a3a;
    --radio-hover: #3a3a3a;
    --shadow: rgba(0, 0, 0, 0.3);
    --accent-colour: #FFB703;
}

/* ==========================================================================
   2. GLOBAL & BASE STYLES
   ========================================================================== */
body {
    margin-top: 20px;
    font-family: "Oxanium", sans-serif;
    padding: 20px;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s, color 0.3s;
    -webkit-text-size-adjust: none;
    -moz-text-size-adjust: none;
    text-size-adjust: none;
}

h1 {
    color: var(--text-primary);
    margin: 0;
}

p {
    line-height: 1.6;
    margin-bottom: 15px;
    color: #555;
}

ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

li {
    margin-bottom: 8px;
    color: #555;
}

/* ==========================================================================
   3. LAYOUT COMPONENTS (Navbar, Header, About)
   ========================================================================== */
.navbar {
    background-color: #002C49;
    position: relative;
    padding: 0;
    top: 0;
    z-index: 10000;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.navbar-container {
    max-width: 2400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
}

.navbar-brand {
    color: white;
    font-size: 48px;
    font-weight: bold;
    text-decoration: none;
    padding: 15px 0;
}

.navbar-brand:hover {
    color: #FFB703;
}

.navbar-menu {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 30px;
}

.navbar-menu li {
    margin-left: 2rem;
}

.navbar-menu a {
    color: white;
    text-decoration: none;
    font-size: 16px;
    padding: 5px 10px;
    border-radius: 4px;
    transition: background-color 0.3s ease;
}

.navbar-menu a:hover {
    background-color: #FFB703;
    color: black;
}

.hamburger {
    display: none;
    cursor: pointer;
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    font-family: "Oxanium", monospace;
    padding: 0;
    z-index: 1000;
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.about-container {
    max-width: 800px;
    margin: 40px auto;
    background-color: white;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.quote-box {
    background-color: #f9f9f9;
    padding: 20px;
    border-left: 4px solid #d32f2f;
    margin-top: 30px;
}

/* ==========================================================================
   4. FORM CONTROLS & INPUTS
   ========================================================================== */
.filter-container {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    max-width: 1200px;
    flex-wrap: wrap;
    align-items: center;
}

/* Consolidated Input Styles */
.filter-input,
.stop-input {
    flex: 1;
    min-width: 150px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}

.filter-input::placeholder,
.stop-input::placeholder {
    color: var(--text-secondary);
}

.stop-input:disabled {
    background-color: var(--border-color);
    color: var(--text-secondary);
    cursor: not-allowed;
    opacity: 0.6;
}

/* Consolidated Button Base Styles */
.dark-mode-btn,
.stop-apply-btn {
    background-color: var(--header-bg);
    color: var(--header-text);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s;
}

.dark-mode-btn {
    padding: 10px 15px;
}

.stop-apply-btn {
    padding: 10px 20px;
}

.dark-mode-btn:hover,
.stop-apply-btn:hover:not(:disabled) {
    background-color: var(--hover-bg);
}

.stop-apply-btn:disabled {
    background-color: var(--border-color);
    color: var(--text-secondary);
    cursor: not-allowed;
    opacity: 0.6;
}

.station-dropdown {
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}

/* Filter Route Dropdown Menu */
#filter-route {
    width: 100%;
    max-width: 300px;
    padding: 12px 16px;
    font-size: 16px;
    border: 2px solid #ccc;
    border-radius: 6px;
    background-color: #ffffff;
    color: #333333;
    cursor: pointer;
    transition: all 0.3s ease;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%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;
    padding-right: 40px;
}

#filter-route:hover {
    border-color: #999;
}

#filter-route:focus {
    outline: none;
    border-color: #0066cc;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

#filter-route option {
    background-color: #ffffff;
    color: #333333;
    padding: 10px;
}

/* Radio Control Groups */
.control-group {
    margin-bottom: 1.5rem;
}

.control-group > label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
    color: var(--text-primary, #333);
}

.controls-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
}

.radio-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.radio-option {
    position: relative;
}

.radio-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    cursor: pointer;
}

.radio-option label {
    display: inline-block;
    padding: 0.75rem 1.25rem;
    border: 2px solid var(--border-color, #ccc);
    border-radius: 6px;
    background-color: var(--bg-primary, #fff);
    color: var(--text-primary, #333);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    margin: 0;
}

.radio-option input[type="radio"]:hover + label {
    border-color: var(--accent-colour, #0066cc);
    background-color: var(--radio-hover, #f0f0f0);
}

.radio-option input[type="radio"]:checked + label {
    background-color: #0066cc;
    color: white;
    border-color: var(--accent-colour, #0066cc);
    font-weight: 600;
}

.radio-option input[type="radio"]:focus + label {
    outline: 2px solid var(--accent-colour, #0066cc);
    outline-offset: 2px;
}

.show-all-container {
    border: 1px solid #444444;
    border-radius: 4px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 10px;

}

/* ==========================================================================
   5. DEPARTURE BOARD & TABLES
   ========================================================================== */
.departure-board-container {
    margin-bottom: 20px;
    padding: 15px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 2px 4px var(--shadow);
}

.departure-board-container table {
    overflow: hidden;
}

.departure-board-title {
    font-weight: bold;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.departure-board-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    align-items: center;
}

table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    background-color: var(--bg-secondary);
    box-shadow: 0 2px 4px var(--shadow);
    transition: background-color 0.3s;
}

thead {
    background-color: var(--header-bg);
    color: var(--header-text);
}

th {
    padding: 12px;
    text-align: left;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    position: relative;
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}

tbody tr:hover,
#departureBoard tbody tr:hover {
    background-color: var(--row-hover);
}

/* Table Alignment Defaults */
td:nth-child(2), th:nth-child(2) {
    text-align: center;
}

td:nth-child(3), th:nth-child(3),
td:nth-child(5), th:nth-child(5),
td:nth-child(7), th:nth-child(7) {
    text-align: right;
}

#busTable th:hover {
    background-color: var(--hover-bg);
}

#busTable th::after {
    content: ' ⇅';
    font-size: 12px;
    opacity: 0.5;
    margin-left: 5px;
}

#busTable th.sorted-asc::after {
    content: ' ↑';
    opacity: 1;
}

#busTable th.sorted-desc::after {
    content: ' ↓';
    opacity: 1;
}

/* Departure Board Overrides */
#departureBoard {
    width: 100%;
    table-layout: auto;
    margin-top: 15px;
}

/* Left Aligned Columns */
#departureBoard thead th:nth-child(1), #departureBoard tbody td:nth-child(1),
#departureBoard thead th:nth-child(2), #departureBoard tbody td:nth-child(2),
#departureBoard thead th:nth-child(5), #departureBoard tbody td:nth-child(5),
#departureBoard thead th:nth-child(6), #departureBoard tbody td:nth-child(6) {
    text-align: left;
}

/* Right Aligned Columns */
#departureBoard thead th:nth-child(4), #departureBoard tbody td:nth-child(4),
#departureBoard thead th:nth-child(7), #departureBoard tbody td:nth-child(7) {
    text-align: right;
}

/* Font Sizing Overrides */
#departureBoard tbody td:nth-child(2),
#departureBoard tbody td:nth-child(5),
#departureBoard tbody td:nth-child(7) {
    font-size: 1.2em;
}

#departureBoard tbody td:nth-child(6) {
    font-size: 0.85em;
    color: #808080;
}

#departureBoard tbody td:nth-child(3) {
    padding: 0;
}

#departureBoard tbody td:nth-child(3) > div {
    display: flex;
    align-items: center;
    justify-content: center;
}

#departureBoard tbody td:nth-child(3) .boxed-text {
    background-color: white;
    color: black;
    font-weight: bold;
    font-size: 1.2em;
    padding: 2px 12px;
    border-radius: 8px;
    max-width: 70%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
}

#departureBoardBody tr td {
    overflow: hidden;
}

.hidden-column {
    display: none !important;
}

/* ==========================================================================
   6. ROUTE & STATUS BADGES
   ========================================================================== */
/* Route Base Styles */
.route-corridor, .route-local, .route-express,
.route-regional, .route-rural, .route-ecs, .route-cancelled {
    color: white;
    font-weight: bold;
    font-size: large;
}

/* Route Colours */
.route-corridor {
    background-color: #71A434;
}

.route-local {
    background-color: #814099;
}

.route-express {
    background-color: #CD173F;
}

.route-regional {
    background-color: #00254B;
}

.route-rural {
    background-color: #84BCE6;
    color: #000;
}

/* Override text colour */
.route-ecs {
    background-color: #848484;
}

/* Status Base Colours & Combo Bindings */
.on-time, #ontimeCount {
    background-color: #90EE90;
    color: #000;
}

.early, #earlyCount {
    background-color: #FF6B6B;
    color: #000;
}

.late, #lateCount {
    background-color: #FFFF00;
    color: #000;
}

.very-early, #vearlyCount {
    background-color: #8B0000;
    color: white;
}

.very-late, #vlateCount {
    background-color: #FFA500;
    color: #000;
}

.unknown {
    background-color: #CCCCCC;
    color: #333;
}

.aw-dep {
    background-color: #0099AA;
    color: white;
}

.ad-sev {
    background-color: #50AA50;
    color: white;
}

.cancelled, .route-cancelled {
    background-color: #000000;
    color: white;
}

.gtfs-error {
    background-color: #3a0091;
    color: white;
}

.garage {
    background-color: #ffffff;
    color: #000000;
}

.retired {
    background-color: #431b0a;
    color: white;
}

.destroyed {
    background-color: #392b26;
    color: white;
}

/* Count Pill Formatting */
#earlyCount, #ontimeCount, #lateCount, #vearlyCount, #vlateCount {
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: bold;
}

.inactive-destination {
    opacity: 0.5;
    font-style: italic;
    font-size: small;
}


/* ==========================================================================
   7. WIDGETS & UTILITIES (Clock, Legend, Errors)
   ========================================================================== */
.ticker {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: #FFB703;
    color: black;
    padding: 2px;
    margin: 0;
    overflow: hidden;
    white-space: nowrap;
    box-sizing: border-box;
    margin-bottom: 20px;
    --scroll-duration: 30s;
    z-index: 100000;
    display: flex;
    align-items: center;
}

.ticker-content {
    font-size: 14pt;
    padding-left: 100%;
    animation: scroll-left var(--scroll-duration) linear infinite;
    white-space: pre;
}

@keyframes scroll-left {
    0% {
        transform: translateX(0);
    }
    100% {
        transform: translateX(-100%);
    }
}

.clock {
    text-align: center;
    margin-top: 20px;
    font-size: 3.0em;
    font-weight: bold;
    font-family: "Nova Mono", monospace;
}

.clock-seconds {
    font-size: 0.8em;
}

.clock_float {
    position: fixed;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100000;
    background-color: #002C49AA;
    color: #FFB703;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: bold;
    font-family: "Nova Mono", monospace;
    font-size: 32px;
}

.legend-container {
    margin-bottom: 20px;
    margin-top: 20px;
    padding: 15px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 2px 4px var(--shadow);
}

.legend-title {
    font-weight: bold;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 1px solid var(--border-color);
}

.legend-label {
    font-size: 14px;
    color: var(--text-primary);
}

.error {
    color: #d32f2f;
    padding: 20px;
    font-size: 16px;
}

.no-results {
    padding: 20px;
    text-align: center;
    color: var(--text-primary);
    font-size: 16px;
}

.strikethrough {
    text-decoration: line-through;
    text-decoration-thickness: 2.5px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #7c7c7c;
    transition: 0.3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #002C49;
}

input:checked + .slider:before {
    transform: translateX(26px);
}


/* ==========================================================================
   8. DARK MODE OVERRIDES (Applied dynamically to the body class)
   ========================================================================== */
body.dark-mode {
    background-color: #1a1a1a;
    color: #e0e0e0;
}

body.dark-mode .about-container {
    background-color: #2d2d2d;
    color: #e0e0e0;
}

body.dark-mode h1,
body.dark-mode h2 {
    color: #FFB703;
}

body.dark-mode p,
body.dark-mode li {
    color: #b0b0b0;
}

body.dark-mode .quote-box {
    background-color: #333;
    border-left-color: #FFB703;
}

body.dark-mode #filter-route {
    background-color: #2a2a2a;
    color: #e0e0e0;
    border-color: #555555;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23e0e0e0' stroke-width='2'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
}

body.dark-mode #filter-route:hover {
    border-color: #777777;
    background-color: #333333;
}

body.dark-mode #filter-route:focus {
    border-color: #4da6ff;
    box-shadow: 0 0 0 3px rgba(77, 166, 255, 0.2);
}

body.dark-mode #filter-route option {
    background-color: #2a2a2a;
    color: #e0e0e0;
}

/* ==========================================================================
   9. MEDIA QUERIES & ANIMATIONS
   ========================================================================== */
@keyframes rollUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

#departureBoardBody tr.animate-roll-up {
    animation: rollUp 1.6s ease-out forwards;
}

/* Prefer dark */
@media (prefers-color-scheme: dark) {}


/* Mobile & Portrait Viewport Adjustments */
@media (orientation: portrait) {
    #clock_float {
        display: none;
    }

    .hamburger {
        display: block;
    }

    .navbar-menu {
        display: none;
        position: absolute;
        top: 60px;
        right: 80px;
        width: 30%;
        background-color: #002C49;
        flex-direction: column;
        list-style: none;
        padding: 1rem 0;
        z-index: 1000;
    }

    .navbar-menu.active {
        display: flex;
    }

    .navbar-menu li {
        margin: 1rem 2rem;
    }
}
