:root {
    --bg: #0f172a;
    --sidebar: #1e293b;
    --surface: #334155;
    --border: #475569;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --accent: #14b8a6;
    --accent-hover: #0d9488;
    --danger: #ef4444;
    --gold: #f59e0b;
    --purple: #8b5cf6;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

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

/* --- Toolbar --- */

#toolbar {
    height: 56px;
    background: var(--sidebar);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
    z-index: 100;
}

.toolbar-logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    text-decoration: none;
    letter-spacing: -0.5px;
    white-space: nowrap;
}

.toolbar-controls {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
}

.toolbar-controls input {
    flex: 1;
    max-width: 400px;
    padding: 8px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.toolbar-controls input:focus {
    border-color: var(--accent);
}

.toolbar-controls select {
    padding: 8px 32px 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

.toolbar-controls select:focus {
    border-color: var(--accent);
}

#suggestions {
    list-style: none;
    position: absolute;
    top: 100%;
    left: 0;
    width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 6px 6px;
    z-index: 1000;
    max-height: 240px;
    overflow-y: auto;
}

#suggestions:empty { display: none; }

#suggestions li {
    padding: 10px 14px;
    font-size: 13px;
    cursor: pointer;
    border-bottom: 1px solid rgba(71, 85, 105, 0.4);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#suggestions li:hover {
    background: var(--accent);
    color: white;
}

#suggestions li:last-child { border-bottom: none; }

.mode-toggle {
    display: flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.mode-btn {
    padding: 8px 14px;
    background: transparent;
    color: var(--text-muted);
    border: none;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.mode-btn:not(:last-child) { border-right: 1px solid var(--border); }
.mode-btn:hover { color: var(--text); }
.mode-btn.active { background: var(--accent); color: #fff; }

button#analyze {
    padding: 8px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
}

button#analyze:hover { background: var(--accent-hover); }
button#analyze:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Main layout --- */

#app {
    display: flex;
    height: calc(100vh - 56px);
}

body:has(#demo-banner:not(.hidden)) #app {
    height: calc(100vh - 56px - 37px);
}

body:has(#demo-banner:not(.hidden)) #toolbar {
    margin-top: 37px;
}

main {
    flex: 1;
    position: relative;
    min-width: 0;
}

#map {
    width: 100%;
    height: 100%;
}

/* Map loading overlay */
#map-loading {
    position: absolute;
    inset: 0;
    z-index: 500;
    background: rgba(15, 23, 42, 0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
}

.map-loading-ring {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255,255,255,0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Right panel --- */

#panel {
    width: 460px;
    min-width: 460px;
    background: var(--sidebar);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.empty-state {
    padding: 60px 32px;
    text-align: center;
}

.empty-state h2 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 12px;
}

.empty-state p {
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.6;
    max-width: 320px;
    margin: 0 auto;
}

/* --- Panel actions --- */

#panel-actions {
    padding: 20px 24px;
    border-top: 1px solid var(--border);
}

.btn-primary-action {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}
.btn-primary-action:hover { opacity: 0.9; }

.more-tools {
    margin-top: 12px;
}
.more-tools summary {
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px 0;
    user-select: none;
}
.more-tools summary:hover { color: var(--text); }
.tools-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
}

.action-row {
    display: flex;
    gap: 8px;
}

.btn-action {
    flex: 1;
    padding: 9px 12px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    white-space: nowrap;
}

.btn-action:hover { border-color: var(--accent); background: rgba(20, 184, 166, 0.08); }
.btn-action:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-action-gold:hover { border-color: var(--gold); background: rgba(245, 158, 11, 0.08); }
.btn-action-teal { border-color: rgba(20, 184, 166, 0.3); }
.btn-action-purple:hover { border-color: var(--purple); background: rgba(139, 92, 246, 0.08); }
.btn-action-muted:hover { border-color: var(--danger); background: rgba(239, 68, 68, 0.08); color: var(--danger); }

/* --- Stats --- */

#stats {
    padding: 20px 24px;
}

#stats:empty { display: none; }

.grade-card {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--surface);
    border-radius: 10px;
    padding: 20px 24px;
    margin-bottom: 16px;
}

.grade-letter {
    font-size: 48px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -2px;
}

.grade-info { flex: 1; }
.grade-score { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.grade-summary { font-size: 13px; color: var(--text-muted); line-height: 1.5; }
.grade-revenue { font-size: 13px; color: var(--accent); margin-top: 6px; }
.grade-revenue strong { color: var(--text); }

.location-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 0 12px;
    font-size: 14px;
    font-weight: 600;
}

.location-header:not(:first-child) {
    padding-top: 20px;
    border-top: 1px solid var(--border);
    margin-top: 16px;
}

.location-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.location-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 8px;
}

.stat-card {
    background: var(--surface);
    border-radius: 8px;
    padding: 14px;
    border-top: 3px solid var(--accent);
}

.ring-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 10px;
    color: var(--text-muted);
}

.stat-row {
    display: flex;
    align-items: baseline;
    gap: 4px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 18px;
    font-weight: 700;
}

