:root {
  --bg: #f4f1ea;
  --panel: #fbf9f4;
  --card: #ffffff;
  --card-hover: #f3ede0;
  --thumb: #ebe6da;
  --border: #dcd5c6;
  --accent: #a87a28;
  --accent-hover: #8f6620;
  --accent-soft: #f3e6c8;
  --on-accent: #ffffff;
  --text: #1f1d1a;
  --text2: #6b665c;
  --muted: #9a9488;
  --danger: #c0392b;
  --danger-hover: #a93226;
  --sombra: 0 12px 40px rgba(0, 0, 0, .18);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212; --panel: #1a1a1a; --card: #232323; --card-hover: #2c2c2c; --thumb: #2e2e2e;
    --border: #353535; --accent: #dfb15b; --accent-hover: #c59b4c; --accent-soft: #3a2f1a;
    --on-accent: #121212; --text: #f5f5f5; --text2: #a3a3a3; --muted: #6e6e6e;
    --danger: #f87171; --danger-hover: #ef4444; --sombra: 0 12px 40px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121212; --panel: #1a1a1a; --card: #232323; --card-hover: #2c2c2c; --thumb: #2e2e2e;
  --border: #353535; --accent: #dfb15b; --accent-hover: #c59b4c; --accent-soft: #3a2f1a;
  --on-accent: #121212; --text: #f5f5f5; --text2: #a3a3a3; --muted: #6e6e6e;
  --danger: #f87171; --danger-hover: #ef4444; --sombra: 0 12px 40px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }

/* ---------- botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  background: transparent; cursor: pointer; text-decoration: none; color: var(--text);
  white-space: nowrap; transition: background .12s, border-color .12s, opacity .12s;
}
.btn.redondo { border-radius: 19px; height: 36px; }
.btn.ancho { width: 100%; justify-content: flex-start; }
.btn.primario { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primario:hover { background: var(--accent-hover); }
.btn.contorno { border-color: var(--border); }
.btn.contorno:hover, .btn.fantasma:hover { background: var(--card-hover); }
.btn.fantasma { color: var(--text2); height: 32px; justify-content: flex-start; width: 100%; font-size: 13px; }
.btn.peligro { color: var(--danger); }
.btn.rojo { background: var(--danger); color: #fff; font-weight: 600; }
.btn.rojo:hover { background: var(--danger-hover); }
.btn:disabled, .btn.desactivado { opacity: .45; pointer-events: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type="text"], input[type="password"], input[type="search"], input:not([type]), select {
  height: 38px; width: 100%; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--card);
}

.marca { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 19px; white-space: nowrap; }
.rombo { color: var(--accent); }
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0; font-size: 13px; }
.ayuda { color: var(--text2); font-size: 13px; margin: 0 0 12px; }

/* ---------- ingreso ---------- */
.ingreso { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.tarjeta-ingreso {
  width: min(400px, 100%); background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px 28px; display: grid; gap: 12px;
}
.tarjeta-ingreso .marca.grande { font-size: 18px; margin-bottom: 8px; }
.tarjeta-ingreso h1 { font-size: 22px; margin: 4px 0 0; }
.tarjeta-ingreso label { display: grid; gap: 6px; color: var(--text2); font-size: 13px; }

/* ---------- estructura ---------- */
.app { height: 100%; display: grid; grid-template-rows: 64px 1fr 28px; }
.cabecera {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 20px 0 24px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.acciones-cabecera { display: flex; align-items: center; gap: 10px; min-width: 0; }
.buscador { display: flex; align-items: center; gap: 6px; }
.buscador input[type="search"] { width: 280px; border-radius: 18px; height: 36px; }
.chip-todas input { width: 16px; height: 16px; margin: 0; }
.chip-todas { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text2); cursor: pointer; white-space: nowrap; }
.chip-todas input { accent-color: var(--accent); }

.cuerpo { display: grid; grid-template-columns: 260px minmax(0, 1fr) 360px; min-height: 0; }
.cuerpo > * { min-width: 0; }
.lateral {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 22px 12px 16px; min-height: 0;
}
.rotulo { font-size: 11px; font-weight: 700; color: var(--muted); margin: 0 10px 8px; letter-spacing: .04em; }
#lista-secciones { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
#lista-secciones button {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  height: 40px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent;
  color: var(--text2); cursor: pointer; text-align: left;
}
#lista-secciones button:hover { background: var(--card-hover); }
#lista-secciones button.activa { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
#lista-secciones .n { font-size: 12px; color: var(--muted); }
#lista-secciones .activa .n { color: var(--accent); }
.pie-lateral { margin-top: auto; padding: 0 6px; }
.espacio-barra { height: 6px; background: var(--thumb); border-radius: 3px; overflow: hidden; }
.espacio-barra span { display: block; height: 100%; background: var(--accent); width: 0; }
#espacio-texto { font-size: 11px; color: var(--muted); margin: 6px 0 0; }

.centro { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.encabezado-galeria { display: flex; align-items: baseline; gap: 14px; padding: 22px 28px 12px; flex-wrap: wrap; }
.encabezado-galeria h2 { margin: 0; font-size: 24px; }
.resumen { color: var(--text2); font-size: 13px; }
.galeria {
  flex: 1; overflow-y: auto; padding: 4px 24px 24px 28px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; align-content: start;
}
.tarjeta {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 8px;
  cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 6px; min-width: 0;
}
.tarjeta:hover { background: var(--card-hover); }
.tarjeta.sel { border: 2px solid var(--accent); padding: 7px; }
.miniatura {
  aspect-ratio: 172 / 124; background: var(--thumb); border-radius: 8px; overflow: hidden;
  display: grid; place-items: center; color: var(--muted); font-size: 12px;
}
.miniatura img { width: 100%; height: 100%; object-fit: contain; display: block; }
.tarjeta .t { font-weight: 700; font-size: 13px; padding: 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tarjeta .a { color: var(--text2); font-size: 12px; padding: 0 2px 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tarjeta .c { color: var(--muted); font-size: 11px; padding: 0 2px; }
.mensaje-vacio { color: var(--text2); padding: 30px 4px; grid-column: 1 / -1; }

.detalle { background: var(--panel); border-left: 1px solid var(--border); overflow-y: auto; padding: 18px 18px 24px; position: relative; }
.foto-detalle {
  width: 100%; aspect-ratio: 320 / 260; background: var(--thumb); border-radius: 12px; overflow: hidden;
  display: grid; place-items: center; color: var(--muted); margin-bottom: 14px;
}
.foto-detalle img { width: 100%; height: 100%; object-fit: contain; display: block; cursor: zoom-in; }
.detalle-vacio { text-align: center; color: var(--text2); }
#det-titulo { font-size: 19px; margin: 0; overflow-wrap: anywhere; }
.det-artista { color: var(--accent); margin: 2px 0 0; font-size: 14px; }
.det-categoria { color: var(--text2); font-size: 12px; margin: 2px 0 12px; }
.det-acciones { display: grid; gap: 6px; }
.det-archivos { font-size: 11px; color: var(--muted); margin: 12px 2px 0; overflow-wrap: anywhere; }
.det-admin { display: grid; gap: 1px; }
.btn-cerrar-detalle { display: none; }

.barra-estado {
  background: var(--panel); border-top: 1px solid var(--border); color: var(--text2);
  font-size: 12px; padding: 0 12px; display: flex; align-items: center; white-space: nowrap; overflow: hidden;
}

/* ---------- menú de usuario ---------- */
.menu-usuario { position: relative; }
.menu {
  position: absolute; right: 0; top: 44px; z-index: 30; min-width: 220px; padding: 6px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--sombra);
  display: grid;
}
.menu button { border: 0; background: transparent; text-align: left; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--card-hover); }
.menu hr { margin: 4px 0; }

/* ---------- ventanas ---------- */
.capa-modal {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .5);
  display: grid; place-items: center; padding: 16px;
}
.modal {
  width: min(620px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--sombra); padding: 24px 28px;
}
.modal.grande { width: min(860px, 100%); }
.modal h2 { margin: 0 0 4px; font-size: 20px; }
.modal h2.peligro { color: var(--danger); }
.modal .sub { color: var(--text2); font-size: 13px; margin: 0 0 16px; }
.campo { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 10px; margin: 8px 0; }
.campo > span { color: var(--text2); }
.archivo-fila { display: flex; align-items: center; gap: 8px; min-width: 0; }
.archivo-fila .nombre-archivo { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.archivo-fila .nombre-archivo.vacio { color: var(--muted); }
.botonera { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.progreso { height: 8px; background: var(--thumb); border-radius: 4px; overflow: hidden; margin-top: 14px; }
.progreso span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.texto-progreso { font-size: 12px; color: var(--text2); margin: 6px 0 0; }
.vista-previa {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 20px 24px;
  max-height: 65vh; overflow-y: auto; color: var(--text);
}
.vista-previa img { max-width: 100%; height: auto; }
.vista-previa table { border-collapse: collapse; }
.vista-previa td, .vista-previa th { border: 1px solid var(--border); padding: 4px 8px; }
.tabla-usuarios { width: 100%; border-collapse: collapse; margin: 6px 0 12px; }
.tabla-usuarios td { padding: 8px 6px; border-bottom: 1px solid var(--border); }
.etiqueta { font-size: 11px; background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 10px; }
.foto-grande { max-width: 100%; max-height: 80vh; display: block; margin: 0 auto; border-radius: 8px; }

.aviso {
  position: fixed; left: 50%; bottom: 44px; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; box-shadow: var(--sombra);
  max-width: calc(100% - 32px);
}

/* ---------- pantallas chicas ---------- */
@media (max-width: 1100px) {
  .cuerpo { grid-template-columns: 220px minmax(0, 1fr); }
  .detalle {
    position: fixed; right: 0; top: 64px; bottom: 28px; width: min(380px, 100%); z-index: 20;
    box-shadow: var(--sombra); display: none;
  }
  .detalle.abierto { display: block; }
  .btn-cerrar-detalle {
    display: block; position: absolute; right: 10px; top: 8px; border: 0; background: var(--card);
    border-radius: 50%; width: 32px; height: 32px; cursor: pointer; z-index: 2;
  }
  .buscador input[type="search"] { width: 200px; }
}
@media (max-width: 900px) {
  .marca-texto { display: none; }
}
@media (max-width: 760px) {
  .app { grid-template-rows: auto 1fr 28px; }
  .cabecera { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .marca-texto { font-size: 16px; }
  .acciones-cabecera { flex-wrap: wrap; width: 100%; }
  .marca-texto { display: inline; }
  .buscador { flex: 1 1 100%; min-width: 0; }
  .buscador input[type="search"] { width: auto; flex: 1; min-width: 0; }
  .cuerpo { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  html, body { overflow-x: hidden; }
  .lateral { border-right: 0; border-bottom: 1px solid var(--border); padding: 10px 16px; }
  .rotulo, .pie-lateral { display: none; }
  #lista-secciones { display: flex; overflow-x: auto; gap: 6px; }
  #lista-secciones button { white-space: nowrap; height: 34px; }
  .encabezado-galeria { padding: 14px 16px 8px; }
  .galeria { padding: 4px 16px 16px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .detalle { top: 0; bottom: 0; width: 100%; }
  .campo { grid-template-columns: 1fr; gap: 4px; }
}
