/* ============================================================
   TURING ERP v2 — Estilos por módulo (PR2: Dashboard + CRUD base)
   Reglas específicas de página que NO encajan en tokens/components.
   ============================================================ */

/* ---------- Dashboard (content.php) ---------- */

/* reports.js hace append de <h3>{valor}</h3><p>{label}</p> dentro de los
   contenedores .amountTotalSales / .amountTotalBuying / .amountCost /
   .amountTotalSale. Estilamos esas etiquetas para que caigan como
   .kpi-val / .kpi-lab sin tocar reports.js. */
.kpi .amountTotalSales,
.kpi .amountTotalBuying,
.kpi .amountCost,
.kpi .amountTotalSale{ display:flex; flex-direction:column; gap:4px; }

.kpi .amountTotalSales h3, .kpi .amountTotalSales h4,
.kpi .amountTotalBuying h3, .kpi .amountTotalBuying h4,
.kpi .amountCost h3, .kpi .amountCost h4,
.kpi .amountTotalSale h3, .kpi .amountTotalSale h4{
  font-family: var(--font-mono);
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--fg-1);
  line-height: 1.1;
  margin: 0;
  font-variant-numeric: tabular-nums;
}
.kpi .amountTotalSales h3, .kpi .amountTotalBuying h3,
.kpi .amountCost h3, .kpi .amountTotalSale h3 { font-size: 24px; }
.kpi .amountTotalSales h4, .kpi .amountTotalBuying h4,
.kpi .amountCost h4, .kpi .amountTotalSale h4 { font-size: 19px; }

.kpi .amountTotalSales p, .kpi .amountTotalBuying p,
.kpi .amountCost p, .kpi .amountTotalSale p{
  /* El label ya lo pintamos arriba en .kpi-lab; ocultamos el <p>
     que inyecta reports.js para no duplicar. */
  display: none;
}

.kpi-accent-bar{
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; border-radius: 3px 0 0 3px;
  background: var(--accent);
}
.kpi-accent-bar.success { background: var(--success); }
.kpi-accent-bar.warning { background: var(--warning); }
.kpi-accent-bar.danger  { background: var(--danger); }
.kpi-accent-bar.info    { background: var(--info); }

.kpi-cta{
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; color: var(--fg-3); text-decoration: none;
  transition: color .12s ease;
}
.kpi-cta:hover{ color: var(--accent); }

.chart-card .card-body{ padding: 16px; }
#myChart{ max-height: 360px; }

/* ---------- CRUD genérico (usuarios / clientes / productos) ---------- */

/* Toolbar encima de la tabla — reemplaza el antiguo .box-header.with-border */
.page-toolbar{
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-3) var(--r-3) 0 0;
  border-bottom: 0;
  flex-wrap: wrap;
}
.page-toolbar .right{ margin-left: auto; display: flex; gap: 6px; align-items: center; }

/* Card que contiene la tabla (abajo del toolbar) */
.table-card{
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--r-3) var(--r-3);
  overflow: hidden;
}
.table-card .table-wrap{ padding: 4px 4px 0; }

/* Badges de estado (reemplazan <button class="btn btn-xs btn-success">Activado</button>) */
.status-badge{
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 8px;
  font-size: 11px; font-weight: 550; letter-spacing: .01em;
  border-radius: var(--r-pill);
  border: 1px solid transparent;
}
.status-badge.on  { background: var(--success-soft); color: var(--success-ink); }
.status-badge.off { background: var(--danger-soft);  color: var(--danger-ink); }

/* Accciones en la última columna de la tabla */
.row-actions{ display: inline-flex; gap: 4px; }
.row-actions .btn{ height: 28px; padding: 0 8px; font-size: 12px; }
.row-actions .btn-icon{ width: 28px; padding: 0; }

