:root {
    --app-bg: #f3f6fa;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --border: #dbe3ed;
    --text: #172033;
    --muted: #64748b;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

body {
    background: var(--app-bg);
    color: var(--text);
    font-size: 0.95rem;
}

a {
    color: var(--primary);
}

a:hover {
    color: var(--primary-dark);
}

.app-navbar {
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.06);
    backdrop-filter: blur(14px);
}

.navbar-brand {
    color: var(--text);
    font-weight: 800;
    letter-spacing: 0;
}

.navbar-brand:hover,
.app-navbar .nav-link {
    color: var(--text);
}

.app-navbar .nav-link {
    border-radius: 8px;
    font-weight: 600;
    padding: 0.5rem 0.75rem;
}

.app-navbar .nav-link:hover,
.app-navbar .nav-link:focus {
    background: var(--surface-soft);
    color: var(--primary-dark);
}

.navbar-toggler {
    border-color: var(--border);
}

.navbar-toggler-icon {
    filter: invert(1);
    opacity: 0.75;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 800;
}

.version-pill {
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.12rem 0.45rem;
    text-decoration: none;
}

.version-pill:hover,
.version-pill:focus {
    background: var(--surface-soft);
    color: var(--primary);
}

.user-chip {
    border: 1px solid var(--border);
    background: var(--surface-soft);
    align-items: center;
    display: inline-flex;
    gap: 0.45rem;
}

.nav-avatar,
.nav-initials {
    border-radius: 50%;
    height: 26px;
    width: 26px;
}

.nav-avatar {
    object-fit: cover;
}

.nav-initials {
    align-items: center;
    background: var(--primary);
    color: #fff;
    display: inline-flex;
    font-size: 0.75rem;
    font-weight: 800;
    justify-content: center;
}

.dropdown-menu {
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 0.45rem;
}

.dropdown-item {
    border-radius: 7px;
}

