/* UI v2 (beta): one floating tool rail, one panel, search on the map. Active only with html.ui2 (?ui=2).
   Same markup and scripts as the classic view, so nothing changes for crawlers or users who do not opt in. */

/* ---- no duplicate toolbar above the map ---- */
html.ui2 .hero-toolbar,
html.ui2 .tools-share {
    display: none !important;
}
html.ui2 .hero-map-card {
    padding: 10px;
}

/* Two modes, one set of modules.
   Page mode (desktop, embedded map): the modules (route data, likes, times, comments) sit on the page under the map,
   the rail only has map tools. App mode (mobile, fullscreen): the map fills the screen and the same modules open
   from the rail. Only pages that show the modules themselves (the track page) are switched. */
html.ui2:has(.trackdetail-community) .leaflet-sidebar-tabs > ul:first-child {
    display: none;
}
@media (max-width: 999px) {
    /* below 1000px the map is (almost) full height already: app mode */
    html.ui2:has(.trackdetail-community) .leaflet-sidebar-tabs > ul:first-child {
        display: block;
    }
}
html.ui2:has(.trackdetail-community) body.fullscreen .leaflet-sidebar-tabs > ul:first-child {
    display: block;
}

/* start page: route data and comments are on the page (card under the map, section at the bottom),
   the rail keeps the tools. In app mode (fullscreen, below 1000px) route info and comments join the rail again. */
html.ui2:has(.mytrack-card) .leaflet-sidebar-tabs li:has(a[href="#tabinfo"]),
html.ui2:has(.mytrack-card) .leaflet-sidebar-tabs li:has(a[href="#tabcomments"]) {
    display: none;
}
@media (max-width: 999px) {
    html.ui2:has(.mytrack-card) .leaflet-sidebar-tabs li:has(a[href="#tabinfo"]),
    html.ui2:has(.mytrack-card) .leaflet-sidebar-tabs li:has(a[href="#tabcomments"]) {
        display: block;
    }
}
html.ui2:has(.mytrack-card) body.fullscreen .leaflet-sidebar-tabs li:has(a[href="#tabinfo"]),
html.ui2:has(.mytrack-card) body.fullscreen .leaflet-sidebar-tabs li:has(a[href="#tabcomments"]) {
    display: block;
}

/* ---- sidebar: a transparent layer, rail and panel float on the map ---- */
html.ui2 .leaflet-sidebar {
    background: none;
    box-shadow: none !important;
    border: none !important;
    pointer-events: none;
    width: auto;
    max-width: none;
    right: 0;
    border-radius: 0 !important;
}
html.ui2 .leaflet-sidebar.collapsed {
    width: auto;
}
@media (min-width: 768px) {
    html.ui2 .leaflet-sidebar {
        top: 10px;
        bottom: 10px;
        left: 10px;
    }
}
html.ui2 .leaflet-sidebar-left ~ .leaflet-control-container .leaflet-left,
html.ui2 .leaflet-sidebar-left.collapsed ~ .leaflet-control-container .leaflet-left {
    left: 60px;
}

/* rail: two floating groups */
html.ui2 .leaflet-sidebar-tabs {
    background: none;
    width: 46px;
    pointer-events: none;
}
html.ui2 .leaflet-sidebar-tabs > ul {
    width: 46px;
    background-color: #fff;
    border-radius: 14px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
    padding: 4px 0;
    pointer-events: auto;
}
html.ui2 .leaflet-sidebar-tabs > ul + ul {
    bottom: 0;
}
html.ui2 .leaflet-sidebar-tabs > ul > li {
    position: relative;
    height: 42px;
    margin: 0 4px;
    width: 38px;
    border-radius: 10px;
    overflow: visible;
}
html.ui2 .leaflet-sidebar-tabs > ul > li > a {
    line-height: 42px;
}
html.ui2 .leaflet-sidebar-tabs > ul > li:hover {
    background-color: #eaf3fd;
    color: #0074d9;
}
html.ui2 .leaflet-sidebar-tabs > ul > li.active {
    background-color: #0074d9;
    color: #fff;
}
/* divider before the account / community group */
html.ui2 .leaflet-sidebar-tabs > ul > li:has(a[href="#tabuser"]) {
    margin-top: 7px;
}
html.ui2 .leaflet-sidebar-tabs > ul > li:has(a[href="#tabuser"]):before {
    content: "";
    position: absolute;
    top: -4px;
    left: 6px;
    right: 6px;
    height: 1px;
    background-color: #e2e5ea;
}
/* labels on hover (desktop) */
@media (hover: hover) and (min-width: 768px) {
    html.ui2 .leaflet-sidebar-tabs > ul > li[data-label]:hover:after {
        content: attr(data-label);
        position: absolute;
        left: 48px;
        top: 50%;
        transform: translateY(-50%);
        white-space: nowrap;
        background-color: #0b2a4a;
        color: #fff;
        font-size: .75rem;
        font-weight: 600;
        padding: 5px 9px;
        border-radius: 7px;
        pointer-events: none;
        z-index: 5;
    }
}
html.ui2 .leaflet-sidebar-tabs > ul > li.active[data-label]:hover:after {
    display: none;
}
/* login-only features: small lock while signed out */
html.ui2 body:not(.loggedin) .leaflet-sidebar-tabs a[href="#tablikes"]:after,
html.ui2 body:not(.loggedin) .leaflet-sidebar-tabs a[href="#tabtimes"]:after {
    content: "\f023";
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    position: absolute;
    right: 3px;
    bottom: 5px;
    font-size: .45rem;
    line-height: 1;
    color: #99a;
}

