/* =====================================================================
   Playground · Interactive map UI
   Volt-green / olive on charcoal (dark) or off-white (light).
   Auto-switches via prefers-color-scheme.
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    /* Brand */
    --volt: #CEFE29;
    --volt-glow: rgba(206, 254, 41, 0.35);
    --olive: #5C6E1A;
    --olive-bright: #748A22;

    /* Light theme defaults */
    --bg-body:     #FAFAFA;
    --bg-card:     #FFFFFF;
    --bg-elevated: #FFFFFF;
    --bg-input:    #F1F1F0;
    --bg-input-focus: #FFFFFF;
    --bg-subtle:   #F1F1F0;

    --text-primary:   #111315;
    --text-secondary: #6E7376;
    --text-muted:     #8E9396;

    --border:       rgba(17, 19, 21, 0.10);
    --border-focus: var(--volt);
    --border-strong: rgba(17, 19, 21, 0.18);

    --accent:       var(--volt);          /* button background */
    --accent-text:  var(--olive);          /* accent text/icon */
    --accent-on:    #111315;               /* foreground on --accent */

    --danger:    #b91c1c;
    --danger-bg: rgba(185, 28, 28, 0.10);

    --shadow-md: 0 12px 28px -10px rgba(17, 19, 21, 0.14);
    --shadow-sm: 0 2px 6px rgba(17, 19, 21, 0.06);
    --radius-sm: 6px;
    --radius-md: 10px;
    --transition: 0.18s ease-in-out;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-body:     #111315;
        --bg-card:     #1A1D20;
        --bg-elevated: #1A1D20;
        --bg-input:    #1F2225;
        --bg-input-focus: #1A1D20;
        --bg-subtle:   #1F2225;

        --text-primary:   #FFFFFF;
        --text-secondary: #8E9396;
        --text-muted:     #4A4E51;

        --border:       rgba(255, 255, 255, 0.08);
        --border-strong: rgba(255, 255, 255, 0.15);

        --accent-text: var(--volt);

        --danger:    #f87171;
        --danger-bg: rgba(248, 113, 113, 0.14);

        --shadow-md: 0 12px 28px -10px rgba(0, 0, 0, 0.65);
        --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.5);
    }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text-primary);
    background: var(--bg-body);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* ============ MAP ============ */
#map-container { position: absolute; inset: 0; }
#map { width: 100%; height: 100%; z-index: 1; }

/* ============ FLOATING UI CARD ============ */
.sidebar {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 360px;
    max-height: calc(100vh - 40px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ============ HEADER ============ */
.header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 24px; }
h1 { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); letter-spacing: -0.01em; }
.subtitle { font-size: 0.75rem; color: var(--text-secondary); margin-top: 2px; }

/* ============ CONTENT ============ */
.content { padding: 16px 20px; overflow-y: auto; }
.content::-webkit-scrollbar { width: 4px; }
.content::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }

/* ============ STATUS BADGE ============ */
.status-badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 999px;
    font-size: 0.7rem; font-weight: 500;
    background: var(--bg-subtle); border: 1px solid var(--border);
    color: var(--text-secondary); margin-bottom: 16px;
}
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); }
.status-dot.online { background: var(--volt); box-shadow: 0 0 8px var(--volt-glow); }
.status-dot.offline { background: var(--danger); }

/* ============ API KEY ============ */
.api-key-section { margin-bottom: 16px; }
.api-key-section label {
    display: block; font-size: 0.7rem; font-weight: 600;
    color: var(--text-secondary); margin-bottom: 4px; text-transform: uppercase;
    letter-spacing: 0.05em;
}
.api-key-input {
    width: 100%; padding: 8px 10px;
    background: var(--bg-input); border: 1px solid var(--border); color: var(--text-primary);
    border-radius: var(--radius-sm); font-size: 0.8rem;
    transition: all var(--transition);
}
.api-key-input:focus {
    outline: none; border-color: var(--border-focus);
    background: var(--bg-input-focus);
    box-shadow: 0 0 0 3px var(--volt-glow);
}

