/* ==========================================================================
   PAINEL LOGÍSTICO - GRUPO PRIME
   Estilos Principais (Layout, Sidebar, Mapa, Header e Componentes Gerais)
   ========================================================================== */

:root {
    /* Cores de Marca & Primárias */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --primary-border: #bfdbfe;

    /* Superfícies & Fundos */
    --bg-body: #e2e8f0;
    --bg-card: #ffffff;
    --bg-subtle: #f8fafc;
    --bg-header: #0f172a;
    --map-bg: #f8fafc;

    /* Tipografia & Contrastes */
    --text-dark: #0f172a;
    --text-main: #1e293b;
    --text-light: #64748b;
    --text-muted: #94a3b8;
    --white: #ffffff;

    /* Bordas & Linhas */
    --border: #e2e8f0;
    --border-subtle: #edf2f7;

    /* Estados & Alertas */
    --success: #10b981;
    --success-light: #ecfdf5;
    --success-border: #a7f3d0;
    --success-text: #059669;

    --danger: #ef4444;
    --danger-light: #fef2f2;
    --danger-border: #fecaca;
    --danger-text: #dc2626;

    --warning: #f59e0b;
    --secondary: #f1f5f9;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Poppins', sans-serif;
}

body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--bg-body);
    color: var(--text-dark);
    overflow: hidden;
}

/* Header */
header {
    height: 60px;
    flex-shrink: 0;
    background: var(--bg-header);
    color: var(--white);
    padding: 0.75rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1001;
    box-shadow: 0 2px 5px -1px rgba(0, 0, 0, 0.12);
}

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

.header-button {
    font-size: 1rem;
    line-height: 1.25;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 7px;
    letter-spacing: 0;
    background: transparent;
    color: var(--white);
    font-family: 'Poppins', sans-serif;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.header-button i {
    color: var(--primary);
    font-size: 0.95rem;
}

.header-button:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.35);
}

.main-container {
    display: flex;
    flex: 1;
    height: calc(100vh - 70px);
    position: relative;
}

/* Sidebar */
.sidebar {
    width: 500px;
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    box-shadow: 4px 0 15px rgba(0, 0, 0, 0.05);
}

.filters {
    padding: 1rem 1.25rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.filters-grid {
    display: grid;
    grid-template-columns: minmax(0, 6fr) minmax(0, 4fr);
    gap: 0.75rem;
    align-items: end;
}

.form-group {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-light);
    margin-bottom: 0.5rem;
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.875rem;
    transition: all 0.2s;
    background: var(--bg-subtle);
    color: var(--text-dark);
    appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

select.form-control {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1em;
}

#searchBox {
    appearance: auto;
    background-image: none;
    cursor: text;
}

.toggle-container {
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: var(--bg-subtle);
    border-radius: 8px;
    border: 1px solid var(--border);
    cursor: pointer;
}

.toggle-container span {
    font-size: 0.8rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

/* Results Area */
.results-header {
    padding: 1rem 1.5rem;
    background: var(--bg-subtle);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.results-header .title {
    font-weight: 700;
    font-size: 1rem;
}

.results-header .title button {
    border: 0;
    background: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 0.9rem;
    margin-right: 0.35rem;
}

.badge-count {
    background: var(--primary);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
}

.results-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    background: var(--bg-subtle);
}

.results-list::-webkit-scrollbar {
    width: 6px;
}

.results-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: 8px;
    padding: 0.8rem 1rem;
    margin-bottom: 0.65rem;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
    cursor: pointer;
}

.card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    border-color: #93c5fd;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.4rem;
}

.carrier-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.carrier-title {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.carrier-name i {
    color: var(--primary);
}

.carrier-name i.top-score-star {
    color: #f59e0b !important;
    font-size: 1rem;
    line-height: 1;
    filter: drop-shadow(0 1px 2px rgba(245, 158, 11, 0.45));
    animation: starPulse 2.5s ease-in-out infinite alternate;
}

@keyframes starPulse {
    0% { transform: scale(1); filter: drop-shadow(0 1px 2px rgba(245, 158, 11, 0.45)); }
    100% { transform: scale(1.15); filter: drop-shadow(0 2px 5px rgba(245, 158, 11, 0.7)); }
}

.tag-uf {
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid var(--primary-border);
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.75rem;
}

.card-body {
    font-size: 0.8rem;
    color: var(--text-light);
}

.card-body .info-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
}

.card-body .info-row i {
    margin-top: 0.25rem;
    width: 14px;
    text-align: center;
}

.card-body strong {
    color: var(--text-dark);
    font-weight: 600;
}

.tag-branca {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.45rem;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-top: 0.25rem;
}

.tag-branca.yes {
    background: var(--success-light);
    color: var(--success-text);
    border: 1px solid var(--success-border);
}

.tag-branca.no {
    background: var(--danger-light);
    color: var(--danger-text);
    border: 1px solid var(--danger-border);
}

.tda-alert {
    color: var(--danger);
    font-weight: 700;
}

.card-content-layout {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 0.5rem;
}

.card-content-layout .card-body {
    flex: 1;
    min-width: 0;
}

/* Map Area & Legend */
.map-container {
    flex: 1;
    position: relative;
    background: var(--map-bg);
}

#map {
    width: 100%;
    height: 100%;
    background: var(--map-bg);
}

.map-overlay-title {
    position: absolute;
    top: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 999;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    padding: 0.75rem 1.5rem;
    border-radius: 99px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.map-overlay-title:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.map-legend {
    position: absolute;
    bottom: 50px;
    right: 1.5rem;
    z-index: 999;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    padding: 1rem;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border);
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-dark);
}

.color-box {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    display: inline-block;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* Status Bar */
.status-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 0.25rem 1.25rem;
    display: flex;
    align-items: center;
    min-height: 24px;
    font-size: 0.8rem;
    z-index: 1000;
}

#statusIcon {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    line-height: 1;
    user-select: none;
    transition: transform 0.2s ease;
}

#statusIcon:hover {
    transform: scale(1.2);
}

.custom-tooltip {
    background: var(--text-dark);
    color: white;
    border: none;
    border-radius: 8px;
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.5rem 1rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.custom-tooltip .leaflet-tooltip-pane {
    border: none;
}

.leaflet-interactive {
    transition: fill 0.3s ease, fill-opacity 0.3s ease, stroke-width 0.2s ease;
}

/* Loader */
.loader-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.95);
    z-index: 1002;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1rem;
    text-align: center;
}

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

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

@media (max-width: 1024px) {
    .main-container { flex-direction: column; }
    .sidebar { width: 100%; height: 50%; border-right: none; border-bottom: 1px solid var(--border); }
    .map-container { height: 50%; }
    .map-legend { display: none; }
}
