/* ===================================================
   MAIZ Y AGENTE – Sistema Profesional
   Diseño Moderno – Versión 2.0
   =================================================== */

/* ========== RESET ========== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Paleta principal */
    --color-primary: #059669;
    --color-primary-dark: #047857;
    --color-primary-light: #d1fae5;
    --color-primary-bg: #ecfdf5;
    
    /* Acentos */
    --color-gold: #d4a853;
    --color-gold-light: #fef3c7;
    --color-gold-dark: #b8860b;
    
    /* Estados */
    --color-danger: #ef4444;
    --color-danger-light: #fef2f2;
    --color-warning: #f59e0b;
    --color-warning-light: #fffbeb;
    --color-success: #10b981;
    --color-success-light: #f0fdf4;
    --color-info: #3b82f6;
    --color-info-light: #eff6ff;
    
    /* Superficies */
    --color-white: #ffffff;
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-surface-hover: #f1f5f9;
    
    /* Texto */
    --color-text: #1e293b;
    --color-text-secondary: #64748b;
    --color-text-muted: #94a3b8;
    
    /* Bordes */
    --color-border: #e2e8f0;
    --color-border-light: #f1f5f9;
    
    /* Sombras */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.06), 0 4px 10px rgba(0, 0, 0, 0.03);
    --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.08);
    
    /* Bordes redondeados */
    --radius-xs: 6px;
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --radius-full: 9999px;
    
    /* Transiciones */
    --transition-fast: 0.15s ease;
    --transition: 0.25s ease;
    --transition-slow: 0.35s ease;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 1rem;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.app-container {
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
    overflow-x: hidden;
}

/* ========== LOGIN ========== */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
    background: linear-gradient(135deg, var(--color-primary-bg) 0%, var(--color-bg) 100%);
}

.login-box {
    background: var(--color-white);
    border-radius: var(--radius-xl);
    padding: 3rem 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-xl);
    text-align: center;
    border: 1px solid var(--color-border);
}

.login-box h2 {
    font-size: 1.8rem;
    color: var(--color-primary);
    margin-bottom: 0.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.login-box h2::after {
    content: '';
    display: block;
    width: 50px;
    height: 3px;
    background: var(--color-gold);
    margin: 0.8rem auto 1.5rem;
    border-radius: 2px;
}

.login-box input {
    width: 100%;
    padding: 0.85rem 1.2rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 1rem;
    margin-bottom: 1rem;
    transition: var(--transition);
    background: var(--color-bg);
}

.login-box input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.1);
    outline: none;
    background: var(--color-white);
}

.login-box button {
    width: 100%;
    padding: 0.85rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    letter-spacing: -0.3px;
}

.login-box button:hover {
    background: var(--color-primary-dark);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.login-box button:active {
    transform: translateY(0);
}

/* ========== BARRA SUPERIOR ========== */
.top-bar {
    background: var(--color-white);
    border-radius: var(--radius-lg);
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border-light);
    overflow-x: hidden;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 600;
    font-size: 0.95rem;
    flex-shrink: 0;
    color: var(--color-text);
}

.user-info small {
    color: var(--color-text-secondary);
    font-weight: 400;
    background: var(--color-bg);
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
}

.top-bar select {
    padding: 0.5rem 2rem 0.5rem 1rem;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--color-border);
    font-size: 0.9rem;
    background: var(--color-white);
    max-width: 220px;
    cursor: pointer;
    transition: var(--transition-fast);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%2364748b'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
}

.top-bar select:hover {
    border-color: var(--color-primary);
}

.top-bar button {
    background: var(--color-danger);
    color: white;
    border: none;
    padding: 0.5rem 1.4rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.9rem;
}

.top-bar button:hover {
    background: #dc2626;
    box-shadow: var(--shadow-md);
}

/* ========== PESTAÑAS ========== */
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1.25rem;
    background: var(--color-white);
    padding: 0.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
    border: 1px solid var(--color-border-light);
    overflow-x: auto;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
    background: transparent;
    color: var(--color-text-secondary);
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    font-size: 0.88rem;
    border: none;
    transition: var(--transition);
    white-space: nowrap;
    letter-spacing: -0.2px;
}

.tab:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.tab.active {
    background: var(--color-primary);
    color: white;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(5, 150, 105, 0.3);
}

/* ========== SELECTOR MÓVIL ========== */
.mobile-tabs-select {
    display: none;
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    border: 1.5px solid var(--color-border);
    font-size: 1rem;
    margin-bottom: 1.25rem;
    background: var(--color-white);
    box-shadow: var(--shadow-xs);
}

.panel { display: none; }

