/* ============================================================
   AVÍCOLA SANTA ANA — Sistema de Producción
   Identidad visual: Negro / Amarillo #FEDD00 / Blanco
   ============================================================ */

/* Variables */
:root {
    --sa-yellow: #FEDD00;
    --sa-black:  #000000;
    --sa-white:  #FFFFFF;
    --sa-light:  #F8F8F8;
    --sa-gray:   #CCCCCC;
    --sa-gray-dark: #666666;
    --sidebar-width: 240px;
    --topbar-height: 56px;
}

/* Reset y base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: system-ui, 'Segoe UI', sans-serif;
    font-size: 14px;
    color: var(--sa-black);
    background: var(--sa-white);
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; }

/* ============================================================
   LOGIN — split layout
   ============================================================ */
body.login-page {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
}

/* Panel izquierdo — negro */
.login-panel-left {
    width: 45%;
    background: var(--sa-black);
    display: flex;
    flex-direction: column;
    padding: 40px 48px;
    position: relative;
    overflow: hidden;
}

.login-panel-left::before {
    content: '';
    position: absolute;
    bottom: -80px;
    right: -80px;
    width: 320px;
    height: 320px;
    border-radius: 50%;
    background: rgba(254,221,0,0.06);
    pointer-events: none;
}

.login-brand img {
    height: 100px;
    width: auto;
}

.login-tagline {
    margin-top: auto;
    padding-bottom: 48px;
}

.login-tagline h1 {
    font-size: 32px;
    font-weight: 800;
    color: var(--sa-white);
    line-height: 1.2;
    margin-bottom: 12px;
}

.login-tagline h1 span {
    color: var(--sa-yellow);
}

.login-tagline p {
    font-size: 14px;
    color: #888;
    line-height: 1.6;
    max-width: 280px;
}

.login-copyright {
    font-size: 12px;
    color: #444;
    margin-top: 32px;
}

/* Panel derecho — blanco */
.login-panel-right {
    width: 55%;
    background: var(--sa-white);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.login-form-box {
    width: 100%;
    max-width: 360px;
}

.login-form-box h2 {
    font-size: 28px;
    font-weight: 700;
    color: var(--sa-black);
    margin-bottom: 8px;
}

.login-form-box .login-subtitle {
    font-size: 14px;
    color: var(--sa-gray-dark);
    margin-bottom: 36px;
}

.btn-microsoft {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 13px 20px;
    background: var(--sa-black);
    color: var(--sa-white);
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    text-decoration: none;
}

.btn-microsoft:hover { background: #222; }

.btn-microsoft::before {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 21 21'%3E%3Crect x='1' y='1' width='9' height='9' fill='%23f25022'/%3E%3Crect x='11' y='1' width='9' height='9' fill='%237fba00'/%3E%3Crect x='1' y='11' width='9' height='9' fill='%2300a4ef'/%3E%3Crect x='11' y='11' width='9' height='9' fill='%23ffb900'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
}

.login-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0;
    color: var(--sa-gray);
    font-size: 12px;
}
.login-divider::before, .login-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--sa-gray);
}

.login-domain-note {
    text-align: center;
    font-size: 12px;
    color: #aaa;
    line-height: 1.5;
}

.login-domain-note strong {
    color: var(--sa-gray-dark);
}

.login-error {
    margin-top: 16px;
    padding: 10px 14px;
    background: #fff3f3;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    color: #721c24;
    font-size: 13px;
    text-align: center;
}

/* Responsive: colapsar en pantallas chicas */
@media (max-width: 680px) {
    body.login-page { flex-direction: column; }
    .login-panel-left { width: 100%; padding: 32px 24px 40px; min-height: 220px; }
    .login-panel-right { width: 100%; padding: 32px 24px; }
    .login-tagline { padding-bottom: 0; }
}

/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* --- SIDEBAR --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sa-black);
    color: var(--sa-white);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 18px 20px 16px;
    border-bottom: 1px solid #222;
}

.sidebar-brand img {
    width: 160px;
    height: auto;
    display: block;
}

.sidebar-brand .brand-sub {
    display: block;
    font-size: 10px;
    color: #555;
    margin-top: 6px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
}

.sidebar-nav .nav-section {
    padding: 12px 20px 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: #555;
    text-transform: uppercase;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: #ccc;
    font-size: 13px;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
    background: #111;
    color: var(--sa-white);
}

.sidebar-nav a.active {
    border-left-color: var(--sa-yellow);
    color: var(--sa-yellow);
    background: #111;
    font-weight: 600;
}

.sidebar-nav .nav-icon {
    width: 18px;
    text-align: center;
    font-size: 15px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid #222;
    font-size: 12px;
    color: #666;
}

.sidebar-footer .user-name {
    display: block;
    color: #bbb;
    font-weight: 600;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer .user-role {
    display: inline-block;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 10px;
    background: #222;
    color: #888;
    text-transform: capitalize;
    margin-bottom: 10px;
}

.sidebar-footer a.logout-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #666;
    font-size: 12px;
    transition: color 0.15s;
}

