/* Route Crafter Styles */

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

#appLayout {
    display: flex;
    height: 100%;
    min-height: 0;
    width: 100%;
}

.controls-sidebar {
    flex: 0 0 460px;
    width: 460px;
    min-height: 0;
    overflow: hidden;
    background: #fff;
    border-right: 1px solid #d8d8d8;
    box-shadow: 2px 0 12px rgba(0,0,0,0.12);
    z-index: 500;
}

.map-shell {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    position: relative;
}

#map {
    height: 100%;
    width: 100%;
    /* Make the map fill the entire viewport */
}

#controls {
    height: 15vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #f4f4f4;
    border-top: 1px solid #ddd;
}

button,
input,
select,
label,
p {
    margin: 5px 5px;
    padding: 10px 10px;
    font-size: 15px;
    cursor: pointer;
}

/* Ensure statistics use the same font size as labels on desktop */
#routeLength {
    font-size: 15px;
}

/* Hide statistics when empty */
#routeLength:empty {
    display: none;
}

button {
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
}

button:hover {
    background-color: #0056b3;
}

/* Add this to your CSS section */
.button-loading {
    position: relative;
    pointer-events: none;
    /* Disable clicking while loading */
    opacity: 0.7;
}

.button-loading .spinner {
    position: absolute;
    top: 50%;
    right: 15px;
    width: 16px;
    height: 16px;
    margin-top: -8px;
    /* Half of spinner height to center vertically */
    border: 2px solid transparent;
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

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

/* Styles for the filter control from combined.html */
.leaflet-control-filters {
    background: #f0f0f0;
    padding: 8px 12px;
    font-size: 14px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
    border-radius: 5px;
    max-width: 300px;
    display: none; /* Hidden by default */
}

.leaflet-control-filters label {
    display: block;
    margin-bottom: 6px;
}

.leaflet-control-filters input[type="date"],
.leaflet-control-filters input[type="text"] {
    width: 100%;
    box-sizing: border-box;
}

.leaflet-control-filters button,
#toggleFilterBtn {
    margin-top: 6px;
    width: 100%;
    cursor: pointer;
}

.image-type-btn {
    display: inline-block;
    margin: 0;
    padding: 4px 8px;
    font-size: 12px;
    border: 1px solid #ccc;
    background-color: #f9f9f9;
    color: #333;
    cursor: pointer;
    border-radius: 3px;
    flex: 1;
    min-width: 0;
    box-sizing: border-box;
}

.image-type-btn:hover {
    background-color: #e9e9e9;
    color: #333;
}

.image-type-btn.active {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}

/* Date preset buttons */
.date-preset-btn {
    display: inline-block;
    margin: 0;
    padding: 4px 8px;
    font-size: 12px;
    border: 1px solid #ccc;
    background-color: #f9f9f9;
    color: #333;
    cursor: pointer;
    border-radius: 3px;
    flex: 1;
    text-align: center;
}

.date-preset-btn:hover {
    background-color: #e9e9e9;
    color: #333;
}

/* Style for the zoom tip */
.leaflet-control-filters .zoom-tip {
    font-size: 12px;
    color: #555;
    margin: 12px;
    font-style: italic;
}

/* Debug Menu Styles */
.debug-menu-container {
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.debug-menu-container button {
    font-size: 13px;
    padding: 6px 10px;
    margin: 2px 0;
}

#debugMenuToggle {
    background-color: #6c757d;
    transition: background-color 0.2s;
}

#debugMenuToggle:hover {
    background-color: #545b62;
}

#debugMenuContent {
    min-width: 200px;
}

/* Context Menu Styles */
.context-menu {
    position: fixed;
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 1000;
    min-width: 200px;
    display: none;
}

.context-menu-item {
    margin: 5px 5px;
    padding: 10px 10px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    font-size: 15px;
    font-family: Arial, sans-serif;
    color: #333;
}

.context-menu-item:last-child {
    border-bottom: none;
}

.context-menu-item:hover {
    background-color: #f5f5f5;
}

.context-menu-item:active {
    background-color: #e0e0e0;
}

.context-menu-divider {
    height: 1px;
    background-color: #ccc;
    margin: 5px 0;
}