.dropdown-header {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.app-shell {
    max-width: 1500px;
}

.page-heading {
    align-items: center;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-heading h1,
h1.h3,
.h3 {
    color: var(--text);
    font-weight: 800;
    letter-spacing: 0;
}

.eyebrow {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.card {
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}

.card.shadow-sm {
    box-shadow: var(--shadow) !important;
}

.card-header,
.card-footer {
    background: var(--surface-soft);
    border-color: var(--border);
}

.table {
    --bs-table-striped-bg: #f8fafc;
}

.table td,
.table th {
    vertical-align: middle;
}

.table thead th {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.btn {
    border-radius: 8px;
    font-weight: 700;
}

.btn-primary {
    --bs-btn-bg: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary-dark);
    --bs-btn-hover-border-color: var(--primary-dark);
}

.form-control,
.form-select {
    border-color: var(--border);
    border-radius: 8px;
}

.trip-photo {
    aspect-ratio: 4 / 3;
    object-fit: cover;
    width: 100%;
    border-radius: 8px;
}

.stat-value {
    font-size: clamp(1.1rem, 1.8vw, 1.6rem);
    font-weight: 800;
    line-height: 1.2;
}

.discovery-progress {
    background: #e5edf4;
    border-radius: 999px;
    height: 1.35rem;
}

.discovery-progress .progress-bar {
    background: var(--primary);
    border-radius: 999px;
    font-weight: 800;
}

.alert {
    border-radius: 10px;
    border-width: 1px;
}

.profile-photo-preview {
    align-items: center;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 14px;
    display: flex;
    height: 180px;
    justify-content: center;
    overflow: hidden;
    width: 180px;
}

.profile-photo-preview.public {
    border-radius: 22px;
    height: 150px;
    width: 150px;
}

.profile-photo-preview img {
    height: 100%;
    object-fit: cover;
    width: 100%;
}

.profile-placeholder {
    align-items: center;
    background: var(--primary);
    color: #fff;
    display: flex;
    font-size: 4rem;
    font-weight: 800;
    height: 100%;
    justify-content: center;
    width: 100%;
}

.public-profile-box {
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
}

.qr-preview {
    background: #fff;
    border-radius: 8px;
    display: block;
    margin: 0 auto 1rem;
    max-width: 180px;
    width: 100%;
}

.public-profile-hero {
    overflow: hidden;
}

.app-footer {
    color: var(--muted);
    font-size: 0.85rem;
    padding: 1.5rem 0 2rem;
}

.app-footer .app-shell {
    align-items: center;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    padding-top: 1rem;
}

@media (max-width: 1199.98px) {
    .app-navbar .navbar-nav {
        align-items: stretch !important;
        gap: 0.15rem;
        padding-top: 0.75rem;
    }

    .user-chip {
        display: inline-block;
        width: 100%;
    }
}

body[data-theme="dark"] {
    --app-bg: #0f172a;
    --surface: #111827;
    --surface-soft: #1f2937;
    --border: #334155;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --shadow: 0 14px 34px rgba(0, 0, 0, 0.35);
}

body[data-theme="dark"] .app-navbar,
body[data-theme="dark"] .card,
body[data-theme="dark"] .dropdown-menu,
body[data-theme="dark"] .form-control,
body[data-theme="dark"] .form-select {
    background-color: var(--surface);
    color: var(--text);
}

body[data-theme="dark"] .form-control,
body[data-theme="dark"] .form-select {
    border-color: var(--border);
}

body[data-theme="dark"] .table {
    --bs-table-bg: var(--surface);
    --bs-table-color: var(--text);
    --bs-table-striped-bg: #182235;
    --bs-table-striped-color: var(--text);
    --bs-table-border-color: var(--border);
}

body[data-theme="dark"] .text-muted {
    color: var(--muted) !important;
}

.leaflet-map {
    min-height: 380px;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: var(--surface-soft);
}

.leaflet-map.compact {
    min-height: 280px;
}

.map-empty {
    border: 1px dashed var(--border);
    border-radius: 10px;
    color: var(--muted);
    padding: 1.5rem;
    text-align: center;
    background: var(--surface-soft);
}

.empty-state {
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 1.5rem;
    color: var(--muted);
    background: var(--surface-soft);
    text-align: center;
}

.empty-state.compact {
    padding: 1rem;
    font-size: 0.95rem;
}

.discovery-list {
    display: grid;
    gap: 0.35rem;
    max-height: 14rem;
    overflow: auto;
    padding-right: 0.25rem;
}

.insight-list {
    display: grid;
    gap: 0.85rem;
}

.insight-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--border);
}

.insight-row:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.insight-row span {
    color: var(--muted);
    font-size: 0.9rem;
}

.insight-row strong {
    max-width: 58%;
    text-align: right;
}

.quick-edit-table {
    min-width: 1500px;
}

.quick-edit-table .form-control,
.quick-edit-table .form-select {
    min-width: 7rem;
}

.quick-edit-table .station-code-input {
    min-width: 5rem;
    text-transform: uppercase;
}

.timeline-hero {
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: flex;
    gap: 1.5rem;
    justify-content: space-between;
    padding: 1.4rem;
}

.timeline-summary {
    align-items: center;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 10px;
    display: grid;
    min-width: 150px;
    padding: 0.9rem 1rem;
    text-align: center;
}

.timeline-summary-number {
    color: var(--primary);
    font-size: 2rem;
    font-weight: 800;
    line-height: 1;
}

.timeline-summary-label {
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 700;
}

.timeline-filter {
    align-items: end;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: grid;
    gap: 1rem;
    grid-template-columns: minmax(160px, 1fr) minmax(180px, 1fr) auto;
    padding: 1rem;
}

.timeline-filter-actions {
    display: flex;
    gap: 0.5rem;
}

.timeline-year-block {
    display: grid;
    gap: 1rem;
    grid-template-columns: 96px 1fr;
    margin-bottom: 1.6rem;
}

.timeline-year-label {
    align-self: start;
    background: var(--primary);
    border-radius: 10px;
    color: #fff;
    font-size: 1.1rem;
    font-weight: 800;
    padding: 0.65rem 0.85rem;
    position: sticky;
    text-align: center;
    top: 82px;
}

.timeline-stream {
    border-left: 2px solid var(--border);
    display: grid;
    gap: 1rem;
    padding-left: 1.25rem;
}

.timeline-month-block {
    position: relative;
}

.timeline-month-marker {
    background: var(--primary);
    border: 4px solid var(--app-bg);
    border-radius: 50%;
    height: 18px;
    left: -1.85rem;
    position: absolute;
    top: 1.05rem;
    width: 18px;
}

.timeline-month-header {
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
    display: flex;
    justify-content: space-between;
    padding: 1rem 1.1rem;
}

.timeline-trip-grid {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 0;
    border-radius: 0 0 12px 12px;
    display: grid;
    gap: 0.65rem;
    padding: 1rem;
}

.timeline-trip-card {
    align-items: stretch;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    display: grid;
    gap: 0.9rem;
    grid-template-columns: 64px 1fr;
    padding: 0.75rem;
    text-decoration: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.timeline-trip-card:hover,
.timeline-trip-card:focus {
    border-color: rgba(15, 118, 110, 0.45);
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.08);
    color: var(--text);
    transform: translateY(-1px);
}

.timeline-date-badge {
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: grid;
    justify-items: center;
    min-height: 64px;
    padding: 0.35rem;
}

.timeline-date-badge strong {
    font-size: 1.35rem;
    line-height: 1;
}

.timeline-date-badge span {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.timeline-trip-content {
    display: grid;
    gap: 0.45rem;
    min-width: 0;
}

.timeline-trip-topline {
    color: var(--muted);
    display: flex;
    font-size: 0.84rem;
    font-weight: 700;
    gap: 0.75rem;
    justify-content: space-between;
}

.timeline-route {
    font-size: 1rem;
    font-weight: 800;
    line-height: 1.25;
}

.timeline-route span {
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 700;
}

.timeline-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.timeline-chip {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    max-width: 100%;
    overflow: hidden;
    padding: 0.25rem 0.55rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.timeline-chip.is-delay {
    background: #fff7ed;
    border-color: #fed7aa;
    color: #9a3412;
}

.timeline-chip.is-on-time {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #047857;
}

body[data-theme="dark"] .leaflet-tile,
body[data-theme="dark"] .leaflet-control-attribution {
    filter: brightness(0.78) contrast(1.08) saturate(0.9);
}

body[data-theme="dark"] .timeline-chip.is-delay {
    background: rgba(154, 52, 18, 0.18);
    border-color: rgba(251, 146, 60, 0.35);
    color: #fdba74;
}

body[data-theme="dark"] .timeline-chip.is-on-time {
    background: rgba(4, 120, 87, 0.18);
    border-color: rgba(52, 211, 153, 0.35);
    color: #6ee7b7;
}

@media (max-width: 767.98px) {
    .timeline-hero {
        align-items: stretch;
        display: grid;
    }

    .timeline-summary {
        text-align: left;
    }

    .timeline-filter {
        grid-template-columns: 1fr;
    }

    .timeline-filter-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .timeline-year-block {
        grid-template-columns: 1fr;
    }

    .timeline-year-label {
        position: static;
        text-align: left;
    }

    .timeline-trip-card {
        grid-template-columns: 54px 1fr;
    }

    .timeline-trip-topline {
        display: grid;
        gap: 0.25rem;
        justify-content: start;
    }
}

/* Timeline infographic layout */
.timeline-page-head {
    align-items: center;
    display: flex;
    gap: 1.5rem;
    justify-content: space-between;
}

.timeline-count {
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: grid;
    min-width: 120px;
    padding: 0.9rem 1rem;
    text-align: center;
}

.timeline-count strong {
    color: var(--primary);
    font-size: 2rem;
    line-height: 1;
}

.timeline-count span {
    color: var(--muted);
    font-weight: 700;
}

.timeline-control-panel {
    align-items: end;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 1rem;
    grid-template-columns: minmax(160px, 1fr) minmax(180px, 1fr) auto;
    padding: 1rem;
}

.timeline-control-actions {
    display: flex;
    gap: 0.5rem;
}

.timeline-canvas {
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 18px;
    overflow: hidden;
    padding: 2rem 1rem 2.4rem;
}

.timeline-year-title {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.timeline-year-title span {
    background: var(--primary);
    border-radius: 999px;
    color: #fff;
    font-size: 1.65rem;
    font-weight: 900;
    letter-spacing: 0;
    padding: 0.45rem 1.6rem;
}

.timeline-track {
    margin: 0 auto;
    max-width: 1120px;
    position: relative;
}

.timeline-track::before {
    background: var(--primary);
    border-radius: 999px;
    bottom: 0;
    content: "";
    left: 50%;
    position: absolute;
    top: 0;
    transform: translateX(-50%);
    width: 4px;
    z-index: 0;
}

.timeline-month-title {
    display: grid;
    gap: 0.2rem;
    justify-items: center;
    margin: 1.4rem 0;
    position: relative;
    z-index: 1;
}

.timeline-month-title span {
    background: var(--surface);
    border: 2px solid var(--primary);
    border-radius: 999px;
    font-size: 1.1rem;
    font-weight: 900;
    padding: 0.35rem 1rem;
    text-transform: capitalize;
}

.timeline-month-title small {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-weight: 700;
    padding: 0.25rem 0.75rem;
}

.timeline-event {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 96px minmax(0, 1fr);
    min-height: 132px;
    position: relative;
    z-index: 1;
}

.timeline-event::before {
    background: var(--primary);
    content: "";
    height: 2px;
    left: 50%;
    position: absolute;
    top: 58px;
    width: calc(50% - 96px);
    z-index: 0;
}

.timeline-event.is-left::before {
    transform: translateX(calc(-100% + 48px));
}

.timeline-event.is-right::before {
    transform: translateX(48px);
}

.timeline-event-card {
    align-self: start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 0.55rem;
    max-width: 430px;
    padding: 1rem;
    position: relative;
    z-index: 2;
}

.timeline-event.is-left .timeline-event-card {
    grid-column: 1;
    justify-self: end;
    text-align: right;
}

.timeline-event.is-right .timeline-event-card {
    grid-column: 3;
    justify-self: start;
}

.timeline-event-kicker {
    color: var(--muted);
    display: flex;
    font-size: 0.82rem;
    font-weight: 800;
    gap: 0.75rem;
    justify-content: space-between;
    text-transform: uppercase;
}

.timeline-event-route {
    color: var(--text);
    font-size: 1.05rem;
    font-weight: 900;
    line-height: 1.25;
    text-decoration: none;
}

.timeline-event-route:hover,
.timeline-event-route:focus {
    color: var(--primary);
}

.timeline-event-route span {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
}

.timeline-event-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.timeline-event.is-left .timeline-event-meta {
    justify-content: flex-end;
}

.timeline-event-meta span {
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    max-width: 100%;
    overflow: hidden;
    padding: 0.25rem 0.55rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.timeline-event-meta .is-delay {
    background: #fff7ed;
    border-color: #fed7aa;
    color: #9a3412;
}

.timeline-event-meta .is-on-time {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #047857;
}

.timeline-node {
    align-items: center;
    align-self: start;
    aspect-ratio: 1;
    border: 4px solid var(--surface);
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 3px var(--primary), var(--shadow);
    color: #fff;
    display: grid;
    grid-column: 2;
    justify-items: center;
    margin: 0 auto;
    padding: 0.65rem;
    position: relative;
    text-decoration: none;
    width: 92px;
    z-index: 3;
}

.timeline-node strong {
    font-size: 1.7rem;
    line-height: 1;
}

.timeline-node span {
    font-size: 0.75rem;
    font-weight: 900;
    text-transform: uppercase;
}

body[data-theme="dark"] .timeline-canvas {
    background: var(--surface-soft);
}

body[data-theme="dark"] .timeline-year-title span {
    background: var(--primary);
    color: #fff;
}

body[data-theme="dark"] .timeline-month-title span,
body[data-theme="dark"] .timeline-month-title small {
    background: var(--surface);
}

body[data-theme="dark"] .timeline-event-meta .is-delay {
    background: rgba(154, 52, 18, 0.18);
    border-color: rgba(251, 146, 60, 0.35);
    color: #fdba74;
}

body[data-theme="dark"] .timeline-event-meta .is-on-time {
    background: rgba(4, 120, 87, 0.18);
    border-color: rgba(52, 211, 153, 0.35);
    color: #6ee7b7;
}

@media (max-width: 991.98px) {
    .timeline-event {
        grid-template-columns: 76px minmax(0, 1fr);
        min-height: 0;
        padding-bottom: 1rem;
    }

    .timeline-track::before {
        left: 38px;
    }

    .timeline-event::before,
    .timeline-event.is-left::before,
    .timeline-event.is-right::before {
        left: 38px;
        top: 46px;
        transform: translateX(32px);
        width: 34px;
    }

    .timeline-event-card,
    .timeline-event.is-left .timeline-event-card,
    .timeline-event.is-right .timeline-event-card {
        grid-column: 2;
        justify-self: stretch;
        max-width: none;
        text-align: left;
    }

    .timeline-event.is-left .timeline-event-meta {
        justify-content: flex-start;
    }

    .timeline-node {
        grid-column: 1;
        width: 76px;
    }
}

@media (max-width: 767.98px) {
    .timeline-page-head {
        align-items: stretch;
        display: grid;
    }

    .timeline-count {
        text-align: left;
    }

    .timeline-control-panel {
        grid-template-columns: 1fr;
    }

    .timeline-control-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .timeline-canvas {
        border-radius: 14px;
        padding: 1.25rem 0.75rem 1.5rem;
    }

    .timeline-month-title small {
        border-radius: 12px;
        text-align: center;
    }

    .timeline-event-kicker {
        display: grid;
        gap: 0.2rem;
        justify-content: start;
    }
}

@media (prefers-color-scheme: dark) {
    body[data-theme="system"] {
        --app-bg: #0f172a;
        --surface: #111827;
        --surface-soft: #1f2937;
        --border: #334155;
        --text: #e5e7eb;
        --muted: #94a3b8;
        --shadow: 0 14px 34px rgba(0, 0, 0, 0.35);
    }

    body[data-theme="system"] .app-navbar,
    body[data-theme="system"] .card,
    body[data-theme="system"] .dropdown-menu,
    body[data-theme="system"] .form-control,
    body[data-theme="system"] .form-select {
        background-color: var(--surface);
        color: var(--text);
    }

    body[data-theme="system"] .table {
        --bs-table-bg: var(--surface);
        --bs-table-color: var(--text);
        --bs-table-striped-bg: #182235;
        --bs-table-striped-color: var(--text);
        --bs-table-border-color: var(--border);
    }

    body[data-theme="system"] .text-muted {
        color: var(--muted) !important;
    }

    body[data-theme="system"] .leaflet-tile,
    body[data-theme="system"] .leaflet-control-attribution {
        filter: brightness(0.78) contrast(1.08) saturate(0.9);
    }

    body[data-theme="system"] .timeline-chip.is-delay {
        background: rgba(154, 52, 18, 0.18);
        border-color: rgba(251, 146, 60, 0.35);
        color: #fdba74;
    }

    body[data-theme="system"] .timeline-chip.is-on-time {
        background: rgba(4, 120, 87, 0.18);
        border-color: rgba(52, 211, 153, 0.35);
        color: #6ee7b7;
    }
}
