/* ============================================================
   Variables
   ============================================================ */
:root {
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --dark-bg:        #11121c;
  --dark-surface:   #1a1c2e;
  --dark-border:    #2a2d48;
  --dark-text:      #dcdff5;
  --dark-muted:     #8b8fb8;
  --dark-sidebar:   #0c0d16;
}

/* ============================================================
   Override color primario de Bootstrap → índigo PhotoCard
   ============================================================ */
:root {
  --bs-primary:           #4f46e5;
  --bs-primary-rgb:       79, 70, 229;
  --bs-link-color:        #4f46e5;
  --bs-link-hover-color:  #4338ca;
}

/* ============================================================
   Base
   ============================================================ */
body {
  font-size: 0.9rem;
}

[data-bs-theme="dark"] body {
  background-color: var(--dark-bg);
  --bs-body-bg:       var(--dark-bg);
  --bs-body-color:    var(--dark-text);
  --bs-border-color:  var(--dark-border);
  --bs-secondary-bg:  var(--dark-surface);
  --bs-tertiary-bg:   var(--dark-surface);
}

[data-bs-theme="light"] {
  --bs-body-bg:      #f4f5fb;
  --bs-secondary-bg: #eceef8;
  --bs-tertiary-bg:  #eceef8;
}

[data-bs-theme="light"] body {
  background-color: #f4f5fb;
}

[data-bs-theme="light"] .card {
  background-color: #fff;
}

[data-bs-theme="light"] .card-header {
  background-color: #f9f9fd !important;
}

/* ============================================================
   Topbar
   ============================================================ */
#topbar {
  height: var(--topbar-height);
  z-index: 1030;
}

/* ============================================================
   Sidebar
   ============================================================ */
#sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1020;
  padding: 1rem 0.75rem;
  transition: transform 0.25s ease;
  flex-shrink: 0;
  border-right: 1px solid transparent;
}

[data-bs-theme="dark"] #sidebar {
  background-color: var(--dark-sidebar);
  border-right-color: var(--dark-border);
}

[data-bs-theme="light"] #sidebar {
  background-color: #eef0fa;
  border-right-color: #dcdff2;
}

#sidebar.hidden {
  transform: translateX(calc(-1 * var(--sidebar-width)));
}

.sidebar-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 0 0.5rem;
  margin-bottom: 0.25rem;
  margin-top: 0.5rem;
}

[data-bs-theme="dark"] .sidebar-section-label  { color: var(--dark-muted); }
[data-bs-theme="light"] .sidebar-section-label { color: #646a8f; }

.sidebar-section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 0.25rem 0.5rem;
  margin-bottom: 0.1rem;
  border-radius: 0.3rem;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s, background 0.15s;
}

