/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; font-size: 14px; }

/* ============================================================
   LAYOUT
   ============================================================ */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ============================================================
   SIDEBAR
   ============================================================ */
#sidebar {
    width: 340px;
    min-width: 340px;
    background: #fff;
    box-shadow: 2px 0 12px rgba(0,0,0,.12);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
}

.sidebar-header {
    background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
    color: #fff;
    padding: 15px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.05rem;
    font-weight: 700;
    flex-shrink: 0;
    letter-spacing: -0.01em;
}
.sidebar-header i { font-size: 1.35rem; }

.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 24px;
}
.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

.sidebar-section {
    padding: 13px 15px;
    border-bottom: 1px solid #f1f5f9;
}

.section-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #64748b;
    margin-bottom: 10px;
}

/* ============================================================
   WAYPOINTS
   ============================================================ */
#waypoints-container { display: flex; flex-direction: column; gap: 5px; }

.waypoint-row {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 2px 0;
    border-radius: 6px;
    position: relative;
}
.waypoint-row.dragging { opacity: 0.3; }
.waypoint-row.drag-over-top    { border-top: 2px solid #0ea5e9; }
.waypoint-row.drag-over-bottom { border-bottom: 2px solid #0ea5e9; }

.wp-drag { cursor: grab; color: #cbd5e1; padding: 4px 2px; flex-shrink: 0; font-size: 1rem; line-height: 1; }
.wp-drag:active { cursor: grabbing; }

.wp-label {
    width: 24px; height: 24px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.72rem; font-weight: 800;
    color: #fff; flex-shrink: 0;
}
.wp-label.wp-start { background: #22c55e; }
.wp-label.wp-end   { background: #ef4444; }
.wp-label.wp-via   { background: #0ea5e9; }

.wp-input-wrap { flex: 1; position: relative; min-width: 0; }

.wp-input {
    width: 100%;
    padding: 5px 10px;
    border: 1.5px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.83rem;
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
    color: #1e293b;
}
.wp-input:focus { outline: none; border-color: #0ea5e9; box-shadow: 0 0 0 3px rgba(14,165,233,.15); }
.wp-input.wp-located { background: #f0fdf4; border-color: #86efac; }

.wp-btn {
    padding: 4px 7px;
    border-radius: 5px;
    border: 1.5px solid #e2e8f0;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    flex-shrink: 0;
    transition: all 0.15s;
}
.wp-btn:hover { background: #f0f9ff; border-color: #0ea5e9; color: #0ea5e9; }
.wp-btn.active { background: #0ea5e9; border-color: #0ea5e9; color: #fff; }
.wp-btn.danger:hover { background: #fef2f2; border-color: #f87171; color: #ef4444; }

/* ============================================================
   AUTOCOMPLETE
   ============================================================ */
.autocomplete-portal {
    position: fixed;
    z-index: 99999;
    background: #fff;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.15);
    min-width: 260px;
    max-height: 220px;
    overflow-y: auto;
}
.autocomplete-portal ul { list-style: none; padding: 4px 0; margin: 0; }
.autocomplete-portal li {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.82rem;
    line-height: 1.35;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    border-bottom: 1px solid #f8fafc;
    color: #334155;
    transition: background 0.1s;
}
.autocomplete-portal li:last-child { border-bottom: none; }
.autocomplete-portal li:hover { background: #f0f9ff; }
.autocomplete-portal li i { color: #94a3b8; margin-top: 1px; flex-shrink: 0; font-size: 0.9rem; }
.autocomplete-portal li .ac-name   { font-weight: 600; color: #1e293b; display: block; }
.autocomplete-portal li .ac-detail { color: #94a3b8; font-size: 0.75rem; display: block; }
.autocomplete-portal .ac-loading,
.autocomplete-portal .ac-empty { padding: 10px 14px; color: #94a3b8; font-size: 0.82rem; text-align: center; }

/* ============================================================
   OPTIONS
   ============================================================ */
.option-group { margin-bottom: 4px; }
.option-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
    color: #475569;
}
.slope-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.68rem;
    color: #94a3b8;
    margin-top: 2px;
}
.slope-hint {
    font-size: 0.72rem;
    color: #94a3b8;
    margin-top: 4px;
    line-height: 1.3;
}

.pref-list { display: flex; flex-direction: column; gap: 4px; }
.pref-item {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.83rem;
    padding: 5px 7px;
    border-radius: 6px;
    color: #334155;
    transition: background 0.15s;
    user-select: none;
}
.pref-item:hover { background: #f8fafc; }
.pref-item i { color: #64748b; width: 16px; text-align: center; }
.pref-item .form-check-input { flex-shrink: 0; }

/* ============================================================
   ROUTENVARIANTEN
   ============================================================ */
.variants-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

.variant-btn {
    padding: 8px 5px 6px;
    border-radius: 8px;
    border: 2px solid #f1f5f9;
    cursor: pointer;
    text-align: center;
    background: #f8fafc;
    transition: all 0.18s;
    position: relative;
}
.variant-btn:hover { transform: translateY(-1px); box-shadow: 0 3px 10px rgba(0,0,0,.1); }
.variant-btn.active { background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.variant-btn.optimal-badge::after {
    content: '★ optimal';
    position: absolute;
    top: -8px; left: 50%; transform: translateX(-50%);
    background: #0ea5e9;
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    white-space: nowrap;
}
.variant-btn.error   { opacity: 0.55; cursor: default; }
.variant-btn.loading { opacity: 0.7; pointer-events: none; }

.vb-icon  { font-size: 1.25rem; display: block; line-height: 1.2; }
.vb-label { font-size: 0.7rem; font-weight: 700; display: block; margin-top: 2px; color: #1e293b; }
.vb-stat  { font-size: 0.65rem; color: #64748b; display: block; margin-top: 2px; min-height: 13px; line-height: 1.3; }
.vb-diff  { font-size: 0.65rem; display: block; min-height: 13px; line-height: 1.3; }
.vb-diff.slower { color: #f97316; }
.vb-diff.faster { color: #10b981; }
.vb-error { font-size: 0.66rem; color: #ef4444; display: block; margin-top: 2px; }

.vb-spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid #94a3b8;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   ROUTENSTATISTIK
   ============================================================ */
.route-stats {
    background: #f8fafc;
    border-radius: 8px;
    padding: 11px 13px;
    border: 1px solid #e2e8f0;
}
.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 0.82rem;
    border-bottom: 1px solid #e9eef4;
}
.stat-row:last-child { border-bottom: none; }
.stat-label { color: #64748b; display: flex; align-items: center; gap: 5px; }
.stat-value { font-weight: 700; color: #1e293b; }

.slope-dot {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 50%;
    margin-right: 2px;
    vertical-align: middle;
}

/* ============================================================
   ABBIEGEANWEISUNGEN
   ============================================================ */
#instructions-list { max-height: 320px; overflow-y: auto; }
#instructions-list::-webkit-scrollbar { width: 3px; }
#instructions-list::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

.instruction-row {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 5px;
    border-radius: 6px;
    cursor: default;
    font-size: 0.82rem;
    transition: background 0.15s;
    border-bottom: 1px solid #f1f5f9;
}
.instruction-row:last-child { border-bottom: none; }
.instruction-row:hover { background: #f0f9ff; }
.instruction-row.highlighted { background: #e0f2fe; }

.instr-icon {
    width: 28px; height: 28px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    font-size: 0.82rem;
    background: #f1f5f9;
    color: #475569;
}
.instr-icon.start  { background: #dcfce7; color: #16a34a; }
.instr-icon.finish { background: #fee2e2; color: #dc2626; }
.instr-icon.turn   { background: #dbeafe; color: #2563eb; }

.instr-body { flex: 1; min-width: 0; }
.instr-main { font-weight: 600; color: #1e293b; line-height: 1.2; }
.instr-sub  { font-size: 0.71rem; color: #94a3b8; margin-top: 1px; }

.instr-leg {
    font-size: 0.74rem;
    color: #64748b;
    flex-shrink: 0;
    text-align: right;
    white-space: nowrap;
}

.instr-empty {
    padding: 12px 8px;
    color: #94a3b8;
    font-size: 0.82rem;
    text-align: center;
}

/* ============================================================
   KARTE
   ============================================================ */
#map-wrapper { flex: 1; position: relative; overflow: hidden; }
#map { width: 100%; height: 100%; background: #e8e0d8; }

/* ============================================================
   HÖHENPROFIL
   ============================================================ */
.elevation-panel {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 180px;
    background: rgba(255,255,255,0.97);
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -4px 16px rgba(0,0,0,.1);
    z-index: 800;
    padding: 8px 14px 12px;
    display: flex;
    flex-direction: column;
}
.elevation-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-size: 0.82rem;
    font-weight: 700;
    color: #334155;
    flex-shrink: 0;
}
.elevation-chart-wrap {
    flex: 1;
    position: relative;
    min-height: 0;
}
#elevation-chart {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
}

/* ============================================================
   LEAFLET TWEAKS
   ============================================================ */
.leaflet-control-zoom {
    border-radius: 8px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,.15) !important;
    border: 1px solid #e2e8f0 !important;
}
.leaflet-control-zoom a { border-radius: 0 !important; color: #334155 !important; }
.leaflet-control-zoom a:first-child { border-radius: 8px 8px 0 0 !important; }
.leaflet-control-zoom a:last-child  { border-radius: 0 0 8px 8px !important; }
.leaflet-control-attribution { font-size: 0.65rem !important; }

.wp-map-icon { background: none !important; border: none !important; }

.route-tooltip {
    background: rgba(0,0,0,.75);
    color: #fff;
    border: none;
    border-radius: 5px;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 4px 8px;
    white-space: nowrap;
}
.route-tooltip::before { display: none; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 700px) {
    #sidebar {
        position: absolute; top: 0; left: 0; right: 0;
        width: 100%; min-width: unset;
        max-height: 55vh;
        z-index: 2000;
    }
    #map-wrapper { margin-top: 55vh; }
}

.btn-group .btn-outline-secondary { font-size: 0.78rem; padding: 4px 8px; }
