/* XPosition - Painel Administrativo | Design para Apresentação */

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

:root {
    --primary: #1a56db;
    --primary-dark: #1341a3;
    --primary-light: #e8f0fe;
    --secondary: #6c757d;
    --success: #0f9d58;
    --warning: #f59e0b;
    --danger: #dc2626;
    --route-color: #2563eb;
    --urban-color: #d97706;
    --crime-color: #dc2626;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #1a56db;
    --card-bg: #ffffff;
    --body-bg: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.07), 0 4px 6px rgba(0,0,0,0.05);
    --radius: 12px;
    --radius-sm: 8px;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--body-bg);
    -webkit-font-smoothing: antialiased;
}

/* ─── SIDEBAR ──────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 100;
    width: 260px;
    padding: 0;
    background: var(--sidebar-bg);
    overflow-y: auto;
    border-right: none;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
}

.sidebar-brand {
    padding: 1.5rem 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-brand-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(26,86,219,0.4);
}

.sidebar-brand-text h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.3px;
}

.sidebar-brand-text p {
    margin: 0;
    font-size: 0.7rem;
    color: rgba(255,255,255,0.4);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.sidebar-section-title {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.3);
    padding: 1rem 1.25rem 0.4rem;
    font-weight: 600;
}

.sidebar .nav-link {
    color: rgba(255,255,255,0.65);
    padding: 0.65rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    border-radius: 0;
    transition: all 0.15s ease;
    font-size: 0.875rem;
    font-weight: 400;
}

.sidebar .nav-link i {
    width: 18px;
    text-align: center;
    font-size: 0.875rem;
    flex-shrink: 0;
    opacity: 0.7;
}

.sidebar .nav-link:hover {
    background-color: var(--sidebar-hover);
    color: #ffffff;
}

.sidebar .nav-link:hover i { opacity: 1; }

.sidebar .nav-link.active {
    background: linear-gradient(135deg, rgba(26,86,219,0.4), rgba(59,130,246,0.2));
    color: #ffffff;
    font-weight: 500;
    border-left: 3px solid var(--primary);
}

.sidebar .nav-link.active i { opacity: 1; }

/* Filtros na sidebar */
.sidebar-filters {
    padding: 0 1rem 1rem;
}

.sidebar-filters .form-label {
    color: rgba(255,255,255,0.5);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    margin-bottom: 0.3rem;
}

.sidebar-filters .form-select,
.sidebar-filters .form-control {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.85);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
}

.sidebar-filters .form-select:focus,
.sidebar-filters .form-control:focus {
    background: rgba(255,255,255,0.09);
    border-color: rgba(26,86,219,0.6);
    color: white;
    box-shadow: 0 0 0 2px rgba(26,86,219,0.25);
}

.sidebar-filters .form-select option {
    background: #1e293b;
    color: rgba(255,255,255,0.85);
}

.sidebar-filters .btn-primary {
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.8rem;
    letter-spacing: 0.2px;
    padding: 0.55rem;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(26,86,219,0.4);
}

.sidebar-filters .btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(26,86,219,0.5);
}

/* ─── MAIN CONTENT ──────────────────────────────────────────── */
main {
    margin-left: 260px;
    min-height: 100vh;
    padding-bottom: 2rem;
}

/* ─── TOP HEADER ────────────────────────────────────────────── */
.top-header {
    background: white;
    border-bottom: 1px solid var(--border-color);
    padding: 0.85rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 50;
}

.top-header h1 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -0.3px;
}

.top-header-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
    display: block;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.header-actions .btn {
    font-size: 0.8rem;
    padding: 0.45rem 0.85rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.view-selector {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--body-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.3rem 0.75rem;
}

.view-selector label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
    margin: 0;
}

.view-selector .form-select {
    border: none;
    background: transparent;
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.25rem 1.5rem 0.25rem 0.25rem;
    color: var(--primary);
    cursor: pointer;
}

.view-selector .form-select:focus {
    box-shadow: none;
}

/* ─── STAT CARDS ────────────────────────────────────────────── */
.stats-row {
    padding: 1.25rem 1.5rem 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
}

