/**
 * AgriTopo • Estilos e Design Responsivo (style.css v2.5)
 * Brant Solutions | AgriNewBras • Prof. Dr. Santos H. B. Dias
 */

:root {
    --primary: #16a34a;
    --primary-dark: #15803d;
    --primary-light: #dcfce7;
    --secondary: #0284c7;
    --secondary-dark: #0369a1;
    --dark: #0f172a;
    --slate: #334155;
    --light: #f8fafc;
    --border: #e2e8f0;
    --card-bg: rgba(255, 255, 255, 0.95);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.15), 0 4px 6px -2px rgba(0,0,0,0.05);
}

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

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--dark);
    background: #0f172a;
}

#app-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    position: relative;
}

/* ==============================================================================
   TOPO DA APLICAÇÃO (HEADER)
   ============================================================================== */
.top-header {
    height: 58px;
    background: #ffffff;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
    gap: 12px;
}

.brand-section {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    flex-shrink: 0;
}

.brand-icon {
    font-size: 26px;
}

.brand-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--dark);
    line-height: 1.2;
}

.brand-subtitle {
    font-size: 11px;
    color: var(--slate);
    font-weight: 500;
}

/* Crachá Oficial do TopoData INPE */
.source-badge {
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

/* Barra de Pesquisa de Município */
.search-wrapper {
    display: flex;
    align-items: center;
    background: var(--light);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2px 10px;
    max-width: 260px;
    width: 100%;
    transition: all 0.2s;
}

.search-wrapper:focus-within {
    border-color: var(--secondary);
    box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.2);
    background: #ffffff;
}

.search-wrapper input {
    border: none;
    background: transparent;
    padding: 5px 8px;
    font-size: 12px;
    width: 100%;
    outline: none;
    color: var(--dark);
}

.search-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 13px;
    color: var(--slate);
}

/* Ações Rápidas do Topo */
.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-header {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f1f5f9;
    color: var(--slate);
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-header:hover {
    background: #e2e8f0;
    color: var(--dark);
}

.btn-header.active {
    background: #0f172a;
    color: #ffffff;
    border-color: #0f172a;
}

.btn-header-primary {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary-dark);
}

.btn-header-primary:hover {
    background: var(--primary-dark);
    color: #ffffff;
}

.btn-header-accent {
    background: var(--secondary);
    color: #ffffff;
    border-color: var(--secondary-dark);
}

.btn-header-accent:hover {
    background: var(--secondary-dark);
    color: #ffffff;
}

.farm-badge {
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid #bbf7d0;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

/* ==============================================================================
   ÁREA PRINCIPAL COM MAPA E PAINEL QGIS
   ============================================================================== */
.main-view {
    flex: 1;
    position: relative;
    display: flex;
    overflow: hidden;
}

#map {
    flex: 1;
    height: 100%;
    z-index: 1;
}

/* Renderização Nítida de Pixels TopoData (Visual R / QGIS) */
.pixelated-raster,
.leaflet-image-layer.pixelated-raster {
    image-rendering: pixelated !important;
    image-rendering: -moz-crisp-edges !important;
    image-rendering: crisp-edges !important;
}

/* ==============================================================================
   PAINEL DE GESTÃO DE TALHÕES ESTILO QGIS (LATERAL ESQUERDA)
   ============================================================================== */
.qgis-panel {
    width: 320px;
    background: #ffffff;
    border-right: 1px solid var(--border);
    z-index: 500;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

.qgis-panel.panel-collapsed {
    margin-left: -320px;
}

.qgis-panel-header {
    padding: 12px 14px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-close-panel {
    background: transparent;
    border: 1px solid #cbd5e1;
    color: #64748b;
    border-radius: 4px;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
    transition: all 0.2s ease;
}

.btn-close-panel:hover {
    background: #fee2e2;
    border-color: #ef4444;
    color: #b91c1c;
}

.qgis-panel-title {
    font-size: 13px;
    color: var(--dark);
    display: flex;
    align-items: center;
    gap: 6px;
}

.qgis-panel-hint {
    padding: 6px 12px;
    background: #eff6ff;
    border-bottom: 1px solid #dbeafe;
    font-size: 11px;
    color: #1e40af;
    line-height: 1.3;
}

.btn-studio-mini {
    background: var(--primary);
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-studio-mini:hover {
    background: var(--primary-dark);
}

.qgis-paddocks-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

/* Linha da Tabela QGIS de Talhões */
.qgis-row {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    transition: all 0.15s ease;
}

.qgis-row:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.qgis-row.row-selected {
    border-color: #f59e0b;
    background: #fffbeb;
    box-shadow: 0 0 0 1px #f59e0b;
}

.row-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

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

.paddock-name-input {
    width: 100%;
    border: 1px solid transparent;
    background: transparent;
    font-size: 12px;
    font-weight: 700;
    color: var(--dark);
    padding: 2px 4px;
    border-radius: 3px;
    outline: none;
}

.paddock-name-input:focus {
    border-color: var(--secondary);
    background: #ffffff;
}

.paddock-meta {
    font-size: 11px;
    color: var(--slate);
    margin-top: 1px;
    padding-left: 4px;
}

.row-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-paddock-action {
    background: #f1f5f9;
    border: 1px solid var(--border);
    padding: 4px 6px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    color: var(--slate);
    transition: all 0.15s;
}

.btn-paddock-action:hover {
    background: #e2e8f0;
    color: var(--dark);
}

.btn-paddock-del:hover {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #b91c1c;
}

/* ==============================================================================
   CONTROLE DE CAMADAS FLUTUANTE (TOP CENTER/RIGHT)
   ============================================================================== */
.floating-layers-bar {
    position: absolute;
    top: 15px;
    left: 335px; /* À direita do painel QGIS */
    z-index: 400;
    background: var(--card-bg);
    backdrop-filter: blur(8px);
    padding: 10px 12px;
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    max-width: calc(100vw - 360px);
    transition: left 0.25s ease;
}

.qgis-panel.panel-collapsed + #map + .floating-layers-bar,
.panel-collapsed ~ .floating-layers-bar {
    left: 15px;
}

.layers-title {
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--slate);
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.layer-buttons-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.layer-btn {
    background: #f1f5f9;
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--slate);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s;
}

.layer-btn:hover {
    background: #e2e8f0;
}

.layer-btn.active {
    background: var(--dark);
    color: #ffffff;
    border-color: var(--dark);
    box-shadow: var(--shadow-sm);
}

/* Slider de Opacidade */
.opacity-slider-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--slate);
}

