:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --card: #1e293b;
  --card2: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent2: #22c55e;
  --danger: #ef4444;
  --border: #334155;
  --radius: 14px;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 76px;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(180deg, #0f172a, #0f172aee);
  backdrop-filter: blur(8px);
  padding: 14px 16px calc(14px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.app-header h1 { font-size: 1.05rem; margin: 0; display: flex; align-items: center; gap: 8px; }
.logo { font-size: 1.3rem; }
.stats { display: flex; flex-direction: column; align-items: flex-end; font-size: 0.8rem; }
.stats #statValue { color: var(--accent2); font-weight: 700; font-size: 0.95rem; }

/* ---------- Layout ---------- */
main { padding: 16px; max-width: 720px; margin: 0 auto; }
.view h2 { margin-top: 4px; }
.hint { color: var(--muted); font-size: 0.9rem; line-height: 1.5; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: #06283d; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; padding: 14px; font-size: 1rem; margin-top: 6px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- Captura ---------- */
.capture-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.capture-slot { display: flex; flex-direction: column; gap: 8px; }
.thumb {
  aspect-ratio: 3 / 4;
  background: var(--card);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  overflow: hidden;
  position: relative;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb span { position: absolute; pointer-events: none; }
.thumb.filled span { display: none; }
.capture-actions { display: flex; gap: 6px; }
.capture-actions .btn { flex: 1; text-align: center; padding: 8px; font-size: 0.82rem; }

.ocr-status {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--card);
  border-radius: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}
.ocr-status .bar { height: 6px; background: var(--border); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.ocr-status .bar > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

/* ---------- Formulario ficha ---------- */
.card-form { margin-top: 18px; background: var(--card); padding: 16px; border-radius: var(--radius); border: 1px solid var(--border); }
.card-form h3 { margin-top: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card-form label { display: flex; flex-direction: column; gap: 5px; font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.card-form input, .card-form select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 0.9rem;
}
.card-form input:focus, .card-form select:focus { outline: 2px solid var(--accent); border-color: transparent; }

.price-result {
  margin: 10px 0 4px;
  padding: 11px 13px;
  border-radius: 10px;
  font-size: 0.88rem;
  line-height: 1.5;
  background: var(--card2);
  border: 1px solid var(--border);
}
.price-result small { color: var(--muted); }
.price-result.ok { border-color: var(--accent2); }
.price-result.err { border-color: var(--danger); }
.price-result.loading { color: var(--muted); }

.pricing-links { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 4px; }
.pricing-links a {
  font-size: 0.8rem;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--card2);
  border: 1px solid var(--border);
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.pricing-links .lbl { width: 100%; font-size: 0.75rem; color: var(--muted); font-weight: 600; }

.ocr-raw { margin-top: 14px; font-size: 0.8rem; color: var(--muted); }
.ocr-raw pre { white-space: pre-wrap; background: var(--bg); padding: 10px; border-radius: 8px; max-height: 160px; overflow: auto; }

.form-actions { display: flex; gap: 10px; margin-top: 16px; }
.form-actions .btn { flex: 1; }

/* ---------- Álbum ---------- */
.toolbar { display: flex; gap: 10px; margin: 12px 0 16px; }
.toolbar input, .toolbar select {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px;
  border-radius: 10px;
  font-size: 0.9rem;
}
.toolbar input { flex: 1; }

.album-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.album-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.1s;
}
.album-item:active { transform: scale(0.98); }
.album-item .pic { aspect-ratio: 3 / 4; background: var(--bg2); }
.album-item .pic img { width: 100%; height: 100%; object-fit: cover; }
.album-item .meta { padding: 8px 10px; }
.album-item .name { font-size: 0.85rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.album-item .sub { font-size: 0.72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.album-item .price { font-size: 0.85rem; color: var(--accent2); font-weight: 700; margin-top: 4px; }

.empty { color: var(--muted); text-align: center; padding: 40px 20px; line-height: 1.6; }

/* ---------- Nav inferior ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  padding: 10px;
  font-size: 1.35rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.nav-btn span { font-size: 0.68rem; }
.nav-btn.active { color: var(--accent); }

/* ---------- Modal detalle ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 40;
}
.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  max-width: 460px;
  width: 100%;
  max-height: 88vh;
  overflow: auto;
  position: relative;
  padding: 18px;
  box-shadow: var(--shadow);
}
.modal-close {
  position: absolute; top: 10px; right: 10px;
  background: var(--card2); border: none; color: var(--text);
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 1rem;
}
.modal-imgs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0 16px; }
.modal-imgs img { width: 100%; border-radius: 10px; }
.detail-row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
.detail-row span:first-child { color: var(--muted); }
.modal .form-actions { margin-top: 18px; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }

/* ---------- Cámara ---------- */
.camera-overlay {
  position: fixed; inset: 0; background: #000; z-index: 60;
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh; /* dvh evita que la barra del móvil tape los controles */
}
.camera-overlay video { flex: 1 1 auto; min-height: 0; width: 100%; object-fit: cover; }
.camera-controls {
  flex: 0 0 auto; /* nunca se encoge: el botón de disparo siempre visible */
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px calc(16px + env(safe-area-inset-bottom));
  background: #000;
}
.shutter {
  width: 68px; height: 68px; border-radius: 50%;
  background: #fff; border: 5px solid #94a3b8; cursor: pointer;
}
.shutter:active { transform: scale(0.92); }

[hidden] { display: none !important; }
