/* Creative Lab PH — sistema visual v1
   Identidad: fondo oscuro + azul eléctrico #0047FF. Mobile-first. Sin frameworks. */

:root {
  --bg: #070b14;
  --surface: #0d1424;
  --surface-2: #131c31;
  --surface-3: #1a2440;
  --border: #1e2a45;
  --border-strong: #2a3a5f;
  --text: #e8edf7;
  --muted: #8a96b0;
  --muted-2: #5c6a88;
  --accent: #0047ff;
  --accent-bright: #2f6bff;
  --accent-soft: rgba(47, 107, 255, 0.12);
  --ok: #22c55e;
  --ok-soft: rgba(34, 197, 94, 0.12);
  --warn: #eab308;
  --warn-soft: rgba(234, 179, 8, 0.12);
  --error: #ef4444;
  --error-soft: rgba(239, 68, 68, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
  --nav-h: 64px;
  --header-h: 56px;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
}

img, video { max-width: 100%; display: block; }

a { color: var(--accent-bright); text-decoration: none; }

button { font-family: inherit; }

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: rgba(7, 11, 20, 0.92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
  color: var(--text);
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-bright) 100%);
  display: grid;
  place-items: center;
  color: #fff;
  flex-shrink: 0;
}

.brand-mark svg { width: 16px; height: 16px; }

.brand small {
  display: block;
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.credits-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid rgba(47, 107, 255, 0.35);
  color: var(--accent-bright);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}

.credits-pill svg { width: 15px; height: 15px; }

/* ---------- Bottom nav (mobile) / side rail (desktop) ---------- */
.app-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: rgba(13, 20, 36, 0.97);
  border-top: 1px solid var(--border);
}

.app-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s;
}

.app-nav a svg { width: 22px; height: 22px; }

.app-nav a.active { color: var(--accent-bright); }
.app-nav a:hover { color: var(--text); }
.app-nav a:focus-visible,
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, label:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}

/* ---------- Layout ---------- */
.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px calc(var(--nav-h) + 32px);
}

.page-title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.page-sub { color: var(--muted); font-size: 14px; margin-top: 2px; }

.section-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 24px 0 10px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card + .card { margin-top: 12px; }

.card-link {
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  color: var(--text);
}

.card-link:hover { border-color: var(--border-strong); background: var(--surface-2); }

.card-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-bright);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.card-icon svg { width: 21px; height: 21px; }

.card-link .chev { margin-left: auto; color: var(--muted-2); flex-shrink: 0; }
.card-link .chev svg { width: 18px; height: 18px; }

.card-link h3 { font-size: 15px; font-weight: 600; }
.card-link p { font-size: 13px; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s, border-color 0.2s;
  text-align: center;
}

.btn svg { width: 18px; height: 18px; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-bright) 100%);
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.12); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-block { width: 100%; }

.btn-sm { min-height: 38px; padding: 8px 14px; font-size: 13px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.field .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }

.input, .select, .textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.input::placeholder, .textarea::placeholder { color: var(--muted-2); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent-bright); outline: none; }

.textarea { min-height: 130px; resize: vertical; line-height: 1.5; }

.select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a96b0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
  cursor: pointer;
}

.form-error {
  display: none;
  font-size: 13px;
  color: var(--error);
  margin-top: 6px;
}
.form-error.visible { display: block; }

/* ---------- Estados / badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge svg { width: 13px; height: 13px; }

.badge-pendiente { background: var(--warn-soft); color: var(--warn); }
.badge-generando { background: var(--accent-soft); color: var(--accent-bright); }
.badge-listo { background: var(--ok-soft); color: var(--ok); }
.badge-fallido { background: var(--error-soft); color: var(--error); }

.spin { animation: spin 1.2s linear infinite; transform-origin: center; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spin { animation: none; }
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
}

.login-box { width: 100%; max-width: 380px; }

.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-bottom: 32px;
  text-align: center;
}

.login-logo .brand-mark { width: 56px; height: 56px; border-radius: 16px; }
.login-logo .brand-mark svg { width: 30px; height: 30px; }
.login-logo h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.login-logo p { color: var(--muted); font-size: 14px; }

.login-footer {
  margin-top: 28px;
  text-align: center;
  font-size: 12px;
  color: var(--muted-2);
}

/* ---------- Avatares ---------- */
.avatar-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.avatar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.avatar-photo {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-size: 34px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #16234a 0%, #0047ff 130%);
}

.avatar-card .info { padding: 12px; }
.avatar-card .info h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.avatar-card .info .meta { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---------- Wizard ---------- */
.wizard-steps {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 0 22px;
}

.wizard-step {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-3);
  transition: background 0.3s;
}
.wizard-step.done { background: var(--accent-bright); }

.photo-slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.photo-slot {
  position: relative;
  aspect-ratio: 3 / 4;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.2s;
}

.photo-slot:hover { border-color: var(--accent-bright); }
.photo-slot svg { width: 22px; height: 22px; }
.photo-slot input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photo-slot.filled { border-style: solid; border-color: var(--ok); }
.photo-slot .slot-check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ok);
  color: #fff;
  display: none;
  place-items: center;
}
.photo-slot .slot-check svg { width: 13px; height: 13px; }
.photo-slot.filled .slot-check { display: grid; }

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