[data-bs-theme="dark"] .sidebar-section-toggle         { color: var(--dark-muted); }
[data-bs-theme="dark"] .sidebar-section-toggle:hover   { color: var(--dark-text); background: rgba(255,255,255,.05); }
[data-bs-theme="light"] .sidebar-section-toggle        { color: #646a8f; }
[data-bs-theme="light"] .sidebar-section-toggle:hover  { color: #2e3358; background: rgba(0,0,0,.05); }

.sidebar-chevron {
  font-size: 0.65rem;
  transition: transform 0.2s ease;
}

.sidebar-section-body {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s ease;
}

.sidebar-section-body.open {
  max-height: 600px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.4rem;
  text-decoration: none;
  font-size: 0.875rem;
  transition: background 0.15s, color 0.15s;
}

.sidebar-link i {
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

[data-bs-theme="dark"] .sidebar-link        { color: #9a9ec4; }
[data-bs-theme="dark"] .sidebar-link:hover  { background-color: rgba(255,255,255,.07); color: var(--dark-text); }
[data-bs-theme="light"] .sidebar-link       { color: #454b70; }
[data-bs-theme="light"] .sidebar-link:hover { background-color: rgba(0,0,0,.06); color: #1b1f3b; }

.sidebar-link.active {
  background-color: var(--bs-primary);
  color: #fff !important;
}

/* ============================================================
   Main content
   ============================================================ */
#main-content {
  margin-top: var(--topbar-height);
  margin-left: var(--sidebar-width);
  padding: 1.5rem;
  min-height: calc(100vh - var(--topbar-height));
  flex-grow: 1;
  transition: margin-left 0.25s ease;
}

#main-content.expanded {
  margin-left: 0;
}

/* ============================================================
   Logos
   ============================================================ */
.login-logo {
  width: 240px;
  height: auto;
  display: block;
  margin: 0 auto;
}

.navbar-logo {
  height: 32px;
  width: auto;
}

/* ============================================================
   Auth page
   ============================================================ */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #4f46e5 0%, #4338ca 55%, #312e81 100%);
}

[data-bs-theme="dark"] .auth-page {
  background: linear-gradient(160deg, #0e0f1f 0%, #14163a 55%, var(--dark-bg) 100%);
}

.auth-box {
  width: 100%;
  max-width: 380px;
  padding: 1rem;
}

/* ============================================================
   Stat cards (dashboard)
   ============================================================ */
.stat-card-link {
  display: block;
  height: 100%;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  border-radius: 0.6rem;
  padding: 1.1rem 1.2rem;
  border-left: 4px solid;
  height: 100%;
  transition: box-shadow .15s, transform .15s;
}

[data-bs-theme="dark"] .stat-card {
  background: var(--dark-surface);
  box-shadow: 0 1px 6px rgba(0,0,0,.35);
}

[data-bs-theme="light"] .stat-card {
  background: #fff;
  box-shadow: 0 1px 6px rgba(67,56,202,.12);
}

.stat-card:hover {
  transform: translateY(-2px);
}

[data-bs-theme="dark"] .stat-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.5); }
[data-bs-theme="light"] .stat-card:hover { box-shadow: 0 4px 16px rgba(67,56,202,.18); }

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-body  { flex-grow: 1; }

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
}

[data-bs-theme="dark"] .stat-value { color: var(--dark-text); }

.stat-label {
  font-size: 0.78rem;
  color: #6c757d;
  margin-top: 0.15rem;
}

/* ============================================================
   Tables
   ============================================================ */
.table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6c757d;
  font-weight: 600;
}

/* ============================================================
   Cards generales
   ============================================================ */
.card {
  border-radius: 0.6rem;
}

[data-bs-theme="dark"] .card {
  background-color: var(--dark-surface);
  border-color: var(--dark-border);
}

/* ============================================================
   Badges
   ============================================================ */
.badge {
  font-weight: 500;
}

.badge-dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  margin-right: 0.35rem;
  flex-shrink: 0;
}

/* ============================================================
   Autofill del browser — dark only
   ============================================================ */
[data-bs-theme="dark"] input:-webkit-autofill,
[data-bs-theme="dark"] input:-webkit-autofill:hover,
[data-bs-theme="dark"] input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0px 1000px var(--dark-surface) inset !important;
  -webkit-text-fill-color: var(--dark-text) !important;
  caret-color: var(--dark-text);
  transition: background-color 5000s ease-in-out 0s;
}

/* ============================================================
   DataTables — layout y temas
   ============================================================ */
div.dt-container .dt-layout-row:first-child {
  padding: 0.75rem 1rem 0.5rem;
  align-items: center;
}

div.dt-container .dt-layout-row:last-child {
  padding: 0.6rem 1rem 0.75rem;
  align-items: center;
}

[data-bs-theme="dark"] div.dt-container .dt-layout-row:last-child {
  border-top: 1px solid var(--dark-border);
}

div.dt-container select,
div.dt-container input[type="search"] {
  border-radius: 0.375rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
}

[data-bs-theme="dark"] div.dt-container select,
[data-bs-theme="dark"] div.dt-container input[type="search"] {
  background-color: var(--dark-surface) !important;
  border-color: var(--dark-border) !important;
  color: var(--dark-text) !important;
}

div.dt-container label,
div.dt-container .dt-info {
  font-size: 0.82rem;
}

[data-bs-theme="dark"] div.dt-container label,
[data-bs-theme="dark"] div.dt-container .dt-info {
  color: var(--dark-muted);
}

div.dt-container .dt-paging nav button {
  border-radius: 0.375rem !important;
  padding: 0.2rem 0.55rem;
  margin: 0 1px;
  font-size: 0.82rem;
}

[data-bs-theme="dark"] div.dt-container .dt-paging nav button {
  color: var(--dark-text) !important;
  background: transparent !important;
  border: 1px solid var(--dark-border) !important;
}

div.dt-container .dt-paging nav button.current,
div.dt-container .dt-paging nav button:hover:not(:disabled) {
  background: var(--bs-primary) !important;
  border-color: var(--bs-primary) !important;
  color: #fff !important;
}

div.dt-container .dt-paging nav button:disabled {
  opacity: .35;
}

