/* ================================================
   ORDEM DOS NAVEGADORES — UI v2 additions
   Toasts · Skeletons · Modal a11y · Empty states
   ================================================ */

/* ════════════════════════════════════════
   TOAST SYSTEM
   ════════════════════════════════════════ */
.toast-container {
  position: fixed;
  bottom: var(--s6);
  right: var(--s6);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  max-width: 420px;
  pointer-events: none;
}

@media (max-width: 640px) {
  .toast-container {
    left: var(--s4);
    right: var(--s4);
    bottom: var(--s4);
    max-width: none;
  }
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  padding: var(--s4) var(--s5);
  background: rgba(11, 20, 34, 0.96);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--gold);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-card);
  color: var(--text-primary);
  font-size: 0.92rem;
  line-height: 1.45;
  min-width: 260px;
  max-width: 420px;
  animation: toast-in 320ms cubic-bezier(.22,.9,.35,1.15);
  position: relative;
}

.toast--success { border-left-color: var(--green); }
.toast--error   { border-left-color: var(--red); }
.toast--warning { border-left-color: var(--amber); }
.toast--info    { border-left-color: var(--cyan); }

.toast-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-top: 1px;
}
.toast--success .toast-icon { color: var(--green); }
.toast--error   .toast-icon { color: var(--red); }
.toast--warning .toast-icon { color: var(--amber); }
.toast--info    .toast-icon { color: var(--cyan); }

.toast-body { flex: 1; min-width: 0; }
.toast-title {
  font-weight: 600;
  margin-bottom: 2px;
  font-size: 0.95rem;
  color: var(--gold-light);
  font-family: 'Cinzel', serif;
  letter-spacing: 0.02em;
}
.toast-msg {
  color: var(--text-primary);
  word-wrap: break-word;
}

.toast-close {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-xs);
  color: var(--text-muted);
  transition: color var(--ease-fast), background var(--ease-fast);
}
.toast-close:hover { color: var(--text-primary); background: var(--bg-input); }

.toast-progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  background: var(--gold);
  opacity: 0.45;
  transform-origin: left;
}

.toast.is-leaving {
  animation: toast-out 240ms cubic-bezier(.4,0,.2,1) forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(24px) scale(.96); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(24px) scale(.96); }
}

/* ════════════════════════════════════════
   SKELETON LOADERS
   ════════════════════════════════════════ */
.skeleton {
  position: relative;
  overflow: hidden;
  background: linear-gradient(
    90deg,
    rgba(255,255,255,0.03) 0%,
    rgba(255,255,255,0.06) 50%,
    rgba(255,255,255,0.03) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.6s ease-in-out infinite;
  border-radius: var(--r-sm);
}

.skeleton--text      { height: 0.95em; margin: 6px 0; }
.skeleton--title     { height: 1.4em;  margin: 8px 0; border-radius: var(--r-xs); }
.skeleton--avatar    { width: 44px; height: 44px; border-radius: var(--r-full); }
.skeleton--thumb     { width: 100%; aspect-ratio: 16/9; border-radius: var(--r-sm); }
.skeleton--card      { height: 120px; border-radius: var(--r-md); }
.skeleton--btn       { width: 110px; height: 36px; border-radius: var(--r-sm); }

.skeleton--w-30 { width: 30%; }
.skeleton--w-50 { width: 50%; }
.skeleton--w-70 { width: 70%; }
.skeleton--w-90 { width: 90%; }

@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; opacity: 0.6; }
}

/* ════════════════════════════════════════
   MODAL A11Y POLISH
   ════════════════════════════════════════ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 5, 10, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s4);
  animation: backdrop-in 220ms ease-out;
}

.modal-backdrop.is-leaving { animation: backdrop-out 180ms ease-in forwards; }

.modal-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-gold);
  border-radius: var(--r-lg);
  max-width: 520px;
  width: 100%;
  max-height: 86vh;
  overflow: auto;
  box-shadow: var(--shadow-card), var(--shadow-gold);
  animation: modal-in 320ms cubic-bezier(.22,.9,.35,1.15);
}
.modal-panel.is-leaving { animation: modal-out 180ms ease-in forwards; }

@keyframes backdrop-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes backdrop-out { to { opacity: 0; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(14px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes modal-out {
  to { opacity: 0; transform: translateY(10px) scale(.98); }
}

/* Focus ring unificado */
:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* ════════════════════════════════════════
   EMPTY STATE — NAUTICAL
   ════════════════════════════════════════ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s12) var(--s6);
  text-align: center;
  gap: var(--s4);
  color: var(--text-secondary);
}
.empty-state__compass {
  width: 72px;
  height: 72px;
  color: var(--gold-dim);
  opacity: 0.5;
  animation: compass-slow-spin 28s linear infinite;
}
.empty-state__title {
  font-family: 'Cinzel', serif;
  font-size: 1.2rem;
  letter-spacing: 0.05em;
  color: var(--gold-light);
  margin: 0;
}
.empty-state__desc {
  font-size: 0.92rem;
  max-width: 38ch;
  color: var(--text-secondary);
  margin: 0;
}
@keyframes compass-slow-spin {
  to { transform: rotate(360deg); }
}

/* ════════════════════════════════════════
   SIDEBAR RAIL MODE (collapsed to icons)
   Toggle by adding .sidebar--rail class
   ════════════════════════════════════════ */
