/* APP LAYOUT */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
  opacity: 0;
  transition: opacity 0.3s;
}

/* SIDEBAR */
#sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  z-index: 10;
}
.brand {
  padding: 0 20px 30px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #e2e8f0;
  margin-bottom: 20px;
}
.brand span {
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
}
.nav-items {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 0 10px;
}
.nav-item {
  padding: 12px 20px;
  border-radius: 8px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 12px;
}
.nav-item:hover,
.nav-item.active {
  background: var(--primary);
  color: var(--text-main);
}
.current-user {
  padding: 20px;
  border-top: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

/* MAIN CONTENT */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-color);
  position: relative;
  overflow: hidden;
}
.view {
  display: none;
  width: 100%;
  height: 100%;
  flex-direction: column;
  padding: 20px;
  overflow-y: auto;
}
.view.active {
  display: flex;
}
.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.view-title {
  font-size: 28px;
  font-weight: 700;
}

/* ==========================================================================
   RESPONSIVE — MESAS & PEDIDOS Y POS (BANANA BYTE)
   Mobile-first & adaptive responsive behavior based on server-responsive.html
   Zero JavaScript modifications, zero HTML alterations.
   ========================================================================== */

/* 1. Global Box-Sizing & Viewport Constraints */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

#app {
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

main {
  min-width: 0;
  max-width: 100%;
}

main > * {
  min-width: 0;
  max-width: 100%;
}

/* 2. Base Tables & Delivery Grid */
#grid-tables,
#grid-delivery {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

