/* Colores corporativos de verdnatura.es: verde lima #8cc63f, casi negro #1a1a1a y grises neutros.
   El lima es relleno (botón principal, selección) con texto #1a1a1a encima: blanco sobre lima no llega
   a 3:1. Para texto y datos en verde se usa el mismo lima oscurecido (#4a7a1c, 5:1 sobre blanco).
   Superficies planas: se separan por un paso de tono o una línea de 1px, nunca por sombra. */
:root {
  --bg: #f8f8f8;
  --surface: #ffffff;
  --raised: #eef0f2;      /* pistas de controles, chips */
  --border: #e0dede;
  --rule: #eeeeee;
  --control: #c8c8c8;
  --text: #1a1a1a;
  --muted: #646a76;       /* el gris azulado de la web (#747a87), oscurecido hasta 5:1 */
  --brand: #8cc63f;       /* relleno de la acción principal */
  --brand-hover: #7db534;
  --on-brand: #1a1a1a;
  --brand-ink: #4a7a1c;   /* el dato: barras, cifra de calientes, enlaces */
  --brand-tint: #eef6e2;
  --warn-bg: #fffbeb; --warn-border: #fde68a; --warn-ink: #92400e;
  --negative: #c4242a;
  --radius: 16px;         /* tarjetas */
  --radius-control: 10px; /* campos */
  --pill: 999px;          /* botones y selectores, como en la web */
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a;
    --surface: #232323;
    --raised: #2d2d2d;
    --border: #333333;
    --rule: #2b2b2b;
    --control: #4a4a4a;
    --text: #f7f7f7;
    --muted: #a9adb6;
    --brand: #8cc63f;
    --brand-hover: #9bd150;
    --on-brand: #1a1a1a;
    --brand-ink: #8cc63f;
    --brand-tint: #2a3820;
    --warn-bg: #2a2210; --warn-border: #4a3a12; --warn-ink: #f2c46d;
    --negative: #e5566f;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1rem; font-weight: 600; margin: 1.75rem 0 .6rem; }
.muted { color: var(--muted); margin: 0; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--brand-ink); outline-offset: 2px; }

