/* ========================================
   DrTranslate - Estilos mejorados y adaptativos
   ======================================== */

:root {
  --primary: #0ea5e9;
  --primary-dark: #0284c7;
  --primary-light: rgba(14, 165, 233, 0.15);
  --accent: #22d3ee;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;

  --bg: #0f172a;
  --bg-glass: rgba(15, 23, 42, 0.7);
  --surface: #1e293b;
  --surface-elevated: rgba(30, 41, 59, 0.8);
  --surface-hover: rgba(51, 65, 85, 0.6);
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --border: rgba(255, 255, 255, 0.1);
  --border-hover: rgba(14, 165, 233, 0.4);

  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 40px rgba(14, 165, 233, 0.2);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  line-height: 1.5;
}

.hidden { display: none !important; }
.btn-full { width: 100%; }

/* ===== Animaciones ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(14, 165, 233, 0.7); }
  70% { box-shadow: 0 0 0 14px rgba(14, 165, 233, 0); }
  100% { box-shadow: 0 0 0 0 rgba(14, 165, 233, 0); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Login ===== */
.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.5s ease;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface-elevated);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 32px;
  text-align: center;
  box-shadow: var(--shadow);
}

.login-icon {
  font-size: 56px;
  margin-bottom: 20px;
  filter: drop-shadow(0 0 8px rgba(14, 165, 233, 0.4));
}

.login-card h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 28px;
}

.login-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-bottom: 16px;
  min-height: 1.2em;
  animation: slideDown 0.3s ease;
}

.login-card input {
  width: 100%;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 20px;
  box-sizing: border-box;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.login-card input::placeholder { color: var(--text-dim); }

.login-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.btn-login {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn-login:hover { background: var(--primary-dark); }
.btn-login:active { transform: scale(0.98); }

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.125rem;
  flex-shrink: 0;
}

.header__actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn-icon {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--surface-hover);
  border-color: var(--border-hover);
  color: var(--accent);
}

.btn-icon:active { transform: scale(0.92); }

/* ===== Cámara ===== */
.camera-view {
  height: 100dvh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  background: #000;
}

.camera-container {
  position: relative;
  flex: 1;
  width: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.camera-container video,
.camera-container canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* SIN espejo: la receta se lee bien */
  transform: none;
}

.viewfinder {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewfinder::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, transparent 40%, rgba(0,0,0,0.6) 100%);
  mask: radial-gradient(circle, transparent 38%, black 42%);
  -webkit-mask: radial-gradient(circle, transparent 38%, black 42%);
}

.viewfinder__corner {
  position: absolute;
  width: 32px;
  height: 32px;
  border: 3px solid var(--accent);
  box-shadow: 0 0 16px rgba(34, 211, 238, 0.6);
}

.viewfinder__corner.tl { top: 24px; left: 24px; border-right: none; border-bottom: none; }
.viewfinder__corner.tr { top: 24px; right: 24px; border-left: none; border-bottom: none; }
.viewfinder__corner.bl { bottom: 24px; left: 24px; border-right: none; border-top: none; }
.viewfinder__corner.br { bottom: 24px; right: 24px; border-left: none; border-top: none; }

.viewfinder__hint {
  position: absolute;
  bottom: 70px;
  color: rgba(255,255,255,0.9);
  font-size: 0.95rem;
  font-weight: 500;
  text-shadow: 0 2px 4px rgba(0,0,0,0.6);
  text-align: center;
  padding: 0 24px;
  letter-spacing: 0.02em;
}

/* Botones inferiores SIEMPRE visibles */
.camera-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: env(safe-area-inset-bottom) 20px 24px;
  background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
  z-index: 20;
}

.btn-capture {
  position: static;
  width: 72px;
  height: 72px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.95);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn-capture:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

.btn-capture:active { transform: scale(0.92); }

.shutter {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 4px solid var(--primary);
  background: #fff;
  animation: pulse 2s infinite;
}

.btn-attach {
  position: static;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  background: rgba(14, 165, 233, 0.9);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  z-index: 20;
  white-space: nowrap;
  transition: background 0.2s, transform 0.1s;
}

.btn-attach:hover {
  background: rgba(14, 165, 233, 1);
  transform: scale(1.02);
}

.btn-attach:active { transform: scale(0.96); }

/* ===== Resultados ===== */
.results-panel {
  position: absolute;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: slideDown 0.3s ease;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}

.results-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.btn-close:hover {
  color: var(--text);
  background: var(--surface);
}

.results-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  overflow-y: auto;
}

.image-preview {
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
  display: block;
}

.text-result {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.result-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.text-result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 0;
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: opacity 0.2s;
}

.btn-link:hover { opacity: 0.8; }

textarea#ocrText {
  flex: 1;
  min-height: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.6;
  resize: vertical;
  font-family: var(--font);
  transition: border-color 0.2s;
}

textarea#ocrText:focus {
  outline: none;
  border-color: var(--border-hover);
}

.text-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.results-footer {
  padding: 4px 0;
  border-top: 1px solid var(--border);
}

.status {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ===== Botones ===== */
.btn-primary,
.btn-secondary {
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  padding: 12px 18px;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 14px rgba(14, 165, 233, 0.4);
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--surface-hover);
  border-color: var(--border-hover);
}

.btn-secondary:active { transform: scale(0.98); }

.btn-full { width: 100%; }

/* ===== Pantallas ===== */
.permission-screen,
.error-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.3s ease;
}

.permission-card,
.error-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface-elevated);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  box-shadow: var(--shadow);
}

.permission-icon,
.error-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(14, 165, 233, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}

.permission-icon svg,
.error-icon svg {
  width: 32px;
  height: 32px;
}

.permission-card h2,
.error-card h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.permission-card p,
.error-card p {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 24px;
}

/* ===== Modal ===== */
.modal {
  padding: 0;
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: transparent;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
}

.modal__content {
  background: var(--surface-elevated);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%;
  max-width: 460px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  animation: slideDown 0.3s ease;
}

.modal__close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
  transition: color 0.2s;
}

.modal__close:hover { color: var(--text); }

.modal h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.translate-pairs {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
}

.translate-pairs > div {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.translate-pairs label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.translate-pairs textarea {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.6;
  resize: vertical;
  font-family: var(--font);
}

.modal__actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

/* ===== Resultado estructurado ===== */
.structured {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.structured__row {
  display: flex;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.95rem;
}

.structured__label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  min-width: 78px;
  flex-shrink: 0;
  padding-top: 2px;
}

.med-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.med-card__title {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 6px;
  color: var(--text);
}

.med-card__line {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.5;
}

.med-card__line b {
  color: var(--text-muted);
  font-weight: 600;
}

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge.ok {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.badge.mid {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

.badge.bad {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-light);
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  margin-bottom: 8px;
}

/* ===== Responsive ===== */
@media (min-width: 640px) {
  body {
    overflow: auto;
    height: auto;
    min-height: 100vh;
  }

  .camera-view {
    height: auto;
    min-height: 100vh;
    background: var(--bg);
  }

  .camera-container {
    max-width: 720px;
    margin: 0 auto;
    padding: 24px;
  }

  .results-panel {
    position: static;
    padding: 24px;
    max-width: 720px;
    margin: 0 auto;
    border-radius: 0 0 var(--radius) var(--radius);
  }
}

@supports (-webkit-touch-callout: none) {
  body {
    overscroll-behavior: none;
  }
}