/* 3. Mobile Viewport & Containers (Portrait <= 599px OR Landscape <= 500px height) */
@media (max-width: 599px), (orientation: landscape) and (max-height: 500px) {
  #app {
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  main {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  /* ============================================================
     MOBILE NAVIGATION DRAWER
     Drawer panel with overlay/backdrop, safe areas, 100dvh,
     full icon + text display, internal vertical scrolling.
     Zero transform on parent ensures position:fixed button is
     always visible and never lost during open/close cycles.
     ============================================================ */

  /* Retracted / Closed Drawer State (.collapsed) */
  aside#sidebar.collapsed {
    position: fixed !important;
    top: 0 !important;
    left: calc(-1 * min(86vw, 320px)) !important;
    width: min(86vw, 320px) !important;
    min-width: 0 !important;
    max-width: min(86vw, 320px) !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    transform: none !important;
    transition:
      left 0.28s cubic-bezier(0.4, 0, 0.2, 1),
      box-shadow 0.28s ease !important;
    z-index: 1000 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    box-shadow: none !important;
    flex: none !important;
    background: #ffffff !important;
  }

  /* Floating drawer trigger toggle button when collapsed */
  aside#sidebar.collapsed .brand button {
    position: fixed !important;
    top: max(6px, env(safe-area-inset-top)) !important;
    left: max(8px, env(safe-area-inset-left)) !important;
    z-index: 1005 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-width: 44px !important;
    min-height: 44px !important;
    width: 44px !important;
    height: 44px !important;
    padding: 0 !important;
    font-size: 18px !important;
    font-weight: 700 !important;
    background: var(--surface) !important;
    color: var(--text-main) !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 10px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12) !important;
    cursor: pointer !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
  }

  /* Open Drawer State (:not(.collapsed)) */
  aside#sidebar:not(.collapsed) {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: min(86vw, 320px) !important;
    min-width: min(86vw, 320px) !important;
    max-width: min(86vw, 320px) !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    transform: none !important;
    transition:
      left 0.28s cubic-bezier(0.4, 0, 0.2, 1),
      box-shadow 0.28s ease !important;
    z-index: 1000 !important;
    background: #ffffff !important;
    box-shadow:
      0 0 0 100vmax rgba(15, 23, 42, 0.48),
      8px 0 28px rgba(0, 0, 0, 0.25) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    padding-top: max(14px, env(safe-area-inset-top)) !important;
    padding-bottom: max(16px, env(safe-area-inset-bottom)) !important;
    padding-left: max(12px, env(safe-area-inset-left)) !important;
    padding-right: max(12px, env(safe-area-inset-right)) !important;
    flex: none !important;
  }

  /* Brand inside Drawer */
  aside#sidebar:not(.collapsed) .brand {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 6px 12px 16px !important;
    margin-bottom: 12px !important;
    border-bottom: 1px solid #f1f5f9 !important;
    width: 100% !important;
  }

  aside#sidebar:not(.collapsed) .brand .brand-text {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
  }

  aside#sidebar:not(.collapsed) .brand .brand-text img {
    width: 32px !important;
    height: 32px !important;
    object-fit: contain !important;
  }

  aside#sidebar:not(.collapsed) .brand .brand-text span {
    display: inline !important;
    font-size: 20px !important;
    font-weight: 800 !important;
    color: var(--text-main) !important;
  }

  aside#sidebar:not(.collapsed) .brand button {
    position: static !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-width: 44px !important;
    min-height: 44px !important;
    width: 44px !important;
    height: 44px !important;
    padding: 0 !important;
    font-size: 18px !important;
    background: #f1f5f9 !important;
    color: var(--text-main) !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 10px !important;
    cursor: pointer !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
  }

  /* Nav items container inside Drawer */
  aside#sidebar:not(.collapsed) .nav-items {
    display: flex !important;
    flex-direction: column !important;
    gap: 6px !important;
    padding: 0 4px !important;
    width: 100% !important;
    flex: 1 0 auto !important;
  }

  /* Nav item in Drawer: ICONOS + TEXTOS VISIBLES */
  aside#sidebar:not(.collapsed) .nav-items .nav-item {
    font-size: 14px !important;
    line-height: 1.3 !important;
    font-weight: 600 !important;
    color: var(--text-muted) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 14px !important;
    padding: 12px 16px !important;
    min-height: 48px !important;
    border-radius: 12px !important;
    cursor: pointer !important;
    transition:
      background 0.15s ease,
      color 0.15s ease !important;
  }

  aside#sidebar:not(.collapsed) .nav-items .nav-item span {
    font-size: 22px !important;
    min-width: 24px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  aside#sidebar:not(.collapsed) .nav-items .nav-item:hover,
  aside#sidebar:not(.collapsed) .nav-items .nav-item.active {
    background: var(--primary) !important;
    color: var(--text-main) !important;
    font-weight: 700 !important;
  }

  /* Current User in Drawer */
  aside#sidebar:not(.collapsed) .current-user {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    padding: 14px 12px !important;
    margin-top: auto !important;
    border-top: 1px solid #f1f5f9 !important;
    width: 100% !important;
  }

  aside#sidebar:not(.collapsed) .current-user #user-icon {
    font-size: 20px !important;
  }

  aside#sidebar:not(.collapsed) .current-user .user-text {
    display: inline-block !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    color: var(--text-main) !important;
  }

  /* Logout & Sound in Drawer */
  aside#sidebar:not(.collapsed) div[style*="padding: 10px 20px"] {
    padding: 4px 12px !important;
    width: 100% !important;
  }

  aside#sidebar:not(.collapsed) div[style*="padding: 10px 20px"] button {
    width: 100% !important;
    min-height: 44px !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    border-radius: 10px !important;
    padding: 10px 12px !important;
  }

  aside#sidebar:not(.collapsed) div[style*="padding: 10px 20px"] button span {
    display: inline !important;
  }

  /* Top Operational Real-Time Bar */
  .top-operational-bar {
    flex: 0 0 auto;
    min-width: 0;
    max-width: 100%;
    padding-top: max(8px, env(safe-area-inset-top)) !important;
    padding-right: max(12px, env(safe-area-inset-right)) !important;
    padding-bottom: 8px !important;
    padding-left: calc(max(8px, env(safe-area-inset-left)) + 52px) !important;
    min-height: 52px !important;
    gap: 8px;
    font-size: 11px;
    overflow: hidden;
  }

  .top-operational-bar > div:first-child {
    min-width: 0;
    max-width: 100%;
    gap: 8px !important;
    overflow: hidden;
  }

  #header-time,
  #header-date,
  #header-shift {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  #operational-ticker-container {
    min-width: 0;
    margin-left: 8px !important;
    overflow: hidden;
  }

  /* Mesas & Pedidos Main View */
  #view-tables {
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 12px 10px calc(20px + env(safe-area-inset-bottom));
    box-sizing: border-box;
  }

  #view-tables .view-header {
    min-width: 0;
    max-width: 100%;
    margin-bottom: 12px;
  }

  #view-tables .view-title {
    font-size: clamp(21px, 5vw, 25px);
    line-height: 1.25;
    letter-spacing: -0.5px;
    margin: 0;
  }

  /* Section Tabs (Tables / Delivery) */
  #view-tables .section-tabs {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 6px;
    margin-bottom: 10px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  #view-tables .section-tabs::-webkit-scrollbar {
    display: none;
  }

  #view-tables .section-tabs .tab-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    min-width: 0;
    min-height: 44px;
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 700;
    border-radius: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
  }

  /* Status Counters Row */
  #view-tables .status-counters-row {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
    font-size: 11px;
    border-radius: 14px;
    justify-content: space-around;
    width: 100%;
    min-width: 0;
    margin-bottom: 10px;
    box-sizing: border-box;
  }

  /* 2-Column Tables & 2-Column Delivery Grid in Mobile */
  #grid-tables,
  #grid-delivery {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  /* Table Cards - Compact, tactile, proportional (Shared by Tables & Delivery) */
  #view-tables .table-card {
    position: relative;
    min-width: 0;
    width: 100%;
    min-height: 122px;
    height: auto;
    aspect-ratio: auto;
    padding: 16px 8px 10px;
    border-radius: 16px;
    overflow: hidden;
    text-align: center;
    transition:
      transform 0.15s ease,
      box-shadow 0.15s ease;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  #view-tables .table-card:active {
    transform: scale(0.975);
  }

  #view-tables .table-card * {
    max-width: 100%;
    min-width: 0;
  }

  #view-tables .table-number,
  #view-tables .table-card .table-number {
    font-size: 28px;
    font-weight: 900;
    line-height: 1;
    margin: 4px 0 2px;
  }

  #view-tables .table-status,
  #view-tables .table-card .table-status {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.5px;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.2;
    text-transform: uppercase;
    text-align: center;
  }

  #view-tables .table-card .table-guests {
    position: absolute;
    bottom: 7px;
    left: 8px;
    font-size: 9.5px;
    font-weight: 700;
    color: var(--text-muted);
    max-width: 48%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #view-tables .table-card .table-server {
    position: absolute;
    bottom: 7px;
    right: 8px;
    font-size: 9px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    max-width: 48%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
  }

  #view-tables .table-card .table-time {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 9.5px;
    font-weight: 700;
    color: var(--text-muted);
  }

  #view-tables .table-card .table-pay {
    position: absolute;
    top: 7px;
    right: 8px;
    font-size: 14px;
  }

  /* Delivery Customer Protection - Prevents collision and adapts neatly */
  #grid-delivery .table-card > div[style*="bottom:25px"],
  #grid-delivery
    .table-card
    > div[style*="position:absolute"]:not(.table-time):not(.table-number):not(
      .table-status
    ) {
    position: absolute !important;
    bottom: 6px !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    padding: 0 6px !important;
    font-size: 9px !important;
    font-weight: 700 !important;
    text-align: center !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    box-sizing: border-box !important;
    pointer-events: none;
  }

  /* Table Actions Dropdown Menu */
  #table-actions-menu {
    max-width: calc(100vw - 24px);
    width: max-content;
    overflow-wrap: anywhere;
  }
}

