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

:root {
    --primary: #667eea;
    --secondary: #00d2ff;
    --accent: #ff44e6;
    --dark: #1a1a2e;
    --gray: #6c757d;
    --light-gray: #f8f9fa;
    --border: #e5e7eb;
    --success: #28a745;
    --danger: #ff4757;
    --warning: #ffc107;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    --radius: 12px;
}

body {
    font-family: 'Inter', sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #e4e8f0 100%);
    padding: 20px;
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

body.dark {
    background: #121212;
    color: #e0e0e0;
}

.app-container {
    max-width: 1600px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 24px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1);
    overflow: hidden;
    transition: background 0.3s;
}

body.dark .app-container {
    background: #1e1e2e;
}

/* Sidebar */
.sidebar {
    background: var(--dark);
    color: white;
    padding: 24px;
    height: calc(100vh - 40px);
    overflow-y: auto;
    position: sticky;
    top: 0;
    transition: background 0.3s;
}

body.dark .sidebar {
    background: #2a2a3a;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.logo-container {
    flex: 1;
}

.logo-img {
    max-width: 150px;
    height: auto;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
}

/* Buscador */
.buscador-container {
    background: rgba(255,255,255,0.08);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 20px;
}

.search-box {
    position: relative;
    margin-bottom: 12px;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #aaa;
}

.search-box input {
    width: 100%;
    padding: 10px 10px 10px 38px;
    border: none;
    border-radius: 8px;
    background: rgba(255,255,255,0.9);
    font-family: 'Inter', sans-serif;
}

.filtros-row {
    display: flex;
    gap: 10px;
}

.filtro-select {
    flex: 1;
    padding: 8px;
    border-radius: 8px;
    border: none;
    background: rgba(255,255,255,0.9);
}

/* Acordeón */
.accordion-item {
    margin-bottom: 12px;
    border-radius: var(--radius);
    background: rgba(255,255,255,0.05);
    overflow: hidden;
}

.accordion-header {
    display: flex;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
    font-weight: 500;
}

.accordion-icon {
    transition: transform 0.3s;
}

.accordion-item.open .accordion-icon {
    transform: rotate(180deg);
}

.accordion-content {
    padding: 0 16px 16px 16px;
    display: none;
}

.accordion-item.open .accordion-content {
    display: block;
}

