:root {
    --bg-dark: #0f0f14;
    --bg-card: rgba(22, 22, 30, 0.95);
    --bg-input: rgba(35, 35, 50, 0.8);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #f0f0f5;
    --text-secondary: #9090a0;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --success: #22c55e;
    --warning: #eab308;
    --danger: #ef4444;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --transition: 0.2s ease;
}

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

body {
    font-family: var(--font-family);
    background: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

.sidebar {
    width: 400px;
    min-width: 400px;
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(20px);
    z-index: 1000;
}

.sidebar-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 4px;
}

.controls {
    padding: 16px 24px;
    flex: 1;
    overflow-y: auto;
}

.control-group {
    margin-bottom: 24px;
    overflow: visible;
}

.control-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

select {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239090a0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

select:hover {
    border-color: var(--accent);
}

select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.range-slider {
    margin: 48px 12px 24px 12px;
    height: 6px;
    border-radius: 3px;
    border: none;
    box-shadow: none;
    background: var(--bg-input);
    overflow: visible;
}

.noUi-connect {
    background: var(--accent);
    cursor: grab;
}

.noUi-connect:active {
    cursor: grabbing;
}

.noUi-horizontal .noUi-handle {
    width: 20px;
    height: 20px;
    right: -10px;
    top: -8px;
    border: 2px solid var(--accent);
    background: var(--bg-card);
    border-radius: 50%;
    box-shadow: none;
    cursor: grab;
    transition: transform var(--transition), border-color var(--transition);
}

.noUi-horizontal .noUi-handle:hover {
    background: var(--bg-input);
}

.noUi-horizontal .noUi-handle:active {
    cursor: grabbing;
    background: var(--accent);
}

.noUi-handle::before,
.noUi-handle::after {
    display: none;
}

.noUi-tooltip {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    font-size: 0.7rem;
    font-family: var(--font-family);
    padding: 4px 8px;
    border-radius: 4px;
    bottom: 24px;
}

.merged-tooltip {
    position: absolute;
    top: -32px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    font-size: 0.7rem;
    font-family: var(--font-family);
    padding: 4px 10px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
    transition: left 0.1s ease-out;
}

.btn-primary,
.btn-secondary {
    width: 100%;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    color: white;
    box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px var(--accent-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.stats-panel {
    padding: 16px 16px;
    border-top: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: 0.8fr 1.2fr;
    gap: 8px;
}

.stat {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.sidebar-footer p {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.sidebar-footer a {
    color: var(--accent);
    text-decoration: none;
}

.sidebar-footer a:hover {
    text-decoration: underline;
}

.map-container {
    flex: 1;
    position: relative;
}

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

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 15, 20, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-overlay p {
    margin-top: 16px;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.leaflet-container {
    background: var(--bg-dark);
    font-family: var(--font-family);
}

.leaflet-control-zoom {
    border: none !important;
    box-shadow: var(--shadow) !important;
}

.leaflet-control-zoom a {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important;
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-input) !important;
}

.leaflet-control-zoom-in {
    border-radius: var(--radius-sm) var(--radius-sm) 0 0 !important;
}

.leaflet-control-zoom-out {
    border-radius: 0 0 var(--radius-sm) var(--radius-sm) !important;
}

.toggle-group {
    margin-bottom: 16px;
}

.control-group .toggle-label {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    user-select: none;
    flex-direction: row;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.05em;
    margin-bottom: 0;
}

.control-group .toggle-label input {
    display: none;
}

.toggle-slider {
    width: 44px;
    min-width: 44px;
    height: 24px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    position: relative;
    transition: var(--transition);
    flex-shrink: 0;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    background: var(--text-secondary);
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: var(--transition);
}

.toggle-label input:checked+.toggle-slider {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle-label input:checked+.toggle-slider::before {
    transform: translateX(20px);
    background: white;
}

.toggle-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.toggle-label input:checked~.toggle-text {
    color: var(--text-primary);
}

.chart-panel {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
}

.chart-panel h3 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

#wards-chart {
    display: flex;
    flex-direction: column;
}

#wards-chart .ward-bar {
    margin-bottom: 4px;
}

.ward-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.ward-name {
    font-size: 0.7rem;
    color: var(--text-secondary);
    width: 100px;
    flex-shrink: 0;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

#modal-ward-list .ward-name {
    width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ward-bar-container {
    flex: 1;
    height: 20px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.ward-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #8b5cf6);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.ward-stats {
    display: flex;
    gap: 6px;
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    flex-shrink: 0;
    justify-content: flex-end;
}

.ward-abs {
    color: var(--text-primary);
    width: 55px;
    text-align: right;
}

.ward-percent {
    color: var(--text-secondary);
    width: 45px;
    text-align: right;
    font-weight: 400;
}

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-footer p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 0;
}

.github-link {
    color: var(--text-secondary);
    transition: var(--transition);
    display: flex;
    align-items: center;
}

.github-link:hover {
    color: var(--text-primary);
    transform: scale(1.1);
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-width: unset;
        height: auto;
        max-height: 50vh;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .controls {
        padding: 16px;
    }

    .stats-panel {
        padding: 12px 16px;
    }

    .chart-panel {
        display: none;
    }
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: #18181f;
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
}

.modal-header h2 {
    font-size: 1.25rem;
    margin: 0;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: capitalize;
}

.close-modal,
.close-modal-details {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.close-modal:hover,
.close-modal-details:hover {
    color: var(--text-primary);
    background: var(--bg-input);
    border-color: var(--border-color);
}

.modal-body {
    padding: 16px 24px;
    overflow-y: auto;
}

.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.875rem;
    padding: 0;
    margin: 12px auto 0;
    display: block;
    text-decoration: underline;
    transition: var(--transition);
}

.btn-link:hover {
    color: #a78bfa;
}

.toggle-buttons {
    display: flex;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 2px;
    margin-top: 8px;
}

.view-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 12px;
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.view-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.view-btn.active {
    background: var(--accent);
    color: white;
    font-weight: 500;
}

.info {
    padding: 12px;
    font-family: var(--font-family);
    background: var(--bg-card);
    background: rgba(22, 22, 30, 0.9);
    box-shadow: var(--shadow);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    backdrop-filter: blur(10px);
}

.info h4 {
    margin: 0 0 8px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.info b {
    color: var(--accent);
    font-size: 1rem;
}

.tooltip-header {
    margin-top: 8px;
    font-size: 0.7rem;
    color: #9090a0;
    font-weight: 600;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 6px;
    margin-bottom: 4px;
}

.tooltip-crime-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tooltip-crime-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    font-size: 0.75rem;
    line-height: 1.3;
}

.tooltip-crime-item span {
    color: var(--text-secondary);
}

.tooltip-crime-item b {
    color: var(--text-primary);
    font-size: 0.75rem;
}

.leaflet-interactive:focus {
    outline: none !important;
}

.details-modal {
    max-width: 500px;
}

.ward-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.stat-box {
    background: var(--bg-input);
    padding: 16px;
    border-radius: var(--radius-sm);
    text-align: center;
    border: 1px solid var(--border-color);
}

.stat-box.trend-positive {
    border-color: rgba(239, 68, 68, 0.4);
    background: rgba(239, 68, 68, 0.1);
}

.stat-box.trend-negative {
    border-color: rgba(34, 197, 94, 0.4);
    background: rgba(34, 197, 94, 0.1);
}

.stat-box h3 {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 8px;
}

.stat-box .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-box .sub-value {
    font-size: 0.8rem;
    margin-top: 4px;
}

.trend-up {
    color: var(--danger);
}

.trend-down {
    color: var(--success);
}

.ward-chart-section h4 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.sparkline-container {
    height: 100px;
    width: 100%;
    display: flex;
    align-items: flex-end;
    gap: 2px;
}

.spark-bar {
    flex: 1;
    background: var(--accent);
    opacity: 0.6;
    transition: height 0.3s ease;
    border-radius: 2px 2px 0 0;
}

.spark-bar:hover {
    opacity: 1;
}