/* =============================================================================
   responsive.css - adaptación a celulares y tablets (iPhone, Android, iPad)
   Se carga SIEMPRE al final, después del resto de hojas de estilo.
   Puntos de corte:
     <= 1180px  modo compacto: menú lateral oculto + barra de navegación inferior
     <=  899px  la caja pasa a una sola columna con barra de cobro fija
     <=  700px  celular: tablas en tarjetas, diálogos a pantalla completa
   ============================================================================= */

:root { --bn-h: 0px; }

html { -webkit-tap-highlight-color: transparent; }
body { touch-action: manipulation; overscroll-behavior-y: none; }
.shell { min-height: 100vh; min-height: 100dvh; }

/* Elementos que solo existen en modo compacto */
.scrim, .bottomnav, .paybar, .topbar__brand { display: none; }
.d-short { display: none; }

/* ---------------------------------------------------------------- utilidades */
.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: var(--s4);
  align-items: start;
}
.split--wide { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); }
.split__side { position: sticky; top: var(--s4); }
.form-row-3 { display: grid; grid-template-columns: 2fr 1.4fr 1fr; gap: var(--s4); }
.table-wrap--tall { max-height: calc(100vh - 230px); overflow: auto; }

/* ----------------------------------------- tablas: de columnas a tarjetas ----
   Se decide por el ancho del contenedor (no de la pantalla), así también
   funciona dentro de diálogos y en columnas angostas de iPad. */
.table-wrap { container: tw / inline-size; }

@container tw (max-width: 460px) {
  .table, .table tbody, .table tfoot { display: block; }
  .table thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%);
  }
  .table tbody tr, .table tfoot tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 16px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
  }
  .table tbody tr:last-child { border-bottom: 0; }
  .table-wrap .table td { display: block; min-width: 0; padding: 0; border: 0; text-align: left; }
  .table-wrap .table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    font-size: 11px; font-weight: 600; letter-spacing: 0.03em;
    text-transform: uppercase; color: var(--text-3);
  }
  .table td[data-label=""]::before, .table td:not([data-label])::before { display: none; }
  .table td:first-child, .table td:last-child, .table td[colspan] { grid-column: 1 / -1; }
  .table td.num, .table td.right, .table td.center { text-align: left; }
  .table td .btn { margin: 0 6px 6px 0; }
  /* Carrito de la caja */
  .table--cart tbody tr { grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px 10px; }
  .table--cart td:nth-child(1) { grid-column: 1 / 3; grid-row: 1; }
  .table--cart td:nth-child(5) { grid-column: 3; grid-row: 1; justify-self: end; }
  .table--cart td:nth-child(2) { grid-column: 1; grid-row: 2; align-self: end; }
  .table--cart td:nth-child(3) { grid-column: 2; grid-row: 2; }
  .table--cart td:nth-child(4) { grid-column: 3; grid-row: 2; align-self: end; text-align: right; }
  .table--cart td:nth-child(1)::before, .table--cart td:nth-child(5)::before { display: none; }
  .table--cart td:nth-child(4) { text-align: right; }
  .table--cart .btn { margin: 0; }
  .table--cart .qty-btn { width: 38px; height: 38px; }
  .table--cart .qty-input { width: 50px; height: 38px; }
  .table--edit td:first-child { grid-column: auto; }
  .table--edit td .input, .table--edit td .input--cell { width: 100% !important; }
  .table--edit td:last-child { grid-column: 1 / -1; }

  /* Tarjetas de 3 columnas: listas con muchos datos cortos */
  .table--c3 tbody tr, .table--c3 tfoot tr { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 12px; }
  .table--c3 td:last-child { grid-column: auto; }
  .table--c3 td.right, .table--c3 td[colspan] { grid-column: 1 / -1; }
  .table--c3 td .input, .table--c3 td .input--cell { width: 100% !important; }
  .table--inv td:nth-child(8) { display: none; }

  /* Productos: variantes y stock en la misma fila; el rango de precios usa todo el ancho */
  .table--prod td:nth-child(4) { grid-column: 1 / -1; }

  /* Ventas: numero | fecha en la primera fila; prendas | pago | total en la segunda */
  .table--sales tbody tr { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .table--sales td:first-child { grid-column: 1; }
  .table--sales td:nth-child(2) { grid-column: 2 / 4; }
  .table--sales td:last-child { grid-column: 1 / -1; }
}