/* Media Player Controls Styles */
.media-controls {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 10px 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    display: none;
    z-index: 1000;
    min-width: 300px;
    font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;
    font-size: 12px;
}

.media-controls.visible {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.media-controls-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.media-btn {
    background: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    min-width: 40px;
}

.media-btn:hover {
    background: #0056b3;
}

.media-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.media-btn.active {
    background: #28a745;
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 5px;
}

.speed-btn {
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 3px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 12px;
}

.speed-btn:hover {
    background: #545b62;
}

.speed-btn.active {
    background: #007bff;
}

.progress-container {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    position: relative;
}

.progress-bar:hover {
    height: 10px;
}

.progress-fill {
    height: 100%;
    background: #007bff;
    width: 0%;
    transition: width 0.1s ease;
}

.progress-bar.dragging {
    cursor: grabbing;
}

.progress-text {
    font-size: 12px;
    color: #666;
    min-width: 80px;
    text-align: center;
}

/* Mobile controls styles */
.leaflet-bar {
    max-width: 90vw;
    max-height: 70vh;
    overflow-y: auto;
}

.leaflet-bar div {
    padding: 5px;
    background: white;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

/* Main controls sidebar */
.main-controls-shell {
    height: 100%;
    min-height: 0;
    display: flex;
}

.main-controls-panel,
.main-controls-panel div {
    box-sizing: border-box;
}

#mainControlsDiv.main-controls-panel {
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 12px;
    color: #222;
    background: #fff;
    font-family: "Helvetica Neue", Arial, sans-serif;
}

.main-controls-panel button,
.main-controls-panel input,
.main-controls-panel select,
.main-controls-panel label {
    box-sizing: border-box;
    margin: 0;
    font-size: 13px;
}

.main-controls-panel button {
    padding: 7px 9px;
    line-height: 1.2;
    white-space: nowrap;
}

.main-controls-panel input,
.main-controls-panel select {
    min-width: 0;
    padding: 7px 8px;
}

.main-controls-panel input[type="checkbox"] {
    width: 18px;
    height: 18px;
    padding: 0;
}

.main-controls-panel .sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 0 10px;
    margin: 0 0 8px;
    border-bottom: 1px solid #e5e5e5;
}

.sidebar-brand-main {
    min-width: 0;
}

.sidebar-brand-title {
    color: #111;
    font-size: 20px;
    font-weight: 700;
    line-height: 1.1;
}

.sidebar-brand-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 3px;
    font-size: 12px;
    line-height: 1.2;
}

.sidebar-brand-version {
    color: #666;
    font-weight: 600;
}

.sidebar-brand-link {
    color: #007bff;
    font-weight: 600;
    text-decoration: none;
}

.sidebar-brand-link:hover {
    color: #0056b3;
    text-decoration: underline;
}

.main-controls-panel .main-controls-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 0 8px;
    border-bottom: 1px solid #e5e5e5;
}

.main-controls-search {
    flex: 1 1 auto;
    width: 100%;
}

.main-controls-toggle {
    display: none;
}

.main-controls-panel .main-controls-content {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    margin-top: 8px;
    padding: 0 4px 0 0;
    overflow-y: auto;
}

.main-controls-panel .main-controls-select-action,
.main-controls-panel .main-controls-actions,
.main-controls-panel .main-controls-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0;
}

.main-controls-select-action select,
.main-controls-input-wide {
    flex: 1 1 auto;
    width: 100%;
}

.main-controls-actions {
    flex-wrap: wrap;
}

.main-controls-actions button {
    flex: 1 1 100px;
}

#setStartingLocationButton.active {
    background-color: #198754;
}

#setStartingLocationButton.active:hover {
    background-color: #157347;
}

.stale-settings-warning {
    padding: 8px 10px;
    border: 1px solid #d99a20;
    border-left-width: 4px;
    border-radius: 4px;
    background: #fff8e6;
    color: #5f3b00;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
}

.stale-settings-warning[hidden] {
    display: none;
}

.main-controls-row label {
    flex: 1 1 48%;
    line-height: 1.25;
}

.main-controls-row select,
.main-controls-row input[type="text"],
.main-controls-row input[type="url"] {
    flex: 1 1 52%;
}

