:root{
  --bg:#F0E6D0;
  --card:#FFFDF6;
  --text:#2C1A0E;
  --muted:#7A5C3E;
  --border:#C9A87A;
  --border2:#E2CBA8;

  --primary:#4A1C00;
  --primaryText:#FFF8F0;

  --dangerBg:#ffefef;
  --dangerBorder:#ffc7c7;

  --shadow:0 10px 26px rgba(74,28,0,.10);
  --shadowStrong:0 22px 60px rgba(74,28,0,.22);

  --radius:14px;
  --radiusSm:10px;
}

*{ box-sizing:border-box; }

body{
  font-family: 'Inter', Arial, sans-serif;
  background:var(--bg);
  margin:0;
  padding:28px 18px;
  color:var(--text);
}

h1, h2, h3{
  font-family: 'Lora', Georgia, serif;
}

h1{
  text-align:center;
  margin:0 0 18px 0;
  font-size:28px;
  letter-spacing:.2px;
}

.card{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:var(--radius);
  padding:14px;
  box-shadow:var(--shadow);
}

/* =====================
   TOPBAR / NAV
   ===================== */
.topbar{
  display:flex;
  gap:10px;
  align-items:center;
  flex-wrap:wrap;
  margin:0 auto 14px auto;
  max-width:1180px;
}

.topbar label{
  color:var(--muted);
  font-size:13px;
  margin-left:6px;
  white-space:nowrap;
}

/* =====================
   INPUTS / SELECTS
   ===================== */
.input, select{
  border:1px solid #C9A87A;
  border-radius:var(--radiusSm);
  padding:9px 10px;
  outline:none;
  background:#FFFDF6;
  min-height:38px;
  font-size:14px;
  color:var(--text);
}

.input:focus, select:focus{
  border-color:#8B5E3C;
  box-shadow:0 0 0 3px rgba(74,28,0,.08);
}

/* =====================
   BOTONES
   ===================== */
.btn{
  border:1px solid #C9A87A;
  border-radius:var(--radiusSm);
  padding:9px 12px;
  cursor:pointer;
  background:#FFFDF6;
  color:var(--text);
  min-height:38px;
  font-size:14px;
  white-space:nowrap;
  transition:transform .05s ease, filter .15s ease, box-shadow .15s ease;
}

.btn:hover{
  filter:brightness(.98);
  box-shadow:0 6px 14px rgba(0,0,0,.06);
}

.btn:active{
  transform:translateY(1px);
}

.btn-primary{
  background:var(--primary);
  color:var(--primaryText);
  border-color:var(--primary);
}

.btn-ghost{
  background:transparent;
}

.btn-danger{
  background:var(--dangerBg);
  border-color:var(--dangerBorder);
}

.btn-success{
  background:#10b981;
  color:#fff;
  border-color:#10b981;
}

.btn:disabled{
  opacity:.55;
  cursor:not-allowed;
  box-shadow:none;
}

.btn-sm{
  padding:7px 10px;
  min-height:34px;
  font-size:13px;
}

button:disabled {
  opacity: .6;
  cursor: not-allowed;
  pointer-events: none;
}

/* =====================
   DIVIDER
   ===================== */
.divider{
  width:1px;
  height:28px;
  background:var(--border);
  margin:0 2px;
}

/* =====================
   LAYOUT
   ===================== */
.page{
  max-width:1180px;
  margin:0 auto;
}

.table-card{
  max-width:1180px;
  margin:0 auto;
}

/* =====================
   TABLA
   ===================== */
.table-wrap{
  overflow:auto;
  -webkit-overflow-scrolling:touch;
  border-radius:var(--radius);
  border:1px solid var(--border);
}

table{
  width:100%;
  border-collapse:collapse;
  background:#FFFDF6;
  border:1px solid #A87B50;
}

th, td{
  border:1px solid #A87B50;
  padding:10px 9px;
  text-align:left;
  font-size:14px;
  vertical-align:top;
  white-space:nowrap;
}

td{
  max-width:320px;
  overflow:hidden;
  text-overflow:ellipsis;
}

