/* === RESET === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #0f0f14;
    --surface: #1a1a24;
    --surface2: #22222e;
    --border: rgba(255,255,255,0.06);
    --text: #eee;
    --text2: #999;
    --accent: #ff6b3d;
    --accent2: #ff8a66;
    --green: #2ecc71;
    --blue: #3498db;
    --radius: 14px;
    --radius-sm: 10px;
    --sidebar-width: 390px;
}

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

#app { width: 100%; height: 100%; position: relative; }

/* === MAP === */
#map { width: 100%; height: 100%; z-index: 1; }

/* === MAP OVERLAY === */
#map-overlay {
    display: none;
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    z-index: 98; background: rgba(0,0,0,0.3);
}
#map-overlay.active { display: block; }

/* === TOPBAR === */
#topbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 100;
    padding: 12px 16px;
    display: flex; align-items: center; justify-content: space-between;
    pointer-events: none;
}
#topbar > * { pointer-events: auto; }

.brand {
    display: flex; align-items: center; gap: 10px;
    background: rgba(26, 26, 36, 0.85); padding: 8px 16px 8px 8px;
    border-radius: 50px; border: 1px solid var(--border);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    animation: slideDown 0.5s ease;
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.brand-icon {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--accent); display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 15px rgba(255, 107, 61, 0.4);
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 4px 15px rgba(255, 107, 61, 0.4); }
    50% { box-shadow: 0 4px 25px rgba(255, 107, 61, 0.7); }
}

.brand span { font-weight: 700; font-size: 15px; letter-spacing: -0.3px; }

#panel-toggle {
    width: 42px; height: 42px; border-radius: 50%;
    background: rgba(26, 26, 36, 0.85); border: 1px solid var(--border);
    color: #fff; font-size: 16px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    transition: all 0.3s ease;
    animation: slideDown 0.5s ease 0.1s both;
}
#panel-toggle:active { background: var(--surface2); transform: scale(0.93); }
#panel-toggle.open i { transform: rotate(180deg); }
#panel-toggle i { transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1); }

/* === SIDEBAR === */
#sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 99;
    background: var(--surface); border-radius: 20px 20px 0 0;
    border: 1px solid var(--border); border-bottom: none;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 50vh; display: flex; flex-direction: column;
    will-change: transform;
}
#sidebar.open { transform: translateY(0); }

.sheet-handle {
    width: 36px; height: 5px; background: rgba(255,255,255,0.25);
    border-radius: 3px; margin: 10px auto 6px; flex-shrink: 0;
    cursor: grab;
}
.sheet-handle:active { cursor: grabbing; }

.sheet-content {
    padding: 4px 16px 20px; overflow-y: auto; flex: 1;
    display: flex; flex-direction: column; gap: 10px;
    -webkit-overflow-scrolling: touch;
}

/* === ROUTE INFO BAR === */
#route-info-bar {
    display: flex; align-items: center; gap: 12px;
    background: var(--surface2); padding: 10px 16px;
    border-radius: var(--radius-sm); border: 1px solid var(--border);
    transition: all 0.3s ease; overflow: hidden;
}
#route-info-bar.route-info-hidden {
    opacity: 0; max-height: 0; padding: 0; margin: 0; border: none;
}
#route-info-bar:not(.route-info-hidden) {
    opacity: 1; max-height: 50px; margin-bottom: 2px;
}
.info-item {
    display: flex; align-items: center; gap: 8px; flex: 1;
    justify-content: center;
}
.info-item i {
    color: var(--accent); font-size: 14px;
}
.info-item span {
    font-size: 15px; font-weight: 700; color: #fff;
}
.info-divider {
    width: 1px; height: 20px; background: rgba(255,255,255,0.1);
}

/* === INPUT ROW === */
.input-row {
    display: flex; align-items: center; gap: 10px;
    background: var(--surface2); border-radius: var(--radius-sm);
    padding: 4px 12px; border: 2px solid transparent;
    transition: all 0.25s ease;
}
.input-row:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(255,107,61,0.08); }

.point-dot {
    width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0;
}
.point-dot.start { background: var(--accent); box-shadow: 0 0 12px rgba(255,107,61,0.7); animation: glowPulse 1.5s ease-in-out infinite; }
.point-dot.end { background: var(--green); box-shadow: 0 0 12px rgba(46,204,113,0.7); animation: glowPulse 1.5s ease-in-out 0.5s infinite; }
.point-dot.stop-dot-color { background: var(--blue); box-shadow: 0 0 10px rgba(52,152,219,0.6); flex-shrink: 0; width: 10px; height: 10px; border-radius: 50%; }
@keyframes glowPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}

.input-row input {
    flex: 1; background: none; border: none; color: var(--text);
    font-size: 14px; padding: 12px 0; outline: none;
    min-width: 0;
}
.input-row input::placeholder { color: var(--text2); }