/* =============================================================== MODO COMPACTO */
@media (max-width: 1180px) {
  :root { --bn-h: calc(56px + env(safe-area-inset-bottom)); }

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

  /* Menú lateral como cajón */
  .sidebar {
    position: fixed; z-index: 60; top: 0; bottom: 0; left: 0;
    height: 100vh; height: 100dvh;
    width: min(300px, 86vw);
    padding-top: env(safe-area-inset-top);
    transform: translateX(-102%);
    transition: transform 0.2s ease;
  }
  .sidebar.is-open { transform: none; box-shadow: var(--shadow-lg); }
  .nav a { padding: 13px var(--s5); }
  .sidebar__user { padding-bottom: calc(var(--s4) + env(safe-area-inset-bottom)); }

  .scrim {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(20, 20, 20, 0.45);
    opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
  }
  body.nav-open .scrim { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }

  /* Barra superior fija */
  .topbar {
    position: sticky; top: 0; z-index: 30;
    height: calc(var(--topbar-h) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) var(--s4) 0;
  }
  .topbar__menu { display: none; }
  .topbar__brand { display: block; font-weight: 600; color: var(--text); font-size: var(--fs-md); }

  /* Navegación inferior, al alcance del pulgar */
  .bottomnav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border-strong);
  }
  .bottomnav a, .bottomnav button {
    display: flex; align-items: center; justify-content: center;
    height: 56px; padding: 0 4px;
    border: 0; border-top: 2px solid transparent; background: none;
    font-size: 12px; font-weight: 500; color: var(--text-3);
    text-decoration: none; cursor: pointer;
  }
  .bottomnav [aria-current="page"] { color: var(--text); border-top-color: var(--accent); font-weight: 600; }

  .page {
    padding: var(--s4) max(var(--s4), env(safe-area-inset-right)) calc(var(--bn-h) + 28px) max(var(--s4), env(safe-area-inset-left));
  }

  .toasts {
    left: var(--s3); right: var(--s3); bottom: calc(var(--bn-h) + var(--s3));
    max-width: none;
  }
  body:has(.paybar:not(.is-hidden):not(.is-empty)) .toasts { bottom: calc(var(--bn-h) + 84px); }

  .split, .split--wide { grid-template-columns: 1fr; }
  .split__side { position: static; }
  .table-wrap--tall { max-height: none; overflow: auto; }
}

/* ------------------------------------------------------ CAJA en tablets / celular */
@media (max-width: 899px) {
  .pos { grid-template-columns: minmax(0, 1fr); padding-bottom: 84px; }
  .pos__side { position: static; }

  .scan__row { flex-wrap: wrap; }
  .scan__row .input { flex: 1 1 100%; }
  .scan__row .btn { flex: 1; }

  .paybar {
    display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
    position: fixed; left: 0; right: 0; bottom: var(--bn-h); z-index: 35;
    padding: 10px max(var(--s4), env(safe-area-inset-right)) 10px max(var(--s4), env(safe-area-inset-left));
    background: var(--surface); border-top: 1px solid var(--border-strong);
    box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.07);
  }
  .paybar.is-hidden, .paybar.is-empty { display: none; }
  .paybar__total { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
  .paybar .btn { min-width: 150px; }
}
@media (min-width: 900px) and (max-width: 1180px) {
  .pos { grid-template-columns: minmax(0, 1fr) 360px; }
  .pos__side {
    position: sticky;
    top: calc(var(--topbar-h) + env(safe-area-inset-top) + var(--s3));
    max-height: calc(100dvh - var(--topbar-h) - var(--bn-h) - 32px);
    overflow-y: auto;
  }
}

/* ============================================================ SCREENS TÁCTILES */
@media (pointer: coarse) {
  .btn { height: 44px; }
  .btn--sm { height: 38px; padding: 0 14px; }
  .btn--lg { height: 52px; }
  .input, .select { height: 44px; }
  .input--lg { height: 54px; }
  .input--cell { height: 42px; }
  .textarea { min-height: 96px; }
  .qty-btn { width: 42px; height: 42px; }
  .qty-input { width: 62px; height: 42px; }
  .chip { height: 42px; min-width: 50px; }
  .seg button { height: 50px; }
  .seg-inline button { height: 40px; }
  .check input { width: 22px; height: 22px; }
  .check { gap: 10px; }
  /* iOS hace zoom al enfocar un campo con letra menor a 16px */
  .input, .select, .textarea, .input--cell, .qty-input, .disc .select { font-size: 16px; }
  .res { padding: 14px var(--s4); }
}

