:root {
  --accent: #e0445b;
  --accent-dark: #c22e44;
  --accent-light: #fdeced;
  --ink: #1c1c26;
  --muted: #6b6b7a;
  --border: #e9e9f0;
  --bg: #f6f6fb;
  --card-bg: #ffffff;
  --radius: 16px;
  --shadow: 0 4px 18px rgba(20, 20, 40, 0.06);
  --shadow-hover: 0 10px 28px rgba(20, 20, 40, 0.12);
  --font-heading: "Poppins", sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
}

h1, h2, h3, h4 { font-family: var(--font-heading); margin: 0; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 32px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-family: var(--font-heading); font-weight: 700; font-size: 18px; letter-spacing: -0.2px; }
.brand-logo { width: 26px; height: 26px; object-fit: cover; border-radius: 6px; vertical-align: middle; margin-right: 4px; }
.user-box { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 14px; }

.container { max-width: 1160px; margin: 0 auto; padding: 32px; }

h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.3px; }
h2 { font-size: 18px; font-weight: 600; margin-bottom: 6px; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 12px; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 32px 0 18px;
  flex-wrap: wrap;
  gap: 12px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

/* ---------- Login ---------- */
.login-wrap {
  min-height: calc(100vh - 65px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card-bg);
  border-radius: 20px;
  padding: 40px 32px;
  box-shadow: var(--shadow-hover);
  position: relative;
  overflow: hidden;
}
.login-card::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0; height: 6px;
  background: linear-gradient(90deg, var(--accent), #ff8a65);
}
.login-brand { text-align: center; margin-bottom: 28px; }
.login-logo { width: 70px; height: 70px; object-fit: cover; border-radius: 14px; display: block; margin: 0 auto 6px; }
.login-brand h1 { font-size: 22px; }
.login-brand .muted { margin-top: 4px; }

/* ---------- Grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
}

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; font-weight: 500; margin: 14px 0 6px; color: var(--ink); }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="file"] {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: var(--font-body);
  background: #fbfbfd;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
  background: #fff;
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s, background 0.15s;
  font-family: var(--font-body);
}
.btn:active { transform: scale(0.97); }
.btn-block { width: 100%; margin-top: 20px; }

.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 4px 14px rgba(224, 68, 91, 0.35); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: #f1f1f6; color: var(--ink); }
.btn-secondary:hover { background: #e6e6ef; }
.btn-danger { background: #fff; color: #c0392b; border: 1.5px solid #f5c9c4; }
.btn-danger:hover { background: #fdf1f0; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--ink); }

.row { display: flex; gap: 10px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }

.error { color: #c0392b; font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 20, 35, 0.45); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: #fff; border-radius: var(--radius); padding: 28px; width: 92%; max-width: 460px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

/* ---------- Lotería cards ---------- */
.loteria-card { transition: transform 0.15s, box-shadow 0.15s; }
.loteria-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); }
.loteria-card h3 { margin: 4px 0; font-size: 17px; }
.estado {
  display: inline-block; font-size: 12.5px; font-weight: 600; padding: 4px 10px;
  border-radius: 20px; margin-top: 6px;
}
.estado.ok { color: #1e8e3e; background: #e8f7ee; }
.estado.pendiente { color: #b8860b; background: #fdf5e3; }

/* ---------- Ficha cards ---------- */
.ficha-card {
  text-align: left; transition: transform 0.15s, box-shadow 0.15s; padding: 14px;
}
.ficha-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); }
.ficha-thumb {
  width: 100%; height: 130px; object-fit: cover; border-radius: 10px;
  background: #f4f4f8; border: 1px solid var(--border);
}
.ficha-nombre { margin: 12px 0 4px; font-size: 15px; }
.ficha-tags { font-size: 12px; color: var(--muted); line-height: 1.5; }

.badge {
  font-size: 13px; color: var(--muted); background: #fafafd;
  border: 1px solid var(--border); padding: 7px 14px; border-radius: 20px;
}
.badge a { color: var(--accent); text-decoration: none; font-weight: 600; word-break: break-all; }

.manual-fallback { margin-top: 16px; font-size: 13px; }
.manual-fallback input[type="file"] { display: inline-block; width: auto; margin: 8px 0; }

progress { margin-top: 12px; height: 8px; width: 100%; accent-color: var(--accent); border-radius: 8px; }

/* ---------- Carrusel de fichas extra (mas de 10) ---------- */
.carousel-wrap { margin-top: 26px; }
.carousel-head {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px;
}
.carousel-head h3 { font-size: 15px; color: var(--muted); font-weight: 600; }
.carousel-controls { display: flex; gap: 8px; }
.carousel-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border);
  background: #fff; cursor: pointer; font-size: 18px; color: var(--ink);
  box-shadow: var(--shadow); transition: background 0.15s;
}
.carousel-btn:hover { background: var(--accent-light); color: var(--accent-dark); }