/* ============ PROFILE SELECTOR ============ */
.profile-selector {
    display: flex; background: var(--bg-subtle);
    border-radius: var(--radius-sm); padding: 4px; margin-bottom: 16px;
    border: 1px solid var(--border);
}
.profile-btn {
    flex: 1; padding: 6px; background: transparent; border: none;
    color: var(--text-secondary); font-size: 0.8rem; font-weight: 500;
    border-radius: 4px; cursor: pointer; transition: all var(--transition);
    display: flex; align-items: center; justify-content: center; gap: 6px;
}
.profile-btn:hover { background: var(--bg-card); color: var(--text-primary); }
.profile-btn.active {
    background: var(--bg-card); color: var(--accent-text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    font-weight: 600;
}
.profile-btn svg { width: 14px; height: 14px; fill: currentColor; }

/* ============ INPUTS ============ */
.inputs-container { margin-bottom: 16px; }
.input-group { position: relative; margin-bottom: 10px; display: flex; align-items: center; gap: 10px; }
.input-icon { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.icon-start { border: 3px solid var(--accent-text); background: var(--bg-card); }
.icon-end { background: var(--danger); }
.input-wrapper { flex: 1; position: relative; }
.location-input {
    width: 100%; padding: 10px 30px 10px 12px;
    background: var(--bg-input); border: 1px solid var(--border); color: var(--text-primary);
    border-radius: var(--radius-sm); font-size: 0.85rem;
    transition: all var(--transition);
}
.location-input:focus {
    outline: none; border-color: var(--border-focus);
    background: var(--bg-input-focus);
    box-shadow: 0 0 0 3px var(--volt-glow);
}
.input-clear {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--text-muted); cursor: pointer;
    display: none; padding: 4px; font-size: 10px;
}
.input-wrapper:has(.location-input.has-value) .input-clear { display: block; }

/* ============ SUGGESTIONS ============ */
.suggestions {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0;
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md); z-index: 2000; max-height: 150px; overflow-y: auto; display: none;
}
.suggestions.show { display: block; }
.suggestion-item { padding: 6px 10px; cursor: pointer; border-bottom: 1px solid var(--border); display: flex; gap: 8px; align-items: flex-start; }
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover { background: var(--bg-subtle); }
.suggestion-item svg { width: 12px; height: 12px; fill: var(--text-muted); margin-top: 3px; flex-shrink: 0; }
.suggestion-main { font-size: 0.75rem; font-weight: 500; color: var(--text-primary); margin-bottom: 1px; line-height: 1.2; }
.suggestion-sub { font-size: 0.65rem; color: var(--text-muted); line-height: 1.2; }

/* ============ BUTTONS ============ */
.btn-group { display: flex; gap: 8px; }
.primary-btn {
    flex: 1; padding: 10px;
    background: var(--accent); color: var(--accent-on);
    border: none; border-radius: var(--radius-sm); font-size: 0.85rem; font-weight: 600;
    cursor: pointer; transition: all var(--transition);
    display: flex; justify-content: center; gap: 6px; align-items: center;
    box-shadow: 0 4px 12px -4px var(--volt-glow);
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 18px -6px var(--volt-glow); }
.primary-btn:active { transform: translateY(0); }
.primary-btn svg { width: 16px; height: 16px; fill: currentColor; }
.secondary-btn {
    padding: 10px 16px;
    background: transparent; color: var(--text-primary);
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 0.85rem; font-weight: 500;
    cursor: pointer; transition: all var(--transition);
}
.secondary-btn:hover { background: var(--bg-subtle); }

/* ============ ROUTE STATS & DIRECTIONS ============ */
.route-stats {
    display: none; margin-top: 16px; padding: 12px;
    background: var(--bg-subtle); border-radius: var(--radius-sm); border: 1px solid var(--border);
}
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-label { font-size: 0.65rem; color: var(--text-secondary); text-transform: uppercase; margin-bottom: 2px; letter-spacing: 0.05em; }
.stat-value { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); letter-spacing: -0.01em; }
.stat-value.time { color: var(--accent-text); }

