/* ─── Design Tokens ────────────────────────────────── */
:root {
    --bg-primary: #0f0f1a;
    --bg-card: #16213e;
    --bg-input: #1e293b;
    --border: #1e293b;
    --accent: #0ea5e9;
    --accent-hover: #38bdf8;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --danger: #ef4444;
    --success: #22c55e;
    --sidebar-width: 380px;
    --detail-width: 400px;
    --radius: 8px;
    --radius-sm: 6px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
}

/* ─── Scrollbar ───────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #475569; }

/* ─── Modal ───────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.7);
    display: flex; align-items: center; justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
    width: 90%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-header { text-align: center; margin-bottom: 24px; }
.modal-header h2 { font-size: 1.5rem; margin-bottom: 8px; }
.modal-header p { color: var(--text-secondary); font-size: 0.9rem; }

.modal-body { display: flex; flex-direction: column; gap: 12px; }
.modal-body input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: monospace;
    outline: none;
    transition: border-color .2s;
}
.modal-body input:focus { border-color: var(--accent); }

.error-text { color: var(--danger); font-size: 0.85rem; }
.hidden { display: none !important; }

/* ─── Buttons ─────────────────────────────────────── */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s, opacity .2s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: #293548; }

.icon-btn {
    background: none; border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: color .2s, background .2s;
}
.icon-btn:hover { color: var(--text-primary); background: rgba(255,255,255,.05); }

/* ─── Sidebar ─────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-primary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 1.4rem; }
.logo-text { font-size: 1.1rem; font-weight: 700; letter-spacing: -.02em; }

/* ─── Mode Tabs ───────────────────────────────────── */
.mode-tabs {
    display: flex;
    padding: 8px 12px;
    gap: 4px;
    border-bottom: 1px solid var(--border);
}
.mode-tab {
    flex: 1;
    min-width: 0;
    padding: 8px 4px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all .2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mode-tab:hover { color: var(--text-primary); background: rgba(255,255,255,.05); }
.mode-tab.active { color: var(--accent); background: rgba(14,165,233,.1); }

/* ─── Mode Panels ─────────────────────────────────── */
.mode-panel { display: none; padding: 16px 20px; flex-direction: column; gap: 12px; }
.mode-panel.active { display: flex; }

.input-group { display: flex; flex-direction: column; gap: 6px; }
.input-group label { font-size: 0.8rem; color: var(--text-secondary); font-weight: 500; }

.input-row { display: flex; gap: 8px; }
.input-row select { flex: 1; }

input[type="text"], select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: border-color .2s;
}
input[type="text"]:focus, select:focus { border-color: var(--accent); }
select { cursor: pointer; }

input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

.hint { font-size: 0.85rem; color: var(--text-secondary); }
.coords-display {
    padding: 8px 12px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-family: monospace;
    color: var(--accent);
}

