/* ============================================================
   Dashboard de Gestión Ganadera — Tema Claro Corporativo
   Paleta: Naranja #e85d26, Verde #059669, Rojo #dc2626
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Figtree:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

:root {
    /* Corporativo HerdData ARROYOS */
    --naranja:       #e85d26;
    --naranja-dim:   #fff3ed;
    --naranja-hover: #c2410c;
    --verde:         #059669;
    --verde-dim:     #ecfdf5;
    --rojo:          #dc2626;
    --rojo-dim:      #fef2f2;
    --ambar:         #d97706;
    --ambar-dim:     #fffbeb;
    --azul:          #0284c7;
    --azul-dim:      #eff6ff;

    /* Base tema claro */
    --bg-base:       #f8fafc;
    --bg-card:       #ffffff;
    --bg-sidebar:    #ffffff;
    --bg-input:      #f1f5f9;

    /* Texto */
    --texto:         #1c1c1a;
    --texto-muted:   #64748b;
    --texto-dim:     #94a3b8;

    /* Bordes */
    --borde:         #e2e8f0;
    --borde-hover:   #cbd5e1;

    /* Tipografía */
    --font-num:      'JetBrains Mono', monospace;
    --font-ui:       'Figtree', sans-serif;

    /* Radios y sombras */
    --radius:        12px;
    --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg:     0 4px 12px rgba(0,0,0,.1), 0 2px 4px rgba(0,0,0,.06);
}

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

body {
    font-family: var(--font-ui);
    background: var(--bg-base);
    color: var(--texto);
    min-height: 100vh;
    line-height: 1.5;
}

/* ==================== HEADER ==================== */
.dash-header {
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--borde);
    padding: 16px 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.dash-header-inner {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
}

.dash-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.dash-brand img {
    height: 36px;
}

.dash-brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--texto);
}

.dash-brand .dash-subtitle {
    font-size: 0.8rem;
    color: var(--texto-muted);
    font-weight: 400;
}

.dash-back {
    color: var(--texto-muted);
    text-decoration: none;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color 0.2s;
}
.dash-back:hover { color: var(--naranja); }

/* ==================== FILTROS ==================== */
.dash-filtros {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.dash-filtros .form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.dash-filtros label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--texto-muted);
}

.dash-filtros select,
.dash-filtros input {
    background: var(--bg-input);
    border: 1px solid var(--borde);
    color: var(--texto);
    padding: 8px 12px;
    border-radius: 8px;
    font-family: var(--font-ui);
    font-size: 0.85rem;
    min-width: 140px;
    outline: none;
    transition: border-color 0.2s;
}
.dash-filtros select:focus,
.dash-filtros input:focus {
    border-color: var(--naranja);
    box-shadow: 0 0 0 3px rgba(232,93,38,.15);
}

.dash-filtros select option {
    background: var(--bg-card);
    color: var(--texto);
}

.btn-limpiar {
    background: transparent;
    border: 1px solid var(--borde);
    color: var(--texto-muted);
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-family: var(--font-ui);
    font-size: 0.8rem;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn-limpiar:hover {
    border-color: var(--rojo);
    color: var(--rojo);
}

/* Banner filtros activos */
.filtros-banner {
    max-width: 1600px;
    margin: 0 auto;
    padding: 8px 24px;
    background: var(--naranja-dim);
    border-bottom: 1px solid var(--naranja);
    font-size: 0.8rem;
    color: var(--naranja);
    display: none;
    align-items: center;
    gap: 8px;
}
.filtros-banner.activo { display: flex; }
.filtros-banner .limpiar-link {
    color: var(--texto);
    text-decoration: underline;
    cursor: pointer;
    margin-left: auto;
}

/* ==================== MAIN CONTAINER ==================== */
.dash-main {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px;
}

/* ==================== KPIs ==================== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--borde);
    border-radius: var(--radius);
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: border-color 0.2s, transform 0.2s;
    box-shadow: var(--shadow);
}
.kpi-card:hover {
    border-color: var(--naranja);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.kpi-icon {
    font-size: 1.6rem;
    margin-bottom: 8px;
    display: block;
}

.kpi-valor {
    font-family: var(--font-num);
    font-size: 2rem;
    font-weight: 700;
    color: var(--texto);
    line-height: 1.1;
}

.kpi-label {
    font-size: 0.78rem;
    color: var(--texto-muted);
    margin-top: 4px;
    font-weight: 500;
}

.kpi-delta {
    font-size: 0.72rem;
    font-family: var(--font-num);
    margin-top: 6px;
    font-weight: 500;
}
.kpi-delta.positivo { color: var(--verde); }
.kpi-delta.negativo { color: var(--rojo); }
.kpi-delta.neutro   { color: var(--texto-muted); }

.kpi-subtitle {
    font-size: 0.72rem;
    color: var(--texto-muted);
    font-family: var(--font-num);
    margin-top: 2px;
}

.kpi-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
}
.kpi-bar.verde  { background: var(--verde); }
.kpi-bar.rojo   { background: var(--rojo); }
.kpi-bar.ambar  { background: var(--ambar); }
.kpi-bar.azul   { background: var(--azul); }

/* ==================== KPI BREAKDOWN (sub-details) ==================== */
.kpi-breakdown {
    font-size: 0.68rem;
    color: var(--texto-muted);
    font-family: var(--font-num);
    margin-top: 4px;
    line-height: 1.5;
}
.kpi-breakdown span {
    margin-right: 6px;
    white-space: nowrap;
}
.kpi-breakdown .bd-macho { color: var(--azul); }
.kpi-breakdown .bd-hembra { color: #db2777; }
.kpi-breakdown .bd-mamon { color: var(--ambar); }

/* ==================== GRÁFICOS (full-width) ==================== */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

@media (max-width: 900px) {
    .charts-grid { grid-template-columns: 1fr; }
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--borde);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.chart-card h3 {
    font-size: 0.85rem;
    color: var(--texto-muted);
    margin-bottom: 12px;
    font-weight: 600;
}

.chart-card canvas {
    width: 100% !important;
    max-height: 220px;
}

/* ==================== TABLA LOTES ==================== */
.lotes-panel {
    background: var(--bg-card);
    border: 1px solid var(--borde);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

.lotes-panel-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--borde);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.lotes-panel-header h3 {
    font-size: 0.9rem;
    font-weight: 600;
}

.lotes-panel-header .badge-count {
    background: var(--naranja-dim);
    color: var(--naranja);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-family: var(--font-num);
}

.lotes-table-wrap {
    max-height: 520px;
    overflow-y: auto;
}

.lotes-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.lotes-table th {
    position: sticky;
    top: 0;
    background: var(--bg-input);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--texto-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--borde);
    white-space: nowrap;
    z-index: 2;
}

.lotes-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--borde);
    white-space: nowrap;
    font-family: var(--font-num);
    font-size: 0.8rem;
}