.main-controls-number {
    flex: 0 0 84px;
    width: 84px;
}

.main-controls-long-field {
    align-items: stretch;
    flex-direction: column;
}

.main-controls-long-field label,
.main-controls-long-field input {
    width: 100%;
}

/* Right-side statistics panel */
.stats-panel {
    z-index: 1000;
    margin-top: 8px;
    margin-right: 8px;
    background: rgba(255,255,255,0.95);
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.12);
}

.stats-panel #statsPanelInner {
    font-family: "Helvetica Neue", Arial, sans-serif;
    color: #222;
}

#routeLength {
    margin: 0;
    padding: 0;
    font-size: 13px;
    line-height: 1.3;
    max-width: 260px;
}

/* Make details smaller when routeLength contains verbose HTML */
#routeLength small, .stats-panel .small-text {
    font-size: 11px;
    color: #666;
}

.cpp-summary {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(0,0,0,0.06);
}

.cpp-summary .small-text {
    margin-top: 4px;
}

.cpp-length {
    margin-top: 0;
    font-size: 13px;
    color: #222;
    line-height: 1.1;
}

.cpp-length strong {
    margin-right: 6px;
}

.cpp-efficiency {
    font-size: 13px; /* match .cpp-length */
    color: #222; /* match .cpp-length color */
    display: inline-block;
    margin-top: 0;
    margin-left: 0;
}