/* ---------- Botones ---------- */
.btn {
  appearance: none; border: 1px solid var(--control); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; padding: .8rem 1.25rem; border-radius: var(--pill); cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  transition: transform .08s ease, background .15s;
}
.btn:hover { background: var(--raised); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.danger { color: var(--negative); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; }
.icon-btn {
  appearance: none; background: none; border: 0; color: inherit; cursor: pointer;
  width: 44px; height: 44px; display: grid; place-items: center; border-radius: var(--pill);
}
.icon-btn:hover { background: var(--raised); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  padding: 2rem 1.5rem; border-radius: var(--radius); text-align: center;
}
.login-card .logo { width: 64px; height: 64px; margin-bottom: 1rem; }
.login-card h1 { font-size: 1.25rem; }
.login-card form { margin-top: 1.25rem; display: grid; gap: .75rem; }
.login-card input { text-align: center; font-size: 1.5rem; letter-spacing: .4em; }

/* ---------- Estructura ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) max(8px, calc((100% - 720px) / 2 + 8px)) 6px max(16px, calc((100% - 720px) / 2 + 16px));
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .6rem; min-width: 0; line-height: 1.2; }
.brand img { width: 28px; height: 28px; flex: none; }
.brand strong { display: block; font-size: .95rem; }
.brand small { display: block; font-size: .75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: .25rem; }
.net { display: inline-flex; align-items: center; gap: 6px; font-size: .75rem; color: var(--muted); padding: 0 6px; }
.net-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand-ink); }
.net-dot.off { background: var(--warn-ink); }
.badge {
  font-size: .75rem; font-weight: 600; padding: .2rem .6rem; border-radius: 99px; white-space: nowrap;
  background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-border);
}

main { max-width: 720px; margin: 0 auto; padding: 20px 16px calc(var(--tabbar-h) + var(--safe-b) + 24px); }
.view-head { margin-bottom: 1rem; }
.view-head p { margin: 0; }
.view-head-action { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.view-head-action .btn { flex: none; padding: .6rem 1rem; }
.note { font-size: .85rem; margin-top: 1rem; }
.view-head-action > p { margin: 0; align-self: center; }

/* Códigos de evento: grandes y espaciados, para dictarlos y teclearlos sin error */
.code-input { text-transform: uppercase; letter-spacing: .12em; font-weight: 600; }
.login-card .code-input { text-align: center; font-size: 1.25rem; }
.code-input::placeholder { text-transform: none; letter-spacing: normal; font-weight: 400; }
.tag.code { letter-spacing: .08em; background: var(--text); color: var(--bg); }
.tag.live { background: var(--brand); color: var(--on-brand); }

/* Admin */
.admin-tabs { margin-bottom: 1.25rem; }
.event-filter { margin: 0 0 10px; }
.drive-links { display: flex; flex-wrap: wrap; gap: 8px; margin: -4px 0 1rem; }
.add-row { display: flex; gap: 8px; }
.add-row input { margin: 0; }
.add-row .btn { flex: none; }
.lead-list li.plain { grid-template-columns: minmax(0, 1fr) auto; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 120px); justify-content: center;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar button {
  background: none; border: 0; color: var(--muted); font: inherit; font-size: .75rem; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer;
}
.tabbar button.active { color: var(--text); }
.tabbar button.active svg { color: var(--brand-ink); }

/* ---------- Escanear ---------- */
.scan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.scan-btn {
  appearance: none; font: inherit; color: var(--text); cursor: pointer; margin: 0; /* #cardBtn es un <label> */
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; display: flex; flex-direction: column; align-items: flex-start; gap: .2rem; text-align: left;
  transition: transform .08s ease, border-color .15s;
}
.scan-btn:hover { border-color: var(--control); }
.scan-btn:active { transform: scale(.98); }
.scan-btn svg { width: 28px; height: 28px; margin-bottom: .5rem; color: var(--brand-ink); }
.scan-btn strong { font-size: 1.05rem; }
.scan-btn small { color: var(--muted); font-size: .85rem; }
.scan-btn.primary {
  grid-column: 1 / -1; min-height: 150px; justify-content: flex-end;
  background: var(--brand); border-color: var(--brand); color: var(--on-brand);
}
.scan-btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.scan-btn.primary svg { color: inherit; width: 40px; height: 40px; }
.scan-btn.primary strong { font-size: 1.3rem; }
.scan-btn.primary small { color: inherit; opacity: .8; }

/* ---------- Valoración de clientes: de 1 a 5 estrellas ---------- */
.rating { flex: none; white-space: nowrap; font-size: .85rem; letter-spacing: 1px; color: var(--brand-ink); }

.switch.existing-client { margin-bottom: 1.25rem; }

/* En el formulario: cinco estrellas grandes; se rellenan hasta la elegida */
.stars { display: flex; gap: 2px; margin: -4px 0 1rem -6px; }
.stars label { position: relative; margin: 0; width: 48px; height: 48px; display: grid; place-items: center; cursor: pointer; color: var(--control); }
.stars input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.stars svg { width: 34px; height: 34px; stroke-width: 1.5; }
.stars label:has(input:focus-visible) { outline: 2px solid var(--brand-ink); outline-offset: -2px; border-radius: var(--radius-control); }
.stars:has(input[value="1"]:checked) label:nth-child(-n+1),
.stars:has(input[value="2"]:checked) label:nth-child(-n+2),
.stars:has(input[value="3"]:checked) label:nth-child(-n+3),
.stars:has(input[value="4"]:checked) label:nth-child(-n+4),
.stars:has(input[value="5"]:checked) label:nth-child(-n+5) { color: var(--brand-ink); }
.stars:has(input[value="1"]:checked) label:nth-child(-n+1) svg,
.stars:has(input[value="2"]:checked) label:nth-child(-n+2) svg,
.stars:has(input[value="3"]:checked) label:nth-child(-n+3) svg,
.stars:has(input[value="4"]:checked) label:nth-child(-n+4) svg,
.stars:has(input[value="5"]:checked) label:nth-child(-n+5) svg { fill: var(--brand); }

/* ---------- Formulario ---------- */
.form-head { display: flex; align-items: center; gap: 4px; margin: -6px 0 1rem -10px; }
.form-head h1 { margin: 0; font-size: 1.25rem; }
fieldset { border: 1px solid var(--border); margin: 0 0 1rem; padding: 1rem; background: var(--surface); border-radius: var(--radius); }
legend { float: left; width: 100%; padding: 0; margin-bottom: .75rem; font-weight: 600; }
label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: .75rem; }
.field-label { font-size: .85rem; font-weight: 600; color: var(--muted); margin: 0 0 .4rem; clear: both; }
input, select, textarea {
  display: block; width: 100%; margin-top: .3rem;
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--control); border-radius: var(--radius-control); padding: .65rem .75rem;
  transition: border-color .15s, background .3s;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-ink); outline-offset: -1px; border-color: var(--brand-ink); }
