/* =========================================================
   Mi Gestor — app.css
   Paleta "Bloque Marino" · móvil primero · botones grandes
   ========================================================= */

@font-face {
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('../assets/fonts/space-grotesk-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('../assets/fonts/space-grotesk-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --navy: #1A4778;
  --navy-osc: #143a63;
  --steel: #587797;
  --azul-claro: #a9c1d8;
  --crema: #F3EFE4;
  --crema2: #F7F4EC;
  --tinta: #22303F;
  --tinta2: #2c3947;
  --gris: #5b6672;
  --gris2: #8a94a0;
  --linea: #e9e5da;
  --verde: #2e7d4f;
  --rojo: #b3392e;
  --ambar: #b07818;
  --radio: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  margin: 0;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  background: var(--crema);
  color: var(--tinta);
  min-height: 100%;
  font-size: 16px;
}

.hidden { display: none !important; }
.centrado { text-align: center; }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--navy);
  color: #fff;
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
}
.topbar-mark { width: 26px; height: 26px; }
#topbar-titulo { font-weight: 700; font-size: 18px; letter-spacing: .02em; }
.btn-atras {
  background: rgba(255,255,255,.14); color: #fff; border: 0;
  font-size: 22px; line-height: 1; border-radius: 10px;
  padding: 8px 14px; cursor: pointer;
}