.stat-card.total::before { background: linear-gradient(90deg, var(--primary), #3b82f6); }
.stat-card.rotas::before { background: linear-gradient(90deg, #2563eb, #60a5fa); }
.stat-card.urbanas::before { background: linear-gradient(90deg, #d97706, #fbbf24); }
.stat-card.crimes::before { background: linear-gradient(90deg, #dc2626, #f87171); }

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.85rem;
}

.stat-card-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.stat-card-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.stat-card.total .stat-card-icon { background: var(--primary-light); color: var(--primary); }
.stat-card.rotas .stat-card-icon { background: #dbeafe; color: #2563eb; }
.stat-card.urbanas .stat-card-icon { background: #fef3c7; color: #d97706; }
.stat-card.crimes .stat-card-icon { background: #fee2e2; color: #dc2626; }

.stat-value {
    font-size: 2.1rem;
    font-weight: 800;
    letter-spacing: -1.5px;
    line-height: 1;
    color: var(--text-primary);
}

.stat-card-footer {
    margin-top: 0.5rem;
    font-size: 0.72rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.stat-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 20px;
}

.stat-badge.route { background: #dbeafe; color: #2563eb; }
.stat-badge.urban { background: #fef3c7; color: #d97706; }
.stat-badge.crime { background: #fee2e2; color: #dc2626; }

/* ─── MAP SECTION ───────────────────────────────────────────── */
.map-section {
    padding: 1.25rem 1.5rem;
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 1rem;
}

.map-container {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    overflow: hidden;
    isolation: isolate;
}

.map-container-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: white;
}

.map-container-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.map-badges {
    display: flex;
    gap: 0.4rem;
}

.map-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.7rem;
    font-weight: 500;
    padding: 0.2rem 0.5rem;
    border-radius: 20px;
}

.map-badge.route { background: #dbeafe; color: #2563eb; }
.map-badge.urban { background: #fef3c7; color: #d97706; }
.map-badge.crime { background: #fee2e2; color: #dc2626; }

#map {
    height: 560px;
}

/* ─── RIGHT PANEL ───────────────────────────────────────────── */
.right-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.panel-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.panel-card-header {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-card-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.panel-card-title i {
    color: var(--primary);
    font-size: 0.8rem;
}

.panel-card-body {
    padding: 1rem;
}

/* Legend */
.legend-grid {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(255,255,255,0.8), 0 0 0 3px rgba(0,0,0,0.1);
}

.legend-info {
    flex: 1;
}

.legend-name {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-primary);
    display: block;
}

.legend-count {
    font-size: 0.68rem;
    color: var(--text-secondary);
}

/* Element details */
#elementDetails {
    display: none;
}

#elementDetails.visible {
    display: block;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.78rem;
}

.detail-row:last-child { border-bottom: none; }

.detail-label {
    color: var(--text-secondary);
    font-weight: 500;
    flex-shrink: 0;
    margin-right: 0.5rem;
}

.detail-value {
    color: var(--text-primary);
    font-weight: 600;
    text-align: right;
    word-break: break-word;
}

/* Loading overlay */
.map-loading {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 999;
    gap: 1rem;
    border-radius: var(--radius);
}

.map-loading.hidden { display: none; }

.loading-spinner {
    width: 42px;
    height: 42px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-text {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

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

/* Count animation */
@keyframes countUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.stat-value.animated {
    animation: countUp 0.5s ease-out forwards;
}

/* ─── CATEGORY PILLS ────────────────────────────────────────── */
.category-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    text-transform: capitalize;
}

.category-pill.rota { background: #dbeafe; color: #2563eb; }
.category-pill.denuncia_urbana { background: #fef3c7; color: #d97706; }
.category-pill.crime { background: #fee2e2; color: #dc2626; }
.category-pill.nao_classificada { background: #f1f5f9; color: #64748b; }

/* ─── VIZ BUTTON ────────────────────────────────────────────── */
.viz-btn {
    cursor: pointer;
    border: none;
    background: white;
    text-align: left;
    color: var(--text-primary);
    transition: background 0.15s;
    font-size: 0.78rem;
}

.viz-btn:hover { background: var(--body-bg); }

.viz-btn.active-viz {
    background: var(--primary-light) !important;
    color: var(--primary);
    font-weight: 600;
}

/* ─── CURRENT LOCATION ──────────────────────────────────────── */
.current-location-marker { border: none; background: transparent; }
.current-location-icon { position: relative; width: 20px; height: 20px; }
.current-location-dot {
    position: absolute; top: 50%; left: 50%;
    width: 8px; height: 8px;
    background: var(--primary); border: 2px solid white;
    border-radius: 50%; transform: translate(-50%, -50%);
    z-index: 2; box-shadow: 0 2px 6px rgba(26,86,219,0.4);
}
.current-location-pulse {
    position: absolute; top: 50%; left: 50%;
    width: 20px; height: 20px;
    background: rgba(26,86,219,0.25); border-radius: 50%;
    transform: translate(-50%, -50%);
    animation: location-pulse 2s infinite;
}
@keyframes location-pulse {
    0% { transform: translate(-50%,-50%) scale(0.8); opacity: 1; }
    100% { transform: translate(-50%,-50%) scale(2.2); opacity: 0; }
}

/* ─── MARKER CLUSTER OVERRIDE ───────────────────────────────── */
.marker-cluster-small { background-color: rgba(37,99,235,0.3) !important; }
.marker-cluster-small div { background-color: rgba(37,99,235,0.7) !important; color: white !important; font-weight: 700 !important; }
.marker-cluster-medium { background-color: rgba(217,119,6,0.3) !important; }
.marker-cluster-medium div { background-color: rgba(217,119,6,0.7) !important; color: white !important; font-weight: 700 !important; }
.marker-cluster-large { background-color: rgba(220,38,38,0.3) !important; }
.marker-cluster-large div { background-color: rgba(220,38,38,0.7) !important; color: white !important; font-weight: 700 !important; }

/* ─── CUSTOM MARKER ─────────────────────────────────────────── */
.custom-marker { background: none !important; border: none !important; }

.custom-marker .marker-icon {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: block;
    border: 2px solid rgba(255,255,255,0.9);
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.custom-marker .marker-icon:hover {
    transform: scale(1.4);
    box-shadow: 0 3px 12px rgba(0,0,0,0.4);
}

/* ─── MODAL ─────────────────────────────────────────────────── */
.modal-content {
    border: none;
    border-radius: var(--radius);
    box-shadow: 0 20px 40px rgba(0,0,0,0.15);
}

.modal-header {
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
}

.modal-title { font-weight: 700; font-size: 0.95rem; }

.modal-footer {
    border-top: 1px solid var(--border-color);
    padding: 0.75rem 1.25rem;
}

/* ─── TOAST ─────────────────────────────────────────────────── */
.toast {
    border: none;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(10px);
    min-width: 280px;
}

/* ─── LEAFLET POPUP ─────────────────────────────────────────── */
.leaflet-popup-content-wrapper {
    border-radius: var(--radius-sm) !important;
    box-shadow: var(--shadow-lg) !important;
    border: 1px solid var(--border-color);
}

.leaflet-popup-content {
    margin: 10px 14px;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 0.8rem;
    line-height: 1.5;
}

.leaflet-popup-content strong {
    font-size: 0.85rem;
    color: var(--text-primary);
}

.popup-link {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
    font-size: 0.75rem;
}

.popup-link:hover { text-decoration: underline; }

/* ─── DATA LOADING STATE ────────────────────────────────────── */
.skeleton {
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: skeleton 1.4s ease-in-out infinite;
    border-radius: 4px;
}

@keyframes skeleton {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ─── SCROLLBAR ─────────────────────────────────────────────── */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

/* ─── SIDEBAR BACKDROP ──────────────────────────────────────── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 1050;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    transition: opacity 0.3s;
}
.sidebar-backdrop.show { display: block; }
body.sidebar-open { overflow: hidden; }

/* ─── HAMBURGER BUTTON ──────────────────────────────────────── */
.btn-menu {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}
.btn-menu:hover { background: var(--body-bg); color: var(--text-primary); }

/* ─── HEADER LEFT ───────────────────────────────────────────── */
.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}
.header-title {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.page-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ─── RESPONSIVE ────────────────────────────────────────────── */
@media (max-width: 1200px) {
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .map-section { grid-template-columns: 1fr; }
    .right-panel { flex-direction: row; flex-wrap: wrap; }
    .right-panel .panel-card { flex: 1 1 calc(50% - 0.5rem); min-width: 220px; }
}

@media (max-width: 992px) {
    .btn-menu { display: flex; }
    .sidebar {
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
        z-index: 1100;
    }
    .sidebar.show { transform: translateX(0); }
    main { margin-left: 0; }
}

@media (max-width: 768px) {
    /* Header compacto */
    .top-header { padding: 0.6rem 1rem; gap: 0.5rem; }
    .top-header-subtitle { display: none; }
    .btn-label { display: none; }
    .viz-label { display: none; }
    .header-actions { gap: 0.35rem; }
    .header-actions .btn { padding: 0.45rem 0.6rem; }
    .view-selector { padding: 0.25rem 0.5rem; }
    .view-selector .form-select { font-size: 0.75rem; }

    /* Stats — scroll horizontal */
    .stats-row {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        gap: 0.65rem;
        padding: 0.85rem 1rem;
    }
    .stats-row::-webkit-scrollbar { display: none; }
    .stat-card {
        min-width: 145px;
        flex-shrink: 0;
        scroll-snap-align: start;
    }
    .stat-value { font-size: 1.65rem; }
    .stat-card-footer { font-size: 0.68rem; }

    /* Mapa */
    .map-section { padding: 0 0.75rem 0.75rem; gap: 0.75rem; }
    #map { height: calc(100vh - 230px); min-height: 300px; }

    /* Painel direito em grade 2 cols */
    .right-panel { gap: 0.65rem; }
    .right-panel .panel-card { flex: 1 1 calc(50% - 0.325rem); min-width: 170px; }
}

@media (max-width: 540px) {
    .page-title { font-size: 0.9rem; }
    .stat-card { min-width: 130px; }
    .stat-value { font-size: 1.5rem; }
    .stat-card-footer { display: none; }
    #map { height: calc(100vh - 215px); min-height: 280px; }

    /* Painel direito empilhado */
    .right-panel .panel-card { flex: 1 1 100%; }
}

@media print {
    .sidebar, .header-actions, .no-print { display: none !important; }
    main { margin-left: 0 !important; }
    .stat-card, .map-container { page-break-inside: avoid; }
}
