/* ══════════════════════════════════════════════
   FotoGestión — Design System
   Level: Apple / Linear / Vercel
   ══════════════════════════════════════════════ */

/* Legacy aliases — mapped to tokens.css
   Kept for backward compat; prefer semantic tokens in new code. */
:root {
  --border:        var(--border-default);
  --emerald:       var(--brand);
  --emerald-light: var(--brand-light);
  --emerald-dim:   var(--brand-dim);
  --blue:          var(--accent);
  --blue-dim:      var(--accent-dim);
  --red:           var(--danger);
  --red-dim:       var(--danger-dim);
  --amber:         var(--warning);
  --amber-dim:     var(--warning-dim);
}

/* ── Reset & Base ── */
* { -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Smooth transitions on all interactive elements ── */
button, a, input, select, textarea {
  transition: all var(--duration-normal) var(--ease-default);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand) !important;
  box-shadow: 0 0 0 3px var(--brand-dim);
}

/* ── Custom Scrollbar ── */
::-webkit-scrollbar { width: 3px; height: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-neutral-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-neutral-500); }

/* ══════════════════════════════════════════════
   ANIMATIONS
   ══════════════════════════════════════════════ */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 50%, 90% { transform: translateX(-6px); }
  30%, 70% { transform: translateX(6px); }
}
@keyframes pulse-soft {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes ripple-ring {
  0% { transform: scale(1); opacity: 0.5; }
  100% { transform: scale(2.2); opacity: 0; }
}
@keyframes checkmark-draw {
  to { stroke-dashoffset: 0; }
}
@keyframes progress-indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}
@keyframes border-rotate {
  to { --border-angle: 360deg; }
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-8px) scale(0.96); }
}
@keyframes wave {
  0%, 100% { transform: scaleY(0.4); }
  50% { transform: scaleY(1); }
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* ── Animation Utilities ── */
.anim-fadeIn { animation: fadeIn 0.3s ease both; }
.anim-fadeInUp { animation: fadeInUp 0.4s ease both; }
.anim-slideUp { animation: slideUp 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) both; }
.anim-scaleIn { animation: scaleIn 0.3s ease both; }
.anim-shake { animation: shake 0.5s ease; }
.anim-pulse { animation: pulse-soft 2s ease-in-out infinite; }
.anim-spin { animation: spin 1s linear infinite; }
.anim-float { animation: float 3s ease-in-out infinite; }

/* Staggered entrance — set --i via style="--i:0" etc. */
.stagger {
  animation: fadeInUp 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
  animation-delay: calc(var(--i, 0) * 60ms);
}

/* ══════════════════════════════════════════════
   GLASS & SURFACE EFFECTS
   ══════════════════════════════════════════════ */

.glass {
  background: var(--bg-glass);
  backdrop-filter: blur(var(--blur-md));
  -webkit-backdrop-filter: blur(var(--blur-md));
  border: 1px solid var(--border-default);
}
.glass-hover:hover {
  background: var(--bg-glass-hover);
  border-color: var(--border-hover);
}

.surface {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
}

/* ── Glow Effects ── */
.glow-emerald {
  box-shadow: 0 0 24px var(--brand-glow), 0 0 80px var(--brand-glow-outer);
}
.glow-blue {
  box-shadow: 0 0 24px var(--accent-glow), 0 0 80px var(--accent-glow-outer);
}
.glow-red {
  box-shadow: 0 0 24px var(--danger-glow), 0 0 80px var(--danger-glow-outer);
}
.glow-amber {
  box-shadow: 0 0 24px var(--warning-glow), 0 0 80px var(--warning-glow-outer);
}

/* ══════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ══════════════════════════════════════════════ */