tr:hover td{
  background:#F5EBD8;
}

th{
  position:sticky;
  top:0;
  background:#4A1C00;
  color:#FFF8F0;
  z-index:1;
  font-size:12px;
  text-transform:uppercase;
  letter-spacing:.4px;
  font-weight:600;
  font-family:'Inter', Arial, sans-serif;
}

.actions-cell{
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:wrap;
}

/* =====================
   MODAL
   ===================== */
.modal{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.65);
  display:none;
  align-items:center;
  justify-content:center;
  z-index:9999;
  padding:16px;
  overflow-y:auto;
}

/* El modal de PIN es una verificacion que debe quedar siempre por encima de
   cualquier otro modal ya abierto (ej. Ver cuenta), sin importar el orden en el HTML. */
#modalPin{
  z-index:10050;
}

.modal:not(.hidden){
  display:flex;
}

/* El scroll de la ventana no se pasa a la pagina de atras */
.modal,
.modal-card,
[data-ventana-emergente]{
  overscroll-behavior:contain;
}

.modal.hidden{ display:none !important; }

.modal-card{
  width:min(720px, 94vw);
  max-height:90vh;
  overflow-y:auto;
  background:#FFFDF6;
  border-radius:16px;
  border:1px solid var(--border);
  padding:14px;
  box-shadow:var(--shadowStrong);
  display:flex;
  flex-direction:column;
}

.modal-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  border-bottom:1px solid var(--border2);
  padding-bottom:10px;
  margin-bottom:10px;
}

.modal-header h3{
  margin:0;
  font-size:16px;
}

.modal-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  border-bottom:1px solid var(--border2);
  padding-bottom:10px;
  margin-bottom:10px;
}

.modal-head h3{
  margin:0;
  font-size:16px;
}

.modal-actions{
  display:flex;
  justify-content:flex-end;
  gap:10px;
  margin-top:12px;
  border-top:1px solid var(--border2);
  padding-top:10px;
  flex-wrap:wrap;
}

.modal .input,
.modal select,
.modal textarea{
  width:100%;
}

textarea.input{
  resize:vertical;
  min-height:90px;
  line-height:1.35;
}

/* =====================
   FORM GRID
   ===================== */
.form-grid{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:10px;
}

.form-grid label{
  color:var(--muted);
  font-size:12px;
  display:block;
  margin-bottom:6px;
}

.form-grid .full{ grid-column:1/-1; }

.grid-form{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:12px;
  margin-top:10px;
}

.grid-form label{
  display:flex;
  flex-direction:column;
  gap:5px;
  font-size:13px;
  color:var(--muted);
}

/* =====================
   CHECKBOX
   ===================== */
.check-row{
  display:flex;
  align-items:center;
  gap:10px;
  margin-top:6px;
}
.check-row input[type="checkbox"]{
  width:18px;
  height:18px;
  accent-color:var(--primary);
}

/* =====================
   TOAST
   ===================== */
.toast{
  position:fixed;
  right:16px;
  bottom:16px;
  background:var(--primary);
  color:#fff;
  padding:10px 12px;
  border-radius:12px;
  z-index:10000;
  box-shadow:0 12px 28px rgba(0,0,0,.18);
  max-width:min(380px, 90vw);
  font-size:14px;
}
.toast.hidden{ display:none; }

/* =====================
   SUG (AUTOCOMPLETE)
   ===================== */
.sug{
  margin-top:6px;
  border:1px solid #C9A87A;
  background:#FFFDF6;
  border-radius:10px;
  overflow:hidden;
  max-height:240px;
  overflow:auto;
  box-shadow:0 10px 22px rgba(74,28,0,.12);
  position:relative;
  z-index:50;
}

.sug-item{
  padding:10px;
  cursor:pointer;
  border-bottom:1px solid #E2CBA8;
  line-height:1.25;
  font-size:13px;
}

.sug-item:hover{
  background:#F5EBD8;
}

/* =====================
   TOTALES
   ===================== */
.totals{
  display:flex;
  gap:18px;
  justify-content:flex-end;
  margin-top:12px;
  flex-wrap:wrap;
}

