/* ========================================
   SISTEMA AURA - ESTILOS COMPLETOS
   (Print 1 hoja + Mobile + Demo)
   ======================================== */

:root {
  --navy-900: #0a192f;
  --navy-800: #112240;
  --navy-700: #1e3a5f;
  --blue-600: #2563eb;
  --blue-500: #3b82f6;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --border-focus: #bfdbfe;
  --success: #059669;
  --success-light: #d1fae5;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --shadow-sm: 0 1px 2px 0 rgb(15 23 42 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(15 23 42 / 0.08);
  --shadow-lg: 0 10px 20px -5px rgb(15 23 42 / 0.1);
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-width: 240px;
  --action-bar-height: 68px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }
.hidden { display: none !important; }

/* ========================================
   LAYOUT PRINCIPAL
   ======================================== */
.app-layout { display: flex; min-height: 100vh; position: relative; }
.main-content {
  margin-left: 0 !important;
  margin-right: 0 !important;
  padding: 1rem !important;
  padding-bottom: calc(var(--action-bar-height) + 1rem) !important;
  width: 100% !important;
}
.view { display: none; animation: fadeIn 0.25s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ========================================
   SIDEBAR & ACTION BAR
   ======================================== */
.sidebar {
  width: var(--sidebar-width); background: var(--navy-900); color: white;
  position: fixed; top: 0; left: 0; bottom: 0; padding: 1.5rem 1rem;
  display: flex; flex-direction: column; z-index: 50; box-shadow: var(--shadow-lg);
}
.sidebar-header { text-align: center; padding-bottom: 1.5rem; border-bottom: 1px solid rgba(255,255,255,0.1); margin-bottom: 1rem; }
.sidebar-logo { height: 40px; margin-bottom: 0.5rem; object-fit: contain; }
.sidebar-header h3 { font-size: 1.1rem; font-weight: 600; }
.nav-list { list-style: none; flex: 1; }
.nav-item { padding: 0.875rem 1rem; margin-bottom: 0.5rem; border-radius: var(--radius); cursor: pointer; font-weight: 500; transition: background 0.2s; }
.nav-item:hover, .nav-item.active { background: var(--navy-700); }
.sidebar-footer { padding-top: 1rem; border-top: 1px solid rgba(255,255,255,0.1); text-align: center; }
.sidebar-note { font-size: 0.8rem; opacity: 0.8; padding: 0.5rem; }

.action-bar {
  position: fixed; bottom: 0; left: var(--sidebar-width); right: 0;
  height: var(--action-bar-height); background: var(--navy-900);
  display: flex; align-items: center; justify-content: flex-end;
  padding: 0 2rem; gap: 1rem; box-shadow: 0 -2px 10px rgba(0,0,0,0.1); z-index: 40;
}
.action-btn, .currency-select {
  padding: 0.65rem 1.25rem; border: none; border-radius: var(--radius);
  font-weight: 600; font-size: 0.95rem; cursor: pointer;
  display: flex; align-items: center; gap: 0.5rem; transition: all 0.2s;
}
.action-btn.primary { background: var(--blue-600); color: white; }
.action-btn.primary:hover { background: var(--navy-800); transform: translateY(-1px); }
.action-btn.danger { background: var(--danger); color: white; }
.action-btn.danger:hover { background: #b91c1c; transform: translateY(-1px); }
.currency-select { background: white; color: var(--text-main); border: 1px solid var(--border); min-width: 140px; }

/* ========================================
   COMPONENTES GENERALES
   ======================================== */
.welcome-card { background: var(--bg-card); border-radius: var(--radius-lg); padding: 2.5rem; box-shadow: var(--shadow-lg); max-width: 600px; margin: 2rem auto; text-align: center; }
.welcome-card h1 { font-size: 1.75rem; color: var(--navy-900); margin-bottom: 1rem; }
.welcome-card p { color: var(--text-muted); margin-bottom: 2rem; }
.welcome-actions { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }
.btn-cta { background: var(--navy-800); color: white; padding: 0.75rem 1.5rem; border: none; border-radius: var(--radius); font-weight: 600; cursor: pointer; }
.btn-cta:hover { background: var(--navy-900); }
.demo-features { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.5rem; justify-content: center; }
.demo-features span { background: #f1f5f9; padding: 0.35rem 0.75rem; border-radius: 999px; font-size: 0.85rem; color: var(--text-muted); }

.doc-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem; }
.doc-header h2 { font-size: 1.5rem; color: var(--navy-900); }
.doc-badge { background: var(--success-light); color: var(--success); padding: 0.375rem 0.75rem; border-radius: 9999px; font-size: 0.85rem; }

.section { margin-bottom: 32px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--navy-800); text-transform: uppercase; padding-bottom: 8px; border-bottom: 2px solid var(--navy-800); margin-bottom: 18px; }
.client-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-group { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.form-group label { font-size: 11px; color: var(--text-muted); font-weight: 600; min-width: 120px; }
.editable-input { flex: 1; padding: 0.6rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.95rem; }
.editable-input:focus { outline: none; border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(59,130,246,0.15); }

/* Items Table */
.items-header {
  display: grid; grid-template-columns: 2.5fr 0.4fr 1.2fr 1fr 70px; gap: 12px;
  padding: 10px 14px; background: var(--navy-900); color: white;
  border-radius: var(--radius) var(--radius) 0 0; font-weight: 600; font-size: 11px;
}
.item-row {
  display: grid; grid-template-columns: 2.5fr 0.4fr 1.2fr 1fr 70px; gap: 12px;
  padding: 10px 14px; border: 1px solid var(--border); border-top: none; align-items: start;
}
.item-desc { min-height: 24px; padding: 4px 8px; font-size: 12px; }
.item-qty, .item-price { width: 100%; padding: 6px; border: 1px solid var(--border); border-radius: 4px; font-size: 12px; text-align: center; }
.item-total { text-align: right; font-weight: 600; font-size: 12px; }
.item-actions { display: flex; gap: 4px; justify-content: center; }
.btn-item { width: 28px; height: 28px; border: none; border-radius: 6px; background: #f1f5f9; cursor: pointer; font-size: 14px; }
.btn-add-inline {
  background: var(--navy-800); color: white; border: none; padding: 0.6rem 1.2rem;
  border-radius: var(--radius); font-weight: 500; font-size: 0.9rem; cursor: pointer;
  display: flex; align-items: center; gap: 0.5rem; transition: all 0.2s;
}
.btn-add-inline:hover { background: var(--navy-900); transform: translateY(-1px); }
.add-product-wrapper { margin: 1rem 0 1.5rem; display: flex; justify-content: flex-start; }

/* Totals */
.totals-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; }
.terms-box h3 { font-size: 12px; font-weight: 700; color: var(--navy-800); margin-bottom: 14px; }
.calculations-box { background: #f8fafc; padding: 20px; border-radius: var(--radius-lg); border: 1px solid var(--border); }
.calc-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 12px; border-bottom: 1px solid #e2e8f0; }
.calc-value { font-weight: 600; }
.calc-total { margin-top: 14px; padding-top: 16px; border-top: 2px solid var(--navy-800); font-size: 14px; }
.calc-total-value { font-size: 20px; font-weight: 800; color: var(--navy-900); }
.calc-input { width: 50px; padding: 4px; border: 1px solid var(--border); border-radius: 4px; text-align: center; }

/* Quote Document */
.quote-document {
  background: var(--bg-card); padding: 40px; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 210mm; min-height: 297mm; margin: 0 auto; border: 1px solid var(--border);
}
.quote-header { display: flex; justify-content: space-between; padding-bottom: 24px; border-bottom: 2px solid var(--navy-800); margin-bottom: 32px; gap: 24px; }
.header-left { flex: 1; }
.company-logo { max-width: 160px; margin-bottom: 10px; }
.company-name { font-weight: 700; font-size: 15px; color: var(--navy-900); }
.company-cuit { font-size: 12px; color: var(--text-muted); margin: 3px 0; }
.header-right { text-align: right; min-width: 160px; }
.quote-title { font-size: 24px; font-weight: 800; color: var(--navy-900); margin: 0 0 10px; }
.quote-info { font-size: 12px; color: var(--text-muted); }
.quote-footer { margin-top: 40px; padding-top: 24px; border-top: 1px solid var(--border); text-align: center; font-size: 11px; color: var(--text-muted); }

/* Remitos */
.remito {
  background: var(--bg-card); width: 210mm; min-height: 297mm; padding: 16mm;
  border: 2px solid var(--navy-900); box-shadow: var(--shadow-lg); margin: 0 auto;
}
.header { display: flex; justify-content: space-between; border-bottom: 2px solid var(--navy-900); padding-bottom: 16px; margin-bottom: 16px; }
.empresa-logo img { max-width: 220px; height: auto; display: block; margin-bottom: 10px; }
.empresa-datos { font-size: 11px; color: var(--text-muted); line-height: 1.6; }
.remito-datos { border: 1.5px solid var(--navy-800); padding: 10px 14px; text-align: right; min-width: 180px; border-radius: var(--radius); background: #f8fafc; }
.remito-titulo { font-size: 16px; font-weight: 800; margin-bottom: 8px; color: var(--navy-900); }
.datos-fiscales { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; background: #f8fafc; padding: 10px; margin-bottom: 14px; font-size: 11px; border: 1px solid var(--border); border-radius: var(--radius); }
.dato-fiscal { display: flex; align-items: center; }
.dato-fiscal label { font-weight: 600; color: var(--text-muted); margin-right: 4px; font-size: 10px; }
.cliente-seccion { border: 1.5px solid var(--navy-800); padding: 14px; margin-bottom: 16px; border-radius: var(--radius); }
.cliente-titulo { font-weight: 700; margin-bottom: 12px; font-size: 12px; text-transform: uppercase; color: var(--navy-800); }
.cliente-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.cliente-campo label { font-weight: 600; display: block; margin-bottom: 3px; color: var(--text-muted); font-size: 10px; }
.tabla-seccion table { width: 100%; border-collapse: collapse; font-size: 11px; table-layout: fixed; }
th { background: var(--navy-900); color: white; padding: 10px 8px; text-align: left; font-weight: 600; font-size: 10px; }
td { border: 1px solid var(--border); padding: 6px; vertical-align: top; }
th:nth-child(1), td:nth-child(1) { width: 15%; text-align: center; }
th:nth-child(2), td:nth-child(2) { width: 65%; }
th:nth-child(3), td:nth-child(3) { width: 20%; }
.texto-editable { display: inline-block; min-width: 40px; padding: 3px 8px; font-size: 12px; background: transparent; border-bottom: 1px dashed #cbd5e1; min-height: 20px; }
.texto-editable:focus { outline: none; border-color: var(--blue-500); background: #f0f9ff; }
.firmas { display: flex; justify-content: space-between; margin-top: 30px; padding-top: 20px; border-top: 1px solid var(--border); }
.firma-box { width: 45%; }
.firma-label { font-weight: 600; margin-bottom: 10px; font-size: 11px; color: var(--navy-800); }
.firma-linea { border-bottom: 1.5px solid var(--navy-800); height: 40px; }

/* Demo & Utilities */
.demo-banner {
  background: var(--navy-800); color: white; padding: 0.5rem 1rem; font-size: 0.85rem;
  display: flex; justify-content: center; align-items: center; gap: 1rem;
  position: sticky; top: 0; z-index: 100;
}
.btn-banner-close { background: none; border: none; color: white; font-size: 1.2rem; cursor: pointer; padding: 0 0.5rem; }
.demo-banner.hidden { display: none; }
.btn-print {
  background: var(--success); color: white; border: none; padding: 0.5rem 1rem;
  border-radius: var(--radius); font-weight: 500; font-size: 0.9rem; cursor: pointer;
  display: flex; align-items: center; gap: 0.4rem; transition: all 0.2s;
}
.btn-print:hover { background: #047857; transform: translateY(-1px); }
.menu-toggle {
  display: none; position: fixed; top: 1rem; right: 1rem; z-index: 100;
  background: var(--navy-800); border: none; border-radius: 8px;
  padding: 0.5rem; cursor: pointer; flex-direction: column; gap: 4px;
}
.menu-toggle span { display: block; width: 20px; height: 2px; background: white; border-radius: 2px; }

/* ========================================
    RESPONSIVE MOBILE
   ======================================== */
@media (max-width: 768px) {
  .menu-toggle { display: flex; }
 .sidebar {
  transform: translateX(100%); /* Sidebar oculto a la DERECHA */
  transition: transform 0.3s ease;
  width: 260px;
  right: 0; left: auto; /* Fijar a la derecha */
}
.sidebar.open { transform: translateX(0); box-shadow: -2px 0 10px rgba(0,0,0,0.2); }
  .main-content { margin-left: 0; padding: 1rem; padding-bottom: calc(var(--action-bar-height) + 1rem); }
  .action-bar { left: 0; right: 0; padding: 0.5rem; flex-wrap: wrap; height: auto; min-height: var(--action-bar-height); gap: 0.5rem; justify-content: center; }
  .action-bar .currency-select, .action-btn { flex: 1; min-width: 100px; justify-content: center; font-size: 0.85rem; padding: 0.5rem 0.75rem; margin: 0.25rem; }
  
  .quote-document { width: 100%; padding: 1rem; border-radius: 0; border: none; box-shadow: none; min-height: auto; }
  .quote-header { flex-direction: column; align-items: flex-start; gap: 1rem; padding-bottom: 1rem; }
  .header-right { text-align: left; width: 100%; }
  .client-grid { grid-template-columns: 1fr; gap: 0.75rem; }
  .form-group { flex-direction: column; align-items: flex-start; gap: 0.25rem; width: 100%; }
  .form-group label { min-width: auto; width: 100%; }
  .editable-input { width: 100%; }
  
  .items-header, .item-row {
    grid-template-columns: 1fr 0.6fr 1fr;
    grid-template-areas: "desc qty actions" "desc price total";
    font-size: 0.8rem; gap: 0.5rem;
  }
  .col-desc, .item-desc { grid-area: desc; }
  .col-qty, .item-qty { grid-area: qty; text-align: center; }
  .col-price, .item-price { grid-area: price; }
  .col-total, .item-total { grid-area: total; text-align: right; }
  .col-actions, .item-actions { grid-area: actions; justify-self: end; }
  .totals-grid { grid-template-columns: 1fr; gap: 1.5rem; }
  
  .remito { width: 100%; min-height: auto; padding: 10mm; font-size: 9pt; border: 1px solid var(--border); }
  .header { flex-direction: column; gap: 1rem; }
  .datos-fiscales, .cliente-grid { grid-template-columns: 1fr; }
  .firmas { flex-direction: column; gap: 1.5rem; }
  .firma-box { width: 100%; }
  .tabla-seccion { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  #tablaItems { min-width: 500px; width: 100%; }
  .doc-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
  .btn-print { width: 100%; justify-content: center; }
  .add-product-wrapper { margin: 0.75rem 0 1rem; }
  .btn-add-inline { width: 100%; justify-content: center; }
}

@media (max-width: 480px) {
  .welcome-card { padding: 1.5rem; margin: 0.5rem; }
  .welcome-card h1 { font-size: 1.4rem; }
  .demo-features { flex-direction: column; align-items: center; }
  .calc-input { width: 40px; padding: 0.25rem; font-size: 0.85rem; }
  .action-btn { font-size: 0.8rem; padding: 0.4rem 0.6rem; }
}

/* ========================================
   ️ IMPRESIÓN PERFECTA (1 HOJA - FLEX HORIZONTAL)
   ======================================== */
@media print {
  /* 1. OCULTAR INTERFAZ COMPLETAMENTE */
  .demo-banner, .menu-toggle, .sidebar, .action-bar, .btn-print, 
  .add-product-wrapper, .welcome-card, .doc-header, .no-print,
  .sidebar-note, .demo-features, .col-actions, .item-actions {
    display: none !important;
  }

  /* 2. RESET BASE PARA PAPEL */
  body {
    background: white !important; padding: 0 !important; margin: 0 !important;
    font-size: 10pt !important; line-height: 1.3 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .app-layout { display: block !important; }
  .main-content { margin: 0 !important; padding: 0 !important; width: 100% !important; }
  .view { display: none !important; }
  .view.active { display: block !important; }

  /* 3. DOCUMENTOS A4 */
  .quote-document, .remito {
    width: 100% !important; max-width: 100% !important;
    margin: 0 !important; padding: 10mm !important;
    border: none !important; box-shadow: none !important; background: white !important;
  }

  /* 4. COTIZACIÓN: HEADER & CLIENTES HORIZONTALES */
  .quote-header {
    display: flex !important; flex-direction: row !important;
    justify-content: space-between !important; align-items: flex-start !important;
    padding-bottom: 10px !important; margin-bottom: 15px !important;
    border-bottom: 2px solid #000 !important; gap: 20px !important;
  }
  .header-left, .header-right { width: auto !important; text-align: left !important; }

  .client-grid {
    display: grid !important; grid-template-columns: repeat(2, 1fr) !important;
    gap: 4px 15px !important; page-break-inside: avoid !important;
  }
  .form-group {
    display: flex !important; flex-direction: row !important;
    align-items: center !important; gap: 5px !important;
  }
  .form-group label { min-width: 90px !important; width: auto !important; margin-bottom: 0 !important; }
  .editable-input { width: auto !important; flex: 1 !important; border: none !important; background: transparent !important; padding: 0 !important; }

  /* 5. COTIZACIÓN: TABLA ITEMS (FLEX EVITA APILAMIENTO) */
  .items-header, .item-row {
    display: flex !important; flex-direction: row !important;
    grid-template-columns: none !important; grid-template-areas: none !important;
    gap: 8px !important; padding: 4px 0 !important; border: none !important; align-items: center !important;
  }
  .items-header {
    background: #0a192f !important; color: white !important; font-weight: bold !important;
    padding: 6px 0 !important; border-radius: 0 !important; margin-bottom: 5px !important;
  }
  .item-row { border-bottom: 1px solid #ddd !important; page-break-inside: avoid !important; }
  
  .col-desc, .item-desc { flex: 3 !important; text-align: left !important; }
  .col-qty, .item-qty { flex: 0.8 !important; text-align: center !important; }
  .col-price, .item-price { flex: 1.2 !important; text-align: right !important; }
  .col-total, .item-total { flex: 1.2 !important; text-align: right !important; font-weight: bold !important; }
  .item-qty, .item-price { border: none !important; padding: 0 !important; background: transparent !important; }

  /* 6. COTIZACIÓN: TOTALES & TÉRMINOS */
  .totals-grid {
    display: flex !important; flex-direction: row !important;
    justify-content: space-between !important; gap: 20px !important;
    margin-top: 15px !important; page-break-inside: avoid !important;
  }
  .terms-box, .calculations-box {
    width: 48% !important; background: transparent !important; border: none !important; padding: 0 !important;
  }
  .terms-box h3 { display: none !important; }
  .terms-box .form-group { margin-bottom: 3px !important; }

  /* 7. REMITO: ESTRUCTURA HORIZONTAL FORZADA */
  .remito .header {
    display: flex !important; flex-direction: row !important;
    justify-content: space-between !important; border-bottom: 2px solid #000 !important;
    padding-bottom: 10px !important; margin-bottom: 10px !important;
  }
  .remito .datos-fiscales, .remito .cliente-grid {
    display: grid !important; grid-template-columns: repeat(2, 1fr) !important;
    gap: 4px 15px !important; border: none !important; background: transparent !important;
    padding: 0 !important; margin-bottom: 10px !important;
  }
  .remito .cliente-campo { display: flex !important; flex-direction: row !important; gap: 5px !important; }
  .remito .cliente-campo label { min-width: 80px !important; }

  /* 8. REMITO: TABLA */
  .tabla-seccion { margin: 10px 0 !important; }
  .tabla-seccion table {
    width: 100% !important; table-layout: fixed !important; border-collapse: collapse !important; font-size: 9pt !important;
  }
  .tabla-seccion th, .tabla-seccion td {
    border: 1px solid #000 !important; padding: 4px !important;
    white-space: nowrap !important; overflow: hidden !important; text-overflow: ellipsis !important;
  }
  .tabla-seccion th { background: #0a192f !important; color: white !important; }
  .tabla-seccion th:nth-child(1), .tabla-seccion td:nth-child(1) { width: 15% !important; text-align: center !important; }
  .tabla-seccion th:nth-child(2), .tabla-seccion td:nth-child(2) { width: 65% !important; }
  .tabla-seccion th:nth-child(3), .tabla-seccion td:nth-child(3) { width: 20% !important; }

  /* 9. REMITO: FIRMAS & OBSERVACIONES */
  .observaciones-seccion { margin: 10px 0 !important; page-break-inside: avoid !important; }
  .firmas {
    display: flex !important; flex-direction: row !important;
    justify-content: space-between !important; margin-top: 20px !important; page-break-inside: avoid !important;
  }
  .firma-box { width: 45% !important; }

  /* 10. PAGE BREAKS & FOOTER */
  .section, .items-section, .totals-section, .cliente-seccion, .tabla-seccion { page-break-inside: avoid !important; }
  @page {
    size: A4; margin: 0;
    @bottom-center {
      content: "www.aurasoluciones.com.ar • Página " counter(page);
      font-size: 8pt; color: #666;
    }
  }
}