/* ============================================================================
   DISEÑO SISTEMA COMERCIAL - ESTILO PREMIUM GLASSMORPHISM
   ============================================================================ */

:root {
  --primary: #4f46e5;
  --primary-hover: #3730a3;
  --secondary: #6366f1;
  --dark-bg: #f8fafc;
  --sidebar-bg: #ffffff;
  --glass-bg: #ffffff;
  --glass-border: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #06b6d4;
  --font-family-sans: 'Outfit', 'Inter', system-ui, -apple-system, sans-serif;
  --border-color: #cbd5e1;
  --input-bg: #ffffff;
}

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

body {
  font-family: var(--font-family-sans);
  background-color: var(--dark-bg);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
}

/* Scrollbar personalizado */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: #f1f5f9;
}
::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--secondary);
}

/* ============================================================================
   ESTILOS DE CONTENEDORES Y ESTRUCTURA GENERAL
   ============================================================================ */

.hidden {
  display: none !important;
}

/* Contenedor Glassmorphism General */
.glass-container {
  display: none;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1000;
  backdrop-filter: blur(20px);
  background: rgba(241, 245, 249, 0.7);
}

.glass-container.active {
  display: flex;
}

/* Tarjeta de Login */
.login-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  backdrop-filter: blur(12px);
  border-radius: 24px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  text-align: center;
  animation: fadeIn 0.5s ease-out;
}

.brand {
  margin-bottom: 30px;
}

.brand-icon {
  font-size: 3rem;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
  margin-bottom: 15px;
}

.brand h1 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.brand p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Formularios */
.input-group {
  margin-bottom: 20px;
  text-align: left;
}

.input-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 600;
}

.input-group input, 
.input-group select, 
.input-group textarea {
  width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-family: var(--font-family-sans);
  font-size: 0.95rem;
  transition: all 0.3s ease;
}

.input-group input:focus, 
.input-group select:focus, 
.input-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.3);
}

.form-row {
  display: flex;
  gap: 15px;
}

.form-row .input-group {
  flex: 1;
}

/* Botones Premium */
button {
  cursor: pointer;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border: none;
  color: #fff;
  font-family: var(--font-family-sans);
  font-weight: 600;
  font-size: 1rem;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

.btn-primary:active {
  transform: translateY(0);
}

.alert {
  padding: 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  margin-bottom: 15px;
  text-align: left;
}

.alert-danger {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--danger);
  color: #fca5a5;
}

/* ============================================================================
   ESTRUCTURA DE APLICACIÓN (LAYOUT PRINCIPAL)
   ============================================================================ */

#app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  backdrop-filter: blur(15px);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  padding: 24px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 40px;
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-brand i {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.3s ease;
}

.nav-link:hover {
  color: var(--primary);
  background: rgba(0, 0, 0, 0.04);
}

.nav-link.active {
  border-left: 3px solid var(--primary);
  background: rgba(79, 70, 229, 0.06);
  color: var(--primary);
}

.badge {
  background: var(--danger);
  color: #fff;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: auto;
  font-weight: 700;
}

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--glass-border);
  padding-top: 20px;
}

.user-info {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.user-role {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.btn-logout {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  transition: color 0.3s;
}

.btn-logout:hover {
  color: var(--danger);
}

/* Área de contenido */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 40px;
  overflow-y: auto;
}

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

.content-header h2 {
  font-size: 1.8rem;
  font-weight: 600;
}

.date-badge {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Secciones */
.content-section {
  display: none;
  animation: fadeIn 0.4s ease-out;
}

.content-section.active {
  display: block;
}

/* Métrica Grid (Dashboard) */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 40px;
}

.metric-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  transition: transform 0.3s;
}

.metric-card:hover {
  transform: translateY(-5px);
}

.metric-icon {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.5rem;
  color: #fff;
}