/* ============================================================
   4. POS RESPONSIVE POR ETAPAS (<= 768px)
   Flujo guiado táctil para salón:
   Mesas -> Catálogo de Productos (stage-products) 
          <-> Comanda / Pedido (stage-order)
   ============================================================ */

/* Elementos auxiliares móviles ocultos por defecto fuera de <= 768px */
#pos-order-summary-bar {
  display: none;
}

#btn-back-to-products {
  display: none;
}

@media (max-width: 768px) {
  #view-pos.active {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - 52px);
    width: 100%;
    min-width: 0;
    padding: 0;
    overflow: hidden;
    box-sizing: border-box;
    position: relative;
  }

  /* Altura adaptada para landscape móvil / compacto */
  @media (max-height: 500px) {
    #view-pos {
      height: calc(100dvh - 44px);
    }
  }

  /* SUB-ETAPA 1: PRODUCTOS / CATÁLOGO */
  #view-pos.stage-products .pos-left,
  #view-pos:not(.stage-order) .pos-left {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    min-height: 0;
    min-width: 0;
    border-right: none;
    border-bottom: none;
    overflow: hidden;
    box-sizing: border-box;
  }

  #view-pos.stage-products .pos-right,
  #view-pos:not(.stage-order) .pos-right {
    display: none;
  }

  /* SUB-ETAPA 2: PEDIDO / COMANDA */
  #view-pos.stage-order .pos-left {
    display: none;
  }

  #view-pos.stage-order .pos-right {
    display: flex;
    flex-direction: column;
    flex: 1 1 100%;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: 100%;
    min-height: 0;
    background: var(--surface);
    overflow: hidden;
    box-sizing: border-box;
    margin-top: 0;
  }

  /* Categorías en mobile/tablet <= 768px */
  #view-pos .pos-categories {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    background: var(--surface);
    border-bottom: 1px solid #e2e8f0;
    box-sizing: border-box;
  }

  #view-pos .pos-categories::-webkit-scrollbar {
    display: none;
  }

  #view-pos .cat-btn {
    padding: 8px 16px;
    min-height: 40px;
    font-size: 12px;
    font-weight: 700;
    border-radius: 999px;
    white-space: nowrap;
    flex: 0 0 auto;
    touch-action: manipulation;
  }

  /* Productos en mobile/tablet <= 768px */
  #view-pos .pos-products {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    padding: 12px 12px calc(72px + env(safe-area-inset-bottom));
    align-content: start;
    box-sizing: border-box;
  }

  /* Pantallas extremadamente estrechas (ej. 320px) */
  @media (max-width: 359px) {
    #view-pos .pos-products {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 6px;
      padding: 8px 8px calc(70px + env(safe-area-inset-bottom));
    }
  }

  #view-pos .product-card {
    box-sizing: border-box;
    border-radius: 14px;
    min-width: 0;
    touch-action: manipulation;
  }

  #view-pos .product-img {
    height: 90px;
  }

  #view-pos .product-info {
    padding: 8px 10px;
  }

  #view-pos .product-name {
    font-size: 12px;
    height: 30px;
    line-height: 1.25;
    margin-bottom: 3px;
    overflow-wrap: anywhere;
  }

  #view-pos .product-price {
    font-size: 13px;
    font-weight: 700;
  }

  /* Barra de resumen del pedido (Sticky / Floating dentro de .pos-left) */
  #pos-order-summary-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: #0f172a;
    color: #ffffff;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.25);
    box-sizing: border-box;
    gap: 10px;
  }

  .pos-summary-info {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
  }

  .pos-summary-badge {
    background: var(--primary);
    color: var(--text-main);
    font-size: 12px;
    font-weight: 800;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .pos-summary-text {
    font-size: 13px;
    font-weight: 600;
    color: #e2e8f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .pos-summary-divider {
    color: #64748b;
    font-weight: 700;
  }

  .pos-summary-total {
    font-size: 15px;
    font-weight: 800;
    color: #f8fafc;
    white-space: nowrap;
  }

  .pos-summary-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    min-height: 44px;
    font-size: 13px;
    font-weight: 800;
    background: var(--primary);
    color: var(--text-main);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    touch-action: manipulation;
  }

  .pos-summary-btn .pos-summary-arrow {
    font-size: 15px;
    line-height: 1;
  }

  /* Encabezado de la comanda en mobile/tablet <= 768px */
  #view-pos .order-header {
    flex: 0 0 auto;
    padding: 10px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-color);
    border-bottom: 1px solid #e2e8f0;
    box-sizing: border-box;
    gap: 8px;
  }

  #btn-back-to-products {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 8px 12px;
    min-height: 40px;
    font-size: 12px;
    font-weight: 800;
    background: var(--surface);
    color: var(--text-main);
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    touch-action: manipulation;
  }

  #btn-back-to-products .back-arrow {
    font-size: 14px;
    font-weight: 900;
  }

  #view-pos .order-meta {
    flex: 1 1 auto;
    min-width: 0;
    text-align: left;
  }

  #view-pos .order-meta h3 {
    font-size: 15px;
    font-weight: 800;
    margin: 0;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #view-pos .order-meta p {
    font-size: 11px;
    color: var(--text-muted);
    margin: 2px 0 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Cuerpo de la comanda a pantalla completa en <= 768px */
  #view-pos .order-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 12px 14px;
    box-sizing: border-box;
  }

  #view-pos .course-group {
    margin-bottom: 16px;
  }

  /* Pie de la comanda en mobile/tablet <= 768px */
  #view-pos .order-footer {
    flex: 0 0 auto;
    padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid #e2e8f0;
    background: var(--surface);
    box-sizing: border-box;
  }

  #view-pos .order-totals {
    margin-bottom: 10px;
    gap: 4px;
  }

  #view-pos .total-row {
    font-size: 13px;
  }

  #view-pos .total-row.grand {
    font-size: 20px;
    font-weight: 800;
    margin-top: 4px;
  }

  #view-pos .action-btns {
    gap: 8px;
  }

  #view-pos .action-btns .btn {
    padding: 12px 14px;
    min-height: 46px;
    font-size: 14px;
    font-weight: 700;
    touch-action: manipulation;
  }
}