/* ============================================================
   Select2 — dark theme override
   ============================================================ */
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection {
  background-color: var(--dark-surface) !important;
  border-color: var(--dark-border) !important;
  color: var(--dark-text) !important;
}
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
  color: var(--dark-text) !important;
}
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown {
  background-color: var(--dark-surface) !important;
  border-color: var(--dark-border) !important;
  color: var(--dark-text) !important;
}
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-search__field {
  background-color: var(--dark-bg) !important;
  border-color: var(--dark-border) !important;
  color: var(--dark-text) !important;
}
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option {
  color: var(--dark-text) !important;
}
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option--selected {
  background-color: rgba(var(--bs-primary-rgb),.2) !important;
}

.select2-container--bootstrap-5 .select2-results__option--highlighted {
  background-color: var(--bs-primary) !important;
  color: #fff !important;
}

/* ============================================================
   Sidebar overlay backdrop (mobile)
   ============================================================ */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1015;
  cursor: pointer;
}
#sidebar-overlay.show { display: block; }

/* ============================================================
   Responsive: mobile layout
   ============================================================ */
@media (max-width: 767.98px) {
  #sidebar {
    transform: translateX(calc(-1 * var(--sidebar-width)));
    z-index: 1020;
  }
  #sidebar.show {
    transform: translateX(0);
  }
  #main-content {
    margin-left: 0;
    padding: 0.875rem 0.75rem;
  }

  h4.fw-bold { font-size: 1.05rem; }

  .btn { min-height: 38px; }
  .btn-sm { min-height: 34px; min-width: 34px; }

  .stat-card { padding: 0.7rem 0.85rem; gap: 0.65rem; }
  .stat-icon { width: 38px; height: 38px; font-size: 1.1rem; }
  .stat-value { font-size: 1.1rem; }
  .stat-label { font-size: 0.72rem; }

  .card-body.p-4 { padding: 1rem !important; }

  #main-content .d-flex.justify-content-between.mb-4 {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.75rem;
  }
}

/* ============================================================
   Marca (logo con ícono, sin imagen)
   ============================================================ */
.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 0.5rem;
  background: rgba(255,255,255,.18);
  font-size: 1.05rem;
}

.login-brand .brand-icon {
  width: 56px;
  height: 56px;
  font-size: 1.7rem;
  border-radius: 0.9rem;
}

.login-brand h1 {
  color: #fff;
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0.6rem 0 0.1rem;
}

.login-brand p {
  color: rgba(255,255,255,.75);
  margin: 0;
}

/* ============================================================
   Plantillas — miniatura con fondo de cuadros (muestra la transparencia)
   ============================================================ */
.plantilla-preview {
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  border-radius: 0.6rem 0.6rem 0 0;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #e3e5f0 25%, transparent 25%),
    linear-gradient(-45deg, #e3e5f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e3e5f0 75%),
    linear-gradient(-45deg, transparent 75%, #e3e5f0 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.plantilla-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* ============================================================
   Editor de tarjeta QR
   ============================================================ */
.tarjeta-editor-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1rem;
  background-color: var(--bs-tertiary-bg);
  border-radius: 0.6rem;
}

#lienzo {
  position: relative;
  width: 100%;
  max-width: 640px;
  background: #fff;
  box-shadow: 0 4px 18px rgba(0, 0, 0, .18);
  overflow: hidden;
  user-select: none;
  touch-action: none;
  outline: none;
}

#lienzo.vertical { max-width: 340px; }

#lienzo #fondo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

#sinFondo {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #9a9ec4 !important;
  pointer-events: none;
}

#lienzo .elemento {
  position: absolute;
  cursor: move;
  outline: 1px dashed transparent;
  outline-offset: 2px;
}

#lienzo .elemento:hover      { outline-color: rgba(79, 70, 229, .5); }
#lienzo .elemento.seleccionado { outline: 2px solid #4f46e5; }

#elQr { aspect-ratio: 1 / 1; }
#elQr svg { width: 100%; height: 100%; display: block; pointer-events: none; }

#elCodigo { line-height: 1.15; white-space: nowrap; }

#lienzo .asa {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #4f46e5;
  border: 2px solid #fff;
  border-radius: 3px;
  display: none;
}

#lienzo .elemento.seleccionado .asa { display: block; }
#elQr .asa     { right: -8px; bottom: -8px; cursor: nwse-resize; }
#elCodigo .asa { right: -8px; top: 50%; margin-top: -6px; cursor: ew-resize; }

