/* ══════════════════════════════════════════════
   ux-fixes.css — Correções UX/UI Mesa de Especialistas
   Nielsen Norman · Norman DOET · Garrett Elements
   Material Design 3 · Apple HIG · WCAG 2.1 AA
══════════════════════════════════════════════ */

/* ══════════════════════════════════════════════
   P0: CONTRASTE WCAG AA (4.5:1 mínimo)
   Sobrescreve variáveis de base.css
══════════════════════════════════════════════ */
:root {
  --gold-d:    #A8893D;  /* 4.6:1 sobre ink2 — corrigido de #7A5F28 */
  --parch2:    #D4C4A8;  /* 9.2:1 sobre ink — corrigido de #C8BAA0 */
  --parch3:    #B0A08A;  /* 5.8:1 sobre ink — corrigido de #8C7D66 */
  --text-muted: rgba(237,224,200,0.72);
  
  /* MD3 Type Scale */
  --type-display:  2.25rem;
  --type-headline: 1.5rem;
  --type-title:    1.125rem;
  --type-body:     1rem;
  --type-label:    0.875rem;
  --type-caption:  0.75rem;
}

/* ══════════════════════════════════════════════
   P0: TOUCH TARGETS — 44×44px mínimo (Apple HIG)
══════════════════════════════════════════════ */

/* Elementos que precisam de área de toque maior */
.letter-chip,
.rune-slot,
.hora-cell,
.geo-fig,
.seph-node,
.iching-line,
[role="button"] {
  min-height: 44px;
  min-width: 44px;
  cursor: pointer;
}

/* Touch target invisível para elementos pequenos */
.touch-target-expand {
  position: relative;
}
.touch-target-expand::before {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 44px; height: 44px;
  min-width: 100%; min-height: 100%;
}

/* ══════════════════════════════════════════════
   P1: LOADING STATES — MD3 Progress Indicators
══════════════════════════════════════════════ */

/* Botão em estado de loading */
.btn--loading,
.btn-ghost--loading,
.btn-premium--loading {
  pointer-events: none;
  opacity: 0.7;
  position: relative;
}

.btn--loading .btn-text,
.btn-ghost--loading .btn-text,
.btn-premium--loading .btn-text {
  opacity: 0.5;
}

.btn--loading::after,
.btn-ghost--loading::after,
.btn-premium--loading::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  right: 12px; top: 50%;
  transform: translateY(-50%);
}

/* Skeleton loading para texto */
.skeleton {
  background: linear-gradient(90deg, var(--ink3) 25%, var(--ink4) 50%, var(--ink3) 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
  min-height: 1em;
}

.skeleton-text {
  height: 1em;
  margin-bottom: 0.5em;
  border-radius: 4px;
}

.skeleton-text:last-child {
  width: 70%;
}

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

/* Progress bar linear para operações >2s */
.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--ink3);
  border-radius: 2px;
  overflow: hidden;
  margin: 1rem 0;
}

.progress-bar--indeterminate::after {
  content: '';
  display: block;
  height: 100%;
  background: var(--gold);
  border-radius: 2px;
  animation: progress-indeterminate 1.5s ease-in-out infinite;
}

@keyframes progress-indeterminate {
  0% { transform: translateX(-100%); width: 40%; }
  50% { width: 60%; }
  100% { transform: translateX(250%); width: 40%; }
}

/* ══════════════════════════════════════════════
   P1: ERROR STATES — Feedback específico
══════════════════════════════════════════════ */

.error-message {
  background: rgba(122,21,37,0.15);
  border: 1px solid rgba(122,21,37,0.4);
  border-left: 3px solid var(--crimson);
  padding: 1rem 1.2rem;
  border-radius: var(--radius-md);
  margin: 1rem 0;
  animation: fadeUp 0.3s ease;
}

.error-message__icon {
  font-size: 1.2rem;
  margin-right: 0.5rem;
}

.error-message__title {
  font-family: 'Cinzel', serif;
  font-size: var(--type-label);
  color: #E57373;
  margin-bottom: 0.3rem;
  display: flex;
  align-items: center;
}

.error-message__text {
  font-size: var(--type-body);
  color: var(--parch2);
  line-height: 1.5;
}

.error-message__action {
  margin-top: 0.8rem;
}

/* Tipos específicos de erro */
.error-message--rate-limit {
  border-left-color: var(--gold);
}

.error-message--rate-limit .error-message__title {
  color: var(--gold);
}

.error-message--network {
  border-left-color: #64B5F6;
}

.error-message--network .error-message__title {
  color: #64B5F6;
}

/* ══════════════════════════════════════════════
   P3: EMPTY STATES — NN Group guidelines
══════════════════════════════════════════════ */

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--parch3);
}

.empty-state__icon {
  font-size: 3rem;
  opacity: 0.4;
  margin-bottom: 1rem;
  display: block;
}

.empty-state__title {
  font-family: 'Cinzel', serif;
  font-size: var(--type-title);
  color: var(--parch2);
  margin-bottom: 0.5rem;
}

.empty-state__text {
  font-size: var(--type-body);
  line-height: 1.6;
  max-width: 280px;
  margin: 0 auto 1.2rem;
}

.empty-state__action {
  margin-top: 1rem;
}

