/* CSS Variables */
:root {
    /* Colors */
    --color-primary-green: #009E61;
    --color-primary-blue: #0152BB;
    --color-primary-blue-dark: #013d99;
    --color-primary-red: #FA2020;
    --color-actv-red: #E30613;
    --color-night-blue: #002B57;
    --color-gold: #FFD700;
    --color-orange: #FF9800;

    /* Accent Colors */
    --color-accent-blue: #007bff;
    --color-accent-blue-dark: #0056b3;

    /* Neutral Colors */
    --color-white: #FFFFFF;
    --color-black: #000000;
    --color-bg-gray: #F5F5F5;
    --color-text-gray: #666;
    --color-text-light: #888;
    --color-text-muted: #999;
    --color-text-dark: #333;
    --color-border-gray: #e0e0e0;
    --color-light-gray: #ccc;
    --color-lighter-gray: #eee;
    --color-bg-light: #f0f0f0;
    --color-handle-gray: #D1D1D6;
    --color-spinner-base: #f3f3f3;


    /* Shadows */
    --shadow-card: 0px 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-card-alt: 2px 0px 9.7px -4px rgba(0, 0, 0, 0.24);

    /* Border Radius */
    --radius-sm: 7px;
    --radius-md: 12px;
    --radius-lg: 15px;
    --radius-xl: 25px;
    --radius-round: 50%;

    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;

    /* Fonts */
    --font-primary: 'Inter', sans-serif;
    --font-secondary: 'SF Pro', sans-serif;
}
[data-theme="dark"] {
    --color-primary-green: #00995e;
    --color-primary-blue: #0085ff;
    --color-primary-red: #FA2020;
    --color-night-blue: #0095ff;
    --color-gold: #FFD700;
    --color-orange: #FF9800;

    /* Neutral Colors */
    --color-white: #2a2a2a;
    --color-black: #FFF;
    --color-bg-gray: #111;
    --color-text-gray: #666;
    --color-text-dark: #F5F5F5;
    --color-border-gray: #333;
    --color-light-gray: #555;
    --color-bg-light: #333;
    --bs-body-color: #F5F5F5;

    /* Shadows */
    --shadow-card: 0px 2px 8px rgba(255, 255, 255, 0.1);
    --shadow-card-alt: 2px 0px 9.7px -4px rgba(255, 255, 255, 0.24);

    /* Border Radius */
    --radius-sm: 7px;
    --radius-md: 12px;
    --radius-lg: 15px;
    --radius-xl: 25px;
    --radius-round: 50%;

    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;

    /* Fonts */
    --font-primary: 'Inter', sans-serif;
    --font-secondary: 'SF Pro', sans-serif;
}

/* Global Styles */
body {
    font-family: var(--font-primary);
    background-color: var(--color-bg-gray);
    font-size: 16px;
    line-height: 1.2;
}

#tm-banner {
    border-radius: var(--radius-md);
    border-left: 5px solid var(--color-orange);
    box-shadow: var(--shadow-card);
}

.hidden {
    display: none !important;
}

/* Common Stop Card Components (used by refactored JS) */


.id-badge-small {
    background: var(--color-primary-blue);
    color: white;
    padding: 3px 8px;
    border-radius: 5px;
    font-size: 11px;
    font-weight: bold;
    text-align: center;
    min-width: 45px;
    line-height: 1.2;
}

.id-badge-small.secondary {
    background: var(--color-accent-blue);
}

.chevron {
    font-size: 20px;
    color: var(--color-light-gray);
}

.subsection-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--color-text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--color-border-gray);
}

.stop-card.selected {
    background: #E8F5E9 !important;
    border-left: 4px solid var(--color-primary-green);
}


/* Header Styles */
.header-green {
    background: var(--color-primary-green);
    padding: var(--spacing-lg) var(--spacing-md) 6rem;
    color: white;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    clip-path: polygon(0 0, 100% 0, 100% 75%, 0 100%);
    margin-bottom: -4rem;
    position: relative;
    z-index: 1;
}