.directions-panel { display: none; margin-top: 12px; }
.directions-header {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 0.8rem; font-weight: 600; color: var(--text-secondary);
    cursor: pointer; padding: 8px 0; border-top: 1px solid var(--border);
}
.directions-list { max-height: 0; overflow: hidden; transition: max-height 0.3s ease; }
.directions-list.open { max-height: 300px; overflow-y: auto; padding-right: 4px; }
.direction-step {
    display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border);
}
.direction-step:last-child { border-bottom: none; }
.step-num {
    width: 20px; height: 20px;
    background: color-mix(in oklab, var(--volt) 18%, transparent);
    color: var(--accent-text);
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 0.65rem; font-weight: 700; flex-shrink: 0;
}
.step-instruction { font-size: 0.75rem; color: var(--text-primary); margin-bottom: 2px; }
.step-distance { font-size: 0.65rem; color: var(--text-muted); }

/* ============ MAP CONTROLS ============ */
.locate-control {
    position: absolute; bottom: 30px; right: 20px; z-index: 1000;
    width: 40px; height: 40px;
    background: var(--bg-card); border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center;
    cursor: pointer; box-shadow: var(--shadow-sm);
    color: var(--text-primary);
}
.locate-control:hover { background: var(--bg-subtle); border-color: var(--accent-text); }
.locate-control svg { width: 20px; height: 20px; fill: currentColor; }

.loading-overlay {
    display: none; position: absolute; inset: 0;
    background: color-mix(in oklab, var(--bg-body) 80%, transparent);
    z-index: 900; align-items: center; justify-content: center;
}
.loading-overlay.show { display: flex; }
.loading-spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

.user-location-marker {
    width: 14px; height: 14px;
    background: var(--volt); border: 2px solid var(--bg-card); border-radius: 50%;
    box-shadow: 0 0 12px var(--volt-glow);
}

/* ============ TOAST ============ */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
    padding: 12px 16px;
    background: var(--bg-card); color: var(--text-primary);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent-text);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-size: 0.8rem;
    display: flex; align-items: center; gap: 8px;
}
.toast.error { border-left-color: var(--danger); }

/* ============ MODE SELECTOR ============ */
.mode-selector {
    display: flex; background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 4px;
    margin-bottom: 16px; gap: 2px;
}
.mode-btn {
    flex: 1; padding: 6px 4px;
    background: transparent; border: none;
    color: var(--text-secondary); cursor: pointer;
    font-size: 0.75rem; font-weight: 500;
    border-radius: 4px;
    transition: background var(--transition), color var(--transition);
}
.mode-btn:hover { color: var(--text-primary); }
.mode-btn.active {
    background: var(--bg-card);
    color: var(--accent-text);
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    font-weight: 700;
}

[data-mode-panel] { display: block; }
[data-mode-panel][hidden] { display: none; }

.mode-hint {
    font-size: 0.78rem; color: var(--text-secondary);
    background: var(--bg-subtle); border: 1px solid var(--border);
    padding: 8px 10px; border-radius: var(--radius-sm);
    margin-bottom: 12px; line-height: 1.5;
}

/* ============ ISOCHRONE PANEL ============ */
.iso-ranges {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px 12px; margin-bottom: 10px;
}
.iso-ranges label {
    display: flex; align-items: center; gap: 6px;
    font-size: 0.82rem; color: var(--text-primary);
    cursor: pointer; user-select: none;
}
.iso-ranges input[type=checkbox] {
    cursor: pointer; accent-color: var(--volt);
}
.iso-custom {
    display: flex; gap: 6px; margin-bottom: 12px;
}
.iso-custom input {
    flex: 1; padding: 6px 10px;
    background: var(--bg-input); border: 1px solid var(--border); color: var(--text-primary);
    border-radius: var(--radius-sm); font-size: 0.8rem;
}
.iso-custom input:focus {
    outline: none; border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--volt-glow);
}
.iso-custom .secondary-btn { padding: 6px 12px; }

