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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #0d1117;
    color: #e6edf3;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────── */
#header {
    background: linear-gradient(135deg, #1a1f2e 0%, #16213e 50%, #0f3460 100%);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #30363d;
    flex-shrink: 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}

#header h1 {
    font-size: 1.3rem;
    font-weight: 700;
    color: #e9b44c;
    letter-spacing: 0.5px;
}

#header h1 span {
    color: #c9d1d9;
    font-weight: 300;
    font-size: 0.95rem;
    margin-left: 10px;
}

.header-stats {
    display: flex;
    gap: 20px;
    align-items: center;
}

.stat-pill {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 20px;
    padding: 4px 14px;
    font-size: 0.78rem;
    color: #8b949e;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.stat-pill:hover { background: rgba(255,255,255,0.14); color: #e6edf3; }
.stat-pill strong { color: #e9b44c; }

/* ── Layout ──────────────────────────────────────────────── */
#app {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
#sidebar {
    width: 320px;
    min-width: 280px;
    background: #161b22;
    border-right: 1px solid #30363d;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

#sidebar-top {
    padding: 14px 14px 10px;
    border-bottom: 1px solid #21262d;
}

#search-box {
    width: 100%;
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 8px;
    color: #e6edf3;
    padding: 8px 12px;
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
}

#search-box:focus { border-color: #e9b44c; }
#search-box::placeholder { color: #484f58; }