.sidebar {
  position: relative; /* anchor for ui-rail-toggle */
}
.sidebar--rail {
  width: 72px !important;
  min-width: 72px !important;
}
.sidebar--rail .logo-text,
.sidebar--rail .role-badge,
.sidebar--rail .nav-label,
.sidebar--rail .user-info-text,
.sidebar--rail .sidebar-section-title,
.sidebar--rail .nav-section-label,
.sidebar--rail .nav-item > span:not([class*="badge"]),
.sidebar--rail .nav-badge {
  display: none !important;
}
.sidebar--rail .nav-item,
.sidebar--rail .logo {
  justify-content: center;
}

/* Floating rail toggle button (auto-injected by ui-v2.js) */
.ui-rail-toggle {
  position: absolute;
  bottom: 10px;
  right: -14px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-card, #0d1117);
  border: 1px solid var(--border, rgba(201,168,76,0.25));
  color: var(--gold, #c9a84c);
  cursor: pointer;
  transition: transform .2s var(--ease, ease), background .15s;
  z-index: 10;
  padding: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.ui-rail-toggle:hover {
  background: var(--bg-hover, rgba(201,168,76,0.1));
}
.ui-rail-toggle svg { width: 14px; height: 14px; }
.sidebar--rail .ui-rail-toggle svg { transform: rotate(180deg); }
@media (max-width: 768px) {
  .ui-rail-toggle { display: none; }
}

/* ════════════════════════════════════════
   DENSITY TOGGLE (tables)
   ════════════════════════════════════════ */
[data-density="compact"] td,
[data-density="compact"] th { padding: 6px 10px !important; font-size: 0.88rem; }
[data-density="comfy"] td,
[data-density="comfy"] th   { padding: 16px 18px !important; }

/* ════════════════════════════════════════
   INLINE FORM VALIDATION HINTS
   ════════════════════════════════════════ */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--s4); }
.field__label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.field__input {
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-primary);
  transition: border-color var(--ease-fast), background var(--ease-fast);
}
.field__input:focus {
  outline: none;
  border-color: var(--gold);
  background: rgba(255,255,255,0.06);
}
.field__input:user-invalid {
  border-color: var(--red);
  background: var(--red-dim);
}
.field__hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-height: 1em;
}
.field__input:user-invalid ~ .field__hint { color: var(--red); }

/* ════════════════════════════════════════
   BUTTON — SHIP-WHEEL LOADING
   ════════════════════════════════════════ */
.btn-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.18);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: btn-spin 700ms linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* ════════════════════════════════════════
   STICKY TABLE HEADERS (auto-apply to admin tables)
   ════════════════════════════════════════ */
.admin-content table thead th,
.tabela-clientes thead th,
table.data-table thead th,
table.admin-table thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg-secondary);
  box-shadow: inset 0 -1px 0 var(--border-gold);
}

/* ════════════════════════════════════════
   CUSTOM SCROLLBAR — NAUTICAL
   ════════════════════════════════════════ */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(201,168,76,0.25) transparent;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.15); }
::-webkit-scrollbar-thumb {
  background: rgba(201,168,76,0.22);
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(201,168,76,0.45);
  background-clip: padding-box;
}

/* ════════════════════════════════════════
   TEXT SELECTION — GOLD
   ════════════════════════════════════════ */
::selection      { background: rgba(201,168,76,0.28); color: var(--gold-light); }
::-moz-selection { background: rgba(201,168,76,0.28); color: var(--gold-light); }

/* ════════════════════════════════════════
   BETTER LINK UNDERLINES
   ════════════════════════════════════════ */
.content a[href]:not([class]):not([role]) {
  color: var(--gold-light);
  text-decoration: underline;
  text-decoration-color: rgba(201,168,76,0.4);
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: text-decoration-color var(--ease-fast);
}
.content a[href]:not([class]):not([role]):hover {
  text-decoration-color: var(--gold);
}

/* ════════════════════════════════════════
   PRINT — clean
   ════════════════════════════════════════ */
@media print {
  .sidebar, .topbar, .toast-container, .modal-backdrop { display: none !important; }
  body::before, body::after { display: none !important; }
  body { background: white; color: black; }
}

/* ════════════════════════════════════════
   REDUCED MOTION
   ════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ════════════════════════════════════════
   LOADING BAR TOP (progress indicator)
   ════════════════════════════════════════ */
.loading-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--gold);
  transform-origin: left;
  transform: scaleX(0);
  z-index: 9998;
  box-shadow: 0 0 8px var(--gold-glow);
  transition: transform var(--ease);
}
.loading-bar.is-active { animation: loading-progress 1.8s ease-out forwards; }
@keyframes loading-progress {
  0%   { transform: scaleX(0); }
  40%  { transform: scaleX(0.55); }
  85%  { transform: scaleX(0.85); }
  100% { transform: scaleX(1); }
}

/* ════════════════════════════════════════
   KBD — keyboard key hint
   ════════════════════════════════════════ */
kbd {
  display: inline-block;
  padding: 2px 8px;
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 0.82em;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--text-primary);
  line-height: 1.3;
}

/* ════════════════════════════════════════
   BADGE SYSTEM (reusable)
   ════════════════════════════════════════ */
.ui-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: var(--r-full);
  line-height: 1.5;
}
.ui-badge--gold  { background: var(--gold-subtle); color: var(--gold-light); border: 1px solid var(--border-gold); }
.ui-badge--green { background: var(--green-dim); color: var(--green); border: 1px solid rgba(34,197,94,0.25); }
.ui-badge--red   { background: var(--red-dim); color: var(--red); border: 1px solid rgba(239,68,68,0.25); }
.ui-badge--amber { background: var(--amber-dim); color: var(--amber); border: 1px solid rgba(245,158,11,0.25); }
.ui-badge--cyan  { background: var(--cyan-dim); color: var(--cyan); border: 1px solid var(--border-cyan); }