/* ============================================================
   BLINDAJE DESKTOP Y TABLET PANORÁMICO (>= 769px)
   ============================================================ */
@media (min-width: 769px) {
  #view-pos .pos-left,
  #view-pos.stage-products .pos-left,
  #view-pos.stage-order .pos-left {
    display: flex;
  }

  #view-pos .pos-right,
  #view-pos.stage-products .pos-right,
  #view-pos.stage-order .pos-right {
    display: flex;
  }

  #pos-order-summary-bar {
    display: none;
  }

  #btn-back-to-products {
    display: none;
  }
}

/* 5. Small Mobile Devices (<= 380px, height > 500px) */
@media (max-width: 380px) and (min-height: 501px) {
  #grid-tables,
  #grid-delivery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  #view-tables {
    padding: 8px 6px calc(16px + env(safe-area-inset-bottom));
  }

  #view-tables .table-card {
    min-height: 112px;
    padding: 12px 6px 6px;
    border-radius: 12px;
  }

  #view-tables .table-number,
  #view-tables .table-card .table-number {
    font-size: 24px;
    margin: 3px 0 1px;
  }

  #view-tables .table-status,
  #view-tables .table-card .table-status {
    font-size: 8.5px;
  }

  #view-tables .table-card .table-guests,
  #view-tables .table-card .table-server {
    font-size: 8px;
    bottom: 4px;
  }

  #view-tables .table-card .table-time {
    font-size: 8px;
    top: 5px;
    left: 6px;
  }

  #view-tables .table-card .table-pay {
    font-size: 11px;
    top: 4px;
    right: 6px;
  }

  #grid-delivery .table-card > div[style*="bottom:25px"],
  #grid-delivery
    .table-card
    > div[style*="position:absolute"]:not(.table-time):not(.table-number):not(
      .table-status
    ) {
    bottom: 4px !important;
    font-size: 8px !important;
    padding: 0 4px !important;
  }

  #view-pos .product-img {
    height: 70px;
  }

  #view-pos .product-name {
    font-size: 11px;
    height: 28px;
  }
}

