/*
*
*  Modern Mobile App CSS - 2024-07-25
*
*/

/* Import Google Font */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700;900&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@500;700&display=swap');


/* CSS Variables for theming */
:root {
    --bg-color-light: #f8f9fa;
    --fg-color-light: #ffffff;
    --text-color-light: #212529;
    --text-muted-light: #6c757d;
    --border-color-light: #dee2e6;
    --accent-color-1-light: #004a99;
    --accent-color-2-light: #0099ff;
    --favorite-bg-light: #fff3cd;
    --info-bg-light: #0dcaf0;
    --info-text-light: #000;

    --bg-color-dark: #121212;
    --fg-color-dark: #1e1e1e;
    --text-color-dark: #e9ecef;
    --text-muted-dark: #adb5bd;
    --border-color-dark: #495057;
    --accent-color-1-dark: #2163b0;
    --accent-color-2-dark: #8558d3;
    --favorite-bg-dark: #4d4321;
    --info-bg-dark: #2c3e50;
    --info-text-dark: #fff;

    --bg-color-rgb-light: 248, 249, 250;
    --bg-color-rgb-dark: 18, 18, 18;
}

[data-bs-theme="light"] {
    --bg-color: var(--bg-color-light);
    --fg-color: var(--fg-color-light);
    --text-color: var(--text-color-light);
    --text-muted: var(--text-muted-light);
    --border-color: var(--border-color-light);
    --accent-color-1: var(--accent-color-1-light);
    --accent-color-2: var(--accent-color-2-light);
    --favorite-bg: var(--favorite-bg-light);
    --bg-color-rgb: var(--bg-color-rgb-light);
}

[data-bs-theme="dark"] {
    --bg-color: var(--bg-color-dark);
    --fg-color: var(--fg-color-dark);
    --text-color: var(--text-color-dark);
    --text-muted: var(--text-muted-dark);
    --border-color: var(--border-color-dark);
    --accent-color-1: var(--accent-color-1-dark);
    --accent-color-2: var(--accent-color-2-dark);
    --favorite-bg: var(--favorite-bg-dark);
    --bg-color-rgb: var(--bg-color-rgb-dark);
}

body,
html {
    height: 100%;
    margin: 0;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
}

.app-wrapper {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 0;
    max-width: 100%;
    margin: 0;
    border: none;
    border-radius: 0;
    overflow: hidden;
    /* Prevents content from spilling on rounded corners */
}

.main-app-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding: 1rem;
    max-width: 100%;
}

/* Header/Navbar */
.navbar {
    background-color: var(--fg-color);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

[data-bs-theme="dark"] .navbar {
    box-shadow: 0 2px 10px rgba(255, 255, 255, 0.05);
}

.navbar-text {
    font-weight: 700;
    font-size: 1.25rem;
}

.navbar .bi {
    font-size: 1.5rem;
    color: var(--accent-color-1);
    vertical-align: middle;
}

.station-swap-btn {
    width: 2.25rem;
    height: 2.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    padding: 0;
    margin: 0 0.5rem;
    color: var(--accent-color-1);
    transition: color 0.3s ease, transform 0.2s ease;
    cursor: pointer;
}

.station-swap-btn .bi {
    font-size: 1.5rem;
}

.station-swap-btn:hover,
.station-swap-btn:focus-visible {
    color: var(--accent-color-1);
    transform: scale(1.08);
}

.station-name {
    font-size: 1.1rem;
    font-weight: 700;
}

.spinning {
    animation: spin-refresh 1s linear infinite !important;
    color: white !important;
}

.next-train-refresh.spinning {
    animation: none !important;
}

.next-train-refresh.spinning .bi {
    animation: spin-refresh 1s linear infinite !important;
}

@keyframes spin-refresh {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Next Train Card */
.next-train-card {
    background: linear-gradient(135deg, var(--accent-color-1), var(--accent-color-2));
    color: white;
    border-radius: 1.5rem;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15), 0 3px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.5s ease;
    text-align: center;
    font-family: 'Roboto Mono', monospace;
    position: relative;
    flex-shrink: 0;
    z-index: 10;
    overflow: hidden;
}

[data-bs-theme="dark"] .next-train-card {
    background: linear-gradient(135deg, #4a4a4a, #333333);
}

.next-train-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2), 0 5px 10px rgba(0, 0, 0, 0.15);
}

