/* ============================================================
   IMPROVEMENTS — Sobrepõe melhorias sem alterar arquivos existentes
   Carregado por último em operador.html, então tem precedência.
   ============================================================ */

/* ----------------------------------------------------------------
   1. FOCUS RINGS GLOBAIS — acessibilidade keyboard
   ---------------------------------------------------------------- */
*:focus-visible {
  outline: 2px solid var(--accent, #c9a227);
  outline-offset: 2px;
  border-radius: 6px;
}
button:focus-visible,
[role="button"]:focus-visible,
.btn:focus-visible,
.icon-btn:focus-visible {
  outline: 2px solid var(--accent, #c9a227);
  outline-offset: 2px;
}
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
.field-input:focus-visible,
.field-input:focus,
.select:focus {
  outline: none !important;
  border-color: var(--accent, #c9a227) !important;
  box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.18) !important;
}

/* ----------------------------------------------------------------
   2. TOASTS — visual polido + acessível + mobile-friendly
   ---------------------------------------------------------------- */
#toast-container {
  /* Posicionamento: bottom em desktop, top em mobile (acima da fila) */
  position: fixed;
  z-index: 70;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

@media (min-width: 640px) {
  #toast-container {
    bottom: 16px;
    right: 16px;
    left: auto;
    align-items: flex-end;
    max-width: 380px;
  }
}
@media (max-width: 639px) {
  #toast-container {
    top: 12px;
    left: 12px;
    right: 12px;
    align-items: stretch;
  }
}

.toast-item {
  pointer-events: auto;
  background: rgba(15, 25, 38, 0.96);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-left: 3px solid var(--accent, #c9a227);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  box-shadow: 0 12px 32px -4px rgba(0, 0, 0, 0.5);
  min-width: 280px;
  animation: toast-slide-in 240ms cubic-bezier(0.16, 1, 0.3, 1);
}
.toast-item.removing {
  animation: toast-slide-out 200ms ease forwards;
}
@keyframes toast-slide-in {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-slide-out {
  to { opacity: 0; transform: translateX(20px) scale(0.96); }
}

.toast-item.toast-success { border-left-color: #34d399; }
.toast-item.toast-error   { border-left-color: #f87171; }
.toast-item.toast-warning { border-left-color: #fbbf24; }
.toast-item.toast-info    { border-left-color: #60a5fa; }

.toast-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 2px;
  font-size: 16px;
}
.toast-success .toast-icon { color: #34d399; }
.toast-error   .toast-icon { color: #f87171; }
.toast-warning .toast-icon { color: #fbbf24; }
.toast-info    .toast-icon { color: #60a5fa; }

.toast-body {
  flex: 1;
  min-width: 0;
}
.toast-title {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.96);
  line-height: 1.35;
  margin: 0;
}
.toast-desc {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.62);
  line-height: 1.45;
  margin: 2px 0 0 0;
  word-break: break-word;
}
.toast-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: 4px;
}
.toast-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.85);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms;
}
.toast-btn:hover { background: rgba(255, 255, 255, 0.08); }
.toast-close {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.45);
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  cursor: pointer;
  transition: color 120ms, background 120ms;
}
.toast-close:hover {
  color: rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.06);
}

/* ----------------------------------------------------------------
   3. LOADING STATE EM BOTÕES — espaço pra spinner inline
   ---------------------------------------------------------------- */
.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn.is-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.95);
  animation: btn-spin 720ms linear infinite;
}
@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

/* ----------------------------------------------------------------
   4. MOBILE/TABLET — quebras essenciais
   ---------------------------------------------------------------- */

/* Header app-header mais compacto em mobile */
@media (max-width: 640px) {
  .app-header-inner {
    padding: 0 12px !important;
    height: 52px;
  }
  .brand-text-sub {
    display: none;
  }
  .brand-text-name {
    font-size: 15px;
  }
}

/* Stepper com scroll horizontal em mobile sem quebrar layout */
@media (max-width: 640px) {
  .stepper {
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 4px;
  }
  .stepper::-webkit-scrollbar { display: none; }
  .step {
    flex-shrink: 0;
  }
}

/* Grids 2-col viram 1-col em mobile */
@media (max-width: 768px) {
  .grid.md\:grid-cols-2,
  .grid.md\:grid-cols-3,
  .grid.md\:grid-cols-4 {
    grid-template-columns: 1fr !important;
  }
}

/* Page container e seções com padding consistente em mobile */
@media (max-width: 640px) {
  .page-container {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }
  .surface-elevated {
    padding: 16px !important;
  }
  .section-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
}

/* Touch targets mínimo 44px em mobile */
@media (max-width: 640px) {
  .btn,
  .icon-btn,
  button:not(.toast-close):not(.tab) {
    min-height: 40px;
  }
  .icon-btn {
    width: 40px;
    height: 40px;
  }
  /* Inputs mais altos pra dedo */
  .field-input,
  .select,
  .field-textarea,
  input,
  textarea,
  select {
    font-size: 16px !important; /* evita zoom do iOS no focus */
  }
}

/* Tabbar com scroll horizontal em mobile */
@media (max-width: 640px) {
  .tabbar {
    overflow-x: auto;
    scrollbar-width: none;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }
  .tabbar::-webkit-scrollbar { display: none; }
  .tab {
    flex-shrink: 0;
    white-space: nowrap;
  }
}

/* Modal/dialog full-width em mobile */
@media (max-width: 640px) {
  .modal-content,
  .dialog-content,
  [role="dialog"] {
    width: calc(100vw - 24px) !important;
    max-width: calc(100vw - 24px) !important;
    margin: 12px;
  }
}

/* Select-grid (escolha de tipos de documento) — 1-col em mobile, 2-col em tablet */
.select-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
@media (min-width: 640px) {
  .select-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Esconde elementos só-desktop em mobile */
@media (max-width: 640px) {
  .desktop-only { display: none !important; }
}
@media (min-width: 641px) {
  .mobile-only { display: none !important; }
}

/* ----------------------------------------------------------------
   5. AÇÕES EM CARDS — botões de delete mais óbvios
   ---------------------------------------------------------------- */
.history-card .action-btn,
.action-btn {
  transition: background 140ms, color 140ms, transform 140ms;
}
.action-btn:hover {
  transform: scale(1.05);
}
.action-btn.action-danger:hover {
  background: rgba(239, 68, 68, 0.14);
  color: #f87171;
}

/* ----------------------------------------------------------------
   6. SCROLLBAR sutil
   ---------------------------------------------------------------- */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.22);
  background-clip: padding-box;
}

/* ----------------------------------------------------------------
   7. ANIMATION REDUCE — respeitar preferência do sistema
   ---------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