/* =====================
   VALIDACIÓN
   ===================== */
.req{
  color:#e11d48;
  font-weight:700;
  margin-left:6px;
}
.req-txt{
  color:#64748b;
  font-size:12px;
  margin-left:6px;
}
.input-error{
  border:2px solid #e11d48 !important;
  outline:none;
}

/* =====================
   VENTAS
   ===================== */
.ventas-card{ position:relative; }

.ventas-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  margin-bottom:10px;
  flex-wrap:wrap;
  gap:8px;
}

.ventas-title{ margin:0; }

.ventas-grid{
  display:grid;
  grid-template-columns:360px 360px;
  gap:12px 28px;
  justify-content:start;
  align-items:start;
}

/* =====================
   DETALLE HEAD
   ===================== */
.detalle-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  margin-bottom:10px;
  flex-wrap:wrap;
  gap:8px;
}

.detalle-title{ margin:0; }

/* =====================
   CONTABILIDAD
   ===================== */
.conta-filters{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  margin-top:12px;
  align-items:center;
}
.conta-filters .input{ min-width:180px; }
.link{ text-decoration:underline; }

#contPreviewBody{
  flex:1;
  min-height:0;
  background:#111;
  overflow:hidden;
}

/* =====================
   PEDIDOS
   ===================== */
.day-group{
  border-bottom:1px solid var(--border2);
  padding-bottom:16px;
}

/* =====================
   UTILIDADES
   ===================== */
.hidden{ display:none !important; }
.spacer{ flex:1; }
.muted{ color:#777; }

/* =====================
   NAVEGACIÓN ACTIVA
   ===================== */
.nav-btn {
  background: #4A1C00;
  color: #FFF8F0;
  border-color: #4A1C00;
}

.nav-btn:hover {
  background: #6B3010;
  border-color: #6B3010;
}

.nav-btn.active {
  background: #B8860B;
  border-color: #B8860B;
  box-shadow: 0 4px 12px rgba(184, 134, 11, 0.45);
}

/* =====================
   VISTA DE INICIO
   ===================== */
#view-home {
  max-width: 1100px;
  margin: 40px auto;
  padding: 20px;
}

.home-container {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 60px 80px;
  box-shadow: var(--shadow);
  text-align: center;
}

.home-logo {
  display: flex;
  justify-content: center;
  align-items: center;
}

.home-logo img {
  max-width: 450px;
  width: 100%;
  height: auto;
  border-radius: 0;
}

/* ============================================
   RESPONSIVE DESIGN - MOBILE FIRST
   ============================================ */

/* Tablets y móviles grandes (max 768px) */
@media (max-width: 768px) {
  
  body{ padding:18px 12px; }
  
  /* Header y navegación */
  h1 {
    font-size: 1.3rem;
    margin-bottom:12px;
  }
  
  .topbar button {
    font-size: 0.85rem;
    padding: 8px 12px;
  }
  
  /* Cards */
  .card {
    padding: 12px;
  }
  
  /* Formularios */
  .form-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  
  .grid-form{
    grid-template-columns: 1fr;
  }
  
  .full {
    grid-column: 1;
  }
  
  /* Inputs */
  .input, select, textarea {
    font-size: 16px; /* Evita zoom en iOS */
  }
  
  /* Tablas responsive */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  table {
    min-width: 600px;
    font-size: 0.85rem;
  }
  
  th, td {
    padding: 8px;
    white-space: nowrap;
  }
  
  /* Modales */
  .modal-card {
    width: 95% !important;
    max-width: 95% !important;
    margin: 10px;
    max-height: 90vh;
    overflow-y: auto;
  }
  
  /* Botones en filas */
  .modal-actions {
    flex-direction: column;
    gap: 8px;
  }
  
  .modal-actions button {
    width: 100%;
  }
  
  /* Detalle de venta */
  .detalle-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  
  .detalle-title {
    text-align: center;
  }
  
  /* Totales */
  .totals {
    font-size: 0.9rem;
    flex-direction: column;
    align-items: flex-start;
    gap:6px;
  }
  
  /* Ventas grid */
  .ventas-grid {
    grid-template-columns: 1fr;
  }
  
  .ventas-head {
    flex-direction: column;
    gap: 10px;
    align-items:stretch;
  }
  
  .ventas-btn-precios {
    width: 100%;
  }
  
  /* Filtros responsive */
  .topbar.filtros {
    flex-direction: column;
    align-items: stretch;
  }
  
  .topbar.filtros label {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 5px;
  }
  
  .topbar.filtros .input,
  .topbar.filtros select {
    width: 100%;
  }
  
  .topbar.filtros .btn{
    width:100%;
    text-align:center;
  }
  
  /* Contabilidad filtros */
  .conta-filters{
    flex-direction: column;
    align-items: stretch;
  }
  
  .conta-filters .input,
  .conta-filters .btn{
    width: 100%;
  }
  
  /* Vista home responsive */
  #view-home {
    max-width: 95%;
    margin: 20px auto;
    padding: 10px;
  }
  
  .home-container {
    padding: 40px 20px;
  }
  
  .home-logo img {
    max-width: 400px;
  }
}


