/* ==========================================================================
   BusPlaceMap — foglio di stile principale (mobile-first)
   ========================================================================== */

:root {
    --brand: #2c3e50;
    --brand-dark: #1f2d3a;
    --accent: #e67e22;
    --text: #1c2833;
    --muted: #6b7c8c;
    --surface: #ffffff;
    --ok: #27ae60;
    --warn: #e0a800;
    --danger: #c0392b;
    --radius: 14px;
    --shadow-soft: 0 8px 24px rgba(16, 32, 48, 0.18);
    --shadow-strong: 0 12px 34px rgba(16, 32, 48, 0.26);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    background: #e8eef2;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overscroll-behavior: none;
}

/* --- Mappa a tutto schermo ------------------------------------------------- */

.map-shell {
    position: fixed;
    inset: 0;
}

#map {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    margin: 0;
    background: #dde6ec;
    z-index: 0;
}

/* --- Barra superiore ------------------------------------------------------- */

.app-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding:
        calc(0.65rem + env(safe-area-inset-top, 0px))
        calc(0.85rem + env(safe-area-inset-right, 0px))
        0.65rem
        calc(0.85rem + env(safe-area-inset-left, 0px));
    color: #fff;
    background: linear-gradient(180deg, rgba(44, 62, 80, 0.97), rgba(44, 62, 80, 0.88));
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    box-shadow: 0 6px 20px rgba(16, 32, 48, 0.22);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
}

.brand__mark {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border-radius: 11px;
    color: var(--brand);
    background: #fff;
    box-shadow: inset 0 0 0 1px rgba(44, 62, 80, 0.08);
}

.brand__mark svg {
    width: 22px;
    height: 22px;
}

.brand__text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.15;
}

.brand__title {
    font-size: 1.02rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.brand__subtitle {
    font-size: 0.68rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.66);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Pill di stato --------------------------------------------------------- */

.pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    flex: 0 0 auto;
    padding: 0.34rem 0.66rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
    color: #fff;
    background: rgba(255, 255, 255, 0.14);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.pill__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #fff;
}

.pill.is-loading .pill__dot {
    background: #f1c40f;
    animation: pill-pulse 1.2s ease-in-out infinite;
}

.pill.is-ok .pill__dot {
    background: #2ecc71;
}

.pill.is-empty .pill__dot {
    background: #bdc3c7;
}

.pill.is-error {
    background: rgba(192, 57, 43, 0.9);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}

.pill.is-error .pill__dot {
    background: #fff;
}

@keyframes pill-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.35; transform: scale(0.72); }
}

/* --- Toast ---------------------------------------------------------------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(1.1rem + env(safe-area-inset-bottom, 0px));
    z-index: 1300;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: calc(100% - 2rem);
    max-width: 420px;
    padding: 0.8rem 1rem;
    border-radius: var(--radius);
    color: #fff;
    font-size: 0.84rem;
    line-height: 1.35;
    background: rgba(31, 45, 58, 0.96);
    box-shadow: var(--shadow-strong);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.toast[hidden] {
    display: none;
}

.toast--static {
    position: static;
    transform: none;
    margin: 1rem;
    width: auto;
}

.toast__text {
    flex: 1 1 auto;
}

.toast__action {
    flex: 0 0 auto;
    padding: 0.42rem 0.8rem;
    border: 0;
    border-radius: 9px;
    font: inherit;
    font-weight: 700;
    color: var(--brand-dark);
    background: #fff;
    cursor: pointer;
}

.toast__action:hover {
    background: #e9edf0;
}

.toast__action:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* --- Marker personalizzati ------------------------------------------------ */

.bp-marker {
    background: transparent;
    border: 0;
}

.bp-marker__badge {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 17px;
    line-height: 1;
    background: #fff;
    border: 2px solid var(--brand);
    box-shadow: 0 4px 12px rgba(16, 32, 48, 0.3);
    transition: transform 0.15s ease;
}

.bp-marker__badge.is-pending {
    border-style: dashed;
    border-color: var(--warn);
}

.leaflet-marker-icon:hover .bp-marker__badge,
.bp-marker:focus-visible .bp-marker__badge {
    transform: scale(1.12);
}

/* --- Popup ---------------------------------------------------------------- */

.leaflet-container {
    font-family: inherit;
}

.leaflet-popup-content-wrapper {
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
}

.leaflet-popup-content {
    margin: 0.85rem 1rem;
    line-height: 1.4;
}

.bp-popup {
    min-width: 190px;
    max-width: 250px;
}

.bp-popup__title {
    margin: 0 0 0.4rem;
    font-size: 0.98rem;
    font-weight: 700;
    color: var(--brand-dark);
}

.bp-popup__desc {
    margin: 0 0 0.55rem;
    font-size: 0.82rem;
    color: #41525f;
    white-space: pre-line;
}

.bp-popup__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.bp-popup__chip {
    display: inline-block;
    padding: 0.16rem 0.5rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--brand-dark);
    background: #eef2f5;
}

.bp-popup__chip.is-pending {
    color: #7a5b00;
    background: #fdf3d3;
}

.bp-popup__chip.is-active {
    color: #14643a;
    background: #e2f6ea;
}

/* --- Controlli Leaflet ---------------------------------------------------- */

.leaflet-top .leaflet-control {
    margin-top: calc(4.6rem + env(safe-area-inset-top, 0px));
}

.leaflet-bottom .leaflet-control {
    margin-bottom: calc(1.6rem + env(safe-area-inset-bottom, 0px));
}

.leaflet-control-zoom a {
    color: var(--brand) !important;
}

.leaflet-control-attribution {
    font-size: 10px;
    background: rgba(255, 255, 255, 0.82);
}

/* --- Accessibilita' ------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}

@media (max-width: 360px) {
    .brand__subtitle {
        display: none;
    }

    .pill {
        font-size: 0.68rem;
    }
}
