/* =======================================================
   ESTILOS BASE Y VARIABLES (Tema Oscuro Corporativo)
   ======================================================= */
:root {
    --bg-body: #0f172a;       /* Fondo general oscuro */
    --bg-card: #1e293b;       /* Fondo de las tarjetas */
    --bg-input: #0f172a;      /* Fondo de los campos de texto */
    --border: #334155;        /* Color de las líneas y bordes */
    --text-main: #f8fafc;     /* Texto principal (Blanco) */
    --text-muted: #94a3b8;    /* Texto secundario (Gris) */
    
    --primary: #fdcf00;       /* Azul corporativo */
    --success: #10b981;       /* Verde para aprobaciones/dinero */
    --warning: #f59e0b;       /* Naranja para ISLR/Alertas */
    --danger: #ef4444;        /* Rojo para eliminaciones/deudas */
    --info: #0ea5e9;          /* Azul claro para IVA/Datos */
    
    --radius: 8px;
    --font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body.theme-dark {
    background-color: var(--bg-body);
    color: var(--text-main);
    font-family: var(--font-family);
    display: flex;
    min-height: 100vh;
}

/* =======================================================
   BARRA LATERAL Y CORRECCIÓN DE MÁRGENES (EL FIX)
   ======================================================= */
.sidebar {
    width: 260px;
    background-color: var(--bg-card);
    border-right: 1px solid var(--border);
    position: fixed; /* Flota a la izquierda */
    height: 100vh;
    left: 0;
    top: 0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-header {
    margin-bottom: 30px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 15px;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.nav-btn {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-muted);
    text-align: left;
    padding: 12px 15px;
    font-size: 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.3s ease;
}

.nav-btn:hover, .nav-btn.active {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary);
    font-weight: bold;
}

/* 🔥 ESTA ES LA CORRECCIÓN EXACTA DE LOS MÁRGENES 🔥 */
.main-content {
    margin-left: 260px; /* Empuja el contenido para que no choque con el sidebar */
    width: calc(100% - 260px); /* Resta el tamaño del sidebar del total de la pantalla */
    padding: 30px 40px;
    min-height: 100vh;
}

/* =======================================================
   TARJETAS Y FORMULARIOS
   ======================================================= */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    margin-bottom: 25px;
}

.header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 15px;
}

.form-row {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.form-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 15px;
    flex: 1;
}

.form-group label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.form-control {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 10px 15px;
    border-radius: var(--radius);
    font-size: 0.95rem;
    width: 100%;
    outline: none;
    transition: border 0.3s ease;
}

.form-control:focus {
    border-color: var(--primary);
}

.form-control[readonly] {
    color: var(--text-muted);
    cursor: not-allowed;
}

/* =======================================================
   TABLAS (ESTILO MODERNO CONTABLE)
   ======================================================= */
.table-modern {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table-modern th {
    background: var(--bg-input);
    color: var(--text-muted);
    text-align: left;
    padding: 12px 15px;
    font-weight: normal;
    border-bottom: 2px solid var(--border);
}

.table-modern td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border);
    color: var(--text-main);
    vertical-align: middle;
}

.table-modern tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

/* =======================================================
   BOTONES
   ======================================================= */
.btn {
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 0.95rem;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-main);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-danger-outline {
    background: transparent;
    color: var(--danger);
    border-color: var(--danger);
}

.btn-danger-outline:hover {
    background: rgba(239, 68, 68, 0.1);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.85rem;
}

/* =======================================================
   MODALES (Glassmorphism)
   ======================================================= */
.modal-overlay {
    display: none;
    backdrop-filter: blur(5px);
}

/* =======================================================
   RESPONSIVE / MÓVIL  (capa aditiva, no afecta escritorio)
   ======================================================= */

.menu-toggle {
    display: none;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 1001;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 10px;
    background: var(--primary);
    color: var(--bg-body);
    font-size: 1.3rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
    z-index: 90;
}

/* ---------- TABLET y MÓVIL (≤ 1024px): sidebar como cajón ---------- */
@media (max-width: 1024px) {
    .menu-toggle {
        display: inline-flex;
    }

    .sidebar {
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    body.sidebar-open .sidebar-overlay {
        display: block;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 70px 20px 24px;
    }
}

/* ---------- MÓVIL (≤ 768px) ---------- */
@media (max-width: 768px) {
    .main-content {
        padding: 70px 14px 20px;
    }

    .card {
        padding: 18px 16px;
    }

    /* Encabezados: título arriba, acción a ancho completo debajo */
    .header-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .header-actions .btn,
    .header-actions button {
        width: 100%;
    }

    /* Colapsa grids y flex con anchos fijos por estilo inline */
    .main-content div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    .main-content [style*="min-width"] {
        min-width: 0 !important;
    }

    /* Formularios a una columna */
    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .form-group[style*="flex:2"],
    .form-group[style*="flex: 2"] {
        flex: 1 1 100% !important;
    }

    /* font-size 16px evita el zoom automático de iOS al enfocar */
    .form-control,
    input,
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Botones de guardar/total a ancho cómodo dentro de formularios */
    .main-content [style*="width:200px"],
    .main-content [style*="width: 200px"] {
        width: 100% !important;
    }

    /* Scroll horizontal cómodo en tablas anchas */
    .main-content [style*="overflow-x"] {
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .main-content [style*="overflow-x"]::-webkit-scrollbar {
        height: 8px;
    }

    .main-content [style*="overflow-x"]::-webkit-scrollbar-thumb {
        background: var(--border);
        border-radius: 4px;
    }

    .table-modern th,
    .table-modern td {
        padding: 10px 12px;
    }

    /* Modal de proveedor (usa .card como caja) a casi pantalla completa */
    .modal-overlay .card {
        max-width: 96% !important;
        padding: 22px 18px;
        max-height: 92vh;
        overflow-y: auto;
    }
}

/* ---------- MÓVIL CHICO (≤ 480px) ---------- */
@media (max-width: 480px) {
    .sidebar {
        width: 84vw;
        max-width: 300px;
    }
}