input.filled, textarea.filled { background: var(--brand-tint); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
details summary { cursor: pointer; font-size: .9rem; font-weight: 600; color: var(--brand-ink); margin: .2rem 0 .8rem; }

/* Valoración: una sola opción, control segmentado */
.segmented {
  display: grid; grid-template-columns: repeat(var(--n, 3), 1fr); gap: 3px; padding: 3px; margin-bottom: 1rem;
  background: var(--raised); border-radius: var(--pill);
}
.segmented label {
  margin: 0; display: grid; place-items: center; min-height: 40px; border-radius: var(--pill); cursor: pointer;
  color: var(--text); font-size: .9rem; font-weight: 600;
}
.segmented label, .chip { position: relative; }
.segmented input, .chip input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--brand); color: var(--on-brand); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--brand-ink); outline-offset: 1px; }

.segmented.two { --n: 2; }
.hint { display: block; font-weight: 400; font-size: .8rem; margin-top: .35rem; }
.switch { display: flex; align-items: flex-start; gap: 12px; color: var(--text); font-size: .95rem; margin: 0; cursor: pointer; }
.switch input { appearance: none; flex: none; width: 40px; height: 24px; margin: 0; padding: 0; border-radius: 99px; background: var(--control); border: 0; position: relative; cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); transition: transform .15s; }
.switch input:checked { background: var(--brand-ink); }
.switch input:checked::after { transform: translateX(16px); }
.switch small { display: block; color: var(--muted); font-size: .8rem; font-weight: 400; margin-top: 2px; }
.tag { flex: none; white-space: nowrap; font-size: .75rem; font-weight: 600; padding: .15rem .6rem; border-radius: var(--pill); background: var(--raised); color: var(--muted); }
.tag.admin { background: var(--brand-tint); color: var(--brand-ink); }

/* Chips: reverso de la tarjeta, enlaces a Drive */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 1rem; clear: both; }
.chip {
  display: inline-flex; align-items: center; gap: .3rem; margin: 0; cursor: pointer; user-select: none;
  min-height: 36px; padding: .4rem .85rem; border-radius: 99px; border: 1px solid var(--control); background: var(--surface);
  font-size: .85rem; font-weight: 600; color: var(--text);
}
.chip:has(input:checked) { background: var(--brand-tint); border-color: var(--brand-ink); color: var(--brand-ink); }
.chip:has(input:checked)::before { content: ""; width: 10px; height: 6px; border: solid currentColor; border-width: 0 0 2px 2px; transform: translateY(-2px) rotate(-45deg); }
.chip:has(input:focus-visible) { outline: 2px solid var(--brand-ink); outline-offset: 2px; }

/* Notas de voz: grabar ocupa todo el ancho; grabando, el botón se vuelve rojo con un punto que late */
.voice { margin: 0 0 1rem; }
.voice > .btn { width: 100%; }
.voice .hint { color: var(--muted); }
.voice > .btn svg { width: 20px; height: 20px; }
.btn.recording, .btn.recording:hover { background: var(--negative); border-color: var(--negative); color: #fff; }
.btn.recording svg { display: none; }
.btn.recording::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
@media (prefers-reduced-motion: no-preference) {
  .btn.recording::before { animation: blink 1s ease-in-out infinite; }
}
@keyframes blink { 50% { opacity: .25; } }
.voice-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.voice-list:not(:empty) { margin-top: .6rem; }
.voice-list li {
  display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 6px;
  padding: 2px 8px 2px 2px; border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--bg);
}
.voice-list strong { display: block; font-size: .9rem; color: var(--text); font-variant-numeric: tabular-nums; }
.voice-list small { display: block; font-size: .8rem; color: var(--muted); }
.voice-list li.error small { color: var(--negative); }
.voice-list .play { color: var(--brand-ink); }
.voice-list .i-pause, .voice-list .play.playing .i-play { display: none; }
.voice-list .play.playing .i-pause { display: block; }

