/* ═══════════════════════════════════════════════════
   Reset & Variables
═══════════════════════════════════════════════════ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary:       #1a56db;
  --primary-dark:  #1241b0;
  --primary-light: #e8f0fe;
  --success:       #059669;
  --danger:        #dc2626;
  --danger-dark:   #b91c1c;
  --whatsapp:      #25D366;
  --whatsapp-dark: #1da851;
  --bg:            #f1f5f9;
  --card:          #ffffff;
  --border:        #e2e8f0;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --shadow-sm:     0 1px 2px rgba(0,0,0,.06);
  --shadow:        0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --radius:        8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ═══════════════════════════════════════════════════
   Header
═══════════════════════════════════════════════════ */
.header {
  background: var(--primary);
  color: white;
  padding: 0 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
  position: sticky;
  top: 0;
  z-index: 200;
}

.header-content {
  max-width: 920px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  white-space: nowrap;
}

.logo-icon { font-size: 22px; }

.nav {
  display: flex;
  gap: 6px;
}

.nav-btn {
  background: transparent;
  border: 2px solid rgba(255,255,255,.38);
  color: rgba(255,255,255,.85);
  padding: 6px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}

.nav-btn:hover {
  background: rgba(255,255,255,.16);
  border-color: rgba(255,255,255,.6);
  color: white;
}

.nav-btn.active {
  background: white;
  border-color: white;
  color: var(--primary);
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════
   Main Layout
═══════════════════════════════════════════════════ */
.main {
  max-width: 920px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

.view { display: none; }
.view.active { display: block; }

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

.view-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

/* ═══════════════════════════════════════════════════
   Cards
═══════════════════════════════════════════════════ */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════
   Form Inputs
═══════════════════════════════════════════════════ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label,
label.qty-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.required { color: var(--danger); }

.input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: white;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  appearance: auto;
}

.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,.12);
}

.input-readonly {
  background: #f8fafc;
  color: var(--text-muted);
  cursor: default;
  user-select: none;
}

.textarea {
  resize: vertical;
  min-height: 72px;
}

/* ═══════════════════════════════════════════════════
   Buttons
═══════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 6px;
  border: none;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary { background: #f1f5f9; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #e2e8f0; }

.btn-outline { background: white; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-light); }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-dark); }

.btn-whatsapp { background: var(--whatsapp); color: white; }
.btn-whatsapp:hover { background: var(--whatsapp-dark); }

.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-lg { padding: 10px 24px; font-size: 15px; font-weight: 600; }

/* ═══════════════════════════════════════════════════
   Meta grid (header de cotización)
═══════════════════════════════════════════════════ */
.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.optional {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 10px;
  text-transform: none;
  letter-spacing: 0;
}

/* ═══════════════════════════════════════════════════
   Agregar ítem del catálogo
═══════════════════════════════════════════════════ */
.add-item-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.select-item { flex: 1; min-width: 200px; }

.input-qty-selector { width: 72px; text-align: center; }

/* ═══════════════════════════════════════════════════
   Ítem personalizado (ad-hoc)
═══════════════════════════════════════════════════ */
.adhoc-section { margin-bottom: 14px; }

.adhoc-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
  padding: 14px;
  background: var(--primary-light);
  border: 1.5px dashed var(--primary);
  border-radius: 6px;
}

.adhoc-nombre { flex: 1; min-width: 200px; }
.adhoc-precio { width: 150px; }
.adhoc-actions { display: flex; gap: 8px; }

/* ═══════════════════════════════════════════════════
   Tabla de cotización
═══════════════════════════════════════════════════ */
.table-wrap { overflow-x: auto; }

.quote-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.quote-table thead tr {
  background: var(--primary);
  color: white;
}

.quote-table th {
  padding: 9px 12px;
  font-weight: 600;
  font-size: 12px;
  text-align: left;
}