/* Combined Media query for smaller screens (portrait and landscape mobile) */
@media (max-width: 600px), /* For portrait phones and small tablets */
       (max-height: 450px) and (orientation: landscape) { /* For landscape phones where height is constrained */
    :root {
        --mobile-controls-menu-gap: 8px;
        --mobile-leaflet-footer-height: 26px;
    }

    .leaflet-control-filters {
        max-width: 95%; /* Adjust max-width to a percentage of the screen */
        max-height: 70vh; /* Limit height to prevent overflow on very short screens */
        overflow-y: auto; /* Allow scrolling if content overflows max-height */
        padding: 5px; /* Reduce padding */
        font-size: 12px; /* Smaller font size */
        top: 5px !important; /* Adjust top position for closer to edge */
        right: 5px !important; /* Adjust right position for closer to edge */
    }

    .leaflet-control-filters label {
        margin-bottom: 3px; /* Further reduce margin between labels */
        font-size: 11px; /* Even smaller label font size */
    }

    .leaflet-control-filters input[type="date"],
    .leaflet-control-filters input[type="text"] {
        padding: 3px; /* Further reduce input padding */
        font-size: 11px; /* Even smaller input font size */
    }

    .leaflet-control-filters button {
        padding: 4px 6px; /* Further reduce button padding */
        font-size: 11px; /* Even smaller button font size */
    }

    .leaflet-control-filters .zoom-tip {
        font-size: 10px; /* Smaller tip font size */
    }

    /* Adjust the toggle button styles for better appearance on mobile */
    #toggleFilterBtn {
        padding: 5px 8px; /* Slightly larger padding for better touch target */
        font-size: 12px; /* Keep it readable */
        margin-top: 5px; /* Add margin to separate from other controls */
        margin-right: 5px; /* Keep it consistent with filter menu right margin */
        /* Do NOT set top/right !important here, let Leaflet handle stacking */
    }

     /* Ensure all controls in the top-right have some padding/margin to not stick to the corner */
     .leaflet-top.leaflet-right .leaflet-control {
         margin-top: 5px;
         margin-right: 5px;
     }

     /* Position the toggle filter button at the top of top-right controls */
     .leaflet-top.leaflet-right .leaflet-control:first-child {
         margin-top: 5px;
         margin-right: 5px;
     }

     /* Hide bottom controls when filter menu is open on mobile */
     .leaflet-bottom.hidden-on-mobile {
         display: none !important;
     }

     /* Set max height of leaflet-right controls to 80% from top */
     .leaflet-top.leaflet-right {
         max-height: 80vh;
         overflow-y: auto;
     }

     /* Media controls mobile styles */
     .media-controls {
         min-width: 280px;
         padding: 8px 12px;
         bottom: calc(var(--mobile-leaflet-footer-height, 26px) + var(--mobile-controls-menu-gap, 8px) + env(safe-area-inset-bottom, 0px));
         width: calc(100vw - 16px);
         max-width: 360px;
         box-sizing: border-box;
     }

     .media-controls-row {
         gap: 8px;
     }

     .media-btn {
         padding: 6px 10px;
         font-size: 12px;
         min-width: 35px;
     }

     .speed-btn {
         padding: 3px 6px;
         font-size: 11px;
     }

     .progress-text {
         font-size: 11px;
         min-width: 70px;
     }

     /* Mobile controls styles */
     .leaflet-bar {
         max-width: 95vw;
         max-height: 60vh;
         font-size: 12px;
     }

     .leaflet-bar div {
         padding: 3px;
         font-size: 12px;
     }

     .leaflet-bar input,
     .leaflet-bar select,
     .leaflet-bar button {
         font-size: 12px;
         padding: 6px 8px;
         margin: 2px;
     }

    .leaflet-bar label {
        font-size: 11px;
        margin: 2px 0;
    }

    /* Ensure statistics use the same font size as labels */
    #routeLength {
        font-size: 11px;
        margin-left: 0;
        margin-right: 0;
    }

    /* Hide statistics when empty */
    #routeLength:empty {
        display: none;
    }

    #appLayout {
        display: block;
    }

    .map-shell,
    #map {
        height: 100%;
        width: 100%;
    }

    .controls-sidebar {
        position: fixed;
        right: 8px;
        bottom: calc(var(--mobile-leaflet-footer-height, 26px) + var(--mobile-controls-menu-gap, 8px) + env(safe-area-inset-bottom, 0px));
        left: 8px;
        width: auto;
        max-width: none;
        height: auto;
        min-height: 0;
        margin: 0;
        overflow: visible;
        z-index: 1001;
        background: transparent;
        border-right: 0;
        box-shadow: none;
    }

    body.route-player-visible #mainControlsDiv.main-controls-panel {
        display: none;
    }

    .main-controls-panel,
    .main-controls-panel div {
        font-size: 12px;
        background: transparent;
        border-radius: 0;
        box-shadow: none;
    }

    #mainControlsDiv.main-controls-panel {
        width: 100%;
        height: auto;
        max-width: none;
        max-height: 62vh;
        padding: 8px;
        background: rgba(255, 255, 255, 0.98);
        border: 1px solid #d8d8d8;
        border-radius: 8px;
        box-shadow: 0 2px 12px rgba(0,0,0,0.18);
    }

    .main-controls-panel .main-controls-content {
        max-height: calc(62vh - 56px);
        gap: 6px;
        margin-top: 6px;
        padding: 0 3px 0 0;
    }

    .main-controls-panel .sidebar-brand {
        display: none;
    }

    .main-controls-panel .main-controls-header {
        gap: 5px;
        padding-bottom: 6px;
    }

    .main-controls-toggle {
        display: inline-block;
        flex: 0 0 auto;
    }

    .main-controls-panel button,
    .main-controls-panel input,
    .main-controls-panel select {
        margin: 0;
        font-size: 12px;
        padding: 6px 8px;
    }

    .main-controls-panel label {
        margin: 0;
        font-size: 11px;
    }

    .main-controls-panel input[type="checkbox"] {
        width: 18px;
        height: 18px;
        padding: 0;
    }

    .main-controls-panel .main-controls-select-action,
    .main-controls-panel .main-controls-row {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .main-controls-row label {
        flex: 1 1 150px;
    }

    .main-controls-row select,
    .main-controls-row input[type="text"],
    .main-controls-row input[type="url"] {
        flex: 1 1 150px;
    }

    .main-controls-long-field {
        align-items: center;
        flex-direction: row;
        flex-wrap: nowrap;
    }

    .main-controls-long-field label {
        flex: 0 0 92px;
        width: auto;
    }

    .main-controls-long-field input {
        flex: 1 1 auto;
        width: auto;
        min-width: 0;
        height: 30px;
    }

    .main-controls-number {
        flex-basis: 78px;
        width: 78px;
    }

    .main-controls-actions button {
        flex-basis: 92px;
    }

}
