/* controleProdu.css - VERSÃO REFATORADA E OTIMIZADA */

/* ========================================
   VARIÁVEIS GLOBAIS
   ======================================== */
:root { 
  --gap: 8px;
  --barH: 40px; 
  --cols: 9; 
  --rows-total: 4; 
  --topbarH: 60px;
  
  /* Cores do tema */
  --bg-dark: #2f2f2f;
  --bg-info-bar: #1f2e3a;
  --text-light: #dfe7ee;
  --border-light: rgba(255,255,255,.12);
  --success-color: #4CAF50;
  --success-bg: rgba(76, 175, 80, 0.15);
}

/* ========================================
   CONTAINER PRINCIPAL
   ======================================== */
.controle-produ-container { 
  width: 100%; 
  height: calc(100vh - var(--topbarH));
  overflow: hidden;
  /* Prevenir zoom e seleção */
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.pos-container {
  height: 100%;
  width: 100%;
  display: flex; 
  flex-direction: column;
  overflow: hidden;
}

/* ========================================
   BARRA DE INFORMAÇÕES
   ======================================== */
.info-bar {
  flex: 0 0 var(--barH);
  display: flex; 
  gap: 12px; 
  align-items: center; 
  padding: 0 12px;
  background: var(--bg-info-bar); 
  color: var(--text-light);
  font: 600 14px/1 system-ui, Segoe UI, Roboto, Arial;
  box-shadow: 0 1px 0 rgba(255,255,255,.06);
}

.info-bar > div { 
  flex: 1; 
  text-align: center; 
}

/* ========================================
   GRID CONTAINER
   ======================================== */
.grid-container { 
  flex: 1;
  width: 100%;
  overflow: hidden;
  display: flex;
}

.pos-wrap {
  width: 100%;
  height: 100%;
  display: grid; 
  gap: var(--gap); 
  padding: var(--gap);
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows-total), minmax(0, 1fr));
  box-sizing: border-box;
  background: var(--bg-dark);
  border: 2px solid var(--border-light);
  /* Prevenir zoom no grid */
  touch-action: pan-x pan-y;
}

.grid-1, .grid-2 { 
  display: contents; 
}

/* ========================================
   BOTÕES TOUCH
   ======================================== */
.btn-touch {
  /* Prevenir zoom em todos os botões */
  touch-action: manipulation !important;
  -webkit-tap-highlight-color: transparent;
}

.pos-wrap .btn-touch {
  width: 100%; 
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: clamp(3px, 0.4vh, 6px);
  box-sizing: border-box;
  overflow: hidden;
  transition: transform 0.1s ease;
  position: relative;
  cursor: pointer;
}

.pos-wrap .btn-touch:active:not(.btn-touch-disabled) {
  transform: scale(0.95);
}

.pos-wrap .btn-touch span { 
  font-size: clamp(0.6rem, 1vw, 0.85rem);
  line-height: 1.1;
}

.pos-wrap .btn-touch i { 
  font-size: clamp(0.9rem, 2.2vw, 1.6rem);
  margin-bottom: 2px;
}

/* ========================================
   ESTADOS DOS BOTÕES
   ======================================== */
.pos-wrap .btn-touch.btn-selected {
  background-color: var(--success-bg) !important;
  border-color: var(--success-color) !important;
  border-width: 3px !important;
  box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.3);
}

.pos-wrap .btn-touch.btn-selected i {
  color: var(--success-color);
}

.pos-wrap .btn-touch.btn-selected::after {
  content: '✓';
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--success-color);
  color: white;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
}

/* Botões navegáveis do breadcrumb */
.btn-navigable:not(:disabled) {
  cursor: pointer;
  position: relative;
}

.btn-navigable:not(:disabled):hover {
  opacity: 0.8;
  transform: scale(1.05);
}

.btn-navigable:not(:disabled)::before {
  content: '↩';
  position: absolute;
  top: 2px;
  left: 2px;
  font-size: 10px;
  color: rgba(255,255,255,0.7);
}

/* ========================================
   ANIMAÇÕES
   ======================================== */
@keyframes clickPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(0.92); box-shadow: 0 0 10px rgba(255,255,255,0.3); }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.pos-wrap .btn-touch.btn-clicked {
  animation: clickPulse 0.3s ease-out;
}

.pos-wrap .btn-touch .fa-spinner {
  animation: spin 1s linear infinite;
}

/* ========================================
   SELEÇÃO DE ÁREA (SWAL)
   ======================================== */
.swal-area-selection {
  padding: 1rem;
}

.area-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  max-height: 60vh;
  overflow-y: auto;
  padding: 1rem;
}

.area-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
  border: 2px solid #dee2e6;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  background: white;
  min-height: 120px;
}

.area-option:hover {
  border-color: #007bff;
  background: #f8f9fa;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.area-option.selected {
  border-color: #28a745;
  background: #d4edda;
  position: relative;
}

.area-option.selected::after {
  content: '✓';
  position: absolute;
  top: 8px;
  right: 8px;
  background: #28a745;
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.area-option i {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.area-option span {
  font-weight: 600;
  text-align: center;
  margin-bottom: 0.25rem;
}

.area-option small {
  color: #6c757d;
  font-size: 0.75rem;
}

/* ========================================
   RESPONSIVIDADE
   ======================================== */

/* Telas pequenas (altura < 600px) */
@media (max-height: 600px) { 
  :root { 
    --gap: 5px;
    --barH: 35px;
  }
  
  .pos-wrap .btn-touch {
    padding: 2px;
  }
  
  .pos-wrap .btn-touch span { font-size: 0.55rem; }
  .pos-wrap .btn-touch i { font-size: 0.8rem; }
  
  .pos-wrap .btn-touch.btn-selected::after {
    width: 14px;
    height: 14px;
    font-size: 10px;
  }
}

/* Landscape com altura pequena */
@media (orientation: landscape) and (max-height: 500px) {
  :root {
    --gap: 4px;
    --barH: 32px;
  }
  
  .pos-wrap .btn-touch i {
    font-size: clamp(0.7rem, 1.8vw, 1.2rem);
  }
}

/* Tablets portrait */
@media (min-width: 768px) and (orientation: portrait) {
  :root { --gap: 10px; }
  
  .pos-wrap .btn-touch span {
    font-size: clamp(0.7rem, 1.3vw, 0.95rem);
  }
}

/* Tablets - ajuste da grid de área */
@media (max-width: 768px) {
  .area-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
  
  .area-option {
    padding: 1rem 0.5rem;
    min-height: 100px;
  }
  
  .area-option i { font-size: 1.5rem; }
}

/* Desktop grande */
@media (min-width: 1024px) {
  :root {
    --gap: 12px;
    --barH: 45px;
  }
  
  .pos-wrap .btn-touch span { font-size: 0.9rem; }
  .pos-wrap .btn-touch i { font-size: 1.8rem; }
  
  .pos-wrap .btn-touch.btn-selected::after {
    width: 20px;
    height: 20px;
    font-size: 14px;
  }
}

/* ========================================
   PREVENIR ZOOM E SELEÇÃO (IMPORTANTE)
   ======================================== */
* {
  -webkit-tap-highlight-color: transparent;
}

body {
  touch-action: pan-x pan-y;
}

/* Teclado numérico específico */
.btn-numpad {
  touch-action: manipulation !important;
}

/* Prevenir zoom em inputs do Swal (iOS) */
.swal2-input,
.swal2-textarea {
  font-size: 16px !important;
}