/* ══════════════════════════════════════════════
   P2: FORM FIELDS — MD3 Outlined Text Fields
══════════════════════════════════════════════ */

.field-wrap {
  position: relative;
  margin-bottom: 1.2rem;
}

.field-label {
  display: block;
  font-family: 'Cinzel', serif;
  font-size: var(--type-caption);
  letter-spacing: 0.1em;
  color: var(--parch3);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
}

.field-label--required::after {
  content: ' *';
  color: var(--gold);
}

.field-input,
input.field-input,
select.field-input,
textarea.field-input {
  width: 100%;
  background: var(--ink2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.9rem 1rem;
  color: var(--parch);
  font-family: 'EB Garamond', serif;
  font-size: var(--type-body) !important;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 48px;
}

.field-input:hover {
  border-color: var(--border-l);
}

.field-input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(201,168,76,0.2);
}

.field-input::placeholder {
  color: var(--parch3);
  opacity: 0.7;
}

.field-input--error,
.field-input--error:focus {
  border-color: var(--crimson);
  box-shadow: 0 0 0 2px rgba(122,21,37,0.2);
}

.field-helper {
  font-size: var(--type-caption);
  color: var(--parch3);
  margin-top: 0.3rem;
  line-height: 1.4;
}

.field-helper--error {
  color: #E57373;
}

/* ══════════════════════════════════════════════
   P1: MODALS — Acessibilidade ARIA compliant
══════════════════════════════════════════════ */

/* Focus trap visual indicator */
.modal-overlay[aria-modal="true"] {
  display: flex;
}

.modal-overlay:focus {
  outline: none;
}

/* Escape hint for accessibility */
.modal-escape-hint {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: var(--type-caption);
  color: var(--parch3);
  opacity: 0.6;
}

/* Reading modal improvements */
.reading-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(9,7,12,0.94);
  z-index: 600;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.reading-modal-overlay.open {
  display: flex;
  opacity: 1;
}

.reading-modal-box {
  background: var(--ink2);
  border: 1px solid rgba(201,168,76,0.3);
  border-radius: var(--radius-lg);
  max-width: 600px;
  width: 100%;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: fadeUp 0.3s ease;
  position: relative;
}

.reading-modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--parch3);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
  z-index: 2;
}

.reading-modal-close:hover {
  color: var(--gold);
}

/* ══════════════════════════════════════════════
   P2: DROPDOWN AVATAR — Norman Affordances
══════════════════════════════════════════════ */

.auth-avatar {
  position: relative;
}

/* Chevron indicator */
.auth-avatar::after {
  content: '▾';
  font-size: 8px;
  position: absolute;
  bottom: 2px;
  right: 2px;
  color: var(--gold);
  opacity: 0.7;
}

.auth-avatar[aria-expanded="true"]::after {
  content: '▴';
}

/* ══════════════════════════════════════════════
   P2: SCROLL HORIZONTAL INDICATORS
══════════════════════════════════════════════ */

.scroll-container {
  position: relative;
}

.scroll-container--has-overflow-left::before,
.scroll-container--has-overflow-right::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 40px;
  pointer-events: none;
  z-index: 2;
}

.scroll-container--has-overflow-left::before {
  left: 0;
  background: linear-gradient(90deg, var(--ink) 0%, transparent 100%);
}

.scroll-container--has-overflow-right::after {
  right: 0;
  background: linear-gradient(270deg, var(--ink) 0%, transparent 100%);
}

/* Spread selector scroll indicators */
.spread-selector-wrap {
  position: relative;
}

.spread-arrow {
  opacity: 0.7;
  background: var(--ink2);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s, background 0.2s;
}

.spread-arrow:hover {
  opacity: 1;
  background: var(--ink3);
  border-color: var(--gold);
}

/* ══════════════════════════════════════════════
   P3: 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;
  }
  
  .skeleton {
    animation: none;
    background: var(--ink3);
  }
  
  .progress-bar--indeterminate::after {
    animation: none;
    width: 100%;
  }
}

/* ══════════════════════════════════════════════
   P1: FOCUS VISIBLE — Acessibilidade teclado
══════════════════════════════════════════════ */

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Remove outline em cliques de mouse */
:focus:not(:focus-visible) {
  outline: none;
}

/* Focus ring para elementos customizados */
.btn:focus-visible,
.btn-ghost:focus-visible,
.btn-premium:focus-visible {
  box-shadow: 0 0 0 3px rgba(201,168,76,0.4);
}

/* ══════════════════════════════════════════════
   BUTTON STATES — Disabled
══════════════════════════════════════════════ */

.btn:disabled,
.btn[aria-disabled="true"],
.btn-ghost:disabled,
.btn-ghost[aria-disabled="true"],
.btn-premium:disabled,
.btn-premium[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  pointer-events: none;
}

/* ══════════════════════════════════════════════
   MOBILE FIXES
══════════════════════════════════════════════ */

@media (max-width: 600px) {
  .field-input {
    font-size: 16px !important; /* Previne zoom iOS */
  }
  
  .error-message {
    padding: 0.8rem 1rem;
  }
  
  .empty-state {
    padding: 2rem 1rem;
  }
  
  .empty-state__icon {
    font-size: 2.5rem;
  }
}