.next-train-refresh {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 2.5rem;
    height: 2.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    color: white;
    cursor: pointer;
    z-index: 2;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.next-train-refresh:hover,
.next-train-refresh:focus-visible {
    background: rgba(255, 255, 255, 0.24);
    transform: scale(1.06);
}

.next-train-refresh .bi {
    font-size: 1.35rem;
}

.next-train-content {
    position: relative;
    z-index: 1;
}

.next-train-card.card-enter {
    animation: cardSettle 0.45s ease-out both;
}

.next-train-card.card-enter .next-train-content>* {
    animation: flyIntoCard 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.next-train-card.card-enter .next-train-content>*:nth-child(2) {
    animation-delay: 0.06s;
}

.next-train-card.card-enter .next-train-content>*:nth-child(3) {
    animation-delay: 0.12s;
}

.next-train-card.card-enter .next-train-content>*:nth-child(4) {
    animation-delay: 0.18s;
}

#countdown {
    font-size: clamp(2.5rem, 10vw, 4rem);
    font-weight: 900;
    line-height: 1;
    white-space: nowrap;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

#countdown span {
    display: block;
    font-size: clamp(1rem, 2.5vw, 1.25rem);
    font-weight: 500;
    opacity: 0.8;
}

.next-train-details {
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin-top: 1.5rem;
}

.next-train-details>div {
    flex: 1;
}

.next-train-details h5 {
    font-size: 1rem;
    font-weight: 500;
    opacity: 0.8;
    margin-bottom: 0.25rem;
}

.next-train-details p {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0;
}

#next-train-destination {
    font-size: 2rem;
    font-weight: 700;
}

/* By default (Mobile portrait): Hide extra widgets to keep card identical to original */
.next-train-header-row,
.trip-timeline,
.next-train-deviations,
.next-train-backup,
.deviation-box,
.backup-train-box {
    display: none;
}

/* Header status badge (hidden on mobile portrait) */
.next-train-header-row {
    display: none;
    justify-content: center;
    align-items: center;
    margin-bottom: 0.5rem;
}

.badge-status {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.3rem 0.75rem;
    border-radius: 2rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-ontime {
    background: rgba(40, 167, 69, 0.3);
    color: #4cd964;
    border: 1px solid rgba(76, 217, 100, 0.4);
}

.badge-delayed {
    background: rgba(255, 193, 7, 0.3);
    color: #ffda6a;
    border: 1px solid rgba(255, 218, 106, 0.45);
}

.badge-canceled {
    background: rgba(220, 53, 69, 0.35);
    color: #ff858d;
    border: 1px solid rgba(255, 133, 141, 0.5);
}

/* 1. Trip Timeline (hidden on mobile) */
.trip-timeline {
    display: none;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 1rem;
    padding: 0.75rem 1rem;
    margin: 1rem 0;
    border: 1px solid rgba(255, 255, 255, 0.18);
}

.timeline-station {
    display: flex;
    flex-direction: column;
    min-width: 65px;
}

.timeline-from {
    align-items: flex-start;
    text-align: left;
}

.timeline-to {
    align-items: flex-end;
    text-align: right;
}

.timeline-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #fff;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
    margin-bottom: 0.25rem;
}

.timeline-name {
    font-size: 0.85rem;
    font-weight: 700;
    color: #fff;
    max-width: 95px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.timeline-time {
    font-size: 0.8rem;
    opacity: 0.85;
    color: #fff;
}

.timeline-track {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    padding: 0 0.5rem;
}

.timeline-line {
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.35), #fff, rgba(255, 255, 255, 0.35));
    margin-bottom: 0.25rem;
    position: relative;
}

.timeline-train-icon {
    position: absolute;
    top: 0;
    left: 0.5rem;
    right: 0.5rem;
    height: 1.25rem;
    pointer-events: none;
}

.timeline-train-icon .bi {
    position: absolute;
    top: -0.75rem;
    font-size: 1.15rem;
    color: #fff;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
    animation: trainRideAcross 4.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes trainRideAcross {
    0% {
        left: 0%;
        opacity: 0;
        transform: scale(0.85);
    }
    8% {
        opacity: 1;
        transform: scale(1);
    }
    88% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        left: calc(100% - 1.15rem);
        opacity: 0;
        transform: scale(0.85);
    }
}

.timeline-duration {
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(0, 0, 0, 0.25);
    padding: 0.15rem 0.5rem;
    border-radius: 1rem;
    margin-top: 0.35rem;
    letter-spacing: 0.02em;
    color: #fff;
}

/* 3. Next Train Deviations (hidden on mobile portrait) */
.deviation-box {
    display: none;
    align-items: flex-start;
    gap: 0.5rem;
    background: rgba(255, 193, 7, 0.2);
    border: 1px solid rgba(255, 193, 7, 0.45);
    border-radius: 0.85rem;
    padding: 0.6rem 0.85rem;
    margin-top: 0.85rem;
    text-align: left;
    color: #fff;
    font-size: 0.85rem;
    line-height: 1.4;
}

.deviation-icon {
    font-size: 1.1rem;
    color: #ffda6a;
    flex-shrink: 0;
    margin-top: 0.1rem;
}