/* ================================================================== CELULAR */
@media (max-width: 700px) {
  h1 { font-size: 18px; }
  .page-header { flex-wrap: wrap; margin-bottom: var(--s4); gap: var(--s3); }
  .page-header__actions { width: 100%; }
  .page-header__actions .btn { flex: 1; }

  .d-long { display: none; }
  .d-short { display: inline; }

  .grid-2, .grid-3 { grid-template-columns: 1fr !important; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: var(--s3); }
  .kpis .stat { padding: var(--s3) var(--s4); }
  .stat__value { font-size: clamp(16px, 4.7vw, 22px); overflow-wrap: anywhere; }
  .toolbar input[type="date"] { min-width: 0; }
  .stat__label { font-size: var(--fs-xs); }
  .form-row-3 { grid-template-columns: 1fr; }
  .section-title { flex-direction: column; align-items: flex-start; gap: 2px; }
  .row--between { flex-wrap: wrap; gap: var(--s2); }
  .seg-inline { display: flex; width: 100%; }
  .seg-inline button { flex: 1; padding: 0 var(--s2); }
  .card__header { padding: var(--s3) var(--s4); flex-wrap: wrap; gap: var(--s1); }
  .card__body { padding: var(--s4); }
  .chart-box { height: 240px; }

  /* Barras de filtros */
  .toolbar { gap: var(--s2); }
  .toolbar .input, .toolbar .select { max-width: none !important; flex: 1 1 100%; }
  .toolbar .row { width: 100%; }
  .toolbar .row .input { flex: 1; width: auto !important; }
  .toolbar__spacer { display: none; }
  .toolbar .btn { flex: 1 1 auto; }

  /* Caja */
  .total { font-size: 34px; }
  .side__section { padding: var(--s4); }

  /* Login */
  .auth { padding: var(--s4); align-items: start; padding-top: 12vh; }
  .auth__card { padding: var(--s5); }

  /* Diálogos: hoja inferior (pequeños) o pantalla completa (amplios) */
  dialog.dialog {
    width: 100vw !important; max-width: 100vw; margin: 0;
    border: 0; max-height: 100vh; max-height: 100dvh;
  }
  dialog.dialog[open] { display: flex; flex-direction: column; }
  dialog.dialog.dialog--wide { height: 100vh; height: 100dvh; border-radius: 0; }
  dialog.dialog:not(.dialog--wide) {
    margin-top: auto; border-radius: 14px 14px 0 0;
    max-height: 92vh; max-height: 92dvh;
  }
  dialog.dialog form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
  .dialog__head, .dialog__title { padding: var(--s4) var(--s4) var(--s2); }
  dialog.dialog--wide .dialog__title, dialog.dialog--wide .dialog__head { padding-top: calc(var(--s4) + env(safe-area-inset-top)); }
  .dialog__scroll { flex: 1; min-height: 0; max-height: none; overflow-y: auto; padding: 0 var(--s4) var(--s4); -webkit-overflow-scrolling: touch; }
  .dialog__body { padding: 0 var(--s4) var(--s4); }
  .dialog__foot { flex-wrap: wrap; padding: var(--s3) var(--s4) calc(var(--s3) + env(safe-area-inset-bottom)); }
  .dialog__foot .btn { flex: 1 1 40%; }
}

/* ===================================================== ESCÁNER POR CÁMARA */
.cam { display: flex; flex-direction: column; gap: var(--s3); }
.cam__box {
  position: relative; overflow: hidden;
  width: 100%; max-width: 560px; margin: 0 auto; aspect-ratio: 4 / 3;
  background: #000; border-radius: var(--radius-lg);
}
.cam__video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam__aim {
  position: absolute; left: 8%; right: 8%; top: 36%; height: 28%;
  border: 2px solid rgba(255, 255, 255, 0.9); border-radius: var(--radius);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
}
.cam__status {
  min-height: 48px; padding: var(--s3) var(--s4);
  border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--radius);
  background: var(--surface-2); font-size: var(--fs-base);
}
.cam__status--ok    { border-left-color: var(--success); background: var(--success-soft); }
.cam__status--error { border-left-color: var(--danger);  background: var(--danger-soft); }

/* Dos tarjetas lado a lado en pantallas anchas; apiladas en tablet vertical y celular */
@media (max-width: 899px) { .split-md { grid-template-columns: 1fr !important; } }

/* Tablet vertical: tabla normal pero compacta; Inventario oculta Mínimo y Valor para que siempre se vean las acciones */
@container tw (min-width: 461px) and (max-width: 900px) {
  .table th, .table td { padding-left: 10px; padding-right: 10px; }
  .table--inv th:nth-child(6), .table--inv td:nth-child(6),
  .table--inv th:nth-child(8), .table--inv td:nth-child(8) { display: none; }
}

/* Avisos en tablet: tarjeta flotante a la derecha, no a todo el ancho */
@media (min-width: 701px) and (max-width: 1180px) {
  .toasts { left: auto; right: var(--s4); max-width: 380px; }
}

/* Atajos de teclado: no aplican en pantallas tactiles */
@media (pointer: coarse) { .kbd-hint { display: none; } }

/* Tablas pequeñas que nunca se convierten en tarjetas */
.table-wrap.table-wrap--plain { container-type: normal; }
