/* Track Editor — overlay panel on the map */

#track-editor-overlay {
    /* Docked panel only — does NOT cover the map, so the map stays interactive.
       pointer-events:none lets clicks/drags pass through everywhere except the panel. */
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 4000;
    display: flex;
    align-items: stretch;
    justify-content: flex-end;
    pointer-events: none;
    font-family: inherit;
}

#track-editor-panel {
    pointer-events: auto;
    width: min(640px, 100%);
    max-width: 100%;
    height: 100%;
    background: var(--background, #0b0f14);
    color: var(--text, #e6edf3);
    border-left: 1px solid var(--secondary, #2dd4bf);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Box-select rubber-band drawn over the map canvas */
.te-map-boxdraw {
    position: absolute;
    top: 0;
    left: 0;
    background: rgba(45, 212, 191, 0.15);
    border: 1.5px dashed #2dd4bf;
    pointer-events: none;
    z-index: 10;
    will-change: transform, width, height;
}
.mapboxgl-canvas-container.te-box-active,
.mapboxgl-canvas-container.te-box-active .mapboxgl-canvas {
    cursor: crosshair !important;
    /* Stop the browser from consuming the touch gesture as scroll/zoom so the
       box-select drag is delivered to our pointer handlers. */
    touch-action: none;
}

.te-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex: 0 0 auto;
}
.te-header h2 {
    margin: 0;
    font-size: 1.05rem;
    letter-spacing: 0.02em;
}
.te-header .te-track-name {
    display: block;
    font-size: 0.78rem;
    opacity: 0.7;
    margin-top: 2px;
    word-break: break-all;
}
.te-close-btn {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: inherit;
    border-radius: 6px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    flex: 0 0 auto;
}
.te-close-btn:hover { background: rgba(255, 255, 255, 0.08); }

.te-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
/* Keep each area at its natural height so the body scrolls instead of
   compressing every section when multiple accordions are open. */
.te-body > * {
    flex: 0 0 auto;
}

/* Timeline */
.te-timeline-wrap {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 10px;
}
.te-timeline-wrap svg { width: 100%; height: auto; display: block; }
.te-legend {
    display: flex;
    gap: 16px;
    font-size: 0.78rem;
    margin-top: 6px;
    flex-wrap: wrap;
}
.te-legend span { display: inline-flex; align-items: center; gap: 5px; }
.te-legend i { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }

/* Tool sections */
.te-section {
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    overflow: hidden;
}
.te-section > summary {
    cursor: pointer;
    padding: 10px 12px;
    font-weight: 600;
    font-size: 0.9rem;
    list-style: none;
    user-select: none;
    background: rgba(255, 255, 255, 0.03);
}
.te-section > summary::-webkit-details-marker { display: none; }
.te-section > summary::before { content: '▸ '; opacity: 0.6; }
.te-section[open] > summary::before { content: '▾ '; }
.te-section-body {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.te-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.te-row label { font-size: 0.82rem; opacity: 0.85; }
.te-input, .te-select {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text, #e6edf3);
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 0.85rem;
    min-width: 0;
}
.te-input { width: 110px; }
.te-select {
    flex: 1 1 160px;
    /* solid fallback so native selects don't render OS-default white */
    background-color: #141a22;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' fill='none' stroke='%23e6edf3' stroke-width='1.5'/></svg>");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 26px;
}
/* style the dropdown option list (rendered by the OS) */
.te-select option,
.te-select optgroup {
    background: #141a22;
    color: #e6edf3;
}

.te-btn {
    background: var(--secondary, #2dd4bf);
    color: #06231f;
    border: none;
    border-radius: 6px;
    padding: 7px 12px;
    font-size: 0.83rem;
    font-weight: 600;
    cursor: pointer;
}
.te-btn:hover { filter: brightness(1.1); }
.te-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.te-btn.te-ghost {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: inherit;
}
.te-btn.te-danger { background: #ef4444; color: #fff; }

.te-hint { font-size: 0.76rem; opacity: 0.6; }
.te-affected { font-size: 0.78rem; color: var(--secondary, #2dd4bf); }

/* Selected-point editor */
.te-point-editor { display: none; flex-direction: column; gap: 8px; }
.te-point-editor.active { display: flex; }
.te-point-none { font-size: 0.8rem; opacity: 0.6; }

/* Preview summary */
.te-preview {
    border: 1px solid rgba(45, 212, 191, 0.35);
    background: rgba(45, 212, 191, 0.06);
    border-radius: 8px;
    padding: 12px;
    font-size: 0.84rem;
}
.te-preview h3 { margin: 0 0 8px; font-size: 0.9rem; }
.te-preview table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.te-preview td { padding: 2px 6px; }
.te-preview td:first-child { opacity: 0.7; }
.te-preview .te-stat-old { opacity: 0.6; }
.te-preview .te-stat-arrow { opacity: 0.5; padding: 0 4px; }

/* Footer */
.te-footer {
    flex: 0 0 auto;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding: 12px 16px;
    display: flex;
    gap: 10px;
    align-items: center;
}
.te-footer .te-spacer { flex: 1 1 auto; }

.te-progress {
    display: none;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}
.te-progress.active { display: flex; }
.te-progress-bar {
    height: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
    overflow: hidden;
}
.te-progress-bar > div {
    height: 100%;
    width: 0%;
    background: var(--secondary, #2dd4bf);
    transition: width 0.25s ease;
}
.te-progress-label { font-size: 0.78rem; opacity: 0.85; }

.te-loading, .te-error {
    padding: 24px;
    text-align: center;
    font-size: 0.9rem;
    opacity: 0.8;
}
.te-error { color: #fca5a5; }

@media (max-width: 700px) {
    /* Bottom-sheet layout: the panel docks to the bottom and leaves the map
       visible/reachable above it (a full-height side panel would hide the map
       that box-select needs). */
    #track-editor-overlay {
        align-items: flex-end;
        justify-content: stretch;
    }
    #track-editor-panel {
        width: 100%;
        max-width: 100%;
        height: 70vh;
        max-height: 70vh;
        border-left: none;
        border-top: 1px solid var(--secondary, #2dd4bf);
        border-radius: 14px 14px 0 0;
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
    }

    /* While box-selecting, shrink the sheet so most of the map is exposed for
       the drag. Toggled from JS via enable/disableBoxSelect(). */
    #track-editor-overlay.te-selecting #track-editor-panel {
        height: 40vh;
        max-height: 40vh;
    }

    /* Comfortable touch targets (≈44px) on small screens. */
    .te-btn { padding: 11px 14px; }
    .te-close-btn { width: 40px; height: 40px; font-size: 1.3rem; }
    .te-section > summary { padding: 13px 12px; }
    .te-input { width: 100%; }
    .te-row .te-input { flex: 1 1 120px; }
}

/* Touch devices regardless of width: avoid hover-only affordances feeling
   stuck and give inputs a larger hit area. */
@media (hover: none) and (pointer: coarse) {
    .te-btn { min-height: 40px; }
    .te-input, .te-select { padding: 9px 10px; }
}