.bg-gradient-blue { background: linear-gradient(135deg, #3b82f6, #06b6d4); }
.bg-gradient-purple { background: linear-gradient(135deg, #8b5cf6, #d946ef); }
.bg-gradient-yellow { background: linear-gradient(135deg, #f59e0b, #eab308); }
.bg-gradient-green { background: linear-gradient(135deg, #10b981, #14b8a6); }

.metric-info h3 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 4px;
}

.metric-info p {
  font-size: 1.5rem;
  font-weight: 700;
}

/* Tablas Premium */
.card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 24px;
  backdrop-filter: blur(10px);
}

.card-header {
  margin-bottom: 20px;
}

.card-header h4 {
  font-size: 1.1rem;
  font-weight: 600;
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.table th, .table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--glass-border);
}

.table th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table td {
  font-size: 0.92rem;
}

.table tr:hover td {
  background: rgba(0, 0, 0, 0.02);
}

/* Badges de Estado */
.status-pill {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  display: inline-block;
}

.status-pill.pendiente { background: rgba(245, 158, 11, 0.15); color: #b45309; }
.status-pill.autorizado { background: rgba(16, 185, 129, 0.15); color: #047857; }
.status-pill.facturado { background: rgba(99, 102, 241, 0.15); color: #4338ca; }
.status-pill.suspendido { background: rgba(239, 68, 68, 0.15); color: #b91c1c; }
.status-pill.activo { background: rgba(16, 185, 129, 0.15); color: #047857; }

/* Botones de acción en tabla */
.btn-action {
  background: #f1f5f9;
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-family: var(--font-family-sans);
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-action:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff !important;
  transform: translateY(-1px);
}

.section-actions {
  margin-bottom: 24px;
  display: flex;
  justify-content: flex-end;
}

.section-actions button {
  width: auto;
  padding: 10px 20px;
}

/* ============================================================================
   MODALES Y VISORES
   ============================================================================ */

.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(11, 15, 25, 0.8);
  backdrop-filter: blur(8px);
  justify-content: center;
  align-items: center;
  animation: fadeIn 0.3s;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  border-radius: 24px;
  width: 90%;
  max-width: 550px;
  padding: 32px;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content.wide-modal {
  max-width: 800px;
}

.modal-content.pdf-modal {
  max-width: 850px;
  width: 90%;
  height: 90vh;
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  padding: 24px;
}

.close-modal {
  position: absolute;
  top: 20px;
  right: 20px;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: color 0.2s;
}

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

.modal-content h3 {
  margin-bottom: 12px;
  font-weight: 600;
}

.modal-content p {
  color: var(--text-secondary);
  margin-bottom: 24px;
  font-size: 0.9rem;
}

/* Estilo Facturación Totales */
.facturacion-totals {
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 24px;
}

.total-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.9rem;
  color: white;
}

.total-row.highlight-trib {
  border-bottom: 1px dashed var(--glass-border);
  padding-bottom: 8px;
  color: var(--warning);
}

.total-row.final {
  margin-top: 8px;
  font-weight: 700;
  font-size: 1.15rem;
  color: #fff;
}

.formula-helper {
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 20px;
  font-size: 0.8rem;
}

.formula-helper p {
  margin-bottom: 4px;
  color: var(--text-primary);
}

/* Cuenta corriente modal summary */
.cc-summary-box {
  display: flex;
  justify-content: space-between;
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
}

.cc-summary-box span.deuda {
  color: var(--danger);
  font-weight: 700;
}

.cc-table-container {
  max-height: 400px;
  overflow-y: auto;
}

/* Visor PDF Estilo */
.pdf-viewer-frame {
  background: #1e293b;
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 20px;
  flex: 1;
  overflow-y: auto;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.82rem;
  color: #cbd5e1;
  white-space: pre-wrap;
  margin-bottom: 10px;
}

/* Exportador y Edición */
.section-actions-export {
  margin-bottom: 24px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 16px;
  backdrop-filter: blur(10px);
}
.export-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}
.input-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}
.input-inline label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}
.input-inline input {
  height: 38px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 0 10px;
  outline: none;
}
.btn-action.btn-edit {
  margin-left: 6px;
}
.btn-action.btn-edit:hover {
  background: var(--warning);
  border-color: var(--warning);
  color: #0f172a;
}
.actions-group {
  display: inline-flex;
  gap: 6px;
}
.add-item-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 1.5rem;
}

/* Plantilla Factura Imprimible (Estilo Buyatti Premium A4 Completo) */
.pdf-invoice-template {
  width: 100%;
  max-width: 210mm;
  min-height: 262mm;
  background: #fff !important;
  color: #000 !important;
  font-family: 'Inter', sans-serif;
  padding: 5mm 10mm 10mm 10mm;
  box-sizing: border-box;
  margin: 0 auto;
  white-space: normal !important;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.pdf-invoice-template * {
  color: #000000 !important;
  white-space: normal !important;
}
.invoice-border-box {
  border: 1px dashed #94a3b8;
  margin-bottom: 16px;
}
.invoice-border-box-solid {
  border: 1.5px solid #000;
  margin-bottom: 16px;
}
.invoice-header-table {
  width: 100%;
  border-collapse: collapse;
}
.invoice-header-table td {
  padding: 8px 12px;
  vertical-align: top;
  border: none;
  background: transparent !important;
  color: #000 !important;
}
.header-left {
  width: 45%;
}
.header-center {
  width: 10%;
  text-align: center;
  border-left: 1.5px solid #000 !important;
  border-right: 1.5px solid #000 !important;
}
.letter-box {
  border: 2px solid #000;
  width: 44px;
  height: 44px;
  line-height: 42px;
  font-size: 26px;
  font-weight: 700;
  margin: 0 auto 4px auto;
  text-align: center;
}
.letter-subtext {
  font-size: 7px;
  font-weight: 600;
  line-height: 9px;
  text-transform: uppercase;
}
.header-right {
  width: 45%;
  padding-left: 20px !important;
}
.invoice-title {
  font-size: 20px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.invoice-number {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}
.company-name {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
}
.company-detail {
  font-size: 10px;
  color: #333;
  line-height: 14px;
}
.client-info-box {
  border: 1.5px solid #000;
  padding: 10px;
  margin-bottom: 16px;
  font-size: 11px;
  line-height: 16px;
}
.client-info-table {
  width: 100%;
  border-collapse: collapse;
}
.client-info-table td {
  padding: 3px 6px;
  border: none !important;
  background: transparent !important;
  color: #000 !important;
}
.products-grid-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}
.products-grid-table th {
  background: #f8fafc !important;
  color: #000 !important;
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  border-top: 2px solid #000 !important;
  border-bottom: 2px solid #000 !important;
  padding: 8px;
}
.products-grid-table td {
  padding: 8px;
  font-size: 11px;
  border-bottom: 1px solid #e2e8f0;
  color: #000 !important;
  background: transparent !important;
}
.products-grid-table tr:hover td {
  background: transparent !important;
}
.text-right {
  text-align: right;
}
.totals-summary-box {
  border: 1.5px solid #000;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  background: #f8fafc;
}
.totals-summary-box div {
  font-size: 11px;
  color: #000;
}
.totals-summary-box div.final-total {
  font-size: 14px;
  font-weight: 700;
}
.invoice-footer-notes {
  font-size: 10px;
  line-height: 14px;
  color: #333;
  margin-bottom: 8px;
}

/* Impresión Nativa Limpia A4 portrait */
@media print {
  @page {
    size: A4 portrait;
    margin-top: 0mm;
    margin-bottom: 20mm;
    margin-left: 10mm;
    margin-right: 10mm;
  }
  body * {
    visibility: hidden !important;
  }
  #pdf-view-content, #pdf-view-content * {
    visibility: visible !important;
  }
  #pdf-view-content {
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    max-width: 210mm !important;
    height: auto !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    background: white !important;
    color: black !important;
  }
  .modal {
    position: absolute !important;
    background: transparent !important;
    backdrop-filter: none !important;
    padding: 0 !important;
  }
  .modal-content {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }
  #close-pdf-modal, #btn-imprimir-pdf, .modal-content h3 {
    display: none !important;
  }
}

.btn-action.active-tab {
  background: var(--primary);
  border-color: var(--primary);
  color: white !important;
  font-weight: 600;
}

/* ============================================================================
   ANIMACIONES
   ============================================================================ */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================================
   ESTILOS RESPONSIVOS (MÓVIL Y TABLET)
   ============================================================================ */

.mobile-header {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 992px) {
  #app-container {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    overflow-x: hidden;
  }

  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    padding: 0 16px;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 1500;
  }

  .btn-toggle-sidebar {
    background: none;
    border: none;
    font-size: 1.6rem;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 4px;
    border-radius: 8px;
    transition: background-color 0.2s;
  }

  .btn-toggle-sidebar:hover {
    background: rgba(0, 0, 0, 0.05);
  }

  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text-primary);
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: -285px;
    width: 280px;
    height: 100vh;
    z-index: 2100;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 10px 0 30px rgba(0,0,0,0.15);
    background: var(--sidebar-bg);
  }

  .sidebar.open {
    left: 0;
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 2050;
  }

  .sidebar-backdrop.active {
    display: block;
  }

  .main-content {
    padding: 20px 16px;
    height: auto;
    overflow-y: visible;
  }

  .content-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 20px;
  }

  .content-header h2 {
    font-size: 1.45rem;
  }

  .metrics-grid {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 15px;
    margin-bottom: 24px;
  }

  .metric-card {
    padding: 16px;
    gap: 12px;
  }

  .metric-icon {
    width: 44px;
    height: 44px;
    font-size: 1.25rem;
  }

  .metric-info p {
    font-size: 1.25rem;
  }

  .card {
    padding: 16px;
    margin-bottom: 16px;
    border-radius: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table th, .table td {
    padding: 10px 12px;
    font-size: 0.85rem;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .add-item-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .add-item-row button {
    width: 100%;
  }

  .modal-content {
    padding: 20px;
    width: 95%;
    max-height: 95vh;
    border-radius: 16px;
  }

  .export-filters {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .export-filters .input-inline {
    justify-content: space-between;
    width: 100%;
  }

  .export-filters .input-inline input {
    flex: 1;
    max-width: 200px;
  }

  .section-actions {
    flex-direction: column;
    gap: 10px;
  }

  .section-actions button {
    width: 100%;
  }
}