.stat-label {
    font-size: 11px;
    color: var(--text-muted);
}

/* --- AI Report --- */

#report-container {
    padding: 24px;
    border-top: 1px solid var(--border);
}

#report-container h3 {
    font-size: 14px;
    font-weight: 700;
    color: var(--purple);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.report-text {
    font-size: 14px;
    line-height: 1.8;
    color: var(--text);
}

.report-text p {
    margin-bottom: 14px;
}

.report-copy {
    margin-top: 12px;
    padding: 8px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.report-copy:hover { border-color: var(--accent); color: var(--text); }

/* --- Suggest results --- */

#suggest-results {
    padding: 20px 24px;
    border-top: 1px solid var(--border);
}

#suggest-results h3 {
    font-size: 14px;
    font-weight: 700;
    color: var(--gold);
    margin-bottom: 12px;
}

.suggest-card {
    background: var(--surface);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 8px;
    border-left: 3px solid var(--gold);
    cursor: pointer;
    transition: background 0.15s;
}

.suggest-card:hover { background: #3b4d63; }

.suggest-rank {
    font-size: 12px;
    font-weight: 700;
    color: var(--gold);
    margin-bottom: 4px;
}

.suggest-detail {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.suggest-detail strong { color: var(--text); }

/* Suggest map markers */
.suggest-marker-inner {
    width: 30px;
    height: 30px;
    background: var(--gold);
    border: 2.5px solid #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    font-family: -apple-system, system-ui, sans-serif;
}

/* --- Demo banner --- */

#demo-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 8px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
}

#demo-banner.hidden { display: none; }

#demo-banner a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

/* --- Limit overlay --- */

#limit-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(15, 23, 42, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
}

.limit-modal {
    background: var(--sidebar);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 48px;
    text-align: center;
    max-width: 400px;
}

.limit-modal h2 { font-size: 24px; margin-bottom: 12px; }
.limit-modal p { color: var(--text-muted); margin-bottom: 24px; }

.btn-primary-link {
    display: inline-block;
    padding: 14px 32px;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
}

.limit-note { font-size: 12px !important; margin-top: 16px !important; margin-bottom: 0 !important; }

/* --- Leaflet --- */

.leaflet-popup-content-wrapper { border-radius: 6px; font-family: inherit; }
.leaflet-popup-content { font-size: 13px; line-height: 1.5; margin: 10px 14px; }

/* --- Neighborhood DNA map badge --- */

.dna-map-badge {
    background: none !important;
    border: none !important;
}

.dna-badge-inner {
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    color: #f1f5f9;
    font-size: 12px;
    font-weight: 700;
    padding: 5px 12px;
    border-radius: 6px;
    white-space: nowrap;
    text-align: center;
    border: 1px solid rgba(20, 184, 166, 0.4);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    width: fit-content;
    margin: 0 auto;
}

/* --- Neighborhood DNA --- */

.dna-card {
    background: var(--surface);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 16px;
}

.dna-header { margin-bottom: 14px; }

.dna-type {
    font-size: 16px;
    font-weight: 700;
}

.dna-bars { display: flex; flex-direction: column; gap: 6px; }

.dna-bar-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dna-label {
    font-size: 11px;
    width: 90px;
    flex-shrink: 0;
    color: var(--text-muted);
    text-align: right;
}

.dna-bar-track {
    flex: 1;
    height: 8px;
    background: rgba(255,255,255,0.06);
    border-radius: 4px;
    overflow: hidden;
}

.dna-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s ease-out;
}

.dna-val {
    font-size: 11px;
    width: 24px;
    color: var(--text-muted);
    text-align: right;
}

.dna-traits {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.dna-trait {
    font-size: 11px;
    padding: 3px 10px;
    background: rgba(20, 184, 166, 0.1);
    border: 1px solid rgba(20, 184, 166, 0.2);
    border-radius: 12px;
    color: var(--accent);
}

/* --- Category gaps --- */

.gap-section { margin-top: 14px; }
.gap-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.gap-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

.gap-label {
    font-size: 13px;
    font-weight: 500;
    min-width: 100px;
}

.gap-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

.gap-opp {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: auto;
    white-space: nowrap;
}

/* --- Competitor detail --- */

#competitor-detail {
    padding: 20px 24px;
    border-top: 1px solid var(--border);
}

.comp-detail-card {
    background: var(--surface);
    border-radius: 10px;
    padding: 20px;
    border-left: 4px solid #f97316;
}

.comp-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.comp-detail-header h3 { font-size: 15px; }

.comp-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
}
.comp-close:hover { color: var(--text); }

.comp-detail-stat {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 6px;
}

.comp-detail-note {
    margin-top: 10px;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
    font-style: italic;
}

.comp-loading {
    color: var(--text-muted);
    font-size: 13px;
    padding: 8px 0;
}

/* --- Isochrone animation --- */

.iso-ring {
    transition: fill-opacity 0.6s ease-out, stroke-opacity 0.6s ease-out, opacity 0.6s ease-out;
}

/* --- Animations --- */

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.analyzing { animation: pulse 1.2s ease-in-out infinite; }