/* Categorías */
.categorias-lista {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.categoria-item {
    background: rgba(255,255,255,0.15);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.agregar-categoria {
    display: flex;
    gap: 8px;
}

.agregar-categoria input {
    flex: 1;
    padding: 8px;
    border-radius: 8px;
    border: none;
}

.btn-small {
    background: var(--secondary);
    color: var(--dark);
    border: none;
    padding: 6px 12px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

/* Formulario agregar producto - Ajustes de tamaño */
.codigo-automatico input {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
    background: rgba(255,255,255,0.2);
    border: none;
    border-radius: 8px;
    color: white;
    font-family: monospace;
}
.form-producto input, .form-producto select {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
    border-radius: 8px;
    border: none;
    background: rgba(255,255,255,0.9);
}
.btn-primary {
    width: 100%;
    padding: 10px;
    background: linear-gradient(135deg, var(--secondary), #00a3cc);
    color: var(--dark);
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

/* Productos grid */
.productos-grid {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.producto-card {
    background: rgba(255,255,255,0.08);
    padding: 12px;
    border-radius: var(--radius);
    transition: 0.2s;
}

.producto-card .codigo { font-weight: 700; color: var(--secondary); font-family: monospace; }
.producto-card .desc { font-size: 12px; margin: 6px 0; }
.producto-card .precio { color: #4cd964; font-weight: 700; }
.producto-acciones { display: flex; gap: 8px; margin-top: 8px; }
.btn-editar, .btn-eliminar-catalogo { padding: 4px 10px; border-radius: 6px; border: none; font-size: 10px; cursor: pointer; }
.btn-editar { background: var(--warning); color: var(--dark); }
.btn-eliminar-catalogo { background: var(--danger); color: white; }
.count-badge { background: var(--secondary); color: var(--dark); padding: 2px 8px; border-radius: 20px; font-size: 10px; margin-left: 8px; }

/* Panel principal */
.main-panel {
    padding: 28px;
    overflow-y: auto;
    max-height: calc(100vh - 40px);
    background: white;
    transition: background 0.3s;
}

body.dark .main-panel {
    background: #1e1e2e;
    color: #e0e0e0;
}

/* Encabezado cotización */
.cotizacion-header { margin-bottom: 28px; border-bottom: 2px solid var(--secondary); padding-bottom: 16px; }
.header-top { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 20px; margin-bottom: 16px; }
.header-logo-img { max-height: 80px; width: auto; }
.header-recuadro { background: var(--light-gray); border: 2px solid var(--dark); border-radius: var(--radius); padding: 12px 24px; text-align: center; min-width: 200px; }
body.dark .header-recuadro { background: #2a2a3a; border-color: #444; }
.recuadro-rut, .recuadro-cotizacion, .recuadro-numero { color: inherit; }
.header-descripcion p { font-size: 11px; margin: 2px 0; color: #666; }
body.dark .header-descripcion p { color: #aaa; }

/* Formularios */
.datos-cliente, .terminos-comerciales { background: var(--light-gray); padding: 16px; border-radius: var(--radius); margin-bottom: 20px; }
body.dark .datos-cliente, body.dark .terminos-comerciales { background: #2a2a3a; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 12px; }
.form-group label { font-size: 10px; font-weight: 600; text-transform: uppercase; margin-bottom: 4px; display: block; }
.form-group input { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; width: 100%; }

/* Tabla drag & drop */
.tabla-container { margin: 20px 0; }
.tabla-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.btn-clear { background: none; border: none; color: var(--gray); cursor: pointer; font-size: 12px; padding: 4px 8px; border-radius: 6px; }
.btn-clear:hover { background: #fee2e2; color: var(--danger); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { background: var(--dark); color: white; padding: 10px; text-align: center; }
body.dark th { background: #2a2a3a; }
td { border-bottom: 1px solid var(--border); padding: 8px; text-align: center; }
.drag-table-body tr { cursor: grab; }
.drag-table-body tr:active { cursor: grabbing; }
.drag-over { background: rgba(0,210,255,0.2); }
.empty-table { text-align: center; color: var(--gray); padding: 40px; }

/* Sección "Agregar a cotización" - Ajustes importantes */
.agregar-item {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    align-items: center;
    flex-wrap: wrap;
}
.agregar-item select {
    flex: 3;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 13px;
}
.cantidad-input {
    width: 80px !important;   /* Ancho fijo para cantidad */
    text-align: center;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 13px;
}
.btn-secondary {
    background: var(--success);
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    white-space: nowrap;
}
.btn-secondary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(40,167,69,0.3);
}

/* Totales */
.totales { text-align: right; margin: 20px 0; padding: 20px; background: var(--light-gray); border-radius: var(--radius); }
body.dark .totales { background: #2a2a3a; }
.linea-total { display: flex; justify-content: flex-end; gap: 40px; margin: 8px 0; }
.total-final { font-size: 20px; color: var(--success); font-weight: 800; }

/* Condiciones y bancarios */
.condiciones { background: var(--light-gray); padding: 16px; border-radius: var(--radius); margin: 20px 0; }
.condiciones-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; font-size: 12px; }
.datos-bancarios { background: linear-gradient(135deg, var(--dark), #2d2d44); color: white; padding: 16px; border-radius: var(--radius); text-align: center; margin: 20px 0; }
.edit-text { background: none; border: none; cursor: pointer; font-size: 11px; margin-left: 8px; color: var(--primary); }

/* Botones de herramientas */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
.btn-tool { background: var(--light-gray); border: 1px solid var(--border); padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 12px; transition: 0.2s; }
body.dark .btn-tool { background: #2a2a3a; color: #e0e0e0; border-color: #444; }
.acciones { display: flex; gap: 16px; margin-top: 24px; }
.btn-pdf, .btn-nueva { flex: 1; padding: 14px; border: none; border-radius: 10px; font-weight: 700; cursor: pointer; font-size: 14px; }
.btn-pdf { background: linear-gradient(135deg, var(--success), #218838); color: white; }
.btn-nueva { background: linear-gradient(135deg, var(--gray), #5a6268); color: white; }

/* Modales */
.modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); justify-content: center; align-items: center; }
.modal-content { background: white; padding: 24px; border-radius: 20px; max-width: 600px; width: 90%; max-height: 80vh; overflow-y: auto; }
body.dark .modal-content { background: #1e1e2e; color: #e0e0e0; }
.close-modal { float: right; font-size: 28px; cursor: pointer; }
.historial-list { margin-top: 16px; max-height: 400px; overflow-y: auto; }
.historial-item { background: var(--light-gray); padding: 12px; border-radius: 8px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
body.dark .historial-item { background: #2a2a3a; }

/* Responsive */
@media (max-width: 900px) {
    .app-container { grid-template-columns: 1fr; }
    .sidebar { height: auto; max-height: 400px; position: relative; }
    .mobile-menu-btn { display: block; }
    .sidebar.collapsed .buscador-container, .sidebar.collapsed .accordion-item { display: none; }
    .main-panel { max-height: none; }
    .condiciones-grid { grid-template-columns: 1fr; }
    .header-top { flex-direction: column; align-items: center; }
    .agregar-item {
        flex-direction: column;
        align-items: stretch;
    }
    .cantidad-input {
        width: 100% !important;
    }
    .btn-secondary {
        text-align: center;
    }
}