/* ============ ETA PANEL ============ */
.eta-table-wrap { max-height: 280px; overflow-y: auto; margin-bottom: 10px; }
.eta-table {
    width: 100%; border-collapse: collapse;
    font-size: 0.82rem;
}
.eta-table th {
    text-align: left; padding: 6px 8px;
    color: var(--text-secondary); font-weight: 600;
    font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
    background: var(--bg-subtle); border-bottom: 1px solid var(--border);
    position: sticky; top: 0;
}
.eta-table td {
    padding: 8px; border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}
.eta-table tr:last-child td { border-bottom: none; }
.eta-table td.empty { text-align: center; color: var(--text-muted); font-style: italic; padding: 16px 8px; }
.eta-num {
    display: inline-flex; align-items: center; justify-content: center;
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--danger); color: white;
    font-weight: 700; font-size: 0.72rem;
}
.eta-remove {
    background: transparent; border: none; cursor: pointer;
    color: var(--text-muted); font-size: 0.9rem;
    padding: 2px 6px; border-radius: 4px;
}
.eta-remove:hover { color: var(--danger); background: var(--danger-bg); }

/* Numbered destination pin (Leaflet divIcon) */
.eta-num-pin {
    width: 24px; height: 24px;
    background: var(--danger);
    border: 2px solid var(--bg-card); border-radius: 50%;
    color: white; display: flex;
    align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700;
    font-family: 'Inter', sans-serif;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
}

/* Permanent tooltip floating above each ETA pin */
.leaflet-tooltip.eta-tooltip {
    background: #111315;
    color: #FFFFFF;
    border: none;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.72rem; font-weight: 600;
    box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}
.leaflet-tooltip.eta-tooltip::before { display: none; }
.leaflet-tooltip.eta-origin-tooltip {
    background: var(--olive-bright); color: #FFFFFF;
}

/* ============ DRAW PANEL ============ */
.draw-stat {
    font-size: 0.85rem; color: var(--text-secondary);
    margin-bottom: 10px;
}
.draw-stat strong { color: var(--text-primary); font-variant-numeric: tabular-nums; }

[data-mode-panel="draw"] .secondary-btn { width: 100%; margin-bottom: 6px; }

/* Bring the Leaflet.draw toolbar visually in line */
.leaflet-draw-toolbar a {
    background-color: var(--bg-card) !important;
    border-color: var(--border) !important;
}

/* ============ GEOCODE MODE ============ */
.geo-results { max-height: 320px; overflow-y: auto; margin-top: 4px; }
.geo-result {
    padding: 8px 10px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); margin-bottom: 6px; cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
}
.geo-result:hover { border-color: var(--accent-text); background: var(--bg-subtle); }
.geo-result-name { font-size: 0.82rem; font-weight: 500; color: var(--text-primary); margin-bottom: 2px; }
.geo-result-meta { font-size: 0.7rem; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.geo-tag {
    background: color-mix(in oklab, var(--volt) 18%, transparent);
    color: var(--accent-text); font-weight: 600;
    padding: 1px 6px; border-radius: 999px; text-transform: lowercase;
}
@media (prefers-color-scheme: dark) { .geo-tag { color: var(--volt); } }
.geo-empty { font-size: 0.78rem; color: var(--text-muted); padding: 8px 2px; }
.geo-reverse {
    margin-top: 10px; padding: 10px;
    background: var(--bg-subtle); border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.geo-reverse-text { font-size: 0.82rem; color: var(--text-primary); margin-top: 4px; line-height: 1.4; }

/* ============ MOBILE ============ */
.sidebar-open-btn, .sidebar-toggle, .sidebar-close-btn { display: none !important; }
@media (max-width: 600px) {
    .sidebar { width: calc(100% - 20px); left: 10px; top: 10px; max-height: 50vh; }
    .locate-control { bottom: 20px; right: 10px; }
    .mode-selector .mode-btn { font-size: 0.7rem; padding: 5px 2px; }
}