.sidebar-footer a.logout-link:hover { color: #ccc; }

/* --- TOPBAR --- */
.topbar {
    height: var(--topbar-height);
    background: var(--sa-white);
    border-bottom: 1px solid var(--sa-gray);
    display: flex;
    align-items: center;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--sa-black);
}

.topbar-spacer { flex: 1; }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* --- CONTENIDO PRINCIPAL --- */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.page-content {
    padding: 24px;
    flex: 1;
}

/* ============================================================
   COMPONENTES
   ============================================================ */

/* Botones */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s, background 0.15s;
}

.btn:hover { opacity: 0.85; }

.btn-primary {
    background: var(--sa-yellow);
    color: var(--sa-black);
}

.btn-secondary {
    background: var(--sa-light);
    color: var(--sa-black);
    border: 1px solid var(--sa-gray);
}

.btn-danger {
    background: #dc3545;
    color: var(--sa-white);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-icon {
    padding: 6px 8px;
    background: transparent;
    color: var(--sa-gray-dark);
    border: 1px solid var(--sa-gray);
}

/* KPI Cards */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--sa-white);
    border: 1px solid var(--sa-gray);
    border-radius: 6px;
    padding: 16px;
}

.kpi-card .kpi-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--sa-gray-dark);
    text-transform: uppercase;
    margin-bottom: 8px;
}

.kpi-card .kpi-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--sa-black);
    line-height: 1;
}

.kpi-card .kpi-unit {
    font-size: 13px;
    font-weight: 400;
    color: var(--sa-gray-dark);
    margin-left: 4px;
}

.kpi-card .kpi-sub {
    font-size: 12px;
    color: var(--sa-gray-dark);
    margin-top: 6px;
}

.kpi-card.accent {
    border-top: 3px solid var(--sa-yellow);
}

/* Tarjeta/Panel */
.card {
    background: var(--sa-white);
    border: 1px solid var(--sa-gray);
    border-radius: 6px;
    margin-bottom: 24px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--sa-gray);
}

.card-title {
    font-size: 14px;
    font-weight: 700;
}

.card-body {
    padding: 18px;
}

/* Tabla */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    background: var(--sa-black);
    color: var(--sa-white);
    font-weight: 600;
    padding: 10px 14px;
    text-align: left;
    white-space: nowrap;
}

tbody td {
    padding: 9px 14px;
    border-bottom: 1px solid var(--sa-gray);
    vertical-align: middle;
}

tbody tr:nth-child(even) td { background: var(--sa-light); }
tbody tr:hover td { background: #f0f0f0; }

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
}

.badge-active   { background: #d4edda; color: #155724; }
.badge-draft    { background: #d1ecf1; color: #0c5460; }
.badge-suspended{ background: #fff3cd; color: #856404; }
.badge-finishing{ background: #ffe0b2; color: #7a4100; }
.badge-closed   { background: #e2e3e5; color: #383d41; }
.badge-info     { background: #cce5ff; color: #004085; }
.badge-warning  { background: #fff3cd; color: #856404; }
.badge-critical { background: #f8d7da; color: #721c24; }

/* Formularios */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 5px;
    color: var(--sa-black);
}

.form-control {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--sa-gray);
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
    background: var(--sa-white);
    transition: border-color 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--sa-black);
}

.form-control.is-invalid { border-color: #dc3545; }
.form-text { font-size: 11px; color: var(--sa-gray-dark); margin-top: 4px; }

/* Grid de formularios */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

/* Filtros */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
    align-items: flex-end;
}

.filters .form-group { margin-bottom: 0; }
.filters .form-control { min-width: 140px; }

/* Alertas flash */
.flash {
    padding: 12px 16px;
    border-radius: 4px;
    margin-bottom: 16px;
    font-size: 13px;
    font-weight: 600;
}

.flash-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.flash-error   { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.flash-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.flash-info    { background: #cce5ff; color: #004085; border: 1px solid #b8daff; }

/* Modal */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 500;
    align-items: center;
    justify-content: center;
}

.modal-backdrop.active { display: flex; }

.modal {
    background: var(--sa-white);
    border-radius: 6px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

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

.modal-title { font-weight: 700; font-size: 15px; }

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--sa-gray-dark);
    line-height: 1;
    padding: 0 4px;
}

.modal-close:hover { color: var(--sa-black); }

.modal-body { padding: 20px; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--sa-gray);
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--sa-gray);
    margin-bottom: 20px;
}

.tab-btn {
    padding: 10px 18px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-size: 13px;
    font-weight: 600;
    color: var(--sa-gray-dark);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover { color: var(--sa-black); }

.tab-btn.active {
    color: var(--sa-black);
    border-bottom-color: var(--sa-yellow);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Chart container */
.chart-container {
    position: relative;
    height: 280px;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--sa-gray);
    border-top-color: var(--sa-black);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* Utilidades */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--sa-gray-dark); }
.text-small  { font-size: 12px; }
.text-bold   { font-weight: 700; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }

.w-100 { width: 100%; }

/* Responsive mínimo */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s;
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