.admin-link {
    color: var(--color-white);
    text-decoration: none;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.admin-link:hover {
    opacity: 1;
    color: var(--color-white);
}

.admin-link .material-symbols-outlined {
    font-size: 28px;
}

.header-green.compact {
    padding-bottom: 4rem;
    margin-bottom: -2rem;
}

.header-title {
    font-family: var(--font-primary);
    font-weight: 800;
    font-size: 28px;
    line-height: 1.2;
}

.header-subtitle {
    font-family: var(--font-secondary);
    font-weight: 500;
    font-size: 16px;
    opacity: 0.9;
}

.back-button {
    color: var(--color-white);
    text-decoration: none;
    font-size: 24px;
    display: inline-block;
}

.back-button.circle {
    border: 2px solid var(--color-white);
    border-radius: var(--radius-round);
    line-height: 28px;
}

/* Layout */


.section-title {
    font-family: var(--font-secondary);
    font-weight: 600;
    font-size: 20px;
    color: var(--color-black);
    /* margin: var(--spacing-md) 0 0.75rem; */
}

/* Cards - Base Styles */
.card-base {
    background: var(--color-white);
    box-shadow: var(--shadow-card);
    border-radius: var(--radius-lg);
}



.stop-name {
    font-family: var(--font-secondary);
    font-weight: 700;
    font-size: 20px;
    color: var(--color-black);
}

.stop-name.small {
    font-size: 16px;
}

.stop-desc {
    font-family: var(--font-secondary);
    font-weight: 510;
    font-size: 14px;
    color: var(--color-text-gray);
}

/* Badges */
.line-badge {
    background: var(--color-primary-blue);
    border-radius: var(--radius-sm);
    color: white;
    font-family: var(--font-secondary);
    font-weight: 700;
    font-size: 14px;
}

.line-badge.badge-blue {
    background: var(--color-primary-blue);
}
.line-badge.badge-red {
    background: var(--color-primary-red);
}
.line-badge.badge-night {
    background: var(--color-night-blue);
}
.line-badge.badge-walking {
    background: var(--color-text-gray, #6c757d);
}

.line-badge.large {
    font-size: 18px;
}

/* Buttons */
.btn-primary {
    background: var(--color-primary-blue);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-secondary);
    font-weight: 700;
    font-size: 16px;
    transition: all 0.2s ease;
}

.btn-primary:active {
    transform: scale(0.98);
    background: #013d99;
}

/* Le utility di Bootstrap devono vincere sul radius imposto da .btn/.btn-primary */
.btn.rounded-pill {
    border-radius: var(--bs-border-radius-pill, 50rem);
}

.btn-outline-primary {
    background: var(--color-bg-gray);
    color: var(--color-primary-blue);
    border: 2px solid var(--color-primary-blue);
    border-radius: var(--radius-md);
    font-family: var(--font-secondary);
    font-weight: 700;
    font-size: 16px;
    transition: all 0.2s ease;
}

.btn-outline-primary:active, .btn-check:checked+.btn, .btn.active, .btn.show, .btn:first-child:active, :not(.btn-check)+.btn:active, .btn-outline-primary:focus-visible{
    transform: scale(0.98);
    background: var(--color-primary-blue);
    color: var(--color-white);
    border: none;
}

.btn-secondary {
    background: var(--color-white);
    color: var(--color-primary-blue);
    border: 2px solid var(--color-primary-blue);
    border-radius: var(--radius-md);
    font-family: var(--font-secondary);
    font-weight: 700;
    font-size: 16px;
    transition: all 0.2s ease;
}

.btn-secondary:active {
    transform: scale(0.98);
    background: var(--color-bg-light);
}

/* Map */
#map {
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Loading & Status */
.loading {
    text-align: center;
}

.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--color-primary-green);
    border-radius: var(--radius-round);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

#status {
    border-radius: var(--radius-lg);
}

.mit-licence {
    text-align: center;
    font-size: 12px;
    color: var(--color-text-gray);
}

/* Sciopero */
.sciopero {
    background-color: var(--color-bg-gray);
    color: var(--color-black);
    text-align: center;
    text-decoration: none;
    border-radius: var(--radius-lg);
    border: none;
}

html[data-theme="dark"] .leaflet-layer,
html[data-theme="dark"] .leaflet-control-zoom-in,
html[data-theme="dark"] .leaflet-control-zoom-out,
html[data-theme="dark"] .leaflet-control-attribution,
html[data-theme="dark"] .leaflet-control-fullscreen-button {
    filter: invert(1) hue-rotate(180deg) brightness(95%) contrast(90%);
}
html[data-theme="dark"] .leaflet-container {
    background: #0000;
}

/* Dark theme inputs */
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select {
    background-color: var(--color-white);
    color: var(--color-black);
    border: 1px solid var(--color-primary-blue);
}

.error-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    background-color: #ef4444A0;
    color: white;
    padding: 10px;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    font-size: 12px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 40px);
    overflow: auto;
}
.error-popup {
    margin-bottom: 10px;
}
.error-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.error-popup-title {
    font-weight: 700;
}

/* Bus Status & Overlap Styles */
.bus-div-icon {
    transition: all 0.3s ease;
}

.bus-icon {
    /* Base styles ensured, avoid overriding Leaflet defaults too much except what we need */
    width: 30px;
    height: 30px;
    border-radius: 50%; /* Make them circular */
    color: white;
    font-weight: bold;
    display: flex; /* Flex to center text */
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    border: 2px solid white;
    font-size: 14px;
    transition: all 0.3s ease;
}

/* Scheduled / No Data -> Gray */
.bus-icon.scheduled {
    background-color: #9E9E9E !important; 
    z-index: 400 !important;
}

/* API Flagged Non-Realtime -> Darker Gray with Dashed Border */
.bus-icon.scheduled-api {
    background-color: #616161 !important;
    border: 2px dashed #ccc !important;
    z-index: 400 !important;
}

