:root {
  --crema: #faf9f5;
  --papel: #ffffff;
  --tinta: #1f1e1c;
  --tenue: #6f6a60;
  --borde: #e6e2d8;
  --acento: #2f5bd6;
  --acento-suave: #eaeffc;
  --sombra: 0 1px 2px rgb(31 30 28 / 6%), 0 8px 24px rgb(31 30 28 / 6%);
  --radio: 14px;
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--crema);
  color: var(--tinta);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }

.barra {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: rgb(250 249 245 / 92%);
  backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid var(--borde);
}

.marca {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--tinta);
  font-weight: 650;
  letter-spacing: -.01em;
}
.marca img { border-radius: 8px; }

.acciones { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.boton {
  appearance: none;
  border: 1px solid var(--borde);
  background: var(--papel);
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 550;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .05s;
  white-space: nowrap;
}
.boton:hover { border-color: #cfc9bb; }
.boton:active { transform: translateY(1px); }
.boton:focus-visible { outline: 3px solid var(--acento-suave); outline-offset: 1px; }
.boton.primario { background: var(--tinta); border-color: var(--tinta); color: #fff; }
.boton.primario:hover { background: #33312d; }

.buscador {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--papel);
  border: 1px solid var(--borde);
  border-radius: 10px;
  padding: 0 10px;
  height: 40px;
}
.buscador:focus-within { border-color: #cfc9bb; box-shadow: 0 0 0 3px var(--acento-suave); }
.buscador .lupa { color: var(--tenue); font-size: 18px; line-height: 1; }
.buscador input {
  border: 0;
  outline: 0;
  background: transparent;
  width: min(38vw, 260px);
  padding: 0;
  height: 100%;
}
.buscador input::placeholder { color: #9a9488; }

.migas {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 18px clamp(16px, 4vw, 40px) 4px;
  font-size: 14px;
  color: var(--tenue);
}
.migas button {
  border: 0;
  background: none;
  padding: 2px 4px;
  border-radius: 6px;
  cursor: pointer;
  color: inherit;
}
.migas button:hover { background: #f0ede4; color: var(--tinta); }
.migas .sep { opacity: .5; }
.migas .actual { color: var(--tinta); font-weight: 600; }

main { padding-bottom: 64px; }

.rejilla {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 40px);
}

.tarjeta {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--papel);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  padding: 0;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.tarjeta:hover { border-color: #cfc9bb; box-shadow: var(--sombra); transform: translateY(-1px); }
.tarjeta:focus-visible { outline: 3px solid var(--acento-suave); outline-offset: 2px; }

.miniatura {
  aspect-ratio: 4 / 3;
  background: repeating-conic-gradient(#f3f1ea 0% 25%, #fbfaf6 0% 50%) 0 0 / 18px 18px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-bottom: 1px solid var(--borde);
}
.miniatura img { width: 100%; height: 100%; object-fit: cover; display: block; }
.miniatura .glifo { font-size: 34px; opacity: .55; }
.miniatura .psd {
  font-weight: 700;
  letter-spacing: .06em;
  color: #2b4bb3;
  background: #e8edfd;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
}
.miniatura.carpeta .glifo { font-size: 44px; opacity: .8; }

.datos { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.nombre {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.meta { font-size: 12px; color: var(--tenue); }

.menu {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px solid var(--borde);
  background: rgb(255 255 255 / 92%);
  backdrop-filter: blur(6px);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity .15s;
  font-size: 16px;
  line-height: 1;
}
.tarjeta:hover .menu, .tarjeta:focus-within .menu { opacity: 1; }

.vacio {
  display: grid;
  place-items: center;
  text-align: center;
  gap: 6px;
  padding: 72px 24px 96px;
  color: var(--tenue);
}
.vacio-icono { font-size: 40px; opacity: .7; }
.vacio h2 { margin: 6px 0 0; font-size: 18px; color: var(--tinta); }
.vacio p { margin: 0; line-height: 1.55; font-size: 14px; }

.cargando { padding: 24px clamp(16px, 4vw, 40px); color: var(--tenue); font-size: 14px; }

.aviso-zona {
  position: fixed;
  inset: 12px;
  z-index: 40;
  display: grid;
  place-items: center;
  border: 2px dashed var(--acento);
  border-radius: 20px;
  background: rgb(234 239 252 / 86%);
  color: #22377e;
  font-weight: 650;
  font-size: 16px;
  pointer-events: none;
}

.editor-vista {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: #1e1e1e;
}
.editor-barra {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  background: #1e1e1e;
  color: #9a9a9a;
  border-bottom: 1px solid #2a2a2a;
  min-height: 30px;
  font-size: 12px;
}
.editor-barra .boton {
  background: none;
  border: 0;
  padding: 4px 7px;
  border-radius: 6px;
  color: #8f8f8f;
  font-size: 12px;
  font-weight: 500;
}
.editor-barra .boton:hover { background: #2b2b2b; color: #e8e8e8; }
.editor-nombre { font-weight: 500; font-size: 12px; color: #a9a9a9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.editor-estado { margin-left: auto; font-size: 11px; color: #7f7f7f; white-space: nowrap; }
.editor-estado.ok { color: #7ad19a; }
.editor-estado.fallo { color: #ff9b8a; }
iframe#editor { flex: 1; width: 100%; border: 0; background: #262626; }

.dialogo {
  border: 1px solid var(--borde);
  border-radius: 16px;
  padding: 22px;
  width: min(420px, calc(100vw - 32px));
  box-shadow: var(--sombra);
  background: var(--papel);
  color: var(--tinta);
}
.dialogo::backdrop { background: rgb(31 30 28 / 32%); backdrop-filter: blur(2px); }
.dialogo h2 { margin: 0 0 6px; font-size: 17px; }
.dialogo p { margin: 0 0 14px; color: var(--tenue); font-size: 14px; line-height: 1.5; }
.dialogo input[type="text"] {
  width: 100%;
  border: 1px solid var(--borde);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 4px;
}
.dialogo input[type="text"]:focus { outline: 3px solid var(--acento-suave); border-color: #cfc9bb; }
.dialogo menu { display: flex; justify-content: flex-end; gap: 8px; margin: 16px 0 0; padding: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--tinta);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--sombra);
  max-width: min(90vw, 560px);
}
.toast.error { background: #8f2b22; }

@media (max-width: 640px) {
  .barra { flex-wrap: wrap; }
  .acciones { width: 100%; justify-content: space-between; }
  .buscador { flex: 1; }
  .buscador input { width: 100%; }
  .rejilla { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .editor-nombre { max-width: 40vw; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

.menu-flotante {
  position: fixed;
  z-index: 70;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  padding: 6px;
  background: var(--papel);
  border: 1px solid var(--borde);
  border-radius: 12px;
  box-shadow: var(--sombra);
}
.menu-flotante button {
  border: 0;
  background: none;
  text-align: left;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.menu-flotante button:hover { background: #f3f1ea; }
.menu-flotante button:focus-visible { outline: 2px solid var(--acento-suave); }

[hidden] { display: none !important; }