.resumen-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.resumen-row:last-child { border-bottom: none; }
.resumen-row .k { color: var(--muted); }
.resumen-row .v { font-weight: 600; text-align: right; }

/* ---------- Selección de avatar / formato (radio cards) ---------- */
.pick-list { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; }

.pick-avatar { position: relative; flex-shrink: 0; }
.pick-avatar input { position: absolute; opacity: 0; pointer-events: none; }
.pick-avatar .pick-body {
  width: 88px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 10px 6px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  transition: border-color 0.2s, color 0.2s;
}
.pick-avatar .mini-photo {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #16234a 0%, #0047ff 130%);
}
.pick-avatar input:checked + .pick-body { border-color: var(--accent-bright); color: var(--text); background: var(--accent-soft); }
.pick-avatar input:focus-visible + .pick-body { outline: 2px solid var(--accent-bright); outline-offset: 2px; }

.radio-cards { display: grid; gap: 10px; }

.radio-card { position: relative; }
.radio-card input { position: absolute; opacity: 0; pointer-events: none; }
.radio-card .rc-body {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.radio-card .rc-body svg { width: 20px; height: 20px; color: var(--muted); flex-shrink: 0; margin-top: 2px; }
.radio-card h4 { font-size: 14px; font-weight: 600; }
.radio-card p { font-size: 12.5px; color: var(--muted); }
.radio-card .rc-cost { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--accent-bright); white-space: nowrap; }
.radio-card input:checked + .rc-body { border-color: var(--accent-bright); background: var(--accent-soft); }
.radio-card input:checked + .rc-body svg { color: var(--accent-bright); }
.radio-card input:focus-visible + .rc-body { outline: 2px solid var(--accent-bright); outline-offset: 2px; }

/* ---------- Barra de costo ---------- */
.cost-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin: 20px 0 14px;
  font-size: 14px;
}
.cost-bar .cost-num { font-size: 18px; font-weight: 700; color: var(--accent-bright); }
.cost-bar .cost-after { font-size: 12px; color: var(--muted); }

/* ---------- Galería ---------- */
.filter-chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; }

.chip {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent-soft); border-color: var(--accent-bright); color: var(--accent-bright); }

.gen-grid { display: grid; gap: 14px; margin-top: 14px; }

.gen-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.gen-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background:
    radial-gradient(120% 140% at 20% 0%, rgba(47, 107, 255, 0.28) 0%, transparent 55%),
    linear-gradient(160deg, #101a33 0%, #0a101f 100%);
  display: grid;
  place-items: center;
  color: var(--muted);
}

.gen-thumb .play-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.94);
  color: #0a101f;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
}
.gen-thumb .play-btn:hover { background: #fff; }
.gen-thumb .play-btn svg { width: 22px; height: 22px; margin-left: 3px; }

.gen-thumb .state-icon svg { width: 34px; height: 34px; }

.gen-card .gen-info { padding: 13px 14px; }
.gen-card .gen-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.gen-card h3 { font-size: 14px; font-weight: 600; }
.gen-card .gen-meta { font-size: 12.5px; color: var(--muted); }
.gen-card .gen-script {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.gen-card .gen-actions { margin-top: 10px; display: flex; gap: 8px; }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty-state svg { width: 40px; height: 40px; margin: 0 auto 12px; color: var(--muted-2); }
.empty-state p { font-size: 14px; }

/* ---------- Dashboard ---------- */
.hero-credits {
  background:
    radial-gradient(130% 160% at 85% -10%, rgba(47, 107, 255, 0.35) 0%, transparent 55%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 18px;
  margin-top: 18px;
}
.hero-credits .label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.hero-credits .num { font-size: 36px; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; }
.hero-credits .num span { font-size: 15px; font-weight: 500; color: var(--muted); letter-spacing: 0; }

.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.stat-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stat-box .n { font-size: 22px; font-weight: 700; }
.stat-box .l { font-size: 12px; color: var(--muted); margin-top: 1px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(4, 7, 14, 0.75);
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop.open { display: flex; }

.modal {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: env(safe-area-inset-bottom);
}
.modal h3 { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.modal p { font-size: 14px; color: var(--muted); margin-bottom: 16px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 20px);
  transform: translateX(-50%);
  z-index: 60;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  padding: 12px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { opacity: 1; }

/* ---------- Desktop ---------- */
@media (min-width: 768px) {
  .page { max-width: 860px; padding-bottom: 60px; }
  .app-nav {
    top: var(--header-h);
    bottom: auto;
    left: 0;
    right: 0;
    height: 52px;
    flex-direction: row;
    justify-content: center;
    gap: 8px;
    border-top: none;
    border-bottom: 1px solid var(--border);
  }
  .app-nav a { flex: none; flex-direction: row; gap: 8px; padding: 0 18px; font-size: 13px; }
  .app-nav a svg { width: 18px; height: 18px; }
  body.has-nav .page { padding-top: 72px; }
  .avatar-grid { grid-template-columns: repeat(3, 1fr); }
  .gen-grid { grid-template-columns: 1fr 1fr; }
  .modal-backdrop { align-items: center; }
  .toast { bottom: 32px; }
}