.ui2-login-note {
    display: none;
    margin: 0 0 12px;
    padding: 10px 12px;
    border-radius: 10px;
    background-color: #f1f7fe;
    border: 1px solid #d6e6f7;
    font-size: .9rem;
    line-height: 1.4em;
}
html.ui2 body:not(.loggedin) .ui2-login-note {
    display: block;
}
.ui2-login-note a, .ui2-login-note button {
    font-weight: 700;
    color: #0074d9;
    white-space: nowrap;
}
html.ui2[data-theme="dark"] .ui2-login-note {
    background-color: #1a2330;
    border-color: #2d4a69;
}

/* "search" tab becomes "discover routes": the place search is already on the map */
html.ui2 #tabgeneral > section:first-of-type {
    display: none;
}
/* account panel on the map: only what belongs to the map; password and account live on the account page */
html.ui2 #tabuser .notloggedin > section:nth-of-type(2),
html.ui2 #tabuser .notloggedin > section:nth-of-type(3),
html.ui2 #tabuser .loggedin > section:nth-of-type(1),
html.ui2 #tabuser .loggedin > section:nth-of-type(4) {
    display: none;
}
/* the e-mail address in the panel header just overlaps the content */
html.ui2 #tabuser .leaflet-sidebar-header .username {
    display: none;
}
.ui2-login-cta {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 11px 14px;
    border: none;
    border-radius: 10px;
    background-color: #0074d9;
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
}
.ui2-login-cta:hover {
    background-color: #005fb3;
}
.ui2-account-footer {
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px solid #e6edf5;
    font-size: .8rem;
    color: #99a;
}
.ui2-account-footer a {
    color: #778;
    font-weight: 400;
    text-decoration: none;
}
.ui2-account-footer a:hover {
    color: #0074d9;
    text-decoration: underline;
}
html.ui2 body.loggedin .ui2-account-footer .loggedin {
    display: inline;
}
html.ui2[data-theme="dark"] .ui2-account-footer {
    border-color: #2d333d;
    color: #8791a1;
}
html.ui2[data-theme="dark"] .ui2-account-footer a {
    color: #8791a1;
}

/* panel: a card next to the rail, below the search bar */
html.ui2 .leaflet-sidebar-content {
    pointer-events: auto;
    background-color: #fff;
    border-radius: 14px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, .22);
    left: 56px !important;
    right: auto !important;
    top: 56px;
    bottom: auto;
    width: 380px;
    max-width: calc(100vw - 80px);
    max-height: calc(100% - 66px);
    overflow-y: auto;
}
html.ui2 .leaflet-sidebar.collapsed > .leaflet-sidebar-content {
    display: none;
}
html.ui2 .leaflet-sidebar-pane {
    min-width: 0 !important;
    padding: 6px 20px 20px;
}
html.ui2 .leaflet-sidebar-header {
    position: sticky;
    top: 0;
    z-index: 2;
    margin: 0 -20px 12px;
    height: 48px;
    line-height: 48px;
    padding: 0 56px 0 20px;
    font-size: 1.05rem;
    font-weight: 700;
    color: #0b2a4a;
    background-color: #fff;
    border-bottom: 1px solid #e6edf5;
}
html.ui2 .leaflet-sidebar-close {
    width: 48px;
    height: 48px;
    line-height: 48px;
    color: #667;
}
html.ui2 .leaflet-sidebar-close:hover {
    color: #0074d9;
}

html.ui2 .leaflet-sidebar-pane textarea {
    height: 84px;
    resize: vertical;
}

