/* Chuleta · Reusalia — mismos tokens que altas/caja/citas/fichajes.

   MÓVIL PRIMERO, y aquí no es una preferencia de estilo: esta app se usa con el WhatsApp
   o el chat de Wallapop abierto AL LADO, con una mano, mientras contestas. Por eso:
   buscador pegado arriba (se busca escribiendo, no bajando), un botón COPIAR grande por
   mensaje, y las hojas suben desde abajo, que es donde está el pulgar. */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #4f46e5;
  --brand-soft: #eef2ff;
  --brand-ink: #ffffff;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --star: #f59e0b;
  --err: #dc2626;
  --err-soft: #fee2e2;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --panel: #171b21; --ink: #e8eaed; --muted: #9aa3af;
    --line: #262b33; --brand: #6366f1; --brand-soft: #1e2333;
    --ok-soft: #14321f; --err-soft: #3b1717;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100svh;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font: inherit; }

/* ---------- Cabecera ---------- */
.cab {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.marca { display: flex; align-items: center; gap: 10px; min-width: 0; }
.marca .logo { font-size: 24px; }
.marca h1 { font-size: 18px; margin: 0; }
.marca .sub { margin: 0; font-size: 12px; color: var(--muted); }
.quien {
  display: flex; flex-direction: column; align-items: flex-end; gap: 1px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 12px; padding: 6px 12px; cursor: pointer; min-height: 44px;
  max-width: 45vw;
}
.quien-eti { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
#quienNombre { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.aviso-config {
  padding: 10px 14px; background: var(--err-soft); color: var(--err);
  font-size: 14px; font-weight: 600;
}

/* ---------- Buscador + chips ---------- */
.barra {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg); padding: 10px 14px 6px;
  border-bottom: 1px solid var(--line);
}
.buscador { position: relative; display: flex; align-items: center; }
.buscador .lupa { position: absolute; left: 12px; font-size: 15px; opacity: .7; pointer-events: none; }
.buscador input {
  width: 100%; padding: 12px 40px 12px 38px; min-height: 48px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--ink); font-size: 16px; /* 16px: menos y iOS hace zoom */
}
.buscador input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.limpia {
  position: absolute; right: 6px; width: 34px; height: 34px; border: none;
  background: transparent; color: var(--muted); cursor: pointer; font-size: 15px;
}
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 999px; padding: 7px 13px; font-size: 13px; cursor: pointer; min-height: 36px;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.chip.fav.on { background: var(--star); border-color: var(--star); color: #fff; }

/* ---------- Lista ---------- */
main { padding: 10px 14px 96px; }
.estado, .vacio { color: var(--muted); font-size: 14px; text-align: center; padding: 24px 0; }
.lista { display: flex; flex-direction: column; gap: 10px; }

.tarjeta {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 12px 10px;
}
.tarjeta.archivado { opacity: .55; }
.t-cab { display: flex; align-items: flex-start; gap: 8px; }
.t-titulo {
  flex: 1; min-width: 0; font-weight: 700; font-size: 15px; line-height: 1.3;
  background: none; border: none; color: var(--ink); text-align: left; padding: 0; cursor: pointer;
}
.t-estrella {
  flex: 0 0 auto; border: none; background: transparent; cursor: pointer;
  font-size: 20px; line-height: 1; width: 40px; height: 40px; margin: -8px -6px 0 0;
  color: var(--muted);
}
.t-estrella.on { color: var(--star); }
.t-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 4px 0 6px; }
.eti {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand); font-weight: 600;
}
.eti-uso { background: transparent; color: var(--muted); font-weight: 500; padding-left: 0; }
.t-prev {
  color: var(--muted); font-size: 13px; margin: 0 0 10px; white-space: pre-wrap;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.t-acciones { display: flex; gap: 8px; }
.t-acciones .btn { flex: 1; }

/* ---------- Botones ---------- */
.btn {
  border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink);
  border-radius: 12px; padding: 11px 14px; min-height: 46px; font-weight: 700;
  cursor: pointer; font-size: 15px;
}
.btn:active { transform: translateY(1px); }
.btn-grande { width: 100%; min-height: 54px; font-size: 17px; }
.btn-sec { background: var(--panel); color: var(--ink); border-color: var(--line); font-weight: 600; }
.btn-peligro { color: var(--err); }
.btn.copiado { background: var(--ok); border-color: var(--ok); }