.panel.active {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

/* ========== TARJETAS ========== */
.card {
    background: var(--color-white);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border-light);
    transition: var(--transition);
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card h3, .card h4 {
    color: var(--color-text);
    font-weight: 700;
    margin-bottom: 1rem;
    letter-spacing: -0.3px;
}

.card h3 { font-size: 1.2rem; }
.card h4 { font-size: 1.05rem; }

/* ========== ESTADÍSTICAS ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    width: 100%;
}

.stat-card {
    background: var(--color-white);
    border-radius: var(--radius-md);
    padding: 1rem 1.2rem;
    box-shadow: var(--shadow-xs);
    border: 1px solid var(--color-border-light);
    transition: var(--transition);
    min-width: 0;
    word-break: break-word;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--color-primary);
    border-radius: 4px 0 0 4px;
}

.stat-card.warning::before { background: var(--color-warning); }
.stat-card.danger::before { background: var(--color-danger); }
.stat-card.success::before { background: var(--color-success); }
.stat-card.info::before { background: var(--color-info); }

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--color-text-muted);
    font-weight: 600;
    margin-bottom: 0.3rem;
}

.stat-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--color-text);
    word-break: break-word;
    letter-spacing: -0.3px;
}

.stat-card small {
    color: var(--color-text-muted);
    font-size: 0.75rem;
}

/* ========== TABLAS ========== */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--color-border-light);
}

th {
    background: var(--color-bg);
    font-weight: 600;
    color: var(--color-text-secondary);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 0.7rem 0.6rem;
    text-align: left;
    border-bottom: 2px solid var(--color-border);
    white-space: nowrap;
}

td {
    padding: 0.7rem 0.6rem;
    border-bottom: 1px solid var(--color-border-light);
    font-size: 0.85rem;
    color: var(--color-text);
}

tr:last-child td { border-bottom: none; }

tbody tr {
    transition: var(--transition-fast);
}

tbody tr:hover {
    background: var(--color-primary-bg) !important;
}

tbody tr:nth-child(even) {
    background: var(--color-bg);
}

/* ========== FORMULARIOS ========== */
.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
    align-items: flex-end;
}

.form-group {
    flex: 1;
    min-width: 110px;
}

.form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 0.3rem;
    letter-spacing: 0.2px;
}

input,
select {
    padding: 0.6rem 0.9rem;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--color-border);
    font-size: 0.9rem;
    background: var(--color-white);
    transition: var(--transition-fast);
    width: 100%;
    max-width: 100%;
    color: var(--color-text);
}

input:focus,
select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.1);
    outline: none;
}

input[readonly] {
    background: var(--color-bg);
    color: var(--color-text-secondary);
    cursor: default;
}

button {
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 0.9rem;
    background: var(--color-primary);
    color: white;
    cursor: pointer;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    width: auto;
    white-space: nowrap;
    transition: var(--transition);
    box-shadow: var(--shadow-xs);
    letter-spacing: -0.2px;
}

button:hover {
    opacity: 0.92;
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

button:active { transform: translateY(0); }

button.secondary { background: #64748b; }
button.danger { background: var(--color-danger); }
button.warning { background: var(--color-warning); color: #1e293b; }
button.success { background: var(--color-success); }

/* ========== CAMPOS DE TOTAL ========== */
.big-total {
    font-size: 1.3rem !important;
    font-weight: 700 !important;
    color: var(--color-primary) !important;
    -webkit-text-fill-color: var(--color-primary) !important;
    text-align: center !important;
    background-color: var(--color-primary-light) !important;
    border: 2px solid var(--color-primary) !important;
    letter-spacing: -0.3px;
    opacity: 1 !important;
}

/* ========== MODALES ========== */
.ticket-modal,
.confirm-modal {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    justify-content: center;
    align-items: center;
    z-index: 2000;
    animation: fadeIn 0.2s ease;
}

.ticket-content,
.modal-content {
    background: var(--color-white);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    max-width: 95vw;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    text-align: center;
    box-shadow: var(--shadow-xl);
    animation: slideUp 0.3s ease;
}

.modal-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 1rem;
    flex-wrap: wrap;
}

/* ========== TOAST ========== */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    left: auto;
    background: var(--color-text);
    color: white;
    padding: 0.85rem 1.5rem;
    border-radius: var(--radius-full);
    z-index: 9999;
    box-shadow: var(--shadow-lg);
    animation: slideInRight 0.3s ease;
    text-align: center;
    max-width: 400px;
    font-weight: 500;
    font-size: 0.9rem;
}

.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-danger); }
.toast.warning { background: var(--color-warning); color: var(--color-text); }

/* ========== CHAT ========== */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 400px;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--color-border);
    background: var(--color-white);
}

.chat-messages {
    flex: 1;
    padding: 1rem;
    background: var(--color-bg);
    overflow-y: auto;
}

.chat-message {
    margin-bottom: 0.8rem;
    padding: 0.7rem 1.2rem;
    background: white;
    border-radius: var(--radius-lg);
    max-width: 80%;
    box-shadow: var(--shadow-xs);
    border: 1px solid var(--color-border-light);
}

.chat-input-area {
    display: flex;
    gap: 0.5rem;
    padding: 1rem;
    background: white;
    border-top: 1px solid var(--color-border);
}

.chat-input-area input { flex: 1; }