#toast-container {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 400px;
}
.toast {
  pointer-events: auto;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  backdrop-filter: blur(var(--blur-md));
  -webkit-backdrop-filter: blur(var(--blur-md));
  animation: toast-in 0.3s var(--ease-out) both;
}
.toast.toast-exit {
  animation: toast-out 0.2s ease both;
}
.toast-success {
  background: var(--brand-dim);
  border: 1px solid var(--brand-border);
  color: var(--brand-light);
}
.toast-error {
  background: var(--danger-dim);
  border: 1px solid var(--danger-border);
  color: var(--danger-light);
}
.toast-info {
  background: var(--accent-dim);
  border: 1px solid var(--accent-border);
  color: var(--accent-soft);
}
.toast-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

/* ══════════════════════════════════════════════
   TAB BAR (iOS-style bottom nav)
   ══════════════════════════════════════════════ */

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tabbar-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-blur);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-default);
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  z-index: 100;
}
.tab-bar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 16px 6px;
  color: var(--text-tertiary);
  text-decoration: none;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: color var(--duration-normal);
}
.tab-bar-item:hover, .tab-bar-item:active {
  color: var(--text-disabled);
}
.tab-bar-item.active {
  color: var(--brand);
}
.tab-bar-item svg {
  width: 22px;
  height: 22px;
}
.tab-bar-spacer {
  height: calc(76px + var(--safe-bottom));
}

/* ══════════════════════════════════════════════
   RECORDING / VOICE
   ══════════════════════════════════════════════ */

.record-btn {
  position: relative;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--duration-normal), box-shadow var(--duration-slow);
}
.record-btn:active {
  transform: scale(0.95);
}
.record-btn.is-recording {
  transform: scale(1.05);
}

/* Pulsing rings during recording */
.record-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--y-brand-vivid);
  opacity: 0;
}
.is-recording .record-ring {
  animation: ripple-ring 1.5s ease-out infinite;
}
.is-recording .record-ring:nth-child(2) {
  animation-delay: 0.5s;
}
.is-recording .record-ring:nth-child(3) {
  animation-delay: 1s;
}

/* Audio wave bars */
.wave-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 40px;
}
.wave-bar {
  width: 3px;
  border-radius: 1.5px;
  background: currentColor;
  transform-origin: center;
}
.is-recording .wave-bar {
  animation: wave 0.8s ease-in-out infinite;
}
.wave-bar:nth-child(1) { height: 12px; animation-delay: 0s; }
.wave-bar:nth-child(2) { height: 20px; animation-delay: 0.1s; }
.wave-bar:nth-child(3) { height: 28px; animation-delay: 0.15s; }
.wave-bar:nth-child(4) { height: 36px; animation-delay: 0.2s; }
.wave-bar:nth-child(5) { height: 28px; animation-delay: 0.25s; }
.wave-bar:nth-child(6) { height: 20px; animation-delay: 0.3s; }
.wave-bar:nth-child(7) { height: 12px; animation-delay: 0.35s; }

/* ══════════════════════════════════════════════
   PROCESSING / PROGRESS
   ══════════════════════════════════════════════ */

.progress-bar {
  width: 100%;
  height: 3px;
  background: var(--y-border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--y-brand-vivid);
  transition: width 0.5s ease;
}
.progress-indeterminate .progress-bar-fill {
  width: 30%;
  animation: progress-indeterminate 1.5s ease-in-out infinite;
}

/* AI Sparkle spinner */
.ai-spinner {
  width: 48px;
  height: 48px;
  animation: spin 3s linear infinite;
}
.ai-spinner path {
  fill: var(--brand);
}

/* ══════════════════════════════════════════════
   CONFIDENCE INDICATORS
   ══════════════════════════════════════════════ */

.confidence-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--border-default);
  overflow: hidden;
}
.confidence-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.6s ease;
}
.confidence-high { background: var(--brand); }
.confidence-med  { background: var(--warning); }
.confidence-low  { background: var(--danger); }

.field-warning {
  background: var(--warning-dim);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius-md);
}

/* ══════════════════════════════════════════════
   OCR CONFIDENCE TIERS
   Three-level visual system for AI-extracted fields
   HIGH ≥0.9  |  MED 0.7–0.9  |  LOW <0.7
   ══════════════════════════════════════════════ */