/* Tablets y móviles grandes (max 768px) */
@media (max-width: 768px) {
  .hide-mobile {
    display: none !important;
  }
}

/* Móviles pequeños (max 480px) */
@media (max-width: 480px) {
  
  body{ padding:10px 8px; }
  
  /* Navegación principal con scroll horizontal */
  .card.topbar{
    flex-wrap:nowrap;
    overflow-x:auto;
    -webkit-overflow-scrolling:touch;
    padding:10px;
    gap:6px;
    scrollbar-width:none;
  }
  
  .card.topbar::-webkit-scrollbar{ display:none; }
  
  .card.topbar .btn{
    padding:8px 10px;
    font-size:12px;
    min-height:36px;
    flex-shrink:0;
    white-space:nowrap;
  }
  
  .spacer {
    display: none;
  }
  
  #btnRecargar{
    margin-left:auto;
    flex-shrink:0;
  }
  
  /* Títulos */
  h1 {
    font-size: 1.1rem;
  }
  
  h2 {
    font-size: 1rem;
  }
  
  h3 {
    font-size: 0.95rem;
  }
  
  /* Botones más grandes para touch */
  .btn {
    min-height: 44px;
    padding: 10px 15px;
  }
  
  /* Tablas más compactas */
  table {
    font-size: 0.75rem;
  }
  
  th, td {
    padding: 6px;
  }
  
  /* Ocultar columnas menos importantes en móvil */
  .hide-mobile {
    display: none !important;
  }
  
  /* Toast más pequeño */
  .toast {
    bottom: 10px;
    left: 10px;
    right: 10px;
    max-width: calc(100% - 20px);
    font-size: 0.9rem;
  }
  
  /* Modal: sube desde abajo */
  .modal{
    padding:0;
    align-items:flex-end;
  }

  .modal-card{
    width:100%;
    max-width:100%;
    max-height:92vh;
    border-radius:16px 16px 0 0;
    padding:14px;
  }

  .modal-head h3,
  .modal-header h3{ font-size:15px; }
  
  /* Botones acción en tablas */
  .actions-cell{
    flex-direction:column;
    gap:4px;
  }

  .actions-cell .btn{
    width:100%;
    font-size:12px;
    padding:6px 8px;
  }
  
  /* Pedidos: header del día */
  .day-group > div:first-child{
    flex-direction:column !important;
    align-items:flex-start !important;
    gap:10px;
  }

  .day-group > div:first-child > div:last-child{
    width:100%;
    display:flex;
    gap:8px;
  }

  .day-group > div:first-child > div:last-child .btn{
    flex:1;
    font-size:12px;
    padding:8px 6px;
    text-align:center;
  }

  /* Resumen producción: fila producto */
  [id^="prod-row-"] > div:first-child{
    flex-direction:column !important;
    align-items:flex-start !important;
    gap:8px;
  }

  [id^="prod-row-"] > div:first-child > div:last-child{
    width:100%;
    display:flex;
    flex-wrap:wrap;
    gap:6px;
  }

  [id^="prod-row-"] > div:first-child > div:last-child .btn{
    flex:1;
    font-size:12px;
    text-align:center;
  }

  /* Form cantidad pendiente */
  [id^="pendiente-form-"]{
    flex-wrap:wrap !important;
    gap:8px !important;
  }

  [id^="pendiente-form-"] input[type="number"]{
    width:100% !important;
  }

  [id^="pendiente-form-"] .btn{
    width:100%;
    text-align:center;
  }
  
  /* Historial */
  #historialContainer .table-wrap table{
    min-width:580px;
  }
  
  /* Sug */
  .sug-item{ padding:9px 10px; font-size:12px; }
  
  /* Vista home en móvil */
  #view-home {
    margin: 10px;
    padding: 5px;
  }
  
  .home-container {
    padding: 30px 15px;
  }
  
  .home-logo img {
    max-width: 300px;
  }
}