.mini-btn {
    width: 34px; height: 34px; border-radius: 50%; border: none;
    background: rgba(255,255,255,0.06); color: #fff; cursor: pointer;
    font-size: 13px; flex-shrink: 0; transition: all 0.2s;
    display: flex; align-items: center; justify-content: center;
}
.mini-btn:hover { background: rgba(255,255,255,0.12); }
.mini-btn:active { background: var(--accent); transform: scale(0.9); }

/* === STOP ROW === */
.stop-row {
    display: flex; align-items: center; gap: 10px;
    background: var(--surface2); border-radius: var(--radius-sm);
    padding: 4px 12px; 
    animation: slideIn 0.35s ease;
    transition: all 0.25s ease;
}
@keyframes slideIn {
    from { opacity: 0; transform: translateX(-20px); max-height: 0; }
    to { opacity: 1; transform: translateX(0); max-height: 60px; }
}
.stop-dot {
    width: 10px; height: 10px; border-radius: 50%; background: var(--blue);
    box-shadow: 0 0 10px rgba(52,152,219,0.6); flex-shrink: 0;
}
.stop-num {
    font-size: 11px; color: var(--blue); font-weight: 700; 
    width: 18px; text-align: center; flex-shrink: 0;
}
.stop-row input { flex: 1; background: none; border: none; color: var(--text); font-size: 14px; padding: 12px 0; outline: none; min-width: 0; }
.stop-row input::placeholder { color: var(--text2); }
.remove-btn {
    width: 30px; height: 30px; border-radius: 50%; border: none;
    background: rgba(231,76,60,0.15); color: #e74c3c; cursor: pointer;
    font-size: 12px; flex-shrink: 0; transition: all 0.2s;
    display: flex; align-items: center; justify-content: center;
}
.remove-btn:hover { background: rgba(231,76,60,0.3); }
.remove-btn:active { background: #e74c3c; color: #fff; transform: scale(0.9); }

/* === TEXT BTN === */
.text-btn {
    background: none; border: 1.5px dashed rgba(255,255,255,0.12); color: var(--text2);
    padding: 12px; border-radius: var(--radius-sm); font-size: 13px; cursor: pointer;
    transition: all 0.25s; width: 100%; display: flex; align-items: center; 
    justify-content: center; gap: 6px; font-weight: 500;
}
.text-btn:hover { border-color: var(--accent); color: var(--accent); background: rgba(255,107,61,0.04); }
.text-btn:active { background: rgba(255,107,61,0.1); transform: scale(0.98); }

/* === PICKER LABEL === */
.picker-label { 
    font-size: 11px; color: var(--text2); text-transform: uppercase; 
    letter-spacing: 1.5px; margin-top: 6px; font-weight: 600;
}

/* === COLOR MODE BUTTONS === */
.color-mode-row {
    display: flex; gap: 6px;
}
.mode-btn {
    flex: 1; padding: 8px; border-radius: 8px; border: 2px solid rgba(255,255,255,0.1);
    background: var(--surface2); color: var(--text2); font-size: 12px;
    font-weight: 600; cursor: pointer; transition: all 0.2s;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.mode-btn:hover { border-color: var(--accent); color: #fff; }
.mode-btn.active {
    border-color: var(--accent); background: rgba(255,107,61,0.15);
    color: var(--accent);
}

/* === COLOR PICKERS === */
.color-pickers {
    display: flex; flex-direction: column; gap: 8px;
}
.color-pick-row {
    display: flex; align-items: center; gap: 10px;
    background: var(--surface2); padding: 8px 12px;
    border-radius: var(--radius-sm);
}
.color-pick-row.hidden { display: none; }
.color-pick-row label {
    font-size: 12px; color: var(--text2); flex-shrink: 0;
    min-width: 40px;
}
.color-pick-row input[type="color"] {
    width: 32px; height: 32px; border: 2px solid rgba(255,255,255,0.1);
    border-radius: 8px; cursor: pointer; background: none; padding: 2px;
    flex-shrink: 0;
}
.color-pick-row input[type="color"]:hover { border-color: #fff; }

/* === SLIDER === */
.slider-row {
    display: flex; align-items: center; gap: 10px;
    background: var(--surface2); padding: 10px 14px;
    border-radius: var(--radius-sm);
}
.slider-label {
    font-size: 12px; color: var(--text2); font-weight: 600; flex-shrink: 0;
}
.slider-row input[type="range"] {
    flex: 1; -webkit-appearance: none; appearance: none;
    height: 6px; border-radius: 3px; background: rgba(255,255,255,0.1);
    outline: none; cursor: pointer;
}
.slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--accent); cursor: pointer;
    border: 2px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.slider-val {
    font-size: 12px; color: var(--text); font-weight: 600;
    min-width: 36px; text-align: right; flex-shrink: 0;
}

/* === ICON PICKER === */
.picker-row { display: flex; gap: 8px; flex-wrap: wrap; }

.pick {
    width: 42px; height: 42px; border-radius: 50%;
    background: var(--surface2); border: 2px solid transparent;
    display: flex; align-items: center; justify-content: center;
    font-size: 17px; cursor: pointer; transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1); 
    color: var(--text2); position: relative;
}
.pick:hover { background: rgba(255,107,61,0.08); border-color: rgba(255,107,61,0.3); color: #fff; transform: translateY(-2px); }
.pick:active { transform: scale(0.9); }
.pick.active {
    border-color: var(--accent); background: rgba(255,107,61,0.18);
    color: var(--accent); box-shadow: 0 0 20px rgba(255,107,61,0.3);
    animation: pickPop 0.3s ease;
}
@keyframes pickPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* === BUTTONS === */
.primary-btn {
    width: 100%; padding: 15px; background: var(--accent); border: none;
    border-radius: var(--radius); color: #fff; font-size: 15px; font-weight: 600;
    cursor: pointer; transition: all 0.25s; display: flex; align-items: center;
    justify-content: center; gap: 8px; margin-top: 6px;
    box-shadow: 0 4px 20px rgba(255, 107, 61, 0.3);
    letter-spacing: -0.2px;
}
.primary-btn:hover { background: var(--accent2); transform: translateY(-2px); box-shadow: 0 8px 30px rgba(255, 107, 61, 0.4); }
.primary-btn:active { transform: scale(0.97); box-shadow: 0 2px 10px rgba(255, 107, 61, 0.2); }

.ghost-btn {
    width: 100%; padding: 13px; background: transparent; border: 1.5px solid rgba(231,76,60,0.3);
    border-radius: var(--radius); color: #e74c3c; font-size: 14px; font-weight: 500; cursor: pointer;
    transition: all 0.25s; display: flex; align-items: center; justify-content: center; gap: 6px;
}
.ghost-btn:hover { border-color: rgba(231,76,60,0.6); background: rgba(231,76,60,0.05); }
.ghost-btn:active { background: rgba(231,76,60,0.15); transform: scale(0.98); }

/* === CREDIT === */
#credit {
    position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 97;
    font-size: 10px; color: rgba(255,255,255,0.45); pointer-events: none;
    background: rgba(0,0,0,0.5); padding: 5px 12px; border-radius: 20px;
    white-space: nowrap; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    transition: all 0.3s;
}
#credit strong { color: var(--accent); font-weight: 600; }

/* === LEAFLET OVERRIDES === */
.leaflet-control-zoom { 
    border: none !important; border-radius: 12px !important; overflow: hidden; 
    box-shadow: 0 4px 20px rgba(0,0,0,0.5) !important; 
    transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1) !important;
}
.leaflet-control-zoom a { 
    background: rgba(26, 26, 36, 0.9) !important; color: #fff !important; 
    border: none !important; width: 40px !important; height: 40px !important; 
    line-height: 40px !important; font-size: 18px !important;
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.leaflet-control-zoom a:hover { background: var(--surface2) !important; }
.leaflet-control-attribution { display: none !important; }
.leaflet-routing-container { display: none !important; }

/* === CUSTOM MARKER === */
.custom-div-icon {
    background: none !important; border: none !important;
}
.marker-inner {
    width: 40px; height: 40px; border-radius: 50% 50% 50% 0;
    background: var(--accent); display: flex; align-items: center;
    justify-content: center; font-size: 17px; color: #fff;
    transform: rotate(-45deg); box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    border: 3px solid #fff; transition: all 0.2s;
    animation: dropBounce 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes dropBounce {
    0% { transform: rotate(-45deg) translateY(-30px); opacity: 0; }
    60% { transform: rotate(-45deg) translateY(5px); }
    80% { transform: rotate(-45deg) translateY(-3px); }
    100% { transform: rotate(-45deg) translateY(0); opacity: 1; }
}
.marker-inner i { transform: rotate(45deg); }
.marker-inner.end-marker {
    border-radius: 50%;
    animation: dropBounceEnd 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes dropBounceEnd {
    0% { transform: translateY(-30px); opacity: 0; }
    60% { transform: translateY(5px); }
    80% { transform: translateY(-3px); }
    100% { transform: translateY(0); opacity: 1; }
}
.marker-inner.end-marker i { transform: rotate(0); }
.marker-inner.stop-marker {
    border-radius: 50%;
    animation: dropBounceEnd 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.marker-inner.stop-marker i { transform: rotate(0); }

/* === ROUTE DISTANCE TOOLTIP === */
.route-distance-tooltip {
    background: #1a1a24 !important;
    color: #fff !important;
    border: 2px solid var(--accent) !important;
    border-radius: 20px !important;
    padding: 6px 14px !important;
    font-size: 13px !important;
    font-weight: 700 !important;
    white-space: nowrap !important;
    box-shadow: 0 8px 30px rgba(0,0,0,0.7) !important;
    letter-spacing: -0.3px !important;
}
.route-distance-tooltip::before {
    display: none !important;
}

/* === SUGGESTIONS === */
.suggestions-dropdown {
    box-shadow: 0 12px 40px rgba(0,0,0,0.6);
    animation: fadeDown 0.2s ease;
}
@keyframes fadeDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
.suggestion-item {
    padding: 12px 14px; cursor: pointer; display: flex;
    align-items: flex-start; gap: 10px; font-size: 13px; color: #bbb;
    border-bottom: 1px solid rgba(255,255,255,0.04); transition: all 0.15s;
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover { background: rgba(255,107,61,0.12); color: #fff; }
.suggestion-item i { color: var(--accent); margin-top: 2px; flex-shrink: 0; font-size: 14px; }
.suggestion-item span {
    line-height: 1.4; overflow: hidden; text-overflow: ellipsis;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    line-clamp: 2;
}

/* === SCROLLBAR === */
.sheet-content::-webkit-scrollbar { width: 4px; }
.sheet-content::-webkit-scrollbar-track { background: transparent; }
.sheet-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

@keyframes spin { to { transform: rotate(360deg); } }
.fa-spin { animation: spin 0.8s linear infinite; }

/* === FLOATING TOGGLE === */
#float-toggle {
    position: fixed; top: 16px; left: 16px;
    z-index: 102; pointer-events: none;
    margin-top: 52px;
}
#float-toggle > * { pointer-events: auto; }
.float-btn {
    width: 42px; height: 42px; border-radius: 50%;
    background: rgba(26, 26, 36, 0.85); border: 2px solid var(--accent);
    color: var(--accent); font-size: 16px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    transition: all 0.25s;
}
.float-btn.pan-mode {
    border-color: #fff; color: #fff;
}
.float-btn:active { transform: scale(0.93); }

/* ============================================ */
/* === MOBILE === */
/* ============================================ */
@media (max-width: 767px) {
    #topbar { padding: 10px 12px; }
    .brand { padding: 6px 14px 6px 6px; }
    .brand-icon { width: 32px; height: 32px; }
    .brand span { font-size: 14px; }
    #panel-toggle { width: 38px; height: 38px; font-size: 14px; display: flex; }
    
    #sidebar {
        border-radius: 18px 18px 0 0;
        max-height: 50vh;
    }
    .sheet-content { padding: 4px 12px 16px; gap: 8px; }
    .input-row input { font-size: 16px; padding: 10px 0; }
    .stop-row input { font-size: 16px; }
    .pick { width: 38px; height: 38px; font-size: 15px; }
    .primary-btn { padding: 14px; font-size: 15px; }
    #credit { bottom: 16px; font-size: 9px; padding: 4px 10px; }
}

@media (max-width: 380px) {
    .brand span { font-size: 13px; }
    .brand-icon { width: 28px; height: 28px; }
    .brand { padding: 5px 12px 5px 5px; gap: 6px; }
    .picker-row { gap: 6px; }
    .pick { width: 34px; height: 34px; font-size: 14px; }
}

/* ============================================ */
/* === DESKTOP - RIGHT SIDEBAR === */
/* ============================================ */
@media (min-width: 768px) {
    .sheet-handle { display: none; }
    #map-overlay { display: none !important; }

    #panel-toggle {
        display: flex;
        position: fixed; top: 90px; right: 16px;
        z-index: 101;
        transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }
    #panel-toggle i { transform: rotate(-90deg); }
    #panel-toggle.open { right: calc(var(--sidebar-width) + 24px); }
    #panel-toggle.open i { transform: rotate(90deg); }

    #sidebar {
        top: 0; bottom: 0;
        left: auto; right: 0;
        width: var(--sidebar-width);
        border-radius: 16px 0 0 16px;
        border: 1px solid var(--border);
        border-right: none;
        transform: translateX(100%);
        max-height: none;
        box-shadow: -8px 0 40px rgba(0,0,0,0.5);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }
    #sidebar.open { transform: translateX(0); }
    .sheet-content { padding: 24px 20px 20px; }

    #credit { bottom: 20px; left: 20px; transform: none; }
    .leaflet-control-zoom { right: 16px; }
    .sidebar-open .leaflet-control-zoom { right: calc(var(--sidebar-width) + 24px); }
    #float-toggle {
        top: 100px;
        left: 18px;
        margin-top: 0;
    }
}

@media (min-width: 1024px) {
    :root { --sidebar-width: 420px; }
}