.lotes-table tr:hover td {
    background: var(--naranja-dim);
}

.lotes-table .lote-nombre {
    font-family: var(--font-ui);
    font-weight: 600;
    color: var(--naranja);
}

.lotes-table .text-success { color: var(--verde); }
.lotes-table .text-danger  { color: var(--rojo); }
.lotes-table .text-warning { color: var(--ambar); }
.lotes-table .text-muted   { color: var(--texto-muted); }

/* Badges estado */
.badge-estado {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    font-family: var(--font-ui);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.badge-estado-OK           { background: var(--verde-dim);  color: var(--verde); }
.badge-estado-VIOLA        { background: var(--rojo-dim);   color: var(--rojo); }
.badge-estado-LISTO_VENTA  { background: var(--azul-dim);   color: var(--azul); }
.badge-estado-ATENCION     { background: var(--ambar-dim);  color: var(--ambar); }

/* Fila de totales */
.lotes-table tr.totales td {
    background: var(--bg-input);
    font-weight: 700;
    color: var(--texto);
    position: sticky;
    bottom: 0;
    z-index: 2;
    border-top: 2px solid var(--naranja);
}

/* ==================== RESUMEN SEMANAL ==================== */
.resumen-semanal {
    background: var(--bg-card);
    border: 1px solid var(--borde);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 28px;
    box-shadow: var(--shadow);
}

.resumen-semanal h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 16px;
}

.resumen-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.resumen-item {
    text-align: center;
    padding: 12px;
    background: var(--bg-input);
    border-radius: 8px;
}

.resumen-item .res-label {
    font-size: 0.7rem;
    color: var(--texto-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.resumen-item .res-valor {
    font-family: var(--font-num);
    font-size: 1.3rem;
    font-weight: 700;
}

.resumen-item .res-delta {
    font-size: 0.72rem;
    font-family: var(--font-num);
    margin-top: 2px;
}

/* ==================== ALERTAS ==================== */
.alertas-panel {
    background: var(--bg-card);
    border: 1px solid var(--borde);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 28px;
    box-shadow: var(--shadow);
}

.alertas-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--borde);
    display: flex;
    align-items: center;
    gap: 10px;
}

.alertas-header h3 { font-size: 0.9rem; font-weight: 600; }

.alerta-item {
    padding: 12px 20px;
    border-bottom: 1px solid var(--borde);
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.15s;
}
.alerta-item:hover { background: var(--bg-input); }
.alerta-item:last-child { border-bottom: none; }

.alerta-icon { font-size: 1.3rem; }
.alerta-body { flex: 1; }
.alerta-body .alerta-titulo { font-size: 0.85rem; font-weight: 600; }
.alerta-body .alerta-desc   { font-size: 0.75rem; color: var(--texto-muted); }
.alerta-urgencia {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
}
.alerta-urgencia.alta    { background: var(--rojo-dim);   color: var(--rojo); }
.alerta-urgencia.media   { background: var(--ambar-dim);  color: var(--ambar); }
.alerta-urgencia.baja    { background: var(--azul-dim);   color: var(--azul); }

.no-alertas {
    padding: 24px;
    text-align: center;
    color: var(--texto-muted);
    font-size: 0.85rem;
}