/* 6. Mobile Landscape (max-height <= 500px and orientation landscape) */
@media (orientation: landscape) and (max-height: 500px) {
  #grid-tables,
  #grid-delivery {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  #view-tables {
    padding: 8px 10px calc(10px + env(safe-area-inset-bottom)) !important;
  }

  #view-tables .view-header {
    margin-bottom: 8px;
  }

  #view-tables .view-title {
    font-size: 20px;
    line-height: 1.2;
    margin: 0;
  }

  #view-tables .section-tabs {
    margin-bottom: 6px;
    padding-bottom: 4px;
  }

  #view-tables .section-tabs .tab-btn {
    min-height: 36px;
    padding: 6px 14px;
    font-size: 11px;
  }

  #view-tables .status-counters-row {
    padding: 6px 10px;
    gap: 6px;
    font-size: 10px;
    margin-bottom: 6px;
  }

  #view-tables .table-card {
    min-height: 94px;
    padding: 10px 6px 6px;
    border-radius: 12px;
  }

  #view-tables .table-number,
  #view-tables .table-card .table-number {
    font-size: 22px;
    margin: 2px 0 1px;
  }

  #view-tables .table-status,
  #view-tables .table-card .table-status {
    font-size: 8.5px;
    line-height: 1.1;
  }

  #view-tables .table-card .table-guests,
  #view-tables .table-card .table-server {
    font-size: 8px;
    bottom: 3px;
  }

  #view-tables .table-card .table-time {
    font-size: 8px;
    top: 4px;
    left: 6px;
  }

  #view-tables .table-card .table-pay {
    font-size: 11px;
    top: 3px;
    right: 6px;
  }

  #grid-delivery .table-card > div[style*="bottom:25px"],
  #grid-delivery
    .table-card
    > div[style*="position:absolute"]:not(.table-time):not(.table-number):not(
      .table-status
    ) {
    bottom: 3px !important;
    font-size: 8px !important;
    padding: 0 4px !important;
  }
}