.opacity-slider-wrapper input[type="range"] {
    flex: 1;
    accent-color: var(--primary);
    cursor: pointer;
}

/* ==============================================================================
   SELETOR DE MAPA DE FUNDO (BOTTOM LEFT)
   ============================================================================== */
.basemap-selector-box {
    position: absolute;
    bottom: 25px;
    left: 335px;
    z-index: 400;
    background: var(--card-bg);
    backdrop-filter: blur(8px);
    padding: 6px 12px;
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: left 0.25s ease;
}

.panel-collapsed ~ .basemap-selector-box {
    left: 15px;
}

.basemap-selector-box select {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
    background: white;
    cursor: pointer;
    outline: none;
}

/* ==============================================================================
   LEGENDA DINÂMICA FLUTUANTE (BOTTOM RIGHT)
   ============================================================================== */
.dynamic-legend-box {
    position: absolute;
    bottom: 25px;
    right: 360px;
    z-index: 400;
    background: var(--card-bg);
    backdrop-filter: blur(8px);
    border-radius: 8px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    max-width: 280px;
    font-size: 12px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.legend-header {
    padding: 8px 12px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.legend-content {
    padding: 8px 12px;
    max-height: 220px;
    overflow-y: auto;
}

.legend-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 5px;
}

.legend-color-box {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.15);
}

.legend-text {
    flex: 1;
    font-size: 11px;
}

.legend-val {
    font-size: 11px;
    font-weight: 600;
    color: var(--slate);
    white-space: nowrap;
}

/* ==============================================================================
   PAINEL LATERAL DE ESTATÍSTICAS COMERCIAIS (RIGHT DRAWER)
   ============================================================================== */
.stats-drawer {
    width: 340px;
    background: #ffffff;
    border-left: 1px solid var(--border);
    z-index: 600;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
}

.stats-drawer.drawer-open {
    transform: translateX(0);
}

.drawer-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
}

.drawer-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--dark);
    display: flex;
    align-items: center;
    gap: 6px;
}

.drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.kpi-main-card {
    background: linear-gradient(135deg, #15803d, #16a34a);
    color: white;
    padding: 14px;
    border-radius: 8px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
}

.kpi-main-val {
    font-size: 26px;
    font-weight: 800;
    line-height: 1.1;
    margin-top: 4px;
}

.unit-selector-mini {
    display: flex;
    gap: 10px;
    margin-top: 8px;
    font-size: 11px;
}

.unit-selector-mini label {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

.kpi-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.kpi-card {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
    text-align: center;
}

.kpi-card-lbl {
    font-size: 10px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--slate);
}

.kpi-card-val {
    font-size: 16px;
    font-weight: 700;
    color: var(--dark);
    margin-top: 2px;
}

.kpi-card-sub {
    font-size: 10px;
    color: var(--slate);
    margin-top: 2px;
}

.drawer-section-title {
    font-size: 12px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--slate);
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
}

.drawer-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn-report-main {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-report-main:hover {
    background: var(--primary-dark);
}

/* ==============================================================================
   MODAL DE RELATÓRIO TÉCNICO
   ============================================================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content-wrapper {
    background: white;
    border-radius: 12px;
    width: 100%;
    max-width: 960px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.modal-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: #f8fafc;
}

.close-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--slate);
}

/* ==============================================================================
   MODAL DE PROGRESSO DO DEM
   ============================================================================== */
.progress-card {
    background: white;
    border-radius: 12px;
    padding: 25px;
    width: 380px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.progress-bar-track {
    background: #e2e8f0;
    height: 10px;
    border-radius: 5px;
    overflow: hidden;
    margin: 15px 0 10px 0;
}

.progress-bar-fill {
    background: linear-gradient(90deg, #16a34a, #0284c7);
    height: 100%;
    width: 0%;
    border-radius: 5px;
    transition: width 0.3s ease;
}

/* ==============================================================================
   TOAST NOTIFICATION
   ============================================================================== */
.toast-msg {
    position: fixed;
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--dark);
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 3000;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}

.toast-msg.toast-visible {
    transform: translateX(-50%) translateY(0);
}

.pulse-anim {
    animation: pulse 1.8s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.04); }
    100% { transform: scale(1); }
}

@media (max-width: 900px) {
    .stats-drawer {
        width: 100%;
        max-width: 360px;
    }
    .qgis-panel {
        width: 100%;
        max-width: 320px;
        position: absolute;
        top: 0; bottom: 0; left: 0;
    }
    .dynamic-legend-box {
        right: 15px;
        bottom: 70px;
    }
    .search-wrapper {
        display: none;
    }
    .floating-layers-bar {
        left: 15px;
        top: 55px;
    }
    .basemap-selector-box {
        left: 15px;
    }
}