/* Thumb pequeño (foto de usuario en la tabla) */
.cell-avatar{
  width: 32px; height: 32px; border-radius: 50%;
  object-fit: cover; border: 1px solid var(--border);
  background: var(--bg-subtle);
}

/* ---------- Modales v2 (CRUD forms) ---------- */

/* Los modales existentes usan la estructura de Bootstrap 3 (.modal-dialog >
   .modal-content > .modal-header + .modal-body + .modal-footer).
   Las reglas de components.css ya los estilizan, pero varios modales tienen
   style="background:#3c8dbc; color:white" inline en el header.
   Estos modales migrados ya no incluyen ese estilo; en su lugar usan
   .modal-header.accent para un header con tonalidad indigo suave. */
.modal-header.accent{
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-bottom: 1px solid var(--divider);
}
.modal-header.accent .modal-title{ color: var(--accent-ink); font-weight: 600; }
.modal-header.accent .close{
  color: var(--accent-ink); opacity: 0.6;
  background: transparent; border: 0; font-size: 20px;
  line-height: 1; padding: 0 4px; cursor: pointer;
}
.modal-header.accent .close:hover{ opacity: 1; }

/* Ancho de modal según necesidad (por defecto 560px en components.css) */
.modal-content.md-wide .modal-content,
.modal-dialog.md-wide .modal-content{ width: min(720px, 94vw); }
.modal-dialog.md-wide{ width: min(720px, 94vw); margin: 30px auto; }

/* Body de modal — reemplaza .box-body anidado que hacía de contenedor */
.modal-body > .box-body{ padding: 0; }

/* Grupo de campos (columnas dentro del modal) */
.form-grid{ display: grid; gap: 10px; grid-template-columns: repeat(12, 1fr); }
.form-grid > .col-12{ grid-column: span 12; }
.form-grid > .col-6 { grid-column: span 6; }
.form-grid > .col-4 { grid-column: span 4; }
@media (max-width: 540px){
  .form-grid > .col-6, .form-grid > .col-4 { grid-column: span 12; }
}

/* Input con icono principal (reemplazo de .input-group + .input-group-addon) */
.field-with-icon{
  display: flex; align-items: stretch;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-2);
  background: var(--bg-surface);
  overflow: hidden;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.field-with-icon:focus-within{
  border-color: var(--accent);
  box-shadow: var(--sh-ring);
}
.field-with-icon > .ico{
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; background: var(--bg-subtle);
  color: var(--fg-3); font-size: 13px;
  border-right: 1px solid var(--border);
}
.field-with-icon > .input,
.field-with-icon > input,
.field-with-icon > select{
  flex: 1; border: 0; background: transparent;
  height: var(--input-h);
  padding: 0 10px; font-family: inherit; font-size: 13px;
  color: var(--fg-1);
  outline: none;
}
.field-with-icon > input:focus,
.field-with-icon > select:focus{ outline: none; box-shadow: none; }