/* ---- search + other routes on the map ---- */
html.ui2 .ui2-searchbar {
    position: absolute;
    z-index: 1100;
    top: 10px;
    left: 66px;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: calc(100% - 140px);
}
html.ui2 .ui2-searchbar .search {
    display: flex;
    align-items: center;
    width: 380px;
    max-width: 100%;
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
    padding: 0 5px 0 14px;
    height: 46px;
}
html.ui2 .ui2-searchbar .search i {
    color: #99a;
    margin-right: 8px;
}
html.ui2 .ui2-searchbar .search input[type=text] {
    flex: 1;
    min-width: 0;
    border: none;
    background: none;
    font-size: 1rem;
    padding: 8px 4px;
    outline: none;
}
html.ui2 .ui2-searchbar .search .btn {
    margin: 0;
    padding: 7px 14px;
    border-radius: 8px;
    border: none;
    background-color: #0074d9;
    color: #fff;
}
html.ui2 .ui2-searchbar .btn-off,
html.ui2 .ui2-searchbar .btn-on {
    height: 46px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
    white-space: nowrap;
}
html.ui2 .ui2-searchbar .btn-off {
    background-color: #fff;
    border: none;
    color: #334;
}

/* total distance chip below the search bar on narrow maps */
@media (max-width: 1100px) {
    html.ui2 body .mapinfo {
        top: 64px;
    }
}

/* ---- mobile: panels as a bottom sheet, the map stays visible ---- */
@media (max-width: 767px) {
    html.ui2 .leaflet-sidebar {
        top: 8px;
        bottom: 8px;
        left: 8px;
    }
    html.ui2 .ui2-searchbar {
        top: 8px;
        left: 62px;
        right: 62px;
        max-width: none;
        flex-wrap: wrap;
    }
    html.ui2 .ui2-searchbar .search {
        width: 100%;
        height: 44px;
    }
    html.ui2 .ui2-searchbar .btn-off,
    html.ui2 .ui2-searchbar .btn-on {
        height: 36px;
        font-size: .85rem;
    }
    html.ui2 .leaflet-sidebar-content {
        position: fixed;
        left: 0 !important;
        right: 0 !important;
        top: auto;
        bottom: 0;
        width: auto;
        max-width: none;
        max-height: 68vh;
        border-radius: 18px 18px 0 0;
        z-index: 2500;
        box-shadow: 0 -4px 22px rgba(0, 0, 0, .25);
    }
    html.ui2 .leaflet-sidebar-content:before {
        content: "";
        display: block;
        width: 40px;
        height: 4px;
        margin: 8px auto 0;
        border-radius: 2px;
        background-color: #d5d9df;
    }
    html.ui2 .leaflet-sidebar-header {
        height: 44px;
        line-height: 44px;
    }
    html.ui2 .leaflet-sidebar-close {
        height: 44px;
        line-height: 44px;
    }
    html.ui2 .leaflet-sidebar-close i {
        display: inline-block;
        transform: rotate(-90deg);
    }
}

/* ---- beta badge to switch back ---- */
html.ui2 .ui2-badge {
    position: fixed;
    left: 12px;
    bottom: 12px;
    z-index: 3000;
    background-color: #0b2a4a;
    color: #fff;
    font-size: .75rem;
    font-weight: 600;
    padding: 7px 12px;
    border-radius: 999px;
    text-decoration: none;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .3);
}
html.ui2 .ui2-badge:hover {
    background-color: #0074d9;
    color: #fff;
}
.ui2-badge {
    display: none;
}
html.ui2 .ui2-badge {
    display: inline-block;
}

/* ---- dark mode ---- */
html.ui2[data-theme="dark"] .leaflet-sidebar-tabs > ul,
html.ui2[data-theme="dark"] .leaflet-sidebar-content,
html.ui2[data-theme="dark"] .leaflet-sidebar-header,
html.ui2[data-theme="dark"] .ui2-searchbar .search,
html.ui2[data-theme="dark"] .ui2-searchbar .btn-off {
    background-color: #1c2027;
}
html.ui2[data-theme="dark"] .leaflet-sidebar-tabs > ul > li {
    color: #c3cad6;
}
html.ui2[data-theme="dark"] .leaflet-sidebar-tabs > ul > li:hover {
    background-color: #2b313b;
    color: #4da3ff;
}
html.ui2[data-theme="dark"] .leaflet-sidebar-tabs > ul > li.active {
    background-color: #0074d9;
    color: #fff;
}
html.ui2[data-theme="dark"] .leaflet-sidebar-tabs > ul > li:has(a[href="#tabuser"]):before {
    background-color: #2d333d;
}
html.ui2[data-theme="dark"] .leaflet-sidebar-header {
    color: #fff;
    border-color: #2d333d;
}
html.ui2[data-theme="dark"] .ui2-searchbar .btn-off {
    color: #dfe3ea;
}
html.ui2[data-theme="dark"] .ui2-searchbar .search input[type=text] {
    color: #4da3ff;
}
html.ui2[data-theme="dark"] .leaflet-sidebar-content:before {
    background-color: #3a4250;
}