.ocr-field {
  position: relative;
  border-radius: var(--radius-lg);
  transition: border-color var(--duration-normal) var(--ease-default),
              background var(--duration-normal) var(--ease-default),
              box-shadow var(--duration-normal) var(--ease-default);
}

/* ── HIGH ≥ 0.9 — green subtle, settled ── */
.ocr-field--high {
  border: 1px solid var(--y-border);
  background: var(--y-surface);
}

/* ── MED 0.7–0.9 — amber 2px, tap to review ── */
.ocr-field--med {
  border: 2px solid var(--y-amber);
  background: var(--y-amber-subtle);
  cursor: pointer;
}
.ocr-field--med [readonly] {
  pointer-events: none;
  opacity: 0.85;
}
.ocr-field--med.is-unlocked {
  border-color: var(--y-amber-border);
  background: var(--y-surface);
  cursor: default;
}
.ocr-field--med.is-unlocked [readonly] {
  pointer-events: auto;
  opacity: 1;
}

/* ── LOW < 0.7 — red, forced input ── */
.ocr-field--low {
  border: 2px solid var(--y-er);
  background: var(--y-er-bg);
}
.ocr-field--low:not(.is-resolved) {
  animation: pulse-soft 2.5s ease-in-out infinite;
}
.ocr-field--low.is-resolved {
  border-color: var(--y-brand);
  background: var(--y-brand-subtle);
  animation: none;
}

/* ── OCR Badges ── */
.ocr-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}
.ocr-badge--med {
  background: var(--warning-dim);
  color: var(--warning-light);
  border: 1px solid var(--warning-border);
}
.ocr-badge--low {
  background: var(--danger-dim);
  color: var(--danger-light);
  border: 1px solid var(--danger-border);
}
.ocr-badge--ok {
  background: var(--brand-subtle);
  color: var(--brand-light);
  border: 1px solid var(--brand-border);
}

/* ══════════════════════════════════════════════
   DROP ZONE
   ══════════════════════════════════════════════ */

.drop-zone {
  border: 2px dashed var(--color-white-8);
  border-radius: var(--radius-xl);
  transition: border-color var(--duration-slow), background var(--duration-slow);
}
.drop-zone:hover, .drop-zone.active {
  border-color: var(--accent-border-hover);
  background: var(--accent-subtle);
}

/* ══════════════════════════════════════════════
   PIN KEYPAD
   ══════════════════════════════════════════════ */

.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: transparent;
  transition: all 0.2s var(--ease-spring);
}
.pin-dot.filled {
  background: var(--brand);
  border-color: var(--brand);
  transform: scale(1.15);
}

.keypad-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 1px solid var(--border-default);
  background: var(--bg-glass);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--duration-fast), transform 0.1s;
  user-select: none;
  -webkit-user-select: none;
}
.keypad-btn:hover {
  background: var(--bg-subtle-hover);
}
.keypad-btn:active {
  background: var(--color-white-10);
  transform: scale(0.93);
}

/* ══════════════════════════════════════════════
   SUCCESS OVERLAY
   ══════════════════════════════════════════════ */

.success-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-blur);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.success-checkmark {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--brand-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: scaleIn 0.3s var(--ease-spring);
}
.success-checkmark svg {
  width: 40px;
  height: 40px;
  stroke: var(--brand);
  stroke-dasharray: 36;
  stroke-dashoffset: 36;
  animation: checkmark-draw 0.4s ease 0.2s forwards;
}

/* ══════════════════════════════════════════════
   MISC
   ══════════════════════════════════════════════ */

/* Gradient text */
.text-gradient-emerald {
  background: linear-gradient(135deg, var(--brand), var(--brand-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Hide scrollbar for horizontal scroll */
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* iOS-safe form inputs */
input[type="text"], input[type="number"], input[type="date"], select, textarea {
  font-size: 16px; /* Prevents zoom on iOS */
}

/* Prevent overscroll bounce */
.page-content {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}