/* POS in Landscape: Side-by-side (>= 769px) */
@media (max-height: 500px) and (min-width: 769px) {
  #view-pos.active {
    display: flex;
    flex-direction: row;
    height: calc(100dvh - 44px);
    overflow: hidden;
    padding: 0;
    box-sizing: border-box;
    min-width: 0;
    width: 100%;
  }

  #view-pos .pos-left {
    flex: 1 1 58%;
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid #e2e8f0;
    border-bottom: none;
    box-sizing: border-box;
  }

  #view-pos .pos-categories {
    flex: 0 0 auto;
    padding: 6px 10px;
    gap: 6px;
  }

  #view-pos .pos-categories .cat-btn {
    padding: 6px 12px;
    font-size: 10px;
  }

  #view-pos .pos-products {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 8px;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
  }

  #view-pos .product-card {
    border-radius: 12px;
  }

  #view-pos .product-img {
    height: 70px;
  }

  #view-pos .product-info {
    padding: 6px 8px;
  }

  #view-pos .product-name {
    font-size: 11px;
    height: 28px;
    overflow-wrap: anywhere;
  }

  #view-pos .product-price {
    font-size: 12px;
  }

  #view-pos .pos-right {
    flex: 0 0 42%;
    width: 42%;
    min-width: 250px;
    max-width: 380px;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface);
    box-sizing: border-box;
    margin-top: 0;
  }

  #view-pos .order-header {
    flex: 0 0 auto;
    padding: 6px 10px;
  }

  #view-pos .order-meta h3 {
    font-size: 15px;
  }

  #view-pos .order-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 6px 10px;
  }

  #view-pos .order-footer {
    flex: 0 0 auto;
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  }

  #view-pos .order-totals {
    gap: 2px;
    margin-bottom: 6px;
  }

  #view-pos .total-row {
    font-size: 11px;
  }

  #view-pos .total-row.grand {
    font-size: 16px;
    margin-top: 2px;
  }

  #view-pos .action-btns {
    gap: 5px;
  }

  #view-pos .action-btns .btn {
    padding: 8px 10px;
    min-height: 38px;
    font-size: 12px;
  }
}