#lienzo .guia { position: absolute; background: #ec4899; pointer-events: none; z-index: 5; }
#lienzo .guia-v { left: 50%; top: 0; bottom: 0; width: 1px; }
#lienzo .guia-h { top: 50%; left: 0; right: 0; height: 1px; }

/* ============================================================
   Galería pública del álbum (/a/:codigo)
   ============================================================ */
.galeria-page { background: #f4f5fb; min-height: 100vh; }

.galeria-header {
  background: linear-gradient(160deg, #4f46e5 0%, #4338ca 55%, #312e81 100%);
  position: sticky;
  top: 0;
  z-index: 10;
}

.galeria-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

@media (min-width: 576px) { .galeria-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 992px) { .galeria-grid { grid-template-columns: repeat(4, 1fr); gap: 0.75rem; } }

.galeria-item {
  padding: 0;
  border: 0;
  border-radius: 0.5rem;
  overflow: hidden;
  background: #e3e5f0;
  aspect-ratio: 1 / 1;
  cursor: zoom-in;
}

.galeria-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .2s;
}

.galeria-item:hover img { transform: scale(1.03); }

.visor-cuerpo {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 0 0.5rem 1rem;
}

.visor-cuerpo img {
  max-width: 100%;
  max-height: calc(100vh - 80px);
  object-fit: contain;
}

.visor-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: rgba(255, 255, 255, .15);
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.3rem;
}

.visor-prev { left: 0.75rem; }
.visor-next { right: 0.75rem; }

/* ============================================================
   Editor de plantillas (3 capas) — reutiliza .asa/.guia del editor de tarjeta
   ============================================================ */
/* Mesa de trabajo transparente: cuadrícula gris = zona sin nada encima */
#lienzo.lienzo-transparente {
  overflow: visible;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #d4d6e0 25%, transparent 25%),
    linear-gradient(-45deg, #d4d6e0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d4d6e0 75%),
    linear-gradient(-45deg, transparent 75%, #d4d6e0 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

#mesaCapas { position: absolute; inset: 0; overflow: hidden; }

#mesaCapas .capa { position: absolute; pointer-events: none; }
#mesaCapas .capa img { width: 100%; height: 100%; display: block; }
#capa-fondo   { z-index: 1; }
#capa-foto    { z-index: 2; }
#capa-overlay { z-index: 3; transition: opacity .15s; }

#lienzo.lienzo-transparente { cursor: default; }
#lienzo.lienzo-transparente .guia { z-index: 6; }

#seleccion {
  position: absolute;
  z-index: 5;
  outline: 2px dashed #4f46e5;
  pointer-events: none;
}

#seleccion .asa {
  display: block;
  right: -8px;
  bottom: -8px;
  cursor: nwse-resize;
  pointer-events: auto;
}

#seleccion .etiqueta-capa {
  position: absolute;
  left: 0;
  top: -22px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: #4f46e5;
  color: #fff;
  white-space: nowrap;
}

.tarjeta-capa .seleccionar-capa { cursor: pointer; }
.tarjeta-capa.activa { box-shadow: 0 0 0 2px #4f46e5 !important; }

.muestra-cuadros {
  display: inline-block;
  width: 12px;
  height: 12px;
  vertical-align: -1px;
  border: 1px solid #d4d6e0;
  background-image:
    linear-gradient(45deg, #d4d6e0 25%, transparent 25%),
    linear-gradient(-45deg, #d4d6e0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d4d6e0 75%),
    linear-gradient(-45deg, transparent 75%, #d4d6e0 75%);
  background-size: 6px 6px;
  background-position: 0 0, 0 3px, 3px -3px, -3px 0;
}

.muestra-final { max-height: 70vh; }

/* ============================================================
   Marca PhotoCard (logos en public/img; originales en assets/marca)
   ============================================================ */
/* El logo es negro/rojo: sobre fondos de color va dentro de una "pastilla" blanca */
.marca-pastilla {
  display: inline-flex;
  align-items: center;
  background: #fff;
  border-radius: 0.5rem;
  padding: 3px 10px;
  line-height: 0;
}
.marca-pastilla img { height: 30px; width: auto; }
.marca-pastilla-iso { padding: 5px 7px; }
.marca-pastilla-iso img { height: 28px; }

.login-logo-marca { width: 190px; max-width: 70%; height: auto; }
.galeria-pie-logo { height: 34px; width: auto; opacity: .85; }