/* Realtime -> Ensure high z-index */
.bus-icon.realtime {
    z-index: 1000 !important;
}

/* Mini Markers */
.bus-icon.mini {
    width: 16px !important;
    height: 16px !important;
    font-size: 0px; /* Hide original text */
    min-width: 16px;
    border: 1px solid white;
    z-index: 300 !important;
}

.bus-icon.mini::after {
    content: attr(data-line);
    font-size: 8px;
    display: block;
    line-height: 1;
    color: white;
    font-weight: 800;
}

/* Side Panel for Non-Realtime Buses */
#non-rt-panel {
    position: fixed;
    top: 180px;
    right: 10px;
    width: 220px;
    background: var(--color-white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    z-index: 2000;
    max-height: 50vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.3s ease;
}

/* Dark mode support for panel */
html[data-theme="dark"] #non-rt-panel {
    background: var(--color-bg-gray);
    border: 1px solid var(--color-border-gray);
}

#non-rt-panel.collapsed {
    transform: translateX(190px);
}

#non-rt-panel.hidden {
    display: none;
}

.nr-header {
    background: var(--color-orange);
    color: white;
    padding: 8px 12px;
    font-weight: bold;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nr-header:hover {
    opacity: 0.9;
}

.nr-list {
    overflow-y: auto;
    flex: 1;
    padding: 0;
    margin: 0;
    list-style: none;
}

.nr-item {
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border-gray);
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
    color: var(--color-text-dark);
}

.nr-item:hover {
    background: var(--color-bg-light);
}

.nr-content {
    display: flex;
    flex-direction: column;
}

.nr-badge {
    background: var(--color-text-gray);
    color: white;
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: bold;
    min-width: 28px;
    text-align: center;
    margin-right: 8px;
}

/* Offline Indicator */
.offline-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--color-actv-red);
    color: var(--color-white);
    padding: 8px 16px;
    font-family: 'SF Pro', sans-serif;
    font-size: 13px;
    font-weight: 600;
    z-index: 1000;
    animation: slideDown 0.3s ease;
}

.offline-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-white);
    animation: blink 1.5s infinite;
}

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

/* ===== Condivisione / QR ===== */
/* Widget Share Modal */
.widget-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.widget-modal {
    background: var(--color-white);
    border-radius: 16px;
    max-width: 480px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.widget-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-lighter-gray);
    font-family: 'SF Pro', sans-serif;
    font-weight: 700;
    font-size: 16px;
}

.widget-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--color-text-gray);
}

.widget-modal-body { padding: 20px; }

.widget-modal-desc {
    font-family: 'SF Pro', sans-serif;
    font-size: 13px;
    color: var(--color-text-gray);
    margin-bottom: 16px;
}

.widget-label {
    display: block;
    font-family: 'SF Pro', sans-serif;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.widget-code {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--color-border-gray);
    border-radius: 8px;
    font-family: monospace;
    font-size: 12px;
    resize: none;
    background: var(--color-bg-gray);
    color: var(--color-text-dark);
}

.widget-url-input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--color-border-gray);
    border-radius: 8px;
    font-family: 'SF Pro', sans-serif;
    font-size: 12px;
    background: var(--color-bg-gray);
    color: var(--color-text-dark);
}

.widget-copy-btn {
    display: block;
    width: 100%;
    padding: 10px;
    margin-top: 8px;
    border: none;
    border-radius: 8px;
    background: var(--color-primary-green);
    color: var(--color-white);
    font-family: 'SF Pro', sans-serif;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.widget-copy-btn:hover { opacity: 0.9; }
.widget-copy-link { background: var(--color-primary-blue); }

.widget-preview-label {
    font-family: 'SF Pro', sans-serif;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 16px;
    margin-bottom: 8px;
}

.widget-preview {
    border: 1px solid var(--color-border-gray);
    border-radius: 12px;
    overflow: hidden;
}

/* QR FAB (pulsante flottante in basso a destra, stile del "!" rosso) */
.qr-fab {
    position: fixed;
    right: 18px;
    bottom: calc(100px + env(safe-area-inset-bottom));
    z-index: 90;
    width: 52px;
    height: 52px;
    padding: 0;
    border: none;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--color-primary-green);
    color: #fff;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 22px rgba(0, 0, 0, .25);
    transition: transform .5s;
}

.qr-fab:hover { transform: scale(1.05); }
.qr-fab:active { transform: scale(0.95); }

/* QR Code Modal */
.qr-container {
    display: flex;
    justify-content: center;
    padding: 16px;
    background: var(--color-white);
    border: 1px solid var(--color-border-gray);
    border-radius: 12px;
}

.qr-container svg {
    width: 200px;
    height: 200px;
}

.copy-feedback {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-black);
    color: var(--color-white);
    padding: 10px 24px;
    border-radius: 8px;
    font-family: 'SF Pro', sans-serif;
    font-weight: 600;
    font-size: 13px;
    z-index: 2000;
    animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