/* Sección de permisos dentro del modal (accordion) */
.perm-section{
  border-top: 1px solid var(--divider);
  margin-top: 12px; padding-top: 12px;
}
.perm-section-title{
  font-size: 12px; font-weight: 600; color: var(--fg-2);
  letter-spacing: .02em; margin: 0 0 8px;
  display: flex; align-items: center; gap: 6px; cursor: pointer;
  user-select: none;
}
.perm-section-title .caret{
  font-size: 10px; color: var(--fg-3); transition: transform .15s ease;
}
.perm-section.open .perm-section-title .caret{ transform: rotate(90deg); }
.perm-section-body{ display: none; }
.perm-section.open .perm-section-body{ display: block; }
.perm-grid{
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px 14px; font-size: 12.5px;
}
.perm-grid label{
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--fg-1); cursor: pointer; margin: 0;
  font-weight: 400;
}
.perm-grid input[type="checkbox"]{ margin: 0; }
@media (max-width: 540px){
  .perm-grid{ grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Ventas / Detalle de factura ---------- */

/* Botones de acciones dentro del #modalInvoiceDetail (venta, anular, débito,
   imprimir). Antes era un grid de 2x2 con .col-md-6 + margenes inline. */
.invoice-actions{
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px; margin-top: 14px;
}
.invoice-actions .btn{ justify-content: center; }

/* ---------- Reportes: page-toolbar extendido ---------- */

.page-toolbar .right label{ white-space: nowrap; margin: 0; }
.page-toolbar .btn + .btn{ margin-left: 0; }

/* ---------- POS (crearVenta.php) — v2 rewrite ---------- */

/* Grid responsivo de 2 columnas: form + tabla de productos.
   En ≤992px se apila (tabla debajo del form) y sigue siendo usable. */
.pos-page .pos-grid{
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
@media (max-width: 992px){
  .pos-page .pos-grid{ grid-template-columns: 1fr; }
}
.pos-page .pos-col{ min-width: 0; }

/* Card del POS — hereda .card de components.css, suma acentos de color */
.pos-page .pos-card{ margin-bottom: 0; }
.pos-page .pos-card-form{ border-top: 3px solid var(--success, #17a673); }
.pos-page .pos-card-list{ border-top: 3px solid var(--warning, #f39c12); }
.pos-page .pos-card .card-header{
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--divider);
}
.pos-page .pos-card .card-title{
  margin: 0; font-size: 14px; font-weight: 600; color: var(--fg-1);
  display: inline-flex; align-items: center; gap: 8px;
}
.pos-page .pos-card .card-title i{ color: var(--accent); }
.pos-page .pos-form-body{ padding: 14px; }
/* overflow:hidden para suprimir el scroll horizontal innecesario que aparecía
   por una diferencia de pocos píxeles en la cabecera del datatable. La tabla
   misma puede scrollear internamente vía .table-responsive si hace falta. */
.pos-page .pos-list-body{ padding: 10px 12px; overflow-x: hidden; }

/* Campos del form */
.pos-page .pos-field{ margin-bottom: 12px; }
.pos-page .pos-label{
  display: block;
  font-size: 12px; font-weight: 600;
  color: var(--fg-2); margin: 0 0 4px 2px;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.pos-page .pos-row-inline{
  display: flex; gap: 8px; align-items: stretch;
  flex-wrap: wrap;
}
.pos-page .pos-row-inline .pos-grow{ flex: 1 1 220px; min-width: 0; }
.pos-page .pos-btn-compact{
  flex: 0 0 auto;
  white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.pos-page .pos-sep{
  border: 0; border-top: 1px solid var(--divider);
  margin: 14px 0;
}

/* Totales: 3 columnas en desktop, 1 columna en móvil */
.pos-page .pos-totals{
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
@media (max-width: 560px){
  .pos-page .pos-totals{ grid-template-columns: 1fr; }
}
.pos-page .pos-total{ display: flex; flex-direction: column; min-width: 0; }
.pos-page .pos-total input{ font-variant-numeric: tabular-nums; }
.pos-page .pos-total-final{
  font-size: 18px; font-weight: 600;
  color: var(--success, #17a673);
}

/* Método de pago: fila flexible que envuelve en móvil */
.pos-page .pos-payment-row{
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  margin: 0 0 12px;
}
.pos-page .pos-field-sm{ flex: 1 1 160px; min-width: 140px; margin: 0; }
.pos-page .pos-payment-inputs{
  flex: 1 1 100%;
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  margin-top: 4px;
}
/* Override de los .col-xs-3 que inyecta purchase.js para los inputs de
   "Paga con" / "Vuelto": sin floats y con ancho razonable. */
.pos-page .pos-payment-inputs > [class*="col-"]{
  float: none !important;
  width: auto !important;
  padding: 0 !important;
  flex: 1 1 160px;
  min-width: 140px;
}
.pos-page .pos-payment-inputs .input-group{
  display: flex !important;
  flex-direction: column;
  width: 100%;
}
.pos-page .pos-payment-inputs .input-group > label{
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--fg-3); margin: 0 0 4px;
}
.pos-page .pos-payment-inputs .input-group > .form-control{
  width: 100% !important; height: 34px; font-size: 13px;
  border-radius: var(--r-2);
}
.pos-page .pos-textarea{ resize: vertical; min-height: 72px; }

/* Checkbox fila (modal descuento) */
.pos-page .pos-chk-row{ padding: 6px 0; }
.pos-chk{
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer; font-size: 13px; color: var(--fg-1);
}
.pos-chk input[type="checkbox"]{ margin: 0; width: 16px; height: 16px; }

/* Acciones del card-footer */
.pos-page .pos-actions{
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 14px;
  background: var(--bg-subtle);
  border-top: 1px solid var(--divider);
}
.pos-page .pos-actions .btn{ display: inline-flex; align-items: center; gap: 6px; }

/* Filas de producto dinámicas inyectadas por purchase.js — migramos el row
   BS3 (floats + col-xs-*) a CSS Grid para evitar el overflow y el wrap
   causado por los pseudo-elementos clearfix de Bootstrap (.row::before y
   .row::after existen como flex items y empujan la última columna a otra
   línea). Con grid + neutralización del clearfix queda garantizado que
   las 5 columnas siempre estén en la misma fila. */
.pos-page .newProduct{ margin: 0 0 8px; }
.pos-page .newProduct .row{
  display: grid !important;
  grid-template-columns:
    minmax(0, 1fr)  /* getProductName: crece */
    44px            /* getProductPAmount: cantidad */
    56px            /* getInitialPriceProduct: precio inicial */
    minmax(0, 88px) /* getProductPrice: total con C$ */
    32px;           /* getProductPAmount: botón descuento */
  gap: 6px;
  align-items: center;
  margin: 0 0 6px;
  min-width: 0;
  /* Buffer de seguridad para que el botón de descuento (última columna)
     nunca quede recortado contra el borde del card. */
  padding-right: 6px;
}
/* Neutralizar el clearfix de Bootstrap para que no aparezcan como grid-items */
.pos-page .newProduct .row::before,
.pos-page .newProduct .row::after{ content: none !important; display: none !important; }
.pos-page .newProduct .row > [class*="col-"]{
  float: none !important;
  width: auto !important;
  padding: 0 !important;
  min-width: 0;
  min-height: 0;
}

/* Override del input-group de BS3 (display:table) a flex para que los
   addons no colapsen y el input ocupe el espacio restante. */
.pos-page .newProduct .row .input-group{
  display: flex !important;
  flex-wrap: nowrap;
  width: 100%;
  min-width: 0;
  align-items: stretch;
}
.pos-page .newProduct .row .input-group > .input-group-addon{
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 6px; font-size: 12px; height: 30px;
  border-radius: var(--r-2) 0 0 var(--r-2);
}
.pos-page .newProduct .row .input-group > .form-control{
  flex: 1 1 0; min-width: 0; width: auto !important;
  height: 30px; padding: 4px 6px; font-size: 12.5px;
  border-radius: 0 var(--r-2) var(--r-2) 0;
}
.pos-page .newProduct .row > .getInitialPriceProduct > input.form-control{
  height: 30px; padding: 4px 6px; font-size: 12.5px; width: 100%;
  border-radius: var(--r-2);
}
.pos-page .newProduct .row > .getProductPAmount > input.form-control{
  height: 30px; padding: 4px 6px; font-size: 12.5px; width: 100%;
  border-radius: var(--r-2); text-align: center;
}

.pos-page .newProduct .deleteOrder{
  height: 26px; line-height: 22px; padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
}
/* La celda del grid que aloja el botón de descuento */
.pos-page .newProduct .row > .getProductPAmount:last-child{
  display: flex; align-items: center; justify-content: center;
}
/* El botón .discountLineProduct hereda .btn (padding 12px / height 32px) con
   !important desde shim-adminlte. Forzamos aquí el tamaño compacto para que
   quepa en su columna sin recortarse ni saltar a la siguiente línea. */
.pos-page .newProduct .discountLineProduct{
  height: 30px !important; width: 30px !important;
  min-width: 30px !important; max-width: 30px !important;
  padding: 0 !important; line-height: 28px; text-align: center;
  display: inline-flex !important; align-items: center; justify-content: center;
  cursor: pointer;
}
.pos-page .newProduct .discountLineProduct > i{ font-size: 12px; }

/* Tabla de productos: altura controlada, scroll interno */
.pos-page .pos-list-body .tablePurchase,
.pos-page .pos-list-body .tableOrderSale{ font-size: 13px; }
.pos-page .pos-list-body .btnAddProduct{ white-space: nowrap; }

/* Panel de gastos del cliente dentro del POS */
.pos-page #clientExpensesPanel{
  border: 1px solid var(--warning, #f39c12) !important;
  background: var(--warning-soft, #fffbea) !important;
  color: var(--fg-1);
  border-radius: var(--r-2);
  margin-top: 10px;
}
.pos-page #clientExpensesPanel strong{ color: var(--warning-ink, #b8691a); }
.pos-page #clientExpensesList{
  background: var(--bg-surface) !important;
  border: 1px solid var(--border) !important;
}

/* Responsive: en móvil los botones del footer ocupan todo el ancho */
@media (max-width: 560px){
  .pos-page .pos-actions .btn{ flex: 1 1 100%; justify-content: center; }
  .pos-page .pos-actions .pull-right{ float: none !important; }
  .pos-page .pos-row-inline .pos-btn-compact{ flex: 1 1 auto; justify-content: center; }

  /* Filas de producto: en móvil redefinimos el grid para que el nombre
     ocupe toda la primera línea y cantidad/precios/descuento vayan debajo. */
  .pos-page .newProduct .row{
    grid-template-columns: 48px minmax(0, 1fr) minmax(0, 1fr) 32px;
    grid-template-areas:
      "name name  name  name"
      "qty  init  price disc";
    row-gap: 4px;
  }
  .pos-page .newProduct .row > .getProductName{ grid-area: name; }
  .pos-page .newProduct .row > .getProductPAmount:not(:last-child){ grid-area: qty; }
  .pos-page .newProduct .row > .getInitialPriceProduct{ grid-area: init; }
  .pos-page .newProduct .row > .getProductPrice{ grid-area: price; }
  .pos-page .newProduct .row > .getProductPAmount:last-child{ grid-area: disc; }
}

/* ---------- Foto con preview (usuarios) ---------- */
.photo-upload{
  display: flex; align-items: center; gap: 14px;
  padding: 10px 12px;
  background: var(--bg-subtle);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-2);
}
.photo-upload .preview{
  width: 64px; height: 64px; border-radius: var(--r-2);
  object-fit: cover; background: var(--bg-surface);
  border: 1px solid var(--border);
}
.photo-upload .meta{ flex: 1; }
.photo-upload .meta small{ color: var(--fg-3); display: block; margin-top: 2px; }

/* ============================================================
   Modal "Detalles de factura" — ocultar botón Nota de Débito si el
   documento abierto YA es una ND. ESTRATEGIA: hide por defecto, show
   SÓLO cuando data-doc-type es exactamente "invoice" (lo setea
   purchase.js al click del gear). Si JS no corre (cache viejo, error)
   el botón queda oculto — comportamiento más seguro: una ND sin botón
   es preferible a una ND CON el botón por error.
   ============================================================ */
#modalInvoiceDetail .debtNote { display: none !important; }
#modalInvoiceDetail[data-doc-type="invoice"] .debtNote { display: inline-block !important; }