/* ==================== LOADING ==================== */
.dash-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
    color: var(--texto-muted);
    gap: 12px;
}

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

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

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    .dash-header-inner {
        flex-direction: column;
        align-items: flex-start;
    }
    .dash-filtros {
        width: 100%;
    }
    .dash-filtros select,
    .dash-filtros input {
        min-width: 100%;
    }
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .dash-main { padding: 12px; }
    .lotes-table-wrap { max-height: 400px; }
}

/* Scrollbar tema claro */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-input); }
::-webkit-scrollbar-thumb { background: var(--borde-hover); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--texto-muted); }

/* ==================== RESUMEN SEMANAL (extra) ==================== */
.resumen-semanal {
    background: var(--bg-card);
    border: 1px solid var(--borde);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 24px;
}

.resumen-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.resumen-header h3 {
    font-family: var(--font-ui);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--texto);
}

.resumen-semanas {
    font-family: var(--font-num);
    font-size: 0.85rem;
    color: var(--texto-muted);
    background: var(--bg-input);
    padding: 4px 12px;
    border-radius: 6px;
}

.resumen-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
}

.resumen-metrica {
    text-align: center;
    padding: 12px 8px;
    border-radius: 8px;
    background: var(--bg-input);
    border: 1px solid transparent;
    transition: border-color 0.2s;
}

.resumen-metrica:hover {
    border-color: var(--naranja);
}

.resumen-metrica-icon {
    font-size: 1.3rem;
    margin-bottom: 4px;
}

.resumen-metrica-label {
    font-size: 0.72rem;
    color: var(--texto-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.resumen-metrica-valores {
    display: flex;
    justify-content: center;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 4px;
}

.resumen-actual {
    font-family: var(--font-num);
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--texto);
}

.resumen-anterior {
    font-family: var(--font-num);
    font-size: 0.85rem;
    color: var(--texto-muted);
    text-decoration: line-through;
    opacity: 0.6;
}

.resumen-delta {
    font-family: var(--font-num);
    font-size: 0.78rem;
    font-weight: 500;
}

.resumen-delta.positivo { color: var(--verde); }
.resumen-delta.negativo { color: var(--rojo); }
.resumen-delta.neutro { color: var(--texto-muted); }
.resumen-delta.mejora { color: var(--verde); }

@media (max-width: 1024px) {
    .resumen-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 640px) {
    .resumen-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ==================== TRANSICIÓN SUAVE DE TEMA ==================== */
.dash-kpi,
.dash-table thead th,
.dash-table tbody td,
.dash-table tbody tr,
.dash-header,
.dash-filters select,
.dash-filters input,
.dash-back,
.chart-container,
.dash-semana-card,
.dash-alert {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* ==================== MODO NOCHE ==================== */
[data-theme="dark"] {
    --bg-base:       #0f172a;
    --bg-card:       #1e293b;
    --bg-sidebar:    #1e293b;
    --bg-input:      #334155;

    --texto:         #e2e8f0;
    --texto-muted:   #94a3b8;
    --texto-dim:     #64748b;

    --borde:         #334155;
    --borde-hover:   #475569;

    --naranja-dim:   #431407;
    --verde-dim:     #052e16;
    --rojo-dim:      #450a0a;
    --ambar-dim:     #451a03;
    --azul-dim:      #172554;

    --shadow:        0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
    --shadow-lg:     0 4px 12px rgba(0,0,0,.4), 0 2px 4px rgba(0,0,0,.3);
}

[data-theme="dark"] .dash-header {
    border-bottom-color: var(--borde);
}

[data-theme="dark"] .dash-filters select,
[data-theme="dark"] .dash-filters input {
    background: var(--bg-input);
    color: var(--texto);
    border-color: var(--borde);
}

[data-theme="dark"] .dash-kpi {
    border-color: var(--borde);
}

[data-theme="dark"] .dash-table {
    color: var(--texto);
}
[data-theme="dark"] .dash-table thead th {
    background: #1e293b;
    color: var(--texto);
    border-bottom-color: var(--borde);
}
[data-theme="dark"] .dash-table tbody tr:hover {
    background: rgba(232, 93, 38, 0.08);
}
[data-theme="dark"] .dash-table tbody td {
    border-bottom-color: var(--borde);
    color: var(--texto);
}

[data-theme="dark"] .dash-back {
    color: var(--texto-muted);
}

[data-theme="dark"] .dash-alert {
    background: var(--rojo-dim);
    border-color: var(--rojo);
}

[data-theme="dark"] .dash-semana-card {
    background: var(--bg-card);
    border-color: var(--borde);
}

[data-theme="dark"] .chart-container {
    background: var(--bg-card);
    border-color: var(--borde);
}

/* Override any remaining white backgrounds */
[data-theme="dark"] .dash-kpi .kpi-icon {
    background: var(--bg-input);
}

[data-theme="dark"] .dash-kpi .kpi-subtitle {
    color: var(--texto-muted);
}

[data-theme="dark"] .dash-kpi .kpi-delta {
    color: var(--texto-muted);
}