.filter-row {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.filter-btn {
    background: #21262d;
    border: 1px solid #30363d;
    border-radius: 6px;
    color: #8b949e;
    padding: 4px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-btn:hover, .filter-btn.active {
    border-color: var(--group-color, #e9b44c);
    color: var(--group-color, #e9b44c);
    background: rgba(233,180,76,0.08);
}

.filter-btn.all.active { --group-color: #e6edf3; }
.filter-btn.Eastern.active { --group-color: #3fb950; }
.filter-btn.Western.active { --group-color: #58a6ff; }
.filter-btn.Diaspora.active { --group-color: #f78166; }

#dialect-count {
    font-size: 0.72rem;
    color: #484f58;
    margin-top: 8px;
    padding-left: 2px;
}

/* ── Dialect List ────────────────────────────────────────── */
#dialect-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 8px;
}

#dialect-list::-webkit-scrollbar { width: 5px; }
#dialect-list::-webkit-scrollbar-track { background: transparent; }
#dialect-list::-webkit-scrollbar-thumb { background: #30363d; border-radius: 3px; }

.dialect-item {
    padding: 9px 10px;
    border-radius: 7px;
    cursor: pointer;
    margin-bottom: 3px;
    transition: background 0.15s;
    border-left: 3px solid transparent;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.dialect-item:hover { background: #21262d; }
.dialect-item.selected { background: #1c2433; border-left-color: #e9b44c; }

.dialect-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 4px;
}

.dialect-info { flex: 1; min-width: 0; }

.dialect-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #c9d1d9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dialect-sub {
    font-size: 0.72rem;
    color: #484f58;
    margin-top: 1px;
}

.status-badge {
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 10px;
    flex-shrink: 0;
    margin-top: 2px;
}

/* ── Map ─────────────────────────────────────────────────── */
#map-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

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

/* ── Info Panel ──────────────────────────────────────────── */
#info-panel {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 340px;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 12px;
    padding: 18px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.5);
    z-index: 1000;
    display: none;
    animation: slideUp 0.25s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

#info-panel.visible { display: block; }

#info-close {
    position: absolute;
    top: 10px;
    right: 12px;
    background: none;
    border: none;
    color: #484f58;
    font-size: 1.1rem;
    cursor: pointer;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color 0.2s;
}

#info-close:hover { color: #e6edf3; }

#info-armenian {
    font-size: 1rem;
    color: #e9b44c;
    margin-bottom: 4px;
    font-style: italic;
}

#info-name {
    font-size: 1.2rem;
    font-weight: 700;
    color: #e6edf3;
    margin-bottom: 10px;
}

.info-row {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
    font-size: 0.8rem;
    align-items: flex-start;
}

.info-label {
    color: #484f58;
    min-width: 70px;
    flex-shrink: 0;
}

.info-value { color: #c9d1d9; }

#info-desc {
    margin-top: 12px;
    font-size: 0.8rem;
    color: #8b949e;
    line-height: 1.55;
    border-top: 1px solid #21262d;
    padding-top: 10px;
}

/* ── Legend ──────────────────────────────────────────────── */
#legend {
    position: absolute;
    top: 14px;
    left: 14px;
    background: rgba(22,27,34,0.92);
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 10px 14px;
    z-index: 1000;
    backdrop-filter: blur(6px);
}

#legend h4 {
    font-size: 0.72rem;
    color: #484f58;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
    font-size: 0.76rem;
    color: #8b949e;
}

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

/* ── Color scheme ────────────────────────────────────────── */
.color-Eastern  { background: #3fb950; }
.color-Western  { background: #58a6ff; }
.color-Diaspora { background: #f78166; }

.status-active    { background: rgba(63,185,80,0.2);  color: #3fb950; }
.status-endangered{ background: rgba(210,153,34,0.2); color: #e3b341; }
.status-extinct   { background: rgba(139,68,68,0.2);  color: #f85149; }
.status-diaspora  { background: rgba(87,148,242,0.2); color: #79c0ff; }

/* ── Leaflet overrides ───────────────────────────────────── */
.leaflet-container { background: #0d1117; }
.leaflet-control-zoom a {
    background: #161b22 !important;
    color: #e6edf3 !important;
    border-color: #30363d !important;
}
.leaflet-control-zoom a:hover { background: #21262d !important; }

.custom-popup .leaflet-popup-content-wrapper {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    color: #e6edf3;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
}

.custom-popup .leaflet-popup-tip { background: #161b22; }

.popup-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #e6edf3;
    margin-bottom: 3px;
}

.popup-arm {
    font-size: 0.78rem;
    color: #e9b44c;
    font-style: italic;
    margin-bottom: 5px;
}

.popup-meta {
    font-size: 0.72rem;
    color: #8b949e;
}

/* ── Theme toggle button ─────────────────────────────────── */
#theme-toggle {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 20px;
    color: #e6edf3;
    font-size: 1rem;
    padding: 4px 12px;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}
#theme-toggle:hover { background: rgba(255,255,255,0.16); }

/* ── Light theme ─────────────────────────────────────────── */
body.light {
    background: #ffffff;
    color: #1f2328;
}

body.light #header {
    background: linear-gradient(135deg, #f0f4ff 0%, #e8edf8 50%, #dde6f5 100%);
    border-bottom-color: #d0d7de;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

body.light #header h1 { color: #b08000; }
body.light #header h1 span { color: #57606a; }

body.light #theme-toggle {
    background: rgba(0,0,0,0.06);
    border-color: rgba(0,0,0,0.15);
    color: #1f2328;
}
body.light #theme-toggle:hover { background: rgba(0,0,0,0.1); }

body.light .stat-pill {
    background: rgba(0,0,0,0.05);
    border-color: rgba(0,0,0,0.1);
    color: #57606a;
}
body.light .stat-pill strong { color: #b08000; }

body.light #sidebar {
    background: #f6f8fa;
    border-right-color: #d0d7de;
}

body.light #sidebar-top { border-bottom-color: #d8dee4; }

body.light #search-box {
    background: #ffffff;
    border-color: #d0d7de;
    color: #1f2328;
}
body.light #search-box:focus { border-color: #b08000; }
body.light #search-box::placeholder { color: #8c959f; }

body.light .filter-btn {
    background: #eaeef2;
    border-color: #d0d7de;
    color: #57606a;
}
body.light .filter-btn:hover, body.light .filter-btn.active {
    background: rgba(176,128,0,0.08);
}
body.light #dialect-count { color: #8c959f; }

body.light .dialect-item:hover { background: #eaeef2; }
body.light .dialect-item.selected { background: #ddeeff; border-left-color: #b08000; }
body.light .dialect-name { color: #1f2328; }
body.light .dialect-sub { color: #8c959f; }

body.light #info-panel {
    background: #f6f8fa;
    border-color: #d0d7de;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
}
body.light #info-armenian { color: #b08000; }
body.light #info-name { color: #1f2328; }
body.light .info-label { color: #8c959f; }
body.light .info-value { color: #24292f; }
body.light #info-desc { color: #57606a; border-top-color: #d8dee4; }
body.light #info-close { color: #8c959f; }
body.light #info-close:hover { color: #1f2328; }

body.light #legend {
    background: rgba(246,248,250,0.95);
    border-color: #d0d7de;
}
body.light #legend h4 { color: #8c959f; }
body.light .legend-item { color: #57606a; }

body.light .leaflet-container { background: #f0f0f0; }
body.light .leaflet-control-zoom a {
    background: #f6f8fa !important;
    color: #1f2328 !important;
    border-color: #d0d7de !important;
}
body.light .leaflet-control-zoom a:hover { background: #eaeef2 !important; }

body.light .custom-popup .leaflet-popup-content-wrapper {
    background: #f6f8fa;
    border-color: #d0d7de;
    color: #1f2328;
}
body.light .custom-popup .leaflet-popup-tip { background: #f6f8fa; }
body.light .popup-title { color: #1f2328; }
body.light .popup-arm { color: #b08000; }
body.light .popup-meta { color: #57606a; }

/* ── Sidebar toggle button (hidden on desktop) ───────────── */
#sidebar-toggle {
    display: none;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 8px;
    color: #e6edf3;
    font-size: 1.1rem;
    padding: 4px 10px;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}
#sidebar-toggle:hover { background: rgba(255,255,255,0.16); }
body.light #sidebar-toggle {
    background: rgba(0,0,0,0.06);
    border-color: rgba(0,0,0,0.15);
    color: #1f2328;
}

/* ── Tablet (≤ 900px) ────────────────────────────────────── */
@media (max-width: 900px) {
    #sidebar { width: 270px; min-width: 240px; }
    #info-panel { width: 300px; }
    .header-stats { gap: 10px; }
    .stat-pill { padding: 3px 10px; font-size: 0.72rem; }
}

/* ── Mobile (≤ 640px) ────────────────────────────────────── */
@media (max-width: 640px) {
    /* Header */
    #header {
        padding: 8px 12px;
        flex-wrap: wrap;
        gap: 8px;
    }
    #header h1 { font-size: 1rem; }
    #header h1 span { display: none; }
    .header-stats {
        display: none; /* hidden by default; shown when sidebar is open */
    }

    /* Show hamburger */
    #sidebar-toggle { display: block; }

    /* Sidebar becomes a full-height overlay */
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        width: 80vw;
        max-width: 320px;
        z-index: 2000;
        transform: translateX(-100%);
        transition: transform 0.28s ease;
        box-shadow: 4px 0 20px rgba(0,0,0,0.5);
    }
    #sidebar.open {
        transform: translateX(0);
    }

    /* Dim overlay behind sidebar */
    #sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.45);
        z-index: 1999;
    }
    #sidebar-overlay.visible { display: block; }

    /* Map fills full width */
    #map-container { width: 100%; }

    /* Info panel: full width, slides up from bottom */
    #info-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 55vh;
        overflow-y: auto;
        border-radius: 14px 14px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        padding: 14px 16px 24px;
    }

    /* Legend: smaller, top-right */
    #legend {
        top: 10px;
        left: auto;
        right: 10px;
        padding: 8px 10px;
        font-size: 0.7rem;
    }
    #legend h4 { font-size: 0.65rem; }
}