.train-operator-info {
    font-size: 0.95rem;
    font-weight: 600;
    opacity: 0.95;
    margin-top: 0.75rem;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 2. Backup Train Box (hidden on mobile portrait) */
.backup-train-box {
    display: none;
    margin-top: 1rem;
    padding: 0.55rem 0.85rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0.75rem;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.92);
    border: 1px dashed rgba(255, 255, 255, 0.25);
}

/* 5. Dynamic Warning Pulse */
.next-train-card.card-status-warning {
    box-shadow: 0 10px 25px rgba(255, 193, 7, 0.35), 0 3px 6px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 218, 106, 0.45);
}

.next-train-card.card-status-danger {
    box-shadow: 0 10px 30px rgba(220, 53, 69, 0.45), 0 3px 6px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 133, 141, 0.55);
}

.next-train-card.card-pulse-danger {
    animation: dangerPulseGlow 2s ease-in-out infinite;
}

@keyframes dangerPulseGlow {
    0%, 100% {
        box-shadow: 0 10px 25px rgba(220, 53, 69, 0.35), 0 0 15px rgba(220, 53, 69, 0.2);
    }
    50% {
        box-shadow: 0 15px 35px rgba(220, 53, 69, 0.7), 0 0 25px rgba(220, 53, 69, 0.4);
    }
}

/* Departures List */
.departures-scroll-area {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-top: 0.25rem;
    padding-bottom: 1rem;
    display: flex;
    flex-direction: column;
}

.list-group {
    border-radius: 1.5rem;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
    background-color: var(--fg-color);
    border: 1px solid var(--border-color);
    flex-grow: 1;
    min-height: 0;
}

.list-group-item {
    background-color: var(--fg-color);
    border: none;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
    transition: background-color 0.2s ease;
    animation: slideInUp 0.5s ease-out forwards;
    opacity: 0;
}

.list-group-item:last-child {
    border-bottom: none;
}

.list-group-item.favorite {
    background-color: var(--favorite-bg);
}

.list-group-item.active.favorite {
    box-shadow: inset 5px 0 0 0 #ffc107;
}


.list-group-item.active {
    background-color: var(--accent-color-1);
    color: white;
    border-color: var(--accent-color-1);
}

.list-group-item.active .text-muted {
    color: rgba(255, 255, 255, 0.75) !important;
}

.list-group-item.active .text-danger {
    color: #ffcdd2 !important;
}

.list-group-item h5 {
    font-weight: 700;
    font-size: 1.1rem;
}

.list-group-item .fs-4 {
    font-size: 1.15rem !important;
    font-weight: 700;
    white-space: nowrap;
}



.favorite-star {
    cursor: pointer;
    margin-right: 10px;
    transition: transform 0.2s, color 0.2s;
    color: var(--text-muted);
}

.favorite-star:hover {
    transform: scale(1.2);
    color: #ffc107;
}

.bi-star-fill {
    color: #ffc107;
}

/* Buttons */
.btn-primary {
    background-color: var(--accent-color-1);
    border-color: var(--accent-color-1);
    font-weight: 500;
    border-radius: 0.75rem;
    padding: 0.75rem 1.25rem;
}

.btn-primary:hover,
.btn-primary:focus {
    opacity: 0.9;
}

.btn-info {
    background-color: var(--info-bg-light);
    border-color: var(--info-bg-light);
    color: var(--info-text-light);
}

[data-bs-theme="dark"] .btn-info {
    background-color: var(--info-bg-dark);
    border-color: var(--info-bg-dark);
    color: var(--info-text-dark);
}

.text-primary {
    color: #28a745 !important;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    /* Changed for wrapper containment */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(var(--bg-color-rgb), 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1060;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s;
}

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