.fab-nuevo {
  position: fixed; right: 16px; bottom: 16px; width: 56px; height: 56px; border-radius: 50%;
  background: var(--brand); color: #fff; border: none; font-size: 28px; line-height: 1;
  box-shadow: 0 6px 18px rgba(0,0,0,.28); cursor: pointer; z-index: 99997;
}

/* ---------- Hojas (suben desde abajo) ---------- */
.hoja { position: fixed; inset: 0; z-index: 99990; display: flex; align-items: flex-end; }
.hoja-fondo { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.hoja-caja {
  position: relative; width: 100%; max-height: 92svh; overflow-y: auto;
  background: var(--panel); border-radius: 20px 20px 0 0; padding: 14px 16px 20px;
  box-shadow: 0 -8px 30px rgba(0,0,0,.25);
}
.hoja-cab { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.hoja-cab h2 { font-size: 17px; margin: 0; flex: 1; min-width: 0; }
.cerrar {
  border: none; background: transparent; color: var(--muted); font-size: 18px;
  width: 40px; height: 40px; margin: -6px -8px 0 0; cursor: pointer;
}
.hoja-pie { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.acciones { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

.texto {
  white-space: pre-wrap; word-break: break-word; margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; max-height: 42svh; overflow-y: auto;
}
.texto .hueco {
  background: var(--brand-soft); color: var(--brand); border-radius: 5px;
  padding: 0 3px; font-weight: 600;
}
.texto .hueco.lleno { background: var(--ok-soft); color: var(--ok); }

.huecos { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.hueco-campo { display: flex; flex-direction: column; gap: 3px; }
.hueco-campo span { font-size: 12px; color: var(--muted); font-weight: 600; }
.hueco-campo input {
  padding: 11px 12px; min-height: 46px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--ink); font-size: 16px;
}

/* ---------- Editor ---------- */
.campo { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.campo > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.campo input, .campo textarea {
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); font-size: 16px; font-family: inherit;
  min-height: 46px; resize: vertical;
}
.ayuda { font-size: 12.5px; color: var(--muted); margin: 0 0 10px; }
.ayuda code {
  background: var(--brand-soft); color: var(--brand); border-radius: 4px;
  padding: 1px 4px; font-size: 12px;
}
.huecos-aviso {
  font-size: 12.5px; margin: 0 0 10px; padding: 8px 10px; border-radius: 10px;
  background: var(--brand-soft); color: var(--brand);
}
.error {
  font-size: 13.5px; color: var(--err); background: var(--err-soft);
  padding: 9px 11px; border-radius: 10px; margin: 0 0 10px;
}

/* ---------- Historial / quién ---------- */
.hist-lista { display: flex; flex-direction: column; gap: 10px; }
.hist-item { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.hist-meta { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.hist-texto {
  white-space: pre-wrap; word-break: break-word; font-size: 13px; margin: 0 0 8px;
  max-height: 130px; overflow-y: auto; color: var(--ink);
}
.rejilla-quien { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.rejilla-quien button {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 12px; padding: 14px 10px; min-height: 56px; font-weight: 600; cursor: pointer;
}
.rejilla-quien button.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }

.pin-input {
  width: 100%; padding: 12px; min-height: 50px; font-size: 20px; text-align: center;
  letter-spacing: .3em; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--ink); margin-bottom: 10px;
}

/* Avisito flotante (copiado, guardado, error) */
.aviso {
  position: fixed; left: 50%; bottom: 82px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 600; z-index: 99999; box-shadow: var(--shadow);
  max-width: 90vw; text-align: center;
}
.aviso.err { background: var(--err); color: #fff; }

/* ---------- Escritorio: la lista en columnas, el resto igual ---------- */
@media (min-width: 760px) {
  main { max-width: 1100px; margin: 0 auto; }
  .lista { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); align-items: start; }
  .barra { padding-left: max(14px, calc((100vw - 1100px) / 2)); padding-right: max(14px, calc((100vw - 1100px) / 2)); }
  .hoja { align-items: center; justify-content: center; }
  .hoja-caja { max-width: 640px; border-radius: 20px; max-height: 88svh; }
  .hoja-estrecha { max-width: 380px; }
}