/* ========== BUSCADOR ========== */
.search-box input {
    width: 100%;
    padding: 0.6rem 1rem;
    border-radius: var(--radius-full);
    border: 1.5px solid var(--color-border);
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    background: var(--color-bg);
    transition: var(--transition-fast);
}

.search-box input:focus {
    border-color: var(--color-primary);
    background: var(--color-white);
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.08);
}

/* ========== BOTÓN CON CARGA ========== */
button.cargando {
    pointer-events: none;
    opacity: 0.8;
    position: relative;
}

button.cargando::after {
    content: "";
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top: 2px solid white;
    border-radius: 50%;
    animation: girar 0.6s linear infinite;
    margin-left: 8px;
}

/* ========== ANIMACIONES ========== */
@keyframes girar {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(50px); }
    to { opacity: 1; transform: translateX(0); }
}

.card {
    animation: fadeIn 0.4s ease;
}

.ticket-content {
    animation: slideUp 0.3s ease;
}

/* ========== REGLAS PARA MÓVILES ========== */
img, canvas {
    max-width: 100% !important;
    height: auto !important;
    display: block;
}

@media (max-width: 700px) {
    .card { overflow-x: hidden; }
    .card table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    th, td { padding: 0.5rem 0.4rem; font-size: 0.8rem; }
    .stats-grid { grid-template-columns: 1fr; }
    .stat-card { padding: 0.8rem 1rem; }
}

@media (max-width: 900px) {
    body { padding: 0.5rem; }
    .top-bar { flex-direction: column; align-items: flex-start; }
    .top-bar select { width: 100%; max-width: 100%; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .form-row { flex-direction: column; }
    .form-group { min-width: 100%; }
    .big-total { font-size: 1.1rem !important; }
    .panel.active {
        display: block !important;
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
        margin-left: 0 !important;
        padding-left: 0 !important;
        transform: translateX(0) !important;
    }
}

@media (max-width: 500px) {
    .login-box { padding: 2rem 1.5rem; }
    .card { padding: 1rem; }
    .stat-value { font-size: 1.1rem; }
    input, select, button { font-size: 0.85rem; }
    .tabs { display: none; }
    .mobile-tabs-select { display: block; }
    .toast {
        left: 1rem;
        right: 1rem;
        max-width: none;
        border-radius: var(--radius-md);
    }
}

/* ========== ESTILOS ESPECIALES ========== */
.precio-leyes-panel {
    background: var(--color-warning-light);
    border: 1px solid var(--color-gold-light);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 1rem;
}

.precio-leyes-panel h4 {
    color: var(--color-gold-dark);
}

/* Badge para alertas */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 700;
    color: white;
    background: var(--color-danger);
}

/* Fila de estado */
.fila-compra { border-left: 3px solid var(--color-gold) !important; }
.fila-servicio { border-left: 3px solid var(--color-success) !important; }
.fila-saldo { border-left: 3px solid var(--color-info) !important; }
.fila-gasto { border-left: 3px solid var(--color-danger) !important; }
.fila-cierre { border-left: 3px solid var(--color-primary) !important; }

/* Hover en filas */
tbody tr:hover td {
    background: var(--color-primary-bg) !important;
    cursor: pointer;
}
/* ========== COLORES DE FILA EN DASHBOARD ========== */
.fila-compra td { color: #b8860b !important; }
.fila-servicio td { color: #166534 !important; }
.fila-saldo td { color: #2563eb !important; }
.fila-gasto td { color: #991b1b !important; }
.fila-cierre td { color: #0f6e3f !important; font-weight: bold; }

/* ========== COLORES POR OFICINA EN LOTES ========== */
.ofi-color-3 { border-left: 4px solid #16a34a !important; }
.ofi-color-4 { border-left: 4px solid #2563eb !important; }
.ofi-color-6 { border-left: 4px solid #ea580c !important; }
.ofi-color-7 { border-left: 4px solid #ca8a04 !important; }
.ofi-color-8 { border-left: 4px solid #7c3aed !important; }
.ofi-color-9 { border-left: 4px solid #db2777 !important; }
.ofi-color-0 { border-left: 4px solid #64748b !important; }

/* ========== COLORES DE FILA EN DASHBOARD ========== */
.fila-compra td { color: #b8860b !important; }
.fila-servicio td { color: #166534 !important; }
.fila-saldo td { color: #2563eb !important; }
.fila-gasto td { color: #991b1b !important; }
.fila-cierre td { color: #0f6e3f !important; font-weight: bold; }

/* ========== COLORES POR OFICINA EN LOTES ========== */
.ofi-color-3 { border-left: 4px solid #16a34a !important; }
.ofi-color-4 { border-left: 4px solid #2563eb !important; }
.ofi-color-6 { border-left: 4px solid #ea580c !important; }
.ofi-color-7 { border-left: 4px solid #ca8a04 !important; }
.ofi-color-8 { border-left: 4px solid #7c3aed !important; }
.ofi-color-9 { border-left: 4px solid #db2777 !important; }
.ofi-color-0 { border-left: 4px solid #64748b !important; }