.spinner {
    width: 4rem;
    height: 4rem;
    border: 0.4rem solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
    color: var(--accent-color-1);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

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

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes cardSettle {
    from {
        transform: translateY(12px) scale(0.98);
    }

    to {
        transform: translateY(0) scale(1);
    }
}

@keyframes flyIntoCard {
    from {
        transform: translateY(24px);
        opacity: 0;
        filter: blur(2px);
    }

    to {
        transform: translateY(0);
        opacity: 1;
        filter: blur(0);
    }
}

/* Settings page specifics */
.settings-container {
    padding: 1rem;
    display: block;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.form-label {
    font-weight: 500;
}

.form-control,
.form-select {
    border-radius: 0.75rem;
    padding: 0.75rem 1rem;
    background-color: var(--fg-color);
    border-color: var(--border-color);
}

.form-control:focus,
.form-select:focus {
    box-shadow: 0 0 0 0.25rem rgba(var(--accent-color-1-rgb), 0.25);
    border-color: var(--accent-color-1);
}

.form-check-input:checked {
    background-color: var(--accent-color-1);
    border-color: var(--accent-color-1);
}

/* Desktop & Tablet Layout */
@media (min-width: 768px) {
    body {
        background-color: #e9ecef;
    }

    [data-bs-theme="dark"] body {
        background-color: #000;
    }

    .app-wrapper {
        max-width: 1100px;
        margin: 0 auto;
        border-radius: 0;
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.1);
        height: 100%;
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
        border-top: none;
        border-bottom: none;
        position: relative;
        /* Needed for loading overlay positioning */
    }

    .loading-overlay {
        border-radius: 0;
    }

    /* Trip Timeline is only shown on desktop/tablet with sufficient space */
    .trip-timeline:not(.d-none) {
        display: flex;
    }
}

/* ==========================================================================
   Two-Column Layout (Desktop & Landscape)
   Next Train Card on Left, List on Right
   ========================================================================== */
@media (min-width: 768px), (orientation: landscape) and (min-width: 560px) {
    .main-app-container {
        flex-direction: row;
        gap: 1.5rem;
        align-items: stretch;
        height: 100%;
        overflow: hidden;
        padding: 1.25rem 1.5rem;
    }

    /* Left column: Next Train Card */
    .next-train-card {
        order: 1;
        flex: 1 1 45%;
        min-width: 0;
        margin-bottom: 0;
        height: 100%;
        max-height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        overflow-y: auto;
    }

    /* Right column: Departures List */
    .departures-scroll-area {
        order: 2;
        flex: 1 1 55%;
        min-width: 0;
        height: 100%;
        margin-bottom: 0;
        padding-top: 0;
        padding-bottom: 0;
        display: flex;
        flex-direction: column;
    }

    .departures-scroll-area .list-group {
        flex-grow: 1;
        min-height: 0;
    }

    .next-train-content {
        padding: 0.5rem 0;
    }

    #next-train-destination {
        font-size: 1.85rem;
        margin-bottom: 0.25rem;
    }

    #countdown {
        font-size: clamp(2.25rem, 5vw, 3.75rem);
    }

    /* Show rich widgets only on desktop and landscape */
    .next-train-header-row {
        display: flex;
    }

    .next-train-deviations:not(.d-none) {
        display: block;
    }

    .deviation-box {
        display: flex;
    }

    .next-train-backup:not(.d-none) {
        display: block;
    }

    .backup-train-box {
        display: block;
    }
}

/* Compact landscape adjustments for mobile phones */
@media (orientation: landscape) and (max-height: 500px) {
    .main-app-container {
        padding: 0.5rem 0.75rem;
        gap: 0.75rem;
    }

    .next-train-card {
        padding: 0.75rem 1rem;
        border-radius: 1rem;
    }

    #next-train-destination {
        font-size: 1.25rem;
        margin-bottom: 0.15rem;
    }

    #countdown {
        font-size: clamp(1.5rem, 5vw, 2.25rem);
        margin-bottom: 0.15rem;
    }

    .next-train-details {
        margin-top: 0.4rem;
    }

    .next-train-details h5 {
        font-size: 0.75rem;
    }

    .next-train-details p {
        font-size: 1rem;
    }

    .backup-train-box {
        margin-top: 0.4rem;
        padding: 0.35rem 0.5rem;
        font-size: 0.75rem;
    }

    .deviation-box {
        margin-top: 0.4rem;
        padding: 0.35rem 0.5rem;
        font-size: 0.75rem;
    }

    #next-train-details-extra {
        margin-top: 0.35rem;
        font-size: 0.8rem;
    }
}

/* ==========================================================================
   Custom App Modal (Glassmorphic Dialog)
   ========================================================================== */
.app-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.app-modal-backdrop.show {
    opacity: 1;
    visibility: visible;
}

.app-modal-dialog {
    background-color: var(--fg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 1.25rem;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 380px;
    padding: 1.75rem 1.5rem 1.5rem;
    text-align: center;
    transform: scale(0.9) translateY(12px);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.app-modal-backdrop.show .app-modal-dialog {
    transform: scale(1) translateY(0);
}

.app-modal-icon {
    font-size: 2.75rem;
    line-height: 1;
    margin-bottom: 0.85rem;
}

.app-modal-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.app-modal-message {
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    word-break: break-word;
}

.app-modal-footer {
    display: flex;
    justify-content: center;
}

.app-modal-btn {
    min-width: 130px;
    font-weight: 600;
    border-radius: 0.75rem;
    padding: 0.65rem 1.75rem;
    background: linear-gradient(135deg, var(--accent-color-1), var(--accent-color-2));
    border: none;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.app-modal-btn:hover {
    opacity: 0.92;
    color: #ffffff !important;
}

.app-modal-btn:active {
    transform: scale(0.97);
}