/* 7. Tablet & Intermediate Breakpoint (600px - 1023px, height > 500px) */
@media (min-width: 600px) and (max-width: 1023px) and (min-height: 501px) {
  #view-tables {
    min-width: 0;
    max-width: 100%;
    padding: 16px;
    box-sizing: border-box;
  }

  #view-tables .view-header {
    margin-bottom: 14px;
  }

  #view-tables .view-title {
    font-size: 26px;
    line-height: 1.2;
    margin: 0;
  }

  #view-tables .section-tabs {
    margin-bottom: 12px;
  }

  #view-tables .section-tabs .tab-btn {
    min-height: 42px;
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 700;
  }

  #grid-tables,
  #grid-delivery {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  #view-tables .table-card {
    aspect-ratio: auto;
    min-height: 124px;
    padding: 16px 10px 12px;
    border-radius: 16px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  #view-tables .table-number,
  #view-tables .table-card .table-number {
    font-size: 28px;
    font-weight: 900;
    line-height: 1;
    margin: 4px 0 2px;
  }

  #view-tables .table-status,
  #view-tables .table-card .table-status {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.5px;
    text-transform: uppercase;
  }

  #grid-delivery .table-card > div[style*="bottom:25px"],
  #grid-delivery
    .table-card
    > div[style*="position:absolute"]:not(.table-time):not(.table-number):not(
      .table-status
    ) {
    position: absolute !important;
    bottom: 7px !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    padding: 0 6px !important;
    font-size: 9.5px !important;
    font-weight: 700 !important;
    text-align: center !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    box-sizing: border-box !important;
    pointer-events: none;
  }
}

/* POS Tablet: Side-by-side (769px - 1023px, height > 500px) */
@media (min-width: 769px) and (max-width: 1023px) and (min-height: 501px) {
  #view-pos.active {
    display: flex;
    flex-direction: row;
    height: calc(100dvh - 52px);
    overflow: hidden;
    padding: 0;
    box-sizing: border-box;
    min-width: 0;
    width: 100%;
  }

  #view-pos .pos-left {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid #e2e8f0;
    border-bottom: none;
    box-sizing: border-box;
  }

  #view-pos .pos-products {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    padding: 16px;
  }

  #view-pos .pos-right {
    width: 340px;
    flex: 0 0 340px;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface);
    box-sizing: border-box;
    margin-top: 0;
  }

  #view-pos .order-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
  }

  #view-pos .order-footer {
    flex: 0 0 auto;
  }
}

/* Tablet Widescreen (768px - 1023px, height > 500px) */
@media (min-width: 768px) and (max-width: 1023px) and (min-height: 501px) {
  #grid-tables,
  #grid-delivery {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
  }

  #view-tables .table-card {
    min-height: 128px;
    padding: 18px 12px 14px;
  }
}

