:root {
  --fondo: #f4f2ee; --superficie: #ffffff; --superficie-2: #ece9e3; --borde: #dcd7cf;
  --texto: #1c1a17; --texto-2: #6b655c; --acento: #1f5eff; --acento-texto: #ffffff; --acento-suave: #e3eaff;
  --peligro: #c62f2f; --ok: #1d7a46; --aviso: #9a5b00; --aviso-suave: #fff2dc;
  --radio: 14px; --sombra: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .06);
  --e-nuevo: #1f5eff; --e-contactado: #7a4dff; --e-negociacion: #c77700; --e-cliente: #1d7a46; --e-descartado: #8a857d;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #121212; --superficie: #1c1c1e; --superficie-2: #2a2a2d; --borde: #3a3a3e;
    --texto: #f2f0ec; --texto-2: #a19b92; --acento: #5b8cff; --acento-suave: #1d2a4d;
    --aviso-suave: #3a2a0c; --aviso: #f0b45a; --sombra: none; color-scheme: dark;
    --e-nuevo: #7fa3ff; --e-contactado: #b39bff; --e-negociacion: #f0a640; --e-cliente: #4cc585; --e-descartado: #a19b92;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--fondo); color: var(--texto); }
body { font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100dvh; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--acento); }
.oculto { display: none !important; }

#app { max-width: 720px; margin: 0 auto; padding: env(safe-area-inset-top) 16px calc(96px + env(safe-area-inset-bottom)); }
.cabecera { display: flex; align-items: center; gap: 12px; padding: 18px 0 12px; }
.cabecera h1 { font-size: 26px; line-height: 1.15; margin: 0; flex: 1; letter-spacing: -.02em; }
.cabecera .atras { border: 0; background: var(--superficie); width: 40px; height: 40px; border-radius: 50%; font-size: 20px; box-shadow: var(--sombra); cursor: pointer; }

/* navegación inferior */
.nav { position: fixed; left: 0; right: 0; bottom: 0; background: color-mix(in srgb, var(--superficie) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--borde);
  display: flex; justify-content: space-around; align-items: center; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); z-index: 20; }
.nav a { flex: 1; text-align: center; text-decoration: none; color: var(--texto-2); font-size: 12px; padding: 6px 0; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.nav a svg { width: 24px; height: 24px; }
.nav a.activo { color: var(--acento); }
.nav a.escanear { flex: 0 0 auto; margin-top: -26px; }
.nav a.escanear span.boton { width: 62px; height: 62px; border-radius: 50%; background: var(--acento); color: var(--acento-texto);
  display: grid; place-items: center; box-shadow: 0 6px 18px rgb(31 94 255 / .35); }
.nav a.escanear svg { width: 28px; height: 28px; }

/* controles */
.boton { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 12px; padding: 13px 18px;
  background: var(--acento); color: var(--acento-texto); font-weight: 600; cursor: pointer; text-decoration: none; min-height: 48px; }
.boton.secundario { background: var(--superficie-2); color: var(--texto); }
.boton.peligro { background: transparent; color: var(--peligro); }
.boton.ancho { width: 100%; }
.boton:disabled { opacity: .55; }
.fila-botones { display: flex; gap: 10px; flex-wrap: wrap; }
.fila-botones > * { flex: 1; }

label.campo { display: block; margin-bottom: 14px; }
label.campo > span { display: block; font-size: 13px; color: var(--texto-2); margin-bottom: 5px; font-weight: 500; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=search], input[type=date], input[type=url], select, textarea {
  width: 100%; border: 1px solid var(--borde); background: var(--superficie); border-radius: 12px; padding: 12px 14px; min-height: 48px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--acento); box-shadow: 0 0 0 3px var(--acento-suave); }
textarea { min-height: 90px; resize: vertical; }
.multi { display: flex; gap: 8px; margin-bottom: 8px; }
.multi select { width: 118px; flex: 0 0 auto; }
.multi input { flex: 1; min-width: 0; }
.multi .quitar { border: 0; background: none; color: var(--texto-2); font-size: 22px; width: 36px; cursor: pointer; }
.agregar { border: 0; background: none; color: var(--acento); font-weight: 600; padding: 4px 0 12px; cursor: pointer; }