/* ─── Autocomplete ────────────────────────────────── */
.autocomplete-wrapper { position: relative; }
.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0; right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    max-height: 320px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.autocomplete-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background .15s;
    border-bottom: 1px solid rgba(255,255,255,.03);
}
.autocomplete-item:hover { background: rgba(255,255,255,.05); }
.autocomplete-item:last-child { border-bottom: none; }
.ac-emoji { font-size: 1.1rem; flex-shrink: 0; }
.ac-info { flex: 1; min-width: 0; }
.ac-name { font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-address { font-size: 0.75rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-distance { font-size: 0.75rem; color: var(--text-secondary); flex-shrink: 0; }

/* ─── Results ─────────────────────────────────────── */
.results-section {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.results-list { flex: 1; overflow-y: auto; }

.result-card {
    padding: 14px 20px;
    border-bottom: 1px solid rgba(255,255,255,.04);
    cursor: pointer;
    transition: background .15s;
    border-left: 3px solid transparent;
}
.result-card:hover { background: rgba(255,255,255,.03); }
.result-card.active { background: rgba(14,165,233,.08); }

.result-card-header { display: flex; align-items: flex-start; gap: 10px; }
.result-emoji { font-size: 1.1rem; flex-shrink: 0; margin-top: 2px; }
.result-info { flex: 1; min-width: 0; }
.result-name {
    font-size: 0.9rem; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.result-address {
    font-size: 0.8rem; color: var(--text-secondary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-top: 2px;
}
.result-meta {
    display: flex; align-items: center; gap: 8px;
    margin-top: 6px;
}
.result-distance { font-size: 0.75rem; color: var(--text-secondary); }

.category-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: capitalize;
}

/* ─── Empty / Loading / Error ─────────────────────── */
.empty-state, .loading-state, .error-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    gap: 8px;
}
.empty-icon, .error-icon { font-size: 2rem; }
.error-state { color: var(--danger); }

.spinner {
    width: 24px; height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Map ─────────────────────────────────────────── */
#map {
    flex: 1;
    height: 100vh;
    z-index: 1;
}

/* Leaflet overrides */
.leaflet-popup-content-wrapper {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius) !important;
    box-shadow: 0 8px 24px rgba(0,0,0,.5) !important;
}
.leaflet-popup-tip { background: var(--bg-card) !important; }
.leaflet-popup-content { margin: 12px 16px !important; font-size: 0.85rem !important; }
.leaflet-popup-content .popup-name { font-weight: 700; margin-bottom: 4px; }
.leaflet-popup-content .popup-address { color: var(--text-secondary); font-size: 0.8rem; margin-bottom: 8px; }
.leaflet-popup-content .popup-detail-btn {
    display: inline-block;
    padding: 4px 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    cursor: pointer;
    font-weight: 600;
}
.leaflet-popup-content .popup-detail-btn:hover { background: var(--accent-hover); }

.leaflet-control-attribution { background: rgba(15,15,26,.7) !important; color: var(--text-secondary) !important; }
.leaflet-control-attribution a { color: var(--accent) !important; }
.leaflet-control-zoom a {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border-color: var(--border) !important;
}
.leaflet-control-zoom a:hover { background: var(--bg-input) !important; }

/* Cluster overrides */
.marker-cluster-small, .marker-cluster-medium, .marker-cluster-large {
    background: rgba(14,165,233,.3) !important;
}
.marker-cluster-small div, .marker-cluster-medium div, .marker-cluster-large div {
    background: rgba(14,165,233,.6) !important;
    color: #fff !important;
    font-weight: 700;
}

/* Custom marker */
.custom-marker {
    display: flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.custom-marker .marker-emoji {
    transform: rotate(45deg);
    font-size: 14px;
    line-height: 1;
}

/* ─── Detail Panel ────────────────────────────────── */
.detail-panel {
    position: fixed;
    top: 0; right: 0;
    width: var(--detail-width);
    height: 100vh;
    background: var(--bg-primary);
    border-left: 1px solid var(--border);
    z-index: 2000;
    transform: translateX(100%);
    transition: transform .3s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.detail-panel.open { transform: translateX(0); }

.detail-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    position: relative;
}
.detail-header .icon-btn {
    position: absolute;
    top: 12px; right: 12px;
    font-size: 1.4rem;
}
.detail-header h3 { font-size: 1.1rem; padding-right: 32px; margin-bottom: 4px; }
.detail-header .text-secondary { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 8px; }

.detail-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.detail-section { margin-bottom: 20px; }
.detail-section-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 6px 0;
    font-size: 0.85rem;
    gap: 12px;
}
.detail-label { color: var(--text-secondary); flex-shrink: 0; }
.detail-value { text-align: right; word-break: break-word; }

.detail-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.85rem;
}
.detail-link:hover { text-decoration: underline; }

.hours-table { width: 100%; font-size: 0.8rem; border-collapse: collapse; }
.hours-table td { padding: 4px 0; }
.hours-table td:first-child { color: var(--text-secondary); width: 100px; }

.detail-keywords { display: flex; flex-wrap: wrap; gap: 6px; }
.keyword-tag {
    padding: 3px 10px;
    background: var(--bg-input);
    border-radius: 12px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.copy-btn {
    background: none; border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 2px 6px;
    border-radius: 4px;
}
.copy-btn:hover { background: rgba(14,165,233,.1); }

/* ─── Toast ───────────────────────────────────────── */
#toastContainer {
    position: fixed;
    bottom: 24px; right: 24px;
    z-index: 11000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
    animation: toastIn .3s ease;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ─── Sidebar toggle (mobile) ─────────────────────── */
.sidebar-toggle {
    position: fixed;
    top: 12px; left: 12px;
    z-index: 1100;
    width: 40px; height: 40px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 4px;
    cursor: pointer;
}
.sidebar-toggle span {
    display: block; width: 18px; height: 2px;
    background: var(--text-primary);
    border-radius: 1px;
    transition: transform .2s;
}
.sidebar-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 999;
}

/* ─── Pins ────────────────────────────────────────── */
.pin-add-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
}

.pins-list { flex: 1; overflow-y: auto; }

.pin-card {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255,255,255,.04);
    border-left: 3px solid transparent;
    cursor: pointer;
    transition: background .15s;
    gap: 8px;
}
.pin-card:hover { background: rgba(255,255,255,.03); }
.pin-card-body { flex: 1; min-width: 0; }
.pin-card-name { font-size: 0.9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pin-card-meta { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.pin-card-notes { font-size: 0.75rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pin-delete-btn { color: var(--text-secondary); font-size: 1rem; flex-shrink: 0; }
.pin-delete-btn:hover { color: var(--danger); background: rgba(239,68,68,.1); }

.pin-marker {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    box-shadow: 0 2px 8px rgba(0,0,0,.5);
    border: 2px solid rgba(255,255,255,.3);
}
.pin-marker-emoji { transform: rotate(45deg); font-size: 15px; line-height: 1; }

/* ─── Responsive ──────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0; top: 0;
        transform: translateX(-100%);
        transition: transform .3s ease;
        box-shadow: 4px 0 24px rgba(0,0,0,.5);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle.hidden { display: none; }
    .sidebar-toggle { display: flex; }

    #map { width: 100%; }

    .detail-panel { width: 100%; }
}

@media (min-width: 769px) {
    .sidebar-toggle { display: none !important; }
    .sidebar-overlay { display: none !important; }
}

/* ─── Narrate Mode ─────────────────────────────────── */
.input-label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.hint-inline {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: none;
    letter-spacing: 0;
}
.narrate-divider {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin: 6px 0;
}
.narrate-result {
    margin-top: 14px;
    padding: 14px 16px;
    background: var(--bg-input);
    border-radius: var(--radius);
    border-left: 3px solid var(--accent);
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-primary);
    white-space: pre-wrap;
}
.narrate-result .narrate-cached-badge {
    display: inline-block;
    font-size: 0.7rem;
    background: #0ea5e922;
    color: var(--accent);
    border-radius: 4px;
    padding: 1px 6px;
    margin-left: 8px;
    vertical-align: middle;
}
.narrate-meta {
    margin-top: 8px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}