/* 8. Desktop Layout Preservation (>= 1024px) */
@media (min-width: 1024px) {
  #view-tables {
    padding: 20px;
    box-sizing: border-box;
  }

  #view-tables .section-tabs .tab-btn {
    min-height: 42px;
    padding: 10px 20px;
    font-size: 13px;
    font-weight: 700;
  }

  #grid-tables,
  #grid-delivery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
    gap: 15px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  #view-tables .table-card {
    position: relative;
    min-width: 0;
    width: 100%;
    min-height: 130px;
    height: auto;
    aspect-ratio: auto;
    padding: 18px 10px 14px;
    border-radius: 14px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition:
      transform 0.15s ease,
      box-shadow 0.15s ease;
  }

  #view-tables .table-card:hover {
    transform: translateY(-3px);
  }

  #view-tables .table-card:active {
    transform: scale(0.975);
  }

  #view-tables .table-number,
  #view-tables .table-card .table-number {
    font-size: 30px;
    font-weight: 900;
    line-height: 1;
    margin: 4px 0 3px;
  }

  #view-tables .table-status,
  #view-tables .table-card .table-status {
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: 0.5px;
    text-transform: uppercase;
  }

  #view-tables .table-card .table-time {
    position: absolute;
    top: 9px;
    left: 10px;
    font-size: 10px;
    font-weight: 700;
  }

  #view-tables .table-card .table-pay {
    position: absolute;
    top: 8px;
    right: 10px;
    font-size: 14px;
  }

  #view-tables .table-card .table-guests {
    position: absolute;
    bottom: 9px;
    left: 10px;
    font-size: 10px;
    font-weight: 700;
    max-width: 48%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #view-tables .table-card .table-server {
    position: absolute;
    bottom: 9px;
    right: 10px;
    font-size: 9.5px;
    font-weight: 700;
    max-width: 48%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
  }

  #grid-delivery .table-card > div[style*="bottom:25px"],
  #grid-delivery
    .table-card
    > div[style*="position:absolute"]:not(.table-time):not(.table-number):not(
      .table-status
    ) {
    position: absolute !important;
    bottom: 8px !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    padding: 0 8px !important;
    font-size: 10px !important;
    font-weight: 700 !important;
    text-align: center !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    box-sizing: border-box !important;
    pointer-events: none;
  }

  #view-pos {
    height: calc(100dvh - 52px);
  }
}

/* ============================================================
   8. SIDEBAR COMPACTO & TOOLTIPS (PANTALLAS >= 600px, height > 500px)
   Pure CSS tooltips on hover in compact icon mode.
   Zero JavaScript, zero DOM alterations.
   ============================================================ */
@media (min-width: 600px) and (min-height: 501px) {
  /* Distribución vertical canónica con Flexbox */
  aside#sidebar {
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
  }

  aside#sidebar .brand {
    flex: 0 0 auto;
  }

  aside#sidebar #nav-container {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
  }

  aside#sidebar .current-user {
    flex: 0 0 auto;
    margin-top: auto;
  }

  aside#sidebar div[style*="padding: 10px 20px"] {
    flex: 0 0 auto;
  }

  aside#sidebar.collapsed .nav-items .nav-item {
    position: relative;
    transition:
      background 0.15s ease,
      color 0.15s ease,
      transform 0.1s ease;
  }

  aside#sidebar.collapsed .nav-items .nav-item.active {
    background: var(--primary) !important;
    color: var(--text-main) !important;
    box-shadow: inset 3px 0 0 var(--text-main);
  }

  aside#sidebar.collapsed .nav-items .nav-item:hover::after {
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background: #1e293b;
    color: #ffffff;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 6px;
    white-space: nowrap;
    z-index: 1050;
    pointer-events: none;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    opacity: 1;
    line-height: 1.4;
  }

  aside#sidebar.collapsed .nav-items .nav-item:hover::before {
    content: "";
    position: absolute;
    left: calc(100% + 6px);
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-right-color: #1e293b;
    z-index: 1050;
    pointer-events: none;
  }

  aside#sidebar.collapsed #nav-tables:hover::after {
    content: "Mesas & Pedidos / Tables & Orders";
  }
  aside#sidebar.collapsed #nav-kitchen:hover::after {
    content: "Cocina / Kitchen";
  }
  aside#sidebar.collapsed #nav-bar:hover::after {
    content: "Bar";
  }
  aside#sidebar.collapsed #nav-transactions:hover::after {
    content: "Transacciones / Transactions";
  }
  aside#sidebar.collapsed #nav-reports:hover::after {
    content: "Reportes / Reports";
  }
  aside#sidebar.collapsed #nav-shift-management:hover::after {
    content: "Turnos / Staff & Shifts";
  }
  aside#sidebar.collapsed #nav-menu-mgmt:hover::after {
    content: "Gestión de Menú / Menu Management";
  }
  aside#sidebar.collapsed #nav-settings:hover::after {
    content: "Configuración / Settings";
  }
}