/* Móvil muy pequeño (max 380px) */
@media (max-width:380px){
  h1{ font-size:17px; }
  .card.topbar .btn{
    padding:7px 8px;
    font-size:11px;
  }
  th, td{ font-size:11px; padding:6px 5px; }
  
  .home-logo img {
    max-width: 250px;
  }
}

/* Landscape en móviles */
@media (max-height: 500px) and (orientation: landscape) {
  .modal-card {
    max-height: 95vh;
    overflow-y: auto;
  }
}

/* Mejoras para touch */
@media (hover: none) and (pointer: coarse) {
  /* Dispositivos táctiles */
  .btn, button, a {
    min-height: 44px;
    min-width: 44px;
  }
  
  input, select, textarea {
    font-size: 16px; /* Evita zoom automático en iOS */
  }
}


@media (max-width: 600px) {
  button.btn {
    white-space: normal;
    word-break: break-word;
    font-size: 0.75em;
    padding: 4px 6px;
  }
}

/* =====================
   ITEMS DE DESPACHO (Cuentas)
   ===================== */
.despacho-item-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 8px;
  align-items: center;
  background: rgba(255,255,255,0.03);
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 8px;
}
.despacho-item-nombre {
  font-size: 0.9em;
  font-weight: 600;
}
.despacho-item-precio {
  font-size: 0.9em;
  color: #a0aec0;
  white-space: nowrap;
}
.despacho-item-row .despachoItemCantidad {
  margin: 0;
}
.despacho-item-row .btnQuitarItemDespacho {
  padding: 4px 8px;
  font-size: 12px;
}

/* En pantallas angostas (celulares) el grid de 4 columnas comprime todo:
   el nombre del producto se parte en muchas lineas y la casilla de
   cantidad queda tan angosta que corta el numero. Se apila en 2 filas:
   nombre completo arriba, y cantidad/precio/quitar en una fila abajo. */
@media (max-width: 600px) {
  .despacho-item-row {
    grid-template-columns: 1fr 1fr auto;
    grid-template-areas:
      "nombre nombre nombre"
      "cantidad precio quitar";
  }
  .despacho-item-nombre {
    grid-area: nombre;
    margin-bottom: 4px;
  }
  .despacho-item-row .despachoItemCantidad {
    grid-area: cantidad;
    width: 100%;
    font-size: 1.05em;
    text-align: center;
  }
  .despacho-item-precio {
    grid-area: precio;
    text-align: center;
  }
  .despacho-item-row .btnQuitarItemDespacho {
    grid-area: quitar;
    justify-self: end;
  }
}

/* =====================
   BLOQUEAR SCROLL FONDO
   CUANDO HAY MODAL ABIERTO
   ===================== */
body.modal-open {
  overflow: hidden !important;
}

/* =====================
   CUENTAS: DESPACHOS Y ABONOS
   Las filas se acomodan en varias lineas cuando no caben (celulares) en vez
   de montarse unas sobre otras.
   ===================== */