.tarjeta { background: var(--superficie); border-radius: var(--radio); box-shadow: var(--sombra); padding: 16px; margin-bottom: 14px; }
.tarjeta h2 { font-size: 15px; margin: 0 0 12px; color: var(--texto-2); font-weight: 600; }

/* lista */
.buscador { position: sticky; top: 0; z-index: 5; background: var(--fondo); padding: 4px 0 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 0 0 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; border: 1px solid var(--borde); background: var(--superficie); border-radius: 999px; padding: 7px 13px; font-size: 14px; cursor: pointer; white-space: nowrap; }
.chip.activo { background: var(--texto); color: var(--fondo); border-color: var(--texto); }
.chip b { font-weight: 600; opacity: .6; margin-left: 4px; }
.contacto { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--superficie); border-radius: var(--radio);
  margin-bottom: 8px; text-decoration: none; color: inherit; box-shadow: var(--sombra); }
.avatar { width: 48px; height: 48px; border-radius: 12px; flex: 0 0 auto; background: var(--superficie-2); display: grid; place-items: center;
  font-weight: 700; color: var(--texto-2); object-fit: cover; }
img.avatar { width: 64px; height: 40px; border-radius: 8px; border: 1px solid var(--borde); }
.ficha-top img.avatar { width: 96px; height: 60px; cursor: zoom-in; }
.contacto .info { flex: 1; min-width: 0; }
.contacto .nombre { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contacto .sub { color: var(--texto-2); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.etiqueta-etapa { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; white-space: nowrap;
  color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }
.vacio { text-align: center; color: var(--texto-2); padding: 48px 16px; }
.vacio svg { width: 56px; height: 56px; opacity: .5; }

/* escáner */
.lados { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.lado { aspect-ratio: 1.6; border: 2px dashed var(--borde); border-radius: var(--radio); background: var(--superficie); display: grid; place-items: center;
  text-align: center; color: var(--texto-2); cursor: pointer; overflow: hidden; position: relative; font-size: 14px; padding: 8px; }
.lado.lleno { border-style: solid; border-color: var(--acento); padding: 0; }
.lado img { width: 100%; height: 100%; object-fit: cover; }
.lado .x { position: absolute; top: 6px; right: 6px; background: rgb(0 0 0 / .6); color: #fff; border: 0; border-radius: 50%; width: 28px; height: 28px; cursor: pointer; }
.lado svg { width: 32px; height: 32px; display: block; margin: 0 auto 6px; }
.gran-captura { width: 100%; aspect-ratio: 1.6; border-radius: 18px; border: 0; background: var(--acento); color: var(--acento-texto);
  display: grid; place-items: center; font-size: 18px; font-weight: 600; cursor: pointer; margin-bottom: 14px; box-shadow: 0 10px 30px rgb(31 94 255 / .3); }
.gran-captura svg { width: 56px; height: 56px; display: block; margin: 0 auto 10px; }
.ayuda { color: var(--texto-2); font-size: 14px; }
.cargando { text-align: center; padding: 40px 0; }
.giro { width: 42px; height: 42px; border: 4px solid var(--superficie-2); border-top-color: var(--acento); border-radius: 50%; animation: giro .8s linear infinite; margin: 0 auto 14px; }
@keyframes giro { to { transform: rotate(360deg); } }

.aviso { background: var(--aviso-suave); color: var(--aviso); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: 14px; }
.aviso a { color: inherit; font-weight: 600; }
.miniaturas { display: flex; gap: 8px; margin-bottom: 14px; }
.miniaturas img { height: 84px; border-radius: 10px; cursor: zoom-in; box-shadow: var(--sombra); }

/* detalle */
.ficha-top { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.ficha-top .avatar { width: 64px; height: 64px; font-size: 22px; }
.ficha-top h1 { font-size: 22px; margin: 0; line-height: 1.2; }
.ficha-top .sub { color: var(--texto-2); }
.acciones { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.acciones a, .acciones button { background: var(--superficie); border: 0; border-radius: 14px; padding: 12px 4px; text-align: center; font-size: 12px;
  color: var(--texto); text-decoration: none; box-shadow: var(--sombra); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.acciones svg { width: 22px; height: 22px; color: var(--acento); }
.acciones .apagado { opacity: .35; pointer-events: none; }
.dato { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--borde); word-break: break-word; }
.dato:last-child { border-bottom: 0; }
.dato .k { color: var(--texto-2); font-size: 13px; width: 90px; flex: 0 0 auto; padding-top: 2px; }
.etapas { display: flex; flex-wrap: wrap; gap: 8px; }
.etapas button { border: 1px solid var(--borde); background: var(--superficie); border-radius: 999px; padding: 8px 12px; font-size: 14px; cursor: pointer; }
.etapas button.activo { background: var(--c); color: #fff; border-color: var(--c); }
.linea-tiempo { list-style: none; margin: 0; padding: 0; }
.linea-tiempo li { padding: 10px 0; border-bottom: 1px solid var(--borde); }
.linea-tiempo li:last-child { border-bottom: 0; }
.linea-tiempo .meta { font-size: 12px; color: var(--texto-2); }
.nota-nueva { display: flex; gap: 8px; margin-bottom: 8px; }
.nota-nueva select { width: 120px; flex: 0 0 auto; }
.etiquetas-lista { display: flex; flex-wrap: wrap; gap: 6px; }
.etiquetas-lista span { background: var(--superficie-2); border-radius: 999px; padding: 3px 10px; font-size: 13px; }

/* varios */
.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--texto); color: var(--fondo);
  padding: 12px 18px; border-radius: 12px; z-index: 50; font-size: 15px; box-shadow: 0 8px 24px rgb(0 0 0 / .2); max-width: calc(100% - 32px); }
.visor { position: fixed; inset: 0; background: rgb(0 0 0 / .92); z-index: 60; display: grid; place-items: center; padding: 16px; }
.visor img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.entrada { min-height: 100dvh; display: grid; place-items: center; }
.entrada .caja { width: 100%; max-width: 380px; }
.entrada .logo { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 14px; }
.entrada h1 { font-size: 28px; margin: 0 0 4px; letter-spacing: -.02em; }
.entrada p { color: var(--texto-2); margin: 0 0 24px; }
.error-texto { color: var(--peligro); font-size: 14px; min-height: 20px; margin-bottom: 8px; }
.lista-simple { list-style: none; padding: 0; margin: 0; }
.lista-simple li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--borde); }
.lista-simple li:last-child { border-bottom: 0; }
.lista-simple .info { flex: 1; min-width: 0; }
.lista-simple .sub { font-size: 13px; color: var(--texto-2); }
.mini { font-size: 13px; padding: 6px 10px; min-height: 0; border-radius: 8px; }

/* texto leído por el OCR */
.lineas { display: flex; flex-wrap: wrap; gap: 6px; }
.linea { border: 1px solid var(--borde); background: var(--superficie-2); border-radius: 10px; padding: 6px 10px; font-size: 14px; text-align: left; cursor: pointer; max-width: 100%; overflow-wrap: anywhere; }
.linea.usada { opacity: .45; }
.menu-linea { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 0 8px; }
.menu-linea button { border: 0; background: var(--acento); color: var(--acento-texto); border-radius: 999px; padding: 7px 12px; font-size: 14px; font-weight: 600; cursor: pointer; }
.menu-linea button:last-child { background: var(--superficie-2); color: var(--texto); }
.resalte { border-color: var(--acento) !important; box-shadow: 0 0 0 3px var(--acento-suave); transition: box-shadow .3s; }
.texto-leido summary { font-size: 15px; color: var(--texto-2); font-weight: 600; cursor: pointer; list-style: none; }
.texto-leido summary::-webkit-details-marker { display: none; }
.texto-leido summary::after { content: ' ▾'; }
.texto-leido[open] summary { margin-bottom: 12px; }
.texto-leido[open] summary::after { content: ' ▴'; }