/* ---------- Contenido ---------- */
#main {
  max-width: 720px; margin: 0 auto;
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
}
.view { animation: aparecer .18s ease; }
@keyframes aparecer { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

/* ---------- Barra inferior ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex;
  background: #fff;
  border-top: 1px solid var(--linea);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 2px 7px;
  font-family: inherit; font-size: 12px; font-weight: 600;
  color: var(--gris);
}
.tab-ico { font-size: 22px; line-height: 1.1; filter: grayscale(1) opacity(.55); }
.tab.activo { color: var(--navy); }
.tab.activo .tab-ico { filter: none; }

/* ---------- Inicio ---------- */
.saludo { font-size: 26px; font-weight: 700; color: var(--navy); margin: 6px 2px 12px; }

.card-resumen {
  width: 100%; text-align: left;
  background: #fff; border: 1px solid var(--linea); border-radius: var(--radio);
  padding: 14px 16px; margin-bottom: 16px;
  font-family: inherit; font-size: 15.5px; color: var(--tinta2); cursor: pointer;
}
.card-resumen b { color: var(--navy); font-size: 18px; }

.card-copia {
  width: 100%; text-align: left;
  background: #fdf6e3; border: 1px solid #ecd9a8; border-radius: var(--radio);
  padding: 14px 16px; margin-bottom: 16px;
  font-family: inherit; font-size: 13.5px; line-height: 1.5;
  color: var(--gris); cursor: pointer;
}
.card-copia b { display: block; color: var(--ambar); font-size: 15.5px; margin-bottom: 3px; }

.mic-zona { text-align: center; margin: 10px 0 14px; }
.btn-mic {
  width: 108px; height: 108px; border-radius: 50%;
  background: var(--navy); color: var(--crema);
  border: 6px solid #fff;
  box-shadow: 0 10px 26px -10px rgba(20,40,70,.55);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform .12s ease, background .15s ease;
}
.btn-mic:active { transform: scale(.95); }
.btn-mic.escuchando {
  background: var(--rojo);
  animation: pulso 1.2s ease-in-out infinite;
}
@keyframes pulso {
  0%, 100% { box-shadow: 0 0 0 0 rgba(179,57,46,.45); }
  50% { box-shadow: 0 0 0 18px rgba(179,57,46,0); }
}
.mic-hint {
  margin: 12px auto 0; max-width: 420px;
  font-size: 14px; line-height: 1.5; color: var(--gris);
}
.mic-hint em { color: var(--steel); font-style: italic; }

.chat-mensajes { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.msg {
  max-width: 88%; padding: 11px 14px; border-radius: 16px;
  font-size: 15.5px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word;
}
.msg.usuario { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 5px; }
.msg.ia { align-self: flex-start; background: #fff; border: 1px solid var(--linea); color: var(--tinta2); border-bottom-left-radius: 5px; }
.msg.escribiendo { color: var(--gris2); font-style: italic; }
.msg .btn-mini-accion {
  display: inline-block; margin-top: 8px;
  background: var(--navy); color: #fff; border: 0; border-radius: 10px;
  font-family: inherit; font-size: 14px; font-weight: 600;
  padding: 9px 14px; cursor: pointer;
}

/* Tarjeta de borrador en el chat */
.borrador-card {
  align-self: stretch;
  background: #fff; border: 2px solid var(--navy); border-radius: var(--radio);
  padding: 14px 16px;
}
.borrador-tipo {
  font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--steel); font-weight: 700; margin-bottom: 6px;
}
.borrador-cliente { font-size: 17px; font-weight: 700; color: var(--navy); }
.borrador-lineas { margin: 10px 0; font-size: 14.5px; color: var(--tinta2); }
.borrador-linea { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.borrador-linea span:last-child { white-space: nowrap; font-weight: 600; color: var(--navy); }
.borrador-desc { font-size: 13.5px; color: var(--gris); white-space: pre-line; margin: 8px 0; border-left: 3px solid var(--crema); padding-left: 10px; }
.borrador-total {
  display: flex; justify-content: space-between; align-items: baseline;
  border-top: 1px solid var(--linea); padding-top: 10px; margin-top: 6px;
  font-size: 14px; color: var(--gris);
}
.borrador-total b { font-size: 20px; color: var(--navy); }
.borrador-botones { display: flex; gap: 8px; margin-top: 12px; }
.borrador-botones button {
  flex: 1; border-radius: 12px; border: 0; padding: 12px 8px;
  font-family: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
}
.borrador-botones .b-guardar { background: var(--navy); color: #fff; }
.borrador-botones .b-editar { background: var(--crema); color: var(--navy); }

.chat-input-row { display: flex; gap: 8px; margin: 8px 0 4px; }
.chat-input-row input {
  flex: 1; border: 1px solid var(--linea); border-radius: 24px;
  padding: 13px 18px; font-family: inherit; font-size: 16px;
  background: #fff; color: var(--tinta);
}
.chat-input-row input:focus { outline: 2px solid var(--steel); }
.btn-enviar {
  width: 50px; height: 50px; border-radius: 50%; border: 0;
  background: var(--navy); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

.btn-link {
  background: none; border: 0; color: var(--steel); font-family: inherit;
  font-size: 13.5px; text-decoration: underline; cursor: pointer;
  display: block; margin: 4px auto 0;
}

.accesos { display: flex; gap: 10px; margin-top: 18px; }
.btn-acceso {
  flex: 1; background: #fff; border: 1px solid var(--linea); border-radius: var(--radio);
  padding: 16px 10px; font-family: inherit; font-size: 15.5px; font-weight: 700;
  color: var(--navy); cursor: pointer;
}
.btn-acceso:active { background: var(--crema2); }

/* ---------- Listas ---------- */
.buscador {
  width: 100%; border: 1px solid var(--linea); border-radius: 12px;
  padding: 12px 14px; font-family: inherit; font-size: 15.5px; background: #fff;
  margin-bottom: 10px; color: var(--tinta);
}
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--linea); background: #fff; border-radius: 20px;
  padding: 10px 16px; font-family: inherit; font-size: 14px; font-weight: 600;
  color: var(--gris); cursor: pointer;
}
.chip.activo { background: var(--navy); border-color: var(--navy); color: #fff; }

.mini-resumen { font-size: 14px; color: var(--gris); margin-bottom: 10px; }
.mini-resumen b { color: var(--navy); }

.lista-docs { display: flex; flex-direction: column; gap: 10px; }

.grupo-trimestre {
  margin: 8px 2px 0;
  padding: 8px 4px 2px;
  border-bottom: 2px solid var(--azul-claro);
}
.grupo-trimestre b {
  display: block; color: var(--navy); font-size: 15px;
  letter-spacing: .02em;
}
.grupo-trimestre span { font-size: 12.5px; color: var(--gris); }
.doc-item, .cliente-item {
  width: 100%; text-align: left; background: #fff;
  border: 1px solid var(--linea); border-radius: var(--radio);
  padding: 13px 16px; font-family: inherit; cursor: pointer;
}
.doc-item:active, .cliente-item:active { background: var(--crema2); }
.doc-item-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 3px; }
.doc-num { font-weight: 700; color: var(--navy); font-size: 16px; }
.doc-cliente { font-size: 15.5px; color: var(--tinta2); }
.doc-item-bot { display: flex; justify-content: space-between; margin-top: 5px; font-size: 14px; color: var(--gris); }
.doc-item-bot strong { color: var(--navy); font-size: 16px; }

.badge {
  font-size: 11.5px; font-weight: 700; letter-spacing: .04em;
  padding: 4px 10px; border-radius: 12px; text-transform: uppercase;
}
.badge.pendiente { background: #f6ecd7; color: var(--ambar); }
.badge.cobrada, .badge.aceptado { background: #ddefe3; color: var(--verde); }
.badge.rechazado { background: #f5dedb; color: var(--rojo); }

.cliente-item .c-nombre { font-weight: 700; color: var(--navy); font-size: 16.5px; }
.cliente-item .c-datos { font-size: 13.5px; color: var(--gris); margin-top: 3px; line-height: 1.45; }

.vacio { text-align: center; color: var(--gris2); padding: 40px 20px; font-size: 15px; line-height: 1.6; }

.fab {
  position: fixed; right: 18px; bottom: calc(84px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--navy); color: #fff; border: 0;
  font-size: 30px; line-height: 1; cursor: pointer;
  box-shadow: 0 10px 22px -8px rgba(20,40,70,.55);
  z-index: 25;
}

/* ---------- Formularios ---------- */
fieldset {
  border: 1px solid var(--linea); border-radius: var(--radio);
  background: #fff; padding: 14px 16px 16px; margin: 0 0 14px;
}
legend {
  font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--steel); padding: 0 8px;
}
label { display: block; font-size: 13.5px; font-weight: 600; color: var(--gris); margin-bottom: 12px; }
input[type="text"], input[type="date"], input[type="number"], input[type="tel"],
input[type="email"], input[type="password"], input[type="search"], textarea, select {
  display: block; width: 100%; margin-top: 5px;
  border: 1px solid var(--linea); border-radius: 10px;
  padding: 12px 12px; font-family: inherit; font-size: 16px;
  background: var(--crema2); color: var(--tinta);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--steel); background: #fff; }
textarea { resize: vertical; }

.campo-doble { display: flex; gap: 12px; }
.campo-doble label { flex: 1; }

label.check { display: flex; align-items: center; gap: 10px; font-size: 15.5px; color: var(--tinta2); }
label.check input[type="checkbox"] { width: 24px; height: 24px; margin: 0; accent-color: var(--navy); }
label.check input[type="number"] { width: 76px; display: inline-block; margin: 0; }

.segmento {
  display: flex; background: #fff; border: 1px solid var(--linea);
  border-radius: 12px; padding: 4px; margin-bottom: 14px;
}
.seg-btn {
  flex: 1; border: 0; background: none; border-radius: 9px;
  padding: 12px 8px; font-family: inherit; font-size: 15.5px; font-weight: 700;
  color: var(--gris); cursor: pointer;
}
.seg-btn.activo { background: var(--navy); color: #fff; }

/* Autocompletado de cliente */
.autocompletar { position: relative; display: block; }
.sugerencias {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 20;
  background: #fff; border: 1px solid var(--linea); border-radius: 10px;
  box-shadow: 0 12px 24px -10px rgba(20,40,70,.3);
  overflow: hidden;
}
.sugerencias button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 12px 14px; font-family: inherit; font-size: 15px; color: var(--tinta2);
  cursor: pointer; border-bottom: 1px solid var(--crema);
}
.sugerencias button:active { background: var(--crema2); }
.sugerencias .s-nif { color: var(--gris2); font-size: 13px; }

/* Líneas de concepto */
.linea {
  border: 1px solid var(--linea); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 10px; background: var(--crema2);
}
.linea textarea { background: #fff; margin-top: 0; }
.linea-nums { display: flex; gap: 10px; align-items: flex-end; margin-top: 8px; }
.linea-nums label { flex: 1; margin: 0; font-size: 12.5px; }
.linea-nums input { background: #fff; }
.l-importe {
  flex: 1; text-align: right; font-weight: 700; color: var(--navy);
  font-size: 16px; padding-bottom: 12px; white-space: nowrap;
}
.l-borrar {
  border: 0; background: none; font-size: 20px; cursor: pointer;
  padding: 8px 6px 12px; color: var(--rojo);
}

.ed-totales { font-size: 15px; color: var(--gris); }
.ed-totales div { display: flex; justify-content: space-between; padding: 3px 0; }
.ed-totales .t-total { font-weight: 700; color: var(--navy); font-size: 19px; border-top: 1px solid var(--linea); margin-top: 6px; padding-top: 8px; }

.editor-botones { display: flex; gap: 10px; margin: 6px 0 10px; }
.btn-primario {
  flex: 2; background: var(--navy); color: #fff; border: 0; border-radius: var(--radio);
  padding: 16px 12px; font-family: inherit; font-size: 16.5px; font-weight: 700; cursor: pointer;
}
.btn-primario:active { background: var(--navy-osc); }
.btn-sec {
  flex: 1; background: #fff; color: var(--navy); border: 1px solid var(--linea);
  border-radius: var(--radio); padding: 14px 12px;
  font-family: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
}
.btn-sec:active { background: var(--crema2); }
.btn-peligro {
  display: block; width: 100%; background: none; color: var(--rojo);
  border: 1px solid #ecc8c4; border-radius: var(--radio); padding: 13px;
  font-family: inherit; font-size: 15px; font-weight: 700; cursor: pointer; margin-top: 8px;
}
.btn-mini {
  border: 1px solid var(--linea); background: #fff; border-radius: 8px;
  padding: 8px 12px; cursor: pointer; font-size: 16px;
}
.campo-clave { display: flex; gap: 8px; align-items: stretch; }
.campo-clave input { flex: 1; }
.campo-clave .btn-mini { margin-top: 5px; }

.ayuda { font-size: 13.5px; color: var(--gris); line-height: 1.6; margin: 8px 0; }
.ayuda.ok { color: var(--verde); font-weight: 600; }
.ayuda.error { color: var(--rojo); font-weight: 600; }

/* ---------- Detalle de documento ---------- */
#doc-acciones { margin-bottom: 12px; }
.acciones-fila { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.acciones-fila .btn-primario { flex: 2; padding: 14px 10px; }
.acciones-fila .btn-sec { flex: 1; min-width: 100px; }
.estado-chips { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }

#doc-preview-wrap {
  position: relative; overflow: hidden;
  border-radius: 6px; box-shadow: 0 22px 46px -22px rgba(20,40,70,.5);
  background: #fff;
}
#doc-preview { position: relative; width: 794px; transform-origin: top left; }
#doc-acciones-extra { margin-top: 14px; }

/* ---------- Hoja de compartir ---------- */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20,40,70,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--crema); border-radius: 20px 20px 0 0;
  width: 100%; max-width: 520px;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  animation: subir .2s ease;
}
@keyframes subir { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-titulo { font-weight: 700; color: var(--navy); font-size: 17px; margin: 0 4px 12px; }
.sheet-btn {
  display: block; width: 100%; text-align: left;
  background: #fff; border: 1px solid var(--linea); border-radius: 12px;
  padding: 16px; margin-bottom: 8px;
  font-family: inherit; font-size: 16.5px; font-weight: 600; color: var(--tinta2); cursor: pointer;
}
.sheet-btn:active { background: var(--crema2); }
.sheet-cancel { text-align: center; color: var(--gris); font-weight: 700; }

/* ---------- Toast y carga ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--tinta); color: #fff; border-radius: 12px;
  padding: 12px 20px; font-size: 15px; font-weight: 600;
  box-shadow: 0 10px 24px -8px rgba(0,0,0,.4);
  max-width: 90vw; text-align: center;
}
.cargando {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(243,239,228,.86);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  font-size: 16px; font-weight: 600; color: var(--navy);
}
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 5px solid var(--azul-claro); border-top-color: var(--navy);
  animation: girar .8s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }

/* ---------- Escenario oculto para el PDF ---------- */
#pdf-stage {
  position: fixed; left: -10000px; top: 0; width: 794px;
  background: #fff; z-index: -1;
}

/* ---------- Cliente detalle ---------- */
.ficha {
  background: #fff; border: 1px solid var(--linea); border-radius: var(--radio);
  padding: 16px; margin-bottom: 14px;
}
.ficha h2 { margin: 0 0 8px; color: var(--navy); font-size: 21px; }
.ficha .c-datos { font-size: 14.5px; color: var(--gris); line-height: 1.7; }
.ficha-resumen { display: flex; gap: 10px; margin: 12px 0; }
.ficha-resumen div {
  flex: 1; background: var(--crema2); border-radius: 10px; padding: 10px;
  text-align: center; font-size: 12.5px; color: var(--gris);
}
.ficha-resumen b { display: block; font-size: 17px; color: var(--navy); margin-bottom: 2px; }
.subtitulo { font-size: 13px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--steel); margin: 18px 4px 10px; }

/* ---------- PC / pantallas grandes ---------- */
@media (min-width: 760px) {
  body { font-size: 16px; }
  #main { padding-top: 24px; }
  .tabbar { max-width: 720px; left: 50%; transform: translateX(-50%); border-radius: 16px 16px 0 0; border: 1px solid var(--linea); border-bottom: 0; }
  .fab { right: calc(50% - 360px + 18px); }
}