.carousel-track {
  display: flex; gap: 16px; overflow-x: auto; padding-bottom: 10px;
  scroll-snap-type: x mandatory; scroll-behavior: smooth;
}
.carousel-track::-webkit-scrollbar { height: 6px; }
.carousel-track::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.carousel-track .ficha-card { min-width: 220px; max-width: 220px; scroll-snap-align: start; flex-shrink: 0; }


/* ---------- Buscador de fichas ---------- */
.search-box {
  position: relative;
  margin-bottom: 18px;
  max-width: 340px;
}
.search-box input {
  width: 100%;
  padding: 11px 13px 11px 38px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: var(--font-body);
  background: #fbfbfd;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-box input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
  background: #fff;
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  opacity: 0.6;
  pointer-events: none;
}


.codigos-lista { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 6px; }
.codigo-card { text-align: center; padding: 14px; }
.codigo-texto { font-family: monospace; font-size: 14px; font-weight: 700; letter-spacing: 0.5px; color: var(--accent-dark); }
.codigo-info p { font-size: 11.5px; margin: 2px 0; }
.codigo-qr { width: 90px; height: 90px; margin: 8px auto; display: block; border-radius: 8px; border: 1px solid var(--border); }
.codigo-card .row { margin-top: 10px; gap: 6px; justify-content: center; }
.codigo-card .btn { padding: 6px 9px; font-size: 11px; }
.codigos-paginacion { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 4px 0 26px; }

    .btn-scan {
      width: 100%; padding: 12px; margin-top: 10px; border: 1.5px solid #ddd; border-radius: 10px;
      background: #f4f4f4; color: #333; font-weight: 600; font-size: 14px; cursor: pointer;
    }
    .scan-overlay {
      position: fixed; inset: 0; z-index: 1200; background: #000;
      display: flex; align-items: center; justify-content: center;
    }
    .scan-overlay video { width: 100%; height: 100%; object-fit: cover; }
    .scan-marco {
      position: absolute; width: 68vw; height: 68vw; max-width: 280px; max-height: 280px;
      border: 3px solid #fff; border-radius: 16px; box-shadow: 0 0 0 2000px rgba(0,0,0,0.5);
    }
    #scanCerrar {
      position: absolute; bottom: 40px; padding: 12px 22px; border: none; border-radius: 30px;
      background: rgba(255,255,255,0.9); font-weight: 700; font-size: 14px;
    }


    .detail-layout { display: flex; gap: 24px; align-items: flex-start; margin-top: 16px; }
.detail-nav { display: flex; flex-direction: column; gap: 6px; min-width: 230px; position: sticky; top: 16px; }
.detail-nav-btn {
  text-align: left; padding: 12px 14px; border-radius: 10px; border: 1px solid #ddd;
  background: #f7f7f8; cursor: pointer; font-weight: 600; font-size: 14px;
}
.detail-nav-btn.active { background: #e0445b; color: #fff; border-color: #e0445b; }
.detail-panels { flex: 1; min-width: 0; }
.detail-panel { display: none; }
.detail-panel.active { display: block; }
@media (max-width: 760px) {
  .detail-layout { flex-direction: column; }
  .detail-nav { flex-direction: row; overflow-x: auto; width: 100%; position: static; }
}


.preview3d-layout { display: flex; gap: 20px; margin-top: 16px; }
.preview3d-list { display: flex; flex-direction: column; gap: 8px; min-width: 220px; max-height: 460px; overflow-y: auto; }
.preview3d-item { text-align: left; padding: 10px 12px; border-radius: 10px; border: 1px solid #ddd; background: #f7f7f8; cursor: pointer; font-size: 14px; }
.preview3d-item.active { background: #e0445b; color: #fff; border-color: #e0445b; }
.preview3d-item:disabled { opacity: 0.5; cursor: not-allowed; }
.preview3d-stage { flex: 1; min-width: 0; }
@media (max-width: 760px) { .preview3d-layout { flex-direction: column; } }

.acceso-libre-fichas-lista { max-height: 180px; overflow-y: auto; border: 1px solid #ddd; border-radius: 10px; padding: 8px; margin-bottom: 6px; }
.acceso-libre-ficha-item { display: flex; align-items: center; gap: 8px; padding: 6px 4px; font-size: 14px; }
.acceso-libre-ficha-item.libre-activa { color: #1a8a3c; font-weight: 600; }