.quote-table tbody tr { transition: background .1s; }
.quote-table tbody tr:nth-child(even) { background: #f8fafc; }
.quote-table tbody tr:hover { background: var(--primary-light); }

.quote-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.col-num   { width: 40px; color: var(--text-muted); }
.col-qty   { width: 80px; text-align: center; }
.col-price { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.col-action{ width: 44px; text-align: center; }

.qty-inline {
  width: 60px;
  padding: 4px 6px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
.qty-inline:focus { border-color: var(--primary); }

.btn-remove {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.btn-remove:hover { background: #fee2e2; }

.empty-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 28px 12px !important;
  font-style: italic;
  font-size: 13px;
}

/* ═══════════════════════════════════════════════════
   Servicios adicionales
═══════════════════════════════════════════════════ */
.services-list { display: flex; flex-direction: column; gap: 10px; }

.service-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f8fafc;
  transition: background .15s;
}
.service-row:hover { background: var(--primary-light); }

.service-row input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.service-label {
  flex: 1;
  font-weight: 500;
  cursor: pointer;
}

.input-price-sm { width: 120px; }

.service-row-descuento { border-color: #fca5a5; background: #fff5f5; }
.service-row-descuento:hover { background: #fee2e2; }
.service-row-descuento .service-label { color: var(--danger); }
.service-row-descuento input[type="checkbox"] { accent-color: var(--danger); }

/* ═══════════════════════════════════════════════════
   Totales
═══════════════════════════════════════════════════ */
.totals-card { background: #f8fafc; }

.totals-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 32px;
  max-width: 380px;
  margin-left: auto;
}

.totals-label { color: var(--text-muted); font-size: 13.5px; }
.totals-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 13.5px;
}

.descuento-label { color: var(--danger); }
.descuento-value { color: var(--danger); font-weight: 500; }

.total-label {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  padding-top: 10px;
  border-top: 2px solid var(--border);
}
.total-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  padding-top: 10px;
  border-top: 2px solid var(--border);
}

/* ═══════════════════════════════════════════════════
   Exportar
═══════════════════════════════════════════════════ */
.export-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.wa-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.wa-phone { width: 170px; }

/* ═══════════════════════════════════════════════════
   Mantenedor de Ítems
═══════════════════════════════════════════════════ */
.new-item-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.new-item-nombre { flex: 1; min-width: 200px; }
.new-item-precio { width: 160px; }

/* Lista de ítems */
.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  background: #f8fafc;
  transition: background .15s;
}
.item-row:hover { background: var(--primary-light); }
.item-row:last-child { margin-bottom: 0; }

.item-info {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 0;
}

.item-name {
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-price {
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.item-actions { display: flex; gap: 4px; flex-shrink: 0; }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  width: 32px;
  height: 32px;
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.btn-icon.edit:hover  { background: #fef9c3; }
.btn-icon.del:hover   { background: #fee2e2; }

/* Fila de edición inline */
.item-edit-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
}
.item-edit-row .input-edit-nombre { flex: 1; min-width: 160px; }
.item-edit-row .input-edit-precio { width: 130px; }
.item-edit-row .edit-actions { display: flex; gap: 6px; }

.empty-msg {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  padding: 24px;
}

.import-export-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ═══════════════════════════════════════════════════
   Configuración de empresa
═══════════════════════════════════════════════════ */
.config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.config-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

.logo-upload-area {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.logo-preview-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-preview {
  max-height: 64px;
  max-width: 200px;
  border: 1px solid var(--border);
  border-radius: 6px;
  object-fit: contain;
  background: #f8fafc;
  padding: 4px;
}

.logo-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 6px;
  border: 1.5px dashed var(--primary);
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  color: var(--primary);
  background: var(--primary-light);
  transition: background .15s;
}
.logo-upload-btn:hover { background: #d1e0fd; }

/* ═══════════════════════════════════════════════════
   Toast / Notificaciones
═══════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: white;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .22s, transform .22s;
  pointer-events: none;
  z-index: 999;
  max-width: 340px;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-error { background: var(--danger); }
.toast-info  { background: var(--success); }

/* ═══════════════════════════════════════════════════
   Responsive
═══════════════════════════════════════════════════ */
@media (max-width: 640px) {
  .header-content {
    flex-direction: column;
    height: auto;
    padding: 10px 0;
    gap: 8px;
  }

  .nav { width: 100%; }
  .nav-btn { flex: 1; text-align: center; font-size: 12px; padding: 6px 8px; }

  .meta-grid { grid-template-columns: 1fr; }

  .add-item-row { flex-direction: column; align-items: stretch; }
  .select-item { min-width: 100%; }
  .input-qty-selector { width: 100%; }

  .adhoc-form { flex-direction: column; }
  .adhoc-nombre, .adhoc-precio { width: 100%; }
  .adhoc-actions { width: 100%; }

  .export-row { flex-direction: column; align-items: stretch; }
  .wa-group { flex-direction: column; }
  .wa-phone { width: 100%; }
  .btn-lg { width: 100%; }

  .new-item-form { flex-direction: column; }
  .new-item-nombre, .new-item-precio { width: 100%; }

  .config-grid { grid-template-columns: 1fr; }

  .totals-grid { max-width: 100%; }

  .col-price { width: 90px; }

  .toast { left: 16px; right: 16px; bottom: 16px; max-width: none; }
}

@media (max-width: 400px) {
  .main { padding: 12px 10px 48px; }
  .card { padding: 14px; }
  .meta-grid { grid-template-columns: 1fr; }
}