.card-preview { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; margin-bottom: 1rem; }
.card-preview img { width: 100%; max-height: 220px; object-fit: contain; border-radius: 8px; background: #000; display: block; }
.preview-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.preview-actions .scan-status { margin-left: auto; }
a.chip { text-decoration: none; color: var(--brand-ink); }
.scan-status { font-size: .85rem; color: var(--muted); display: inline-flex; align-items: center; gap: .4rem; }
.scan-status.busy::before { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--brand-ink); animation: spin .7s linear infinite; }
.scan-status.error { color: var(--negative); }
@keyframes spin { to { transform: rotate(360deg); } }

.alert { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-ink); padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; }

/* Barra de guardar: fija sobre la barra de pestañas, con su propio fondo para no tapar campos a medias */
.sticky-actions {
  position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b));
  display: flex; gap: 10px; margin: 0 -16px; padding: 10px 16px;
  background: var(--bg); border-top: 1px solid var(--border);
}
.sticky-actions .btn.primary { padding: 1rem; font-size: 1.05rem; }

/* ---------- Lista ---------- */
.list-head { display: flex; gap: 8px; position: sticky; top: 57px; z-index: 5; background: var(--bg); padding: 4px 0 12px; }
.list-head input { margin: 0; }
.lead-list { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.lead-list li {
  display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  min-height: 64px; padding: 10px 14px; cursor: pointer; border-top: 1px solid var(--rule);
}
.lead-list li:first-child { border-top: 0; }
.lead-list li:hover { background: var(--raised); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand-tint); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; font-size: .8rem; }
.lead-main { min-width: 0; }
.lead-main strong, .lead-main small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lead-main small { color: var(--muted); font-size: .85rem; }
.lead-meta { display: grid; justify-items: end; gap: 2px; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.lead-list li.pending .lead-main, .lead-list li.pending .avatar { opacity: .6; }
.lead-list li.pending .lead-meta { color: var(--warn-ink); }
.lead-list li.empty { display: block; min-height: 0; padding: 1.25rem 1rem; cursor: default; color: var(--muted); }
.lead-list li.empty:hover { background: none; }

/* ---------- Panel ---------- */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.kpi { padding: 14px 16px; border-left: 1px solid var(--rule); }
.kpi:first-child { border-left: 0; }
.kpi small { display: block; color: var(--muted); font-size: .85rem; font-weight: 600; }
.kpi span { display: block; font-size: 1.75rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi.hot span { color: var(--brand-ink); }
.drive-status {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px;
  padding: 10px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); font-size: .9rem;
}
.drive-status p { margin: 0; }
.drive-status .btn { flex: none; padding: .45rem 1rem; }
.bars { display: grid; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; row-gap: 4px; font-size: .9rem; }
.bar span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar span { grid-area: 1 / 1; }
.bar b { grid-area: 1 / 2; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.bar i { grid-area: 2 / 1 / 3 / -1; display: block; height: 4px; border-radius: 2px; background: var(--brand-ink); }

/* ---------- Lector QR ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: #000; display: grid; place-items: center; }
.modal video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
/* el marco oscurece el vídeo a su alrededor; no es una sombra decorativa */
.qr-frame { position: relative; width: min(70vw, 300px); aspect-ratio: 1; border-radius: 16px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .5); border: 3px solid #8cc63f; } /* taste-skill-ignore */
.qr-hint { position: absolute; top: calc(env(safe-area-inset-top, 0px) + 24px); color: #fff; font-weight: 600; text-align: center; padding: 0 16px; }
.modal .btn { position: absolute; bottom: calc(var(--safe-b) + 32px); }

/* ---------- Aviso flotante ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 80px);
  background: var(--text); color: var(--bg); padding: .7rem 1.1rem; border-radius: var(--radius); font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2); /* taste-skill-ignore: flota sobre el contenido */
  width: max-content; max-width: calc(100vw - 32px);
}

@media (min-width: 720px) {
  /* Las tres en una fila: mismo alto, contenido al pie y títulos al mismo tamaño, en una sola línea */
  .scan-grid { grid-template-columns: 2fr 1fr 1fr; }
  .scan-btn { min-height: 168px; justify-content: flex-end; }
  .scan-btn svg, .scan-btn.primary svg { width: 32px; height: 32px; margin-bottom: auto; }
  .scan-btn.primary { grid-column: auto; }
  .scan-btn.primary strong { font-size: 1.05rem; }
}