.despacho-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(120,90,60,0.18);
  border-radius: 8px;
  overflow: hidden;
}
.despacho-card-head {
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}
.despacho-card-info { flex: 1 1 170px; min-width: 0; }
.despacho-card-titulo { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.despacho-card-fecha { font-weight: 700; white-space: nowrap; }
.despacho-card-badge {
  padding: 2px 8px; border-radius: 12px; font-size: 0.75em; font-weight: 700;
  color: #fff; white-space: nowrap;
}
.despacho-card-desc {
  font-size: 0.8em; color: #a0aec0; margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.despacho-card-acciones {
  display: flex; align-items: center; gap: 8px; margin-left: auto; flex-shrink: 0;
}
.despacho-card-total { font-weight: 900; white-space: nowrap; }
.despacho-card-acciones .btn { font-size: 11px; padding: 3px 8px; min-height: 30px; white-space: nowrap; }
.despacho-card-acciones .det-chevron { color: #a0aec0; font-size: 0.8em; padding: 0 2px; }
.despacho-card-detalle { border-top: 1px solid rgba(120,90,60,0.18); }

.despacho-items-head,
.despacho-item-fila {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 56px 90px 100px;
  gap: 8px;
  padding: 7px 10px;
  align-items: center;
}
.despacho-items-head {
  background: rgba(0,0,0,0.04); font-size: 0.76em; color: #6b7280; text-transform: uppercase;
}
.despacho-items-head span:nth-child(n+2) { text-align: right; }
.despacho-items-head span:nth-child(2) { text-align: center; }
.despacho-item-fila { border-bottom: 1px solid rgba(0,0,0,0.06); }
.despacho-item-fila:last-child { border-bottom: none; }
.di-nombre { font-size: 0.85em; overflow-wrap: anywhere; }
.di-cant { text-align: center; font-weight: 700; }
.di-precio { text-align: right; color: #a0aec0; font-size: 0.82em; white-space: nowrap; }
.di-valor { text-align: right; font-weight: 600; font-size: 0.85em; white-space: nowrap; }

.abono-card {
  background: rgba(16,185,129,0.05);
  padding: 12px 15px;
  border-radius: 8px;
  border: 1px solid rgba(16,185,129,0.2);
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center;
  gap: 8px 12px;
}
.abono-card-info { flex: 1 1 150px; min-width: 0; }
.abono-card-fecha { font-weight: 700; color: #10b981; }
.abono-card-desc { color: #a0aec0; font-size: 0.85em; margin-left: 10px; overflow-wrap: anywhere; }
.abono-card-acciones { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.abono-card-monto { font-weight: 900; color: #10b981; font-size: 1.1em; white-space: nowrap; }
.abono-card-acciones .btn { font-size: 12px; padding: 4px 8px; min-height: 30px; white-space: nowrap; }

@media (max-width: 600px) {
  .despacho-card-acciones { width: 100%; justify-content: flex-end; }
  .despacho-card-total { margin-right: auto; font-size: 1.05em; }
  .despacho-card-desc { white-space: normal; }

  /* La cabecera de la tabla se oculta y cada producto pasa a 2 lineas:
     nombre completo arriba, y "cantidad x precio ...... valor" abajo. */
  .despacho-items-head { display: none; }
  .despacho-item-fila {
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "nombre nombre nombre"
      "cant precio valor";
    row-gap: 2px;
  }
  .di-nombre { grid-area: nombre; font-weight: 600; }
  .di-cant { grid-area: cant; text-align: left; }
  .di-cant::after { content: " ×"; font-weight: 400; color: #a0aec0; }
  .di-precio { grid-area: precio; text-align: left; }
  .di-valor { grid-area: valor; }
}


/* =====================
   AJUSTES GENERALES PARA CELULAR
   Muchas filas de la app se arman con estilos en linea (texto a la izquierda,
   importe y botones a la derecha). En pantallas angostas se deben poder acomodar
   en varias lineas en vez de montarse o cortarse.
   ===================== */
@media (max-width: 600px) {
  [style*="justify-content:space-between"]:not(.modal-head),
  [style*="justify-content: space-between"]:not(.modal-head) {
    flex-wrap: wrap !important;
    row-gap: 8px;
  }

  /* Formularios de 2 columnas dentro de ventanas: 1 columna en el celular */
  .modal [style*="grid-template-columns:1fr 1fr"],
  .modal [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Filas de productos con 4 columnas fijas (crear cotizacion): nombre arriba, resto abajo */
  .cr-row { grid-template-columns: 1fr 1fr auto !important; }
  .cr-row .cr-nombre { grid-column: 1 / -1; }
}


/* =====================
   PANEL DE DESPACHO (Pedidos)
   ===================== */
.desp-panel { display: grid; gap: 18px; }
.desp-titulo-panel { margin: 0; }
.desp-seccion { border: 1px solid var(--border); border-radius: 12px; padding: 12px; background: #FFFDF6; }
.desp-seccion-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 10px; }
.desp-seccion-head h3 { margin: 0; font-size: 1.05em; }
.desp-contador { background: var(--primary); color: #fff; border-radius: 12px; padding: 1px 9px; font-size: 0.8em; margin-left: 6px; }
.desp-sec-hoy { border-left: 6px solid #16a34a; }
.desp-sec-manana { border-left: 6px solid #6366f1; }
.desp-sec-atrasados { border-left: 6px solid #ef4444; background: #fff5f5; }
.desp-bulk { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 10px; padding: 8px 12px; border-radius: 8px; background: rgba(22,163,74,0.08); border: 1px solid rgba(22,163,74,0.3); }
.desp-bulk label { display: flex; align-items: center; gap: 6px; cursor: pointer; margin: 0; }
.desp-despachar { background: #16a34a; color: #fff; border-color: #16a34a; }
.desp-despachar:disabled { opacity: 0.5; }

.desp-card { background: #fff; border: 1px solid var(--border2); border-radius: 10px; padding: 12px; margin-bottom: 12px; border-left: 4px solid #6366f1; }
.desp-card.desp-hoy { border-left-color: #16a34a; }
.desp-card.desp-atrasados { border-left-color: #ef4444; }
.desp-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 12px; margin-bottom: 8px; }
.desp-titulo { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.desp-titulo input[type="checkbox"] { transform: scale(1.3); }
.desp-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.desp-badge { padding: 3px 9px; border-radius: 12px; font-size: 0.78em; font-weight: 700; color: #fff; background: #6b7280; }
.desp-b-ok { background: #16a34a; }
.desp-b-espera { background: #c2410c; }
.desp-b-atraso { background: #ef4444; }
.desp-b-prog { background: #6366f1; }
.desp-info { display: grid; gap: 3px; font-size: 0.9em; margin-bottom: 8px; }
.desp-desc { white-space: pre-wrap; color: #555; }
.desp-razon { color: #b45309; }
.desp-items { border-top: 1px solid var(--border2); margin-top: 6px; }
.desp-item { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid rgba(0,0,0,0.07); }
.desp-item b { white-space: nowrap; }
.desp-item-nota { display: block; color: #b45309; font-size: 0.85em; }
.desp-nota-box { margin-top: 10px; padding: 10px; border-radius: 8px; background: #f7f1e3; display: grid; gap: 6px; }
.desp-nota-box.con-nota { background: #fff8ed; border: 1px solid #f59e0b; }
.desp-nota-box label { font-weight: 700; font-size: 0.85em; color: #7A5C3E; }
.desp-nota-box .btn { justify-self: start; }
.desp-acciones { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; justify-content: flex-end; }
.desp-totales { margin-top: 8px; }
.desp-totales summary, .desp-otros summary { cursor: pointer; font-weight: 600; color: var(--muted); }
.desp-totales-lista { display: grid; gap: 4px; margin-top: 6px; }
.desp-totales-lista div { display: flex; justify-content: space-between; gap: 12px; padding: 4px 8px; background: #f7f1e3; border-radius: 6px; }
.desp-otros { border: 1px dashed var(--border); border-radius: 12px; padding: 10px 12px; }
.desp-otro { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px 12px; padding: 7px 0; border-bottom: 1px solid rgba(0,0,0,0.07); }
.desp-otro-btns { display: flex; gap: 6px; }
.desp-vacio { margin: 6px 0; }

@media (max-width: 600px) {
  .desp-acciones { justify-content: stretch; }
  .desp-acciones .btn { flex: 1 1 auto; }
  .desp-nota-box .btn { justify-self: stretch; }
}


/* Pedidos atrasados: boton + ventana */
.desp-panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px; }
.desp-btn-atrasados { background: #ef4444; color: #fff; border-color: #ef4444; font-weight: 700; }
.atr-modal { width: min(900px, 96vw); }
.atr-card { background: #fff; border: 1px solid var(--border2); border-left: 4px solid #ef4444; border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
.atr-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px 12px; }
.atr-titulo { display: flex; align-items: center; gap: 8px; cursor: pointer; margin: 0; }
.atr-titulo input[type="checkbox"] { transform: scale(1.3); }
.atr-info { font-size: 0.88em; color: #555; margin: 4px 0; }
.atr-items { border-top: 1px solid var(--border2); }
.atr-item { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-bottom: 1px solid rgba(0,0,0,0.06); font-size: 0.92em; }
.atr-item b { white-space: nowrap; }
.atr-nota { margin-top: 6px; padding: 6px 10px; background: #fff8ed; border: 1px solid #f59e0b; border-radius: 6px; color: #b45309; font-size: 0.88em; white-space: pre-wrap; }
.atr-acciones { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin-top: 10px; }
.atr-fecha-lbl { display: grid; gap: 3px; font-size: 0.8em; color: var(--muted); margin: 0; }
.atr-fecha { width: auto; }
.atr-ok { background: #16a34a; color: #fff; border-color: #16a34a; }
@media (max-width: 600px) {
  .atr-acciones .btn { flex: 1 1 auto; }
  .atr-fecha-lbl { flex: 1 1 100%; }
  .atr-fecha { width: 100%; }
}


/* Botones del panel de despachos (cada uno abre su ventana) */
.desp-botones { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.desp-btn { font-weight: 700; }
.desp-btn-hoy { background: #16a34a; color: #fff; border-color: #16a34a; }
.desp-btn-manana { background: #6366f1; color: #fff; border-color: #6366f1; }
.desp-btn-otros { background: #fff; color: var(--muted); border-style: dashed; }
.atr-modal .desp-seccion { border: none; padding: 0; background: transparent; }
@media (max-width: 600px) {
  .desp-botones .btn { flex: 1 1 100%; }
}

/* ===== Usuario Mario: Pedidos solo para ver =====
   Se ocultan los controles que cambian pedidos (el servidor tambien los bloquea). */
body.solo-ver-pedidos #btnCrearPedido,
body.solo-ver-pedidos #btnOCAutomaticas,
body.solo-ver-pedidos #btnClientesPedidos,
body.solo-ver-pedidos .btnEditarPedido,
body.solo-ver-pedidos .btnEliminarPedido,
body.solo-ver-pedidos .btnEditarHist,
body.solo-ver-pedidos .chk-pedido-bulk,
body.solo-ver-pedidos #view-pedidos div:has(> [id^="btnDespacharSeleccionados-"]),
body.solo-ver-pedidos [data-estado-prod],
body.solo-ver-pedidos [id^="pendiente-form-"],
body.solo-ver-pedidos .desp-acciones,
body.solo-ver-pedidos .desp-bulk,
body.solo-ver-pedidos .chk-desp,
body.solo-ver-pedidos .desp-guardar-nota,
body.solo-ver-pedidos .desp-nota-box:not(.con-nota),
body.solo-ver-pedidos .atr-acciones,
body.solo-ver-pedidos .atr-chk,
body.solo-ver-pedidos .atr-todos,
body.solo-ver-pedidos label:has(> .atr-todos),
body.solo-ver-pedidos .atr-masivo{
  display:none !important;
}
/* La nota de despacho se puede leer, pero no escribir */
body.solo-ver-pedidos .desp-nota{
  pointer-events:none;
  background:#f5f5f5;
}
