/* ===========================================================================
   Burocracia Zero · CRM WhatsApp
   Identidad corporativa oficial: negro (#1d1d1b) + blanco, con morado
   (#9272b0) y amarillo (#ffea63) como secundarios. Tipografía Lexend.
   =========================================================================== */

:root {
  --ink: #1d1d1b;            /* negro de marca */
  --ink-2: #2a2a27;
  --ink-soft: #3a3a36;
  --bg: #f5f4f7;             /* gris muy claro (neutro de marca) */
  --panel: #ffffff;
  --text: #1d1d1b;
  --muted: #6f6d75;
  --border: #e7e5ea;
  --accent: #9272b0;         /* morado Burocracia Zero (secundario) */
  --accent-dark: #77599c;    /* morado con más contraste para botones/texto */
  --accent-deep: #5f4585;
  --accent-light: #f2edf8;
  --yellow: #ffea63;         /* amarillo Burocracia Zero (secundario) */
  --yellow-deep: #eacf3a;
  --yellow-soft: #fff7cf;
  --bubble-out: #efe9f7;
  --danger: #c0392b;
  --amber: #b26a00;
  --ok: #1d7a34;
  --r-lg: 16px;
  --r-md: 12px;
  --r-sm: 9px;
  --shadow-1: 0 1px 2px rgba(29, 29, 27, .05), 0 1px 6px rgba(29, 29, 27, .04);
  --shadow-2: 0 4px 14px rgba(29, 29, 27, .08), 0 2px 6px rgba(29, 29, 27, .05);
  --shadow-3: 0 18px 50px rgba(29, 29, 27, .22);
  --focus: 0 0 0 3px rgba(146, 114, 176, .38);
  --font-body: "Lexend", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-brand: "Lexend", var(--font-body);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  letter-spacing: .1px;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(146, 114, 176, .32); }

/* Scrollbars discretos */
* { scrollbar-width: thin; scrollbar-color: #cfcbc2 transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: #cfcbc2; border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }

/* dvh = alto real visible en el móvil (descuenta la barra del navegador y el
   teclado); con reserva en vh para navegadores antiguos. */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ---------------------------------------------------------------------------
   Barra lateral
--------------------------------------------------------------------------- */
.sidebar {
  width: 248px;
  min-width: 248px;
  background:
    radial-gradient(420px 260px at -30% -10%, rgba(146, 114, 176, .30), transparent 60%),
    linear-gradient(178deg, var(--ink-2) 0%, var(--ink) 55%);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 22px 14px 16px;
  gap: 3px;
  /* El menú ha ido creciendo y en pantallas bajas (portátiles de 13", o con la
     ventana a media altura) no cabe entero. Sin esto los últimos botones se
     salían del degradado y quedaban pintados sobre el fondo claro de la página.
     Que la barra tenga su propio desplazamiento, y que los botones no se
     aplasten para caber. */
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar > * { flex-shrink: 0; }
/* Barra de desplazamiento clara: la general es gris y sobre el degradado
   oscuro de la barra lateral no se ve. */
.sidebar { scrollbar-color: rgba(255, 255, 255, .28) transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .28); }
.brand { display: block; padding: 2px 10px 20px; }
/* Wordmark oficial: «Burocracia» en Lexend grueso, «Zero» debajo en fino. */
.brand-logo {
  font-family: var(--font-brand);
  font-weight: 800;
  font-size: 26px;
  line-height: .9;
  letter-spacing: -.6px;
  color: #fff;
}
.brand-logo span {
  display: block;
  font-weight: 300;
  font-size: 21px;
  letter-spacing: .5px;
  margin-top: 1px;
  color: #fff;
}
.brand-tagline {
  font-size: 10.5px; letter-spacing: .6px; text-transform: uppercase;
  color: rgba(255, 255, 255, .45); margin-top: 9px; font-weight: 600;
}
.brand-sub {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; margin-top: 12px; font-weight: 600;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .09);
  padding: 4px 10px; border-radius: 999px;
  transition: background .15s;
}
.brand-sub:hover { background: rgba(255, 255, 255, .14); }

/* Título de cada grupo del menú. Con veinte pestañas seguidas no se lee
   ninguna: hay que recorrerlas todas para encontrar la que se busca. */
.nav-group {
  font-size: 10px; letter-spacing: .8px; text-transform: uppercase;
  color: rgba(255, 255, 255, .38); font-weight: 700;
  padding: 0 14px; margin: 14px 0 4px;
}

.nav-btn {
  position: relative;
  display: flex; align-items: center; gap: 11px;
  background: none; border: none; color: rgba(255, 255, 255, .78);
  padding: 10px 14px; border-radius: 10px;
  font-size: 13.5px; cursor: pointer; text-align: left;
  font-family: inherit; font-weight: 500; letter-spacing: .1px;
  transition: background .15s, color .15s;
}

/* Iconos de marca: trazo lila, se aclaran a blanco en activo/hover. */
.nav-ico {
  width: 20px; height: 20px; min-width: 20px; flex-shrink: 0;
  fill: none; stroke: #b6a2d6; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
  transition: stroke .15s, transform .15s;
}
.nav-btn:hover .nav-ico { stroke: #fff; }
.nav-btn.active .nav-ico { stroke: var(--yellow); }
.nav-btn.active:hover .nav-ico { transform: none; }
/* Icono con relleno (día de la agenda) hereda el color del trazo. */
.nav-ico [fill="currentColor"] { fill: currentColor; color: #b6a2d6; }
.nav-btn.active .nav-ico [fill="currentColor"] { color: var(--yellow); }
.nav-btn:hover .nav-ico [fill="currentColor"] { color: #fff; }

/* Iconos en botones de la interfaz (adjuntar, nota…). */
.btn-icon { display: inline-flex; align-items: center; justify-content: center; padding: 8px 11px; }
.ui-ico {
  width: 18px; height: 18px; fill: none; stroke: var(--accent-dark);
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
#btn-note-mode.active .ui-ico { stroke: var(--amber); }

/* Paneles emergentes de emojis y stickers */
.chat-compose { position: relative; }
.pop-panel {
  position: absolute; bottom: calc(100% + 8px); left: 12px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-3);
  padding: 10px; z-index: 20; width: min(340px, calc(100% - 24px));
  max-height: 260px; overflow-y: auto;
}
#emoji-panel { display: flex; flex-wrap: wrap; gap: 2px; }
.emoji-cat { width: 100%; font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px; margin: 6px 2px 2px; }
.emoji-btn {
  border: none; background: none; cursor: pointer; font-size: 22px;
  width: 36px; height: 36px; border-radius: 8px; line-height: 1;
}
.emoji-btn:hover { background: var(--accent-light); }
/* Selector de fichas de trámite */
#ficha-panel { display: flex; flex-direction: column; gap: 4px; }
.ficha-pick {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  text-align: left; border: 1px solid var(--border); background: var(--panel);
  border-radius: 9px; padding: 8px 12px; cursor: pointer; font-family: inherit;
  transition: border-color .12s, background .12s;
}
.ficha-pick:hover { border-color: var(--accent); background: var(--accent-light); }
.ficha-pick b { font-size: 13.5px; }
.ficha-pick span { font-size: 11.5px; color: var(--muted); }

.sticker-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sticker-btn {
  border: 1px solid var(--border); background: var(--panel); border-radius: 10px;
  padding: 5px; cursor: pointer; transition: border-color .12s, transform .12s;
}
.sticker-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.sticker-btn img { width: 100%; display: block; border-radius: 7px; }

/* Sticker dentro del chat: sin fondo de burbuja, tamaño contenido */
.chat-messages .msg.sticker {
  background: none; box-shadow: none; padding: 0; max-width: 150px; border-radius: 0;
}
.chat-messages .msg.sticker img { width: 100%; display: block; }
.chat-messages .msg.sticker .msg-meta { text-align: right; margin-top: 2px; }
.nav-btn:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav-btn.active {
  background: linear-gradient(90deg, rgba(146, 114, 176, .32), rgba(146, 114, 176, .15));
  color: #fff; font-weight: 700;
}
.nav-btn.active::before {
  content: ""; position: absolute; left: 0; top: 20%; bottom: 20%;
  width: 3px; border-radius: 3px; background: var(--yellow);
}
.badge {
  background: var(--yellow); color: var(--ink); font-weight: 800;
  border-radius: 999px; font-size: 10.5px; padding: 2px 8px; margin-left: auto;
}

/* ---------------------------------------------------------------------------
   Contenido principal
--------------------------------------------------------------------------- */
.main { flex: 1; overflow-y: auto; padding: 28px 34px 40px; }
.view { animation: viewIn .18s ease-out; }
@keyframes viewIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.view h1 {
  font-family: var(--font-brand); font-size: 26px; font-weight: 700;
  letter-spacing: .2px; margin-bottom: 16px;
}
.view h2 { font-size: 15px; font-weight: 700; margin: 26px 0 12px; letter-spacing: .2px; }
.hidden { display: none !important; }
.hint { color: var(--muted); font-size: 12.5px; line-height: 1.5; margin-bottom: 12px; }
.hint code, label code {
  background: var(--accent-light); color: var(--accent-dark);
  padding: 1px 6px; border-radius: 5px; font-size: 11.5px; font-weight: 600;
}

.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 10px; flex-wrap: wrap; }
.panel-head h1 { margin: 0; }

/* ---------------------------------------------------------------------------
   Tarjetas del panel
--------------------------------------------------------------------------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 18px 14px;
  box-shadow: var(--shadow-1);
  transition: transform .15s, box-shadow .15s;
}
.card:hover { transform: translateY(-1px); box-shadow: var(--shadow-2); }
.card .num {
  font-family: var(--font-brand); font-size: 30px; font-weight: 700; line-height: 1.05;
}
.card .lbl { color: var(--muted); font-size: 12px; font-weight: 500; margin-top: 4px; }
.card.warn .num { color: var(--accent-dark); }
.card.alert .num { color: var(--danger); }

/* --- Gráficas --- */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
@media (max-width: 980px) { .charts-row { grid-template-columns: 1fr; } }
.chart-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 18px 20px; overflow-x: auto;
  box-shadow: var(--shadow-1);
}
.chart-card h3 { font-size: 13px; font-weight: 700; letter-spacing: .2px; margin-bottom: 10px; }
.chart-legend { display: flex; gap: 16px; font-size: 11.5px; color: var(--muted); margin-bottom: 8px; font-weight: 500; }
.chart-legend .key { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-card svg { display: block; width: 100%; height: auto; }
.chart-card .bar { transition: opacity .12s; }
.chart-card .bar:hover { opacity: .72; }
.chart-empty { color: var(--muted); font-size: 13px; padding: 22px 0; text-align: center; }

/* ---------------------------------------------------------------------------
   Listas y filas
--------------------------------------------------------------------------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 12px 16px;
  display: flex; align-items: center; gap: 13px; cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.row:hover { border-color: var(--accent); box-shadow: var(--shadow-2); transform: translateY(-1px); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 650; font-size: 14px; }
.row .sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { text-align: right; font-size: 11.5px; color: var(--muted); white-space: nowrap; }

/* Avatares con iniciales */
.avatar {
  width: 38px; height: 38px; min-width: 38px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13.5px; letter-spacing: .3px; color: #fff;
}
.avatar.a0 { background: linear-gradient(135deg, #9272b0, #77599c); }
.avatar.a1 { background: linear-gradient(135deg, #77599c, #5f4585); }
.avatar.a2 { background: linear-gradient(135deg, #b49fd8, #8d74bf); }
.avatar.a3 { background: linear-gradient(135deg, #4e4458, #2c2733); }
.avatar.avatar-img { background: none; overflow: hidden; padding: 0; }
.avatar.avatar-img img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Foto del cliente en la cabecera del chat */
.chat-avatar-btn {
  position: relative; width: 40px; height: 40px; min-width: 40px; padding: 0;
  border: 0; background: none; cursor: pointer; border-radius: 12px;
}
.chat-avatar-btn .avatar { width: 40px; height: 40px; min-width: 40px; }
.chat-avatar-cam {
  position: absolute; right: -3px; bottom: -3px; font-size: 11px;
  background: #fff; border-radius: 50%; width: 17px; height: 17px;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.msg-setphoto { vertical-align: middle; }
.photo-menu-btn { display: block; width: 100%; text-align: left; margin-bottom: 8px; padding: 11px 14px; }

.tag {
  display: inline-block; background: var(--accent-light); color: var(--accent-dark);
  border-radius: 6px; font-size: 10.5px; font-weight: 700; letter-spacing: .2px;
  padding: 2px 8px; margin: 3px 4px 0 0;
}
.status {
  display: inline-block; border-radius: 999px; font-size: 11px; padding: 3px 10px;
  font-weight: 700; letter-spacing: .2px;
}
.status.pendiente { background: #fdecea; color: var(--danger); }
.status.en_curso { background: #fff3d6; color: var(--amber); }
.status.esperando_documentacion { background: var(--accent-light); color: var(--accent-dark); }
.status.completado { background: #e4f5e8; color: var(--ok); }

/* ---------------------------------------------------------------------------
   Botones y formularios
--------------------------------------------------------------------------- */
.btn {
  background: var(--panel); border: 1px solid var(--border);
  padding: 8px 15px; border-radius: 10px; font-size: 13px; cursor: pointer;
  font-family: inherit; font-weight: 600; color: var(--text);
  transition: border-color .15s, background .15s, box-shadow .15s, transform .1s;
}
.btn:hover { border-color: var(--accent); box-shadow: var(--shadow-1); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn.primary {
  background: linear-gradient(180deg, var(--ink-soft), var(--ink));
  border-color: var(--ink); color: #fff;
  box-shadow: 0 2px 8px rgba(29, 29, 27, .25);
}
.btn.primary:hover { background: linear-gradient(180deg, var(--accent-dark), var(--accent-deep)); border-color: var(--accent-deep); }
.btn.small { padding: 5px 11px; font-size: 12px; border-radius: 8px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }

input, select, textarea { font-family: inherit; color: var(--text); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--accent) !important; box-shadow: var(--focus);
}

.search {
  width: 100%; padding: 11px 16px; border: 1px solid var(--border);
  border-radius: var(--r-md); font-size: 13.5px; margin-bottom: 14px;
  background: var(--panel); box-shadow: var(--shadow-1);
}
.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.chip {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 15px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; font-family: inherit; color: var(--muted);
  transition: all .15s;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------------------------------------------------------------------------
   Bandeja de WhatsApp
--------------------------------------------------------------------------- */
.inbox {
  display: flex; gap: 0; height: calc(100vh - 56px); height: calc(100dvh - 56px);
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-2);
}
.conv-list-panel {
  width: 350px; min-width: 290px; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px; overflow-y: auto;
  background: #fbfaf7;
}
.conv-list-panel .panel-head { margin-bottom: 10px; }
.conv-list-panel h1 { font-size: 19px; }
.conv-search { margin-bottom: 10px; box-shadow: none; }
.conv-list-panel .row { box-shadow: none; }
.chat-panel {
  flex: 1; display: flex; flex-direction: column;
  background:
    radial-gradient(circle at 1px 1px, rgba(29, 26, 34, .05) 1px, transparent 1.6px) 0 0 / 20px 20px,
    linear-gradient(180deg, #efece3, #ece8dd);
}
.chat-empty { margin: auto; color: var(--muted); font-size: 13.5px; }
#chat { display: flex; flex-direction: column; height: 100%; }
.chat-head {
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  padding: 12px 18px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.chat-name { font-weight: 700; font-size: 14.5px; }
.chat-phone { color: var(--muted); font-size: 12px; }
.chat-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chat-tools select {
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px;
  font-size: 12.5px; font-weight: 600; background: var(--panel);
}
/* Subcabecera del chat: ventana de 24 h + nota fija */
.chat-subhead {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 7px 18px; background: rgba(255, 255, 255, .7);
  border-bottom: 1px solid var(--border);
}
.chat-window {
  font-size: 11.5px; font-weight: 700; border-radius: 999px;
  padding: 3px 10px; white-space: nowrap;
}
.chat-window.open { background: #e7f7ea; color: #1f7a3d; }
.chat-window.closed { background: #fbe9e7; color: #b13a2a; }
.chat-window.clickable { cursor: help; }
.chat-window.clickable::after { content: ' ⓘ'; opacity: .7; }
.chat-note {
  flex: 1; min-width: 0; text-align: left; cursor: pointer;
  border: 1px dashed #d9c873; background: #fdf6d8; color: var(--ink, #1d1d1b);
  border-radius: 9px; padding: 5px 11px; font-size: 12px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-note:hover { background: #fbefc2; }
.chat-note.empty { color: var(--muted); font-weight: 500; font-style: italic; opacity: .8; }

.chat-messages { flex: 1; overflow-y: auto; padding: 22px 26px; display: flex; flex-direction: column; gap: 7px; }
.msg {
  max-width: 68%; padding: 9px 13px; border-radius: 14px;
  font-size: 13.5px; line-height: 1.45; white-space: pre-wrap; word-break: break-word;
  box-shadow: 0 1px 2px rgba(29, 26, 34, .1);
}
.msg.in { background: #fff; align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out {
  background: linear-gradient(180deg, #ece5f8, var(--bubble-out));
  align-self: flex-end; border-bottom-right-radius: 4px;
}
.msg .msg-meta { display: block; font-size: 10.5px; color: var(--muted); margin-top: 4px; text-align: right; }
.msg.error { outline: 1.5px solid var(--danger); }
.msg.note {
  background: #fdf6d8; align-self: center; max-width: 78%;
  border: 1px dashed #d9c873; font-size: 13px; border-radius: 12px;
}
.chat-compose {
  display: flex; gap: 8px; padding: 12px 14px;
  background: rgba(255, 255, 255, .95); border-top: 1px solid var(--border);
  align-items: flex-end;
}
.chat-compose select {
  max-width: 140px; padding: 9px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 12.5px;
}
.chat-compose textarea {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 10px 14px; font-size: 13.5px; background: #fbfaf7;
}
#btn-note-mode.active { background: #fdf6d8; border-color: #d9c873; }
.unread-dot {
  background: var(--accent-deep); color: #fff; font-weight: 700; font-size: 10.5px;
  border-radius: 999px; min-width: 19px; height: 19px;
  display: inline-flex; align-items: center; justify-content: center; padding: 0 5px;
  margin-top: 3px;
}
.conv-dot { font-size: 9px; margin-right: 4px; vertical-align: 1px; }
.conv-assigned { font-size: 10.5px; color: var(--accent-dark); font-weight: 700; }

/* Adjuntos */
.msg img.msg-media {
  max-width: 100%; max-height: 280px; border-radius: 10px; display: block;
  margin-bottom: 5px; cursor: pointer;
}
/* Transcripción de una nota de voz */
.msg-transcript {
  display: flex; gap: 6px; margin-top: 6px; padding: 8px 10px;
  background: var(--accent-light); border-radius: 9px;
  font-size: 13px; font-style: italic; color: var(--ink-soft); line-height: 1.45;
}
.msg-transcript span { font-style: italic; }
/* Reproductor de notas de voz en el chat */
.msg-audio { display: block; width: 240px; max-width: 100%; height: 38px; margin: 2px 0 5px; }
/* Mensajes programados (bajo la conversación) */
.chat-scheduled {
  background: #fdf6d8; border-top: 1px solid #e7dca6;
  padding: 8px 16px; display: flex; flex-direction: column; gap: 5px;
}
.chat-scheduled .sched-title { font-size: 11px; font-weight: 700; color: #8a6d1a; }
.sched-item { display: flex; align-items: center; gap: 9px; font-size: 12.5px; }
.sched-when { font-weight: 700; color: var(--accent-dark); white-space: nowrap; }
.sched-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sched-cancel { padding: 2px 8px; }

/* Responder citando un mensaje */
.msg { position: relative; }
.msg-reply {
  position: absolute; top: 4px; right: 4px; border: 0; background: rgba(255,255,255,.7);
  border-radius: 6px; width: 22px; height: 22px; font-size: 13px; cursor: pointer;
  opacity: 0; transition: opacity .12s; line-height: 1; color: var(--accent-dark);
}
.msg:hover .msg-reply { opacity: 1; }
.msg-reply:hover { background: #fff; }
.msg-quote {
  border-left: 3px solid var(--accent); background: rgba(146,114,176,.10);
  border-radius: 6px; padding: 5px 9px; margin-bottom: 5px; font-size: 12.5px;
  color: var(--ink-soft, #4a4750); overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; max-width: 100%;
}
.msg.out .msg-quote { background: rgba(146,114,176,.16); }
/* Barra de respuesta sobre el cuadro de texto */
.reply-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  background: #f3eef9; border-top: 1px solid var(--border);
}
.reply-bar-body { flex: 1; min-width: 0; border-left: 3px solid var(--accent); padding-left: 9px; }
.reply-bar-who { display: block; font-size: 11.5px; font-weight: 700; color: var(--accent-dark); }
.reply-bar-text { display: block; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-bar-x { border: 0; background: none; cursor: pointer; font-size: 15px; color: var(--muted); }

/* Grabación de nota de voz */
.rec-bar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: #fdecea; border-top: 1px solid #f2c9c3;
}
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: recpulse 1s infinite; }
@keyframes recpulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
.rec-label { font-size: 13px; font-weight: 600; color: var(--danger); }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--danger); }
.rec-bar .primary { margin-left: auto; }
#btn-voice.recording { background: var(--danger); color: #fff; }
#btn-notify.active { background: var(--accent-light); }
#btn-select-docs.active { background: var(--accent); color: #fff; }

/* Selección múltiple de documentos → asignar a expediente */
.select-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  background: #eef7f0; border-top: 1px solid #cfe6d6;
}
.select-bar-count { flex: 1; font-size: 13px; font-weight: 600; color: var(--accent-dark); }
.select-bar .btn[disabled] { opacity: .5; cursor: not-allowed; }
/* En modo selección, cada adjunto muestra una casilla y resalta al marcarlo. */
.chat-messages.select-mode .msg-link-case,
.chat-messages.select-mode .msg-reply,
.chat-messages.select-mode .msg-setphoto { pointer-events: none; opacity: .5; }
.msg-select {
  position: absolute; top: 6px; right: 6px; z-index: 3;
  width: 26px; height: 26px; border-radius: 50%;
  background: rgba(255,255,255,.95); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.msg-select input { width: 17px; height: 17px; cursor: pointer; accent-color: var(--accent); margin: 0; }
.chat-messages.select-mode .msg:has(.msg-select) { cursor: pointer; }
.msg.selected { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Visor de imágenes (lightbox) */
.lightbox {
  position: fixed; inset: 0; z-index: 1200; background: rgba(20,18,26,.92);
  display: flex; align-items: center; justify-content: center; padding: 40px;
}
.lightbox-bar { position: absolute; top: 14px; right: 16px; display: flex; gap: 8px; }
.lightbox-bar .btn { background: rgba(255,255,255,.9); }
#lightbox-img { max-width: 94vw; max-height: 88vh; border-radius: 8px; cursor: zoom-in; object-fit: contain; }
#lightbox-img.zoomed { max-width: none; max-height: none; width: auto; cursor: zoom-out; }

/* Galería de adjuntos */
.gallery-box {
  background: var(--panel); border-radius: 14px; width: min(760px, 94vw);
  max-height: 86vh; display: flex; flex-direction: column; overflow: hidden;
}
.gallery-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px; padding: 16px; overflow-y: auto;
}
.gal-item {
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden; cursor: pointer;
  background: #fbfaf7; padding: 0; aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  text-decoration: none; color: inherit;
}
.gal-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gal-file { flex-direction: column; gap: 6px; padding: 10px; text-align: center; }
.gal-ico { font-size: 26px; }
.gal-name { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.gal-item:hover { border-color: var(--accent); }
.msg .msg-file {
  display: inline-flex; align-items: center; gap: 7px;
  background: rgba(29, 26, 34, .06); border-radius: 10px; padding: 9px 13px;
  margin: 2px 0 5px; text-decoration: none; color: inherit; font-weight: 600; font-size: 13px;
  transition: background .15s;
}
.msg .msg-file:hover { background: rgba(29, 26, 34, .11); }

/* ---------------------------------------------------------------------------
   Informes
--------------------------------------------------------------------------- */
.report-filters { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.report-filters label { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.report-filters input[type="date"] { border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 13px; background: var(--panel); }
.rep-table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.rep-table th, .rep-table td { text-align: left; padding: 10px 14px; font-size: 13.5px; border-bottom: 1px solid var(--border); }
.rep-table th { background: #faf9f5; font-weight: 700; font-size: 12px; letter-spacing: .2px; color: var(--muted); text-transform: uppercase; }
.rep-table tr:last-child td { border-bottom: none; }
.rep-table td.num, .rep-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.rep-table td.warn-txt { color: var(--accent-dark); font-weight: 600; }
.perf-table { display: block; overflow-x: auto; }
.rep-bar-row { display: flex; align-items: center; gap: 10px; margin: 7px 0; font-size: 13px; }
.rep-bar-label { width: 150px; min-width: 150px; color: var(--text); }
.rep-bar-track { flex: 1; background: var(--accent-light); border-radius: 6px; height: 20px; overflow: hidden; }
.rep-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-dark)); border-radius: 6px; }
.rep-bar-val { width: 34px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------------------
   Expedientes por bloques (segmento)
--------------------------------------------------------------------------- */
.case-block { margin-bottom: 22px; }
.block-head {
  display: flex; align-items: center; gap: 10px; margin: 0 2px 10px;
}
.block-title { font-family: var(--font-brand); font-weight: 700; font-size: 16px; }
.block-count {
  background: var(--accent-light); color: var(--accent-dark);
  font-weight: 700; font-size: 12px; border-radius: 999px; padding: 1px 10px;
}
.seg-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .2px;
  border-radius: 6px; padding: 1px 7px; margin-left: 6px; vertical-align: 1px;
}
.seg-particular { background: #eef2fb; color: #3f5bd6; }
.seg-autonomo { background: var(--accent-light); color: var(--accent-dark); }
.seg-empresa { background: #eaf6ee; color: #1d7a34; }
.area-badge {
  background: var(--accent-light); color: var(--accent-dark);
  border-radius: 6px; padding: 1px 7px; font-weight: 600; font-size: 11.5px;
}
.chk-badge, .fee-badge, .tax-badge {
  display: inline-block; border-radius: 6px; padding: 1px 7px;
  font-weight: 600; font-size: 11.5px; white-space: nowrap;
}
.chk-badge { background: var(--accent-light); color: var(--muted); }
.chk-badge.ok { background: #e4f5e8; color: var(--ok); }
.fee-badge.due { background: #fdf2e3; color: #a8690a; }
.fee-badge.paid { background: #e4f5e8; color: var(--ok); }
.tax-badge.due { background: #eef0fb; color: #4a4f8a; }
.tax-badge.paid { background: #e4f5e8; color: var(--ok); }
.sub-badge { display: inline-block; border-radius: 6px; padding: 1px 7px; font-weight: 600; font-size: 11.5px; white-space: nowrap; background: #e4f5e8; color: var(--ok); }
.reg-badge { display: inline-block; border-radius: 6px; padding: 1px 7px; font-weight: 600; font-size: 11.5px; white-space: nowrap; background: var(--accent-light); color: var(--accent-dark); }

/* Panel de tareas (kanban) */
.task-filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 16px; }
.tasks-board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; align-items: start; }
.task-col { background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; }
.task-col-head {
  padding: 11px 14px; font-weight: 700; font-size: 13px;
  background: var(--accent-light); color: var(--accent-dark); border-bottom: 1px solid var(--border);
}
.task-col-n { float: right; background: var(--panel); border-radius: 999px; padding: 0 8px; font-size: 12px; }
.task-col-body { padding: 10px; display: flex; flex-direction: column; gap: 9px; min-height: 60px; }
.task-empty { color: var(--muted); text-align: center; font-size: 13px; margin: 8px 0; }
.task-card {
  background: #fbfaf7; border: 1px solid var(--border); border-radius: 11px;
  padding: 10px 12px; box-shadow: 0 1px 2px rgba(29, 26, 34, .05);
}
.task-title { font-weight: 600; font-size: 13.5px; line-height: 1.4; margin-bottom: 6px; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; font-size: 11.5px; color: var(--muted); }
.task-who { font-weight: 700; color: var(--accent-dark); }
.task-who.none { font-weight: 500; font-style: italic; }
.task-due.over { color: var(--danger); font-weight: 700; }
.task-notes { margin-top: 7px; font-size: 12px; color: var(--ink-soft, #4a4750); line-height: 1.45; white-space: pre-wrap; }
.task-actions { display: flex; gap: 6px; margin-top: 9px; }
.task-actions button {
  border: 1px solid var(--border); background: var(--panel); border-radius: 8px;
  padding: 3px 9px; cursor: pointer; font-size: 13px;
}
.task-actions button:disabled { opacity: .3; cursor: default; }
.task-actions button:not(:disabled):hover { border-color: var(--accent); background: var(--accent-light); }
.task-move { font-weight: 700; }
.task-edit { margin-left: auto; }
@media (max-width: 900px) { .tasks-board { grid-template-columns: 1fr; } }

/* Base de conocimiento (tarifas y trámites) */
.kb-search {
  width: 100%; font-family: inherit; font-size: 14px; padding: 11px 14px;
  border: 1px solid var(--border); border-radius: var(--r-md); background: #fbfaf7; margin-bottom: 14px;
}
#kb-panel {
  width: 340px; max-width: 82vw; max-height: 380px; overflow: hidden;
  display: flex; flex-direction: column; padding: 8px;
}
.kb-panel-search {
  font-family: inherit; font-size: 13.5px; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 9px; margin-bottom: 6px; background: #fbfaf7;
}
.kb-panel-list { overflow-y: auto; display: flex; flex-direction: column; gap: 3px; }
.kb-pick {
  text-align: left; border: 1px solid transparent; background: none; border-radius: 8px;
  padding: 8px 10px; cursor: pointer; display: flex; flex-direction: column; gap: 2px;
}
.kb-pick:hover { border-color: var(--accent); background: var(--accent-light); }
.kb-pick-title { font-weight: 600; font-size: 13.5px; }
.kb-pick-meta { font-size: 11.5px; color: var(--muted); }

/* Por cobrar */
.cobro-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 13px 16px; margin-bottom: 10px;
}
.cobro-main { flex: 1; min-width: 0; }
.cobro-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.cobro-name { font-weight: 700; font-size: 14.5px; }
.cobro-total { font-weight: 800; font-size: 15px; color: #a8690a; white-space: nowrap; }
.cobro-items { list-style: none; margin: 6px 0 4px; padding: 0; font-size: 12.5px; color: var(--muted); }
.cobro-items li { padding: 1px 0; }
.cobro-adv { color: var(--accent-dark); font-weight: 600; }

/* Reservas de cita pendientes de pago por transferencia */
.pending-book-card { border: 1px solid #cfe6d6; background: #eef7f0; border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }
.pending-book-head { font-weight: 700; color: var(--accent-dark); margin-bottom: 8px; }
.pending-book-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid #d9ebdf; }
.pending-book-row:first-of-type { border-top: 0; }
.pending-book-row .grow { flex: 1; min-width: 0; }
/* El ingreso que se ha encontrado en el extracto: ocupa su propia línea
   debajo de la reserva, para que se lea antes de pulsar Confirmar. */
.pending-book-row { flex-wrap: wrap; }
.pb-ingreso {
  flex-basis: 100%; font-size: 12.5px; font-weight: 600; color: #1d7a34;
  background: #eaf6ee; border-radius: 8px; padding: 5px 9px; margin: 2px 0 4px;
}
.pb-ingreso.dudoso { color: #a8690a; background: #fdf2e3; }
.pb-emparejar { margin-left: auto; }
.pending-book-head { display: flex; align-items: center; gap: 10px; }
.cobro-age { font-size: 11.5px; color: var(--muted); }
.cobro-age.over { color: var(--danger); font-weight: 600; }
.cobro-actions { display: flex; flex-direction: column; gap: 6px; flex: none; }
.cobro-remind, .cobro-collect { white-space: nowrap; }

/* Calendario de Outlook */
.cal-range { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 16px; }
.empty-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 24px; text-align: center; color: var(--muted); font-size: 13.5px; line-height: 1.6;
}
.cal-day { margin-bottom: 16px; }
.cal-day-head {
  font-weight: 700; font-size: 13px; color: var(--accent-dark); text-transform: capitalize;
  padding: 6px 2px; border-bottom: 2px solid var(--accent-light); margin-bottom: 8px;
}
.cal-ev {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 11px;
  padding: 10px 14px; margin-bottom: 7px;
}
.cal-ev-time {
  font-weight: 700; font-size: 12.5px; color: var(--accent-dark); white-space: nowrap;
  min-width: 92px; font-variant-numeric: tabular-nums;
}
.cal-ev-body { flex: 1; min-width: 0; }
.cal-ev-subj { font-weight: 600; font-size: 13.5px; }
.cal-ev-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.chart-card.chart-wide { grid-column: 1 / -1; }
.exp-badge { display: inline-block; border-radius: 6px; padding: 1px 7px; font-weight: 600; font-size: 11.5px; white-space: nowrap; background: var(--accent-light); color: var(--muted); }
.exp-badge.soon { background: #fdf2e3; color: #a8690a; }
.exp-badge.exp { background: #fdecea; color: var(--danger); }
.card.ok .num { color: var(--ok); }

/* Checklist de documentación (campo del diálogo de expediente) */
.chk-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.chk-row {
  display: flex; align-items: center; gap: 8px; padding: 4px 6px;
  border-radius: 7px; font-size: 13px; cursor: default;
}
.chk-row:hover { background: var(--accent-light); }
.chk-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent-dark); cursor: pointer; }
.chk-row span { flex: 1; }
.chk-done { text-decoration: line-through; color: var(--muted); }
.chk-del {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  font-size: 13px; line-height: 1; padding: 2px 4px; border-radius: 5px;
}
.chk-del:hover { color: var(--danger); background: #fdecea; }
.chk-add { display: flex; gap: 6px; margin-bottom: 8px; }
.chk-add .chk-new { flex: 1; }
.chk-load .chk-ficha { width: 100%; }

/* Enlace de estado del trámite (ficha de cliente) */
.est-link { display: flex; gap: 6px; margin-bottom: 8px; }
.est-link #est-url { flex: 1; font-size: 12.5px; }
.est-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.est-actions .btn { text-decoration: none; }

/* Botón «sugerir respuesta» mientras la IA piensa */
.btn.loading { opacity: 0.5; pointer-events: none; animation: bz-pulse 1s ease-in-out infinite; }
@keyframes bz-pulse { 50% { opacity: 0.85; } }

/* Reparto y compartir clientes/expedientes entre usuarios */
.share-users { display: flex; flex-wrap: wrap; gap: 8px; }
.share-user {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 999px;
  font-size: 13px; background: var(--card);
}
.share-user:hover { background: var(--accent-light); }
.share-user input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent-dark); cursor: pointer; }

/* Agenda de vencimientos */
.agenda-group { margin-bottom: 22px; }
.agenda-head {
  font-family: var(--font-brand); font-weight: 700; font-size: 14.5px;
  margin-bottom: 9px; display: flex; align-items: center; gap: 8px;
}
.agenda-group.g-alert .agenda-head { color: var(--danger); }
.agenda-group.g-warn .agenda-head { color: var(--accent-dark); }
.agenda-row { cursor: pointer; }
.agenda-ico { font-size: 18px; width: 26px; text-align: center; }
.agenda-group.g-alert .agenda-row { border-left: 3px solid var(--danger); }
.agenda-group.g-warn .agenda-row { border-left: 3px solid var(--accent); }

/* ---------------------------------------------------------------------------
   Citas
--------------------------------------------------------------------------- */
.appt-day {
  font-family: var(--font-brand); font-weight: 700; font-size: 14.5px;
  margin: 20px 0 9px; letter-spacing: .2px;
}
.appt-day:first-child { margin-top: 0; }
.appt-time {
  font-family: var(--font-brand); font-weight: 700; font-size: 17px;
  background: var(--accent-light); color: var(--accent-dark);
  border-radius: 10px; padding: 7px 11px; line-height: 1;
}
/* Evento creado directamente en Outlook (solo lectura, no editable en el CRM). */
.appt-row-ext { cursor: default; opacity: .92; }
.appt-row-ext .appt-time { background: #e8eef7; color: #33547e; }
.appt-row-ext .sub { color: #33547e; }

/* ---------------------------------------------------------------------------
   Automatizaciones
--------------------------------------------------------------------------- */
.auto-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 20px 22px; margin-bottom: 14px;
  box-shadow: var(--shadow-1);
}
.auto-card h3 { font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.auto-card h3 label { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.auto-card textarea {
  width: 100%; border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 10px 13px; font-size: 13px; margin: 6px 0 12px; background: #fbfaf7;
}
.auto-card > label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.auto-row { display: flex; gap: 16px; align-items: center; margin: 9px 0; flex-wrap: wrap; }
.auto-row label { display: flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.auto-row input[type="time"], .auto-row input[type="number"], .auto-row input[type="text"], .auto-row select {
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; font-size: 13px; background: #fbfaf7;
}
.day-chip {
  border: 1px solid var(--border); border-radius: 999px; padding: 5px 13px;
  font-size: 12.5px; font-weight: 600; cursor: pointer; background: var(--panel);
  user-select: none; transition: all .12s;
}
.day-chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
input[type="checkbox"] {
  accent-color: var(--accent-dark); width: 15px; height: 15px; cursor: pointer;
}

/* ---------------------------------------------------------------------------
   Pantalla de acceso
--------------------------------------------------------------------------- */
.login-overlay {
  position: fixed; inset: 0; z-index: 50;
  background:
    radial-gradient(700px 480px at 78% 18%, rgba(146, 114, 176, .32), transparent 62%),
    radial-gradient(560px 420px at 12% 88%, rgba(95, 69, 133, .24), transparent 60%),
    linear-gradient(165deg, var(--ink-2), var(--ink) 70%);
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: var(--panel); border-radius: 20px; padding: 36px 38px 32px;
  width: min(380px, 92vw); box-shadow: var(--shadow-3);
}
.login-brand {
  font-family: var(--font-brand); font-weight: 800; font-size: 32px;
  line-height: .86; text-align: center; margin-bottom: 4px; letter-spacing: -.8px;
}
.login-brand span { display: block; font-weight: 300; font-size: 25px; letter-spacing: 0; color: var(--ink); }
.login-tagline {
  text-align: center; color: var(--muted); font-size: 10.5px; font-weight: 600;
  letter-spacing: 1.2px; text-transform: uppercase; margin: 10px 0 24px;
}
.login-error { color: var(--danger); font-size: 12.5px; margin-bottom: 10px; }
/* CAPTCHA del acceso */
.captcha-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.captcha-img {
  border: 1px solid var(--border); border-radius: 10px; background: #fff;
  height: 56px; width: auto; flex: 1; object-fit: contain;
}
#login-captcha-refresh { padding: 8px 12px; font-size: 16px; line-height: 1; }
#login-captcha { letter-spacing: 3px; text-transform: uppercase; font-weight: 700; text-align: center; }

/* ---------------------------------------------------------------------------
   Diálogo
--------------------------------------------------------------------------- */
dialog {
  border: none; border-radius: var(--r-lg); padding: 26px 28px;
  width: min(500px, 92vw); box-shadow: var(--shadow-3);
  font-family: var(--font-body); color: var(--text);
  animation: viewIn .15s ease-out;
}
dialog::backdrop { background: rgba(29, 26, 34, .5); backdrop-filter: blur(2px); }
dialog h2 { font-family: var(--font-brand); font-size: 19px; font-weight: 700; margin-bottom: 16px; }
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; letter-spacing: .2px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 13px; border: 1px solid var(--border);
  border-radius: var(--r-sm); font-size: 13.5px; background: #fbfaf7;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }

/* Campo y navegador de carpetas de SharePoint */
.sp-selected, .sp-empty { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.sp-selected b { word-break: break-all; }
.fp-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.fp-path { font-size: 12.5px; color: var(--muted); word-break: break-all; }
.fp-list { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.fp-row { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 9px; }
.fp-row:hover { border-color: var(--accent); }
.fp-open { cursor: pointer; font-weight: 600; flex: 1; }
.fp-open:hover { color: var(--accent-dark); }

#btn-back-conv { display: none; }

@media (max-width: 760px) {
  /* Barra lateral → carril de iconos */
  .sidebar { width: 62px; min-width: 62px; padding: 14px 7px 12px; }
  .brand { padding: 0 0 12px; text-align: center; }
  .brand-logo, .brand-tagline, .brand-sub { display: none; }
  .brand::before {
    content: "BZ"; font-family: var(--font-brand); font-weight: 800;
    font-size: 21px; color: #fff; display: block;
  }
  .nav-label { display: none; }
  /* En el carril de iconos no cabe el título del grupo, pero la separación
     entre grupos sí orienta: se queda como una raya fina. */
  .nav-group {
    font-size: 0; padding: 0; margin: 9px 10px;
    border-top: 1px solid rgba(255, 255, 255, .13);
  }
  .nav-btn { justify-content: center; padding: 11px 0; font-size: 16px; }
  .nav-btn .badge { position: absolute; top: 3px; right: 5px; margin: 0; }
  .nav-btn.active::before { display: none; }

  .main { padding: 16px 13px 30px; }
  .view h1 { font-size: 21px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 9px; }

  /* Bandeja: lista o chat a pantalla completa, con botón de volver */
  .main { padding: 12px 10px 16px; }
  .inbox { height: calc(100vh - 30px); height: calc(100dvh - 30px); }
  .conv-list-panel { width: 100%; min-width: 0; border-right: none; }
  .inbox .chat-panel { display: none; }
  .inbox.mobile-chat .conv-list-panel { display: none; }
  .inbox.mobile-chat .chat-panel { display: flex; min-width: 0; }
  #btn-back-conv { display: inline-block; }
  .chat-head { padding: 9px 10px; flex-wrap: wrap; gap: 6px; }
  .chat-tools { gap: 5px; }
  .chat-tools select { font-size: 11.5px; padding: 5px 6px; }
  .chat-messages { padding: 12px 10px; }
  .msg { max-width: 86%; }
  /* Compose: cuadro de texto arriba (una fila) y las herramientas en una tira
     que se desliza en horizontal, para que no se amontonen en el móvil. */
  .chat-compose { flex-wrap: wrap; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); gap: 6px; align-items: center; }
  .chat-compose textarea { flex: 1 1 100%; order: -2; min-width: 0; }
  .chat-compose .btn.primary { order: -1; flex: 0 0 auto; }
  .chat-compose > .btn.btn-icon,
  .chat-compose > #tpl-select { flex: 0 0 auto; }
  .chat-compose select { max-width: 120px; }
  .chat-compose .btn.btn-icon { padding: 7px 9px; font-size: 15px; }
  /* Los paneles emergentes (emoji, stickers, respuestas…) no deben desbordar. */
  .pop-panel { max-width: calc(100vw - 28px); }

  /* Las tablas de Informes son más anchas que un móvil. Antes empujaban la
     página entera hacia la derecha (y con ella los títulos); ahora se deslizan
     dentro de su propia tarjeta y el resto se queda quieto. */
  .rep-table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }

  /* Automatizaciones: cada ajuste es una etiqueta con su campo al lado, y
     juntos no caben en 375 px. Que el campo baje de línea. */
  .auto-row { gap: 9px 14px; }
  .auto-row label { flex-wrap: wrap; max-width: 100%; }
  .auto-row input[type="time"], .auto-row input[type="number"],
  .auto-row input[type="text"], .auto-row select { max-width: 100%; }
}

/* La segunda línea de cada fila lleva el cliente Y sus distintivos (área del
   expediente, honorarios, tasa). Venía en una sola línea con puntos suspensivos,
   así que con un nombre largo los distintivos quedaban fuera de la pantalla:
   no recortados, invisibles. Recortar texto vale; esconder un dato, no.

   El umbral va en 1000 px y no en el de móvil porque esto no es cosa de
   teléfonos: pasa igual en una tableta en vertical o con la ventana a media
   pantalla, que es como se trabaja muchas veces.

   Sin `display: flex`: en Clientes esta línea es texto suelto («teléfono · NIF
   · correo») y, como elemento flexible, un correo largo no se puede partir y
   estira la fila entera. `anywhere` deja que esas palabras kilométricas se
   rompan, que es lo único que evita el desborde. */
@media (max-width: 1000px) {
  .row .sub { white-space: normal; overflow: visible; overflow-wrap: anywhere; }
}
/* En horizontal (móvil apaisado, con ancho suficiente) se recupera la vista de
   dos columnas: lista de chats + conversación a la vez. */
@media (min-width: 640px) and (max-width: 900px) and (orientation: landscape) {
  .inbox .chat-panel { display: flex !important; }
  .inbox .conv-list-panel { width: 40%; min-width: 220px; max-width: 320px; border-right: 1px solid var(--border); display: flex !important; }
  .inbox.mobile-chat .conv-list-panel { display: flex !important; }
  #btn-back-conv { display: none; }
}

@media (min-width: 761px) {
  .inbox .chat-panel { display: flex; }
}

/* ---------------------------------------------------------------------------
   Productividad: paleta de comandos, respuestas rápidas, atajos
--------------------------------------------------------------------------- */
.palette {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(29, 29, 27, .42);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
}
.palette.hidden { display: none; }
.palette-box {
  background: var(--panel); width: min(600px, 94vw); border-radius: 16px;
  box-shadow: var(--shadow-3); overflow: hidden; border: 1px solid var(--border);
}
#palette-input {
  width: 100%; border: 0; border-bottom: 1px solid var(--border);
  padding: 17px 20px; font-size: 16px; font-family: inherit; outline: none;
  background: transparent; color: var(--text);
}
.palette-results { max-height: 52vh; overflow-y: auto; padding: 6px; }
.pal-group { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); padding: 10px 12px 4px; }
.pal-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px;
  border-radius: 10px; cursor: pointer;
}
.pal-item.sel { background: var(--accent-light); }
.pal-ico {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-light); color: var(--accent-dark); font-size: 15px;
}
.pal-item.sel .pal-ico { background: var(--accent); color: #fff; }
.pal-main { flex: 1; min-width: 0; }
.pal-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pal-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pal-empty { padding: 24px; text-align: center; color: var(--muted); font-size: 13px; }
.palette-foot {
  display: flex; gap: 16px; padding: 9px 16px; border-top: 1px solid var(--border);
  font-size: 11.5px; color: var(--muted); background: var(--bg);
}
kbd {
  font-family: inherit; font-size: 11px; background: var(--panel);
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px;
  padding: 1px 5px; margin: 0 1px; color: var(--ink-soft);
}
.shortcuts-box { padding: 22px 24px 24px; }
.shortcuts-box h2 { font-family: var(--font-brand); font-size: 18px; margin-bottom: 14px; }
.shortcuts-table { width: 100%; border-collapse: collapse; }
.shortcuts-table td { padding: 7px 4px; font-size: 13.5px; border-bottom: 1px solid var(--border); }
.shortcuts-table td:first-child { width: 42%; white-space: nowrap; }

.inbox-filters { padding: 0 0 8px; flex-wrap: wrap; }
/* Respuestas rápidas (dropdown de plantillas al escribir "/") */
#quick-replies { max-height: 240px; }
.qr-item { display: flex; flex-direction: column; gap: 1px; padding: 8px 11px; border-radius: 9px; cursor: pointer; }
.qr-item.sel, .qr-item:hover { background: var(--accent-light); }
.qr-name { font-size: 13px; font-weight: 700; }
.qr-text { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------------------------------------------------------------------------
   Hoy · fijar conversaciones · etiquetas
--------------------------------------------------------------------------- */
.today-date { color: var(--muted); font-size: 13.5px; font-weight: 600; }
.ty-block { margin-bottom: 22px; }
.ty-head {
  font-family: var(--font-brand); font-weight: 700; font-size: 14.5px;
  margin-bottom: 9px; display: flex; align-items: center; gap: 8px;
}
.ty-block.ty-alert .ty-head { color: var(--danger); }
.ty-row { cursor: pointer; }
/* Incidencias: una fila que no lleva a ninguna parte, así que tampoco debe
   parecer pulsable. */
.ty-row:has(> [data-inc-ok]) { cursor: default; }
.inc-veces {
  font-family: var(--font-brand); font-size: 11.5px; font-weight: 700;
  background: var(--danger); color: #fff; border-radius: 6px; padding: 1px 6px;
  vertical-align: middle;
}
.btn-mini {
  flex: none; border: 1px solid var(--border); background: #fff; cursor: pointer;
  border-radius: 8px; padding: 5px 10px; font-size: 12.5px; font-weight: 600;
  color: var(--muted); font-family: inherit;
}
.btn-mini:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-dark); }
.btn-mini:disabled { opacity: .5; cursor: default; }

/* Buscador de ajustes de Automatizaciones. Pegado arriba, porque con 27 fichas
   hay que poder escribir sin volver al principio de la página. */
.auto-filter {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0 12px; margin-bottom: 4px;
  background: var(--bg); /* opaco: si no, las fichas se leen por debajo al hacer scroll */
}
.auto-filter .search { flex: 1; min-width: 0; margin: 0; }
.auto-filter-count {
  flex: none; font-size: 12.5px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.auto-filter-count.vacio { color: var(--danger); }
/* El filtro esconde, NUNCA quita del documento: «Guardar cambios» lee los
   campos de todas las fichas y si desaparecieran se perderían ajustes. */
.auto-card.filtrada { display: none; }
.auto-group { font-size: 13px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: var(--muted); margin: 26px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.auto-group.filtrada { display: none; }
.auto-sub { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); }
.auto-sub h4 { font-size: 13.5px; font-weight: 700; margin: 0 0 6px; }
.auto-sub h4 label { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.auto-sub > label { display: block; font-size: 12.5px; color: var(--muted); font-weight: 600; margin-top: 8px; }
.auto-sub > label input[type="number"] { margin: 0 6px; }
.auto-empty {
  border: 1px dashed var(--border); border-radius: var(--r-md);
  padding: 22px 18px; text-align: center; color: var(--muted); font-size: 13.5px;
}

/* Aviso de versión nueva. Va abajo y fijo: tiene que verse desde cualquier
   pestaña, porque el problema que anuncia afecta a toda la interfaz. */
#update-banner {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 2000;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--ink); color: #fff; border-radius: 12px;
  padding: 11px 14px; box-shadow: 0 10px 30px rgba(0,0,0,.28);
  font-size: 13.5px; max-width: calc(100vw - 32px);
}
#update-banner .btn { flex: none; background: var(--accent); color: #fff; border-color: transparent; }

/* Lista de copias de seguridad: con tres botones (Descargar, Probar, Restaurar)
   la fila no cabe en un móvil y «Restaurar» —el destructivo— quedaba pegado al
   borde. Que la fila dé la vuelta en vez de apretarse. */
@media (max-width: 760px) {
  #backup-list .row { flex-wrap: wrap; gap: 6px; }
  #backup-list .row .grow { flex: 1 1 100%; }
}

/* Estado de la configuración: una línea por variable, con su consecuencia. */
.cfg-row {
  display: flex; align-items: flex-start; gap: 9px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 9px; margin-bottom: 6px; background: #fff;
}
.cfg-row .grow { flex: 1; min-width: 0; }
.cfg-ico { flex: none; font-size: 13px; line-height: 1.5; }
.cfg-key { font-weight: 700; font-size: 13px; font-family: var(--font-brand); overflow-wrap: anywhere; }
.cfg-row .sub { color: var(--muted); font-size: 12.5px; line-height: 1.45; overflow-wrap: anywhere; }
.cfg-bad { border-color: var(--danger); background: #fdf4f4; }
.cfg-opt { opacity: .72; }
.cfg-tag {
  font-size: 10.5px; font-weight: 600; color: var(--muted); background: var(--accent-light);
  border-radius: 5px; padding: 1px 6px; vertical-align: middle;
}

/* Fichas duplicadas: las dos candidatas, una al lado de la otra, para poder
   compararlas de un vistazo antes de decidir cuál se queda. */
.dup-pair {
  border: 1px solid var(--border); border-radius: var(--r-md); padding: 12px 14px;
  margin-bottom: 12px; background: #fbfaf7;
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.dup-why { grid-column: 1 / -1; }
.dup-side { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.dup-side .title { font-weight: 700; font-size: 13.5px; overflow-wrap: anywhere; }
.dup-side .sub { color: var(--muted); font-size: 12px; margin-top: 2px; overflow-wrap: anywhere; }
.dup-side .dup-keep { margin-top: 9px; width: 100%; }
@media (max-width: 700px) { .dup-pair { grid-template-columns: 1fr; } }

/* Obligaciones periódicas: lista de casillas en la ficha del cliente.
   Los selectores llevan `.obl-list` delante a propósito: dentro de la ficha
   mandan `.field label { display: block }` y `.field input { width: 100% }`,
   que tumbaban el flex y estiraban la casilla a lo ancho de la fila. */
.obl-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 2px 14px; }
.obl-list .obl-item {
  display: flex; align-items: center; gap: 8px; padding: 5px 2px;
  cursor: pointer; font-size: 13px; font-weight: 400; color: var(--text); margin: 0;
}
.obl-list .obl-chk { width: auto; flex: none; margin: 0; }
.obl-list .obl-label { flex: 1; min-width: 0; }
.obl-list .obl-cada {
  flex: none; font-size: 11px; font-weight: 600; color: var(--muted);
  background: var(--accent-light); border-radius: 6px; padding: 1px 7px;
}
.ty-time {
  font-family: var(--font-brand); font-weight: 700; font-size: 16px;
  background: var(--accent-light); color: var(--accent-dark);
  border-radius: 8px; padding: 4px 9px; min-width: 54px; text-align: center;
}
.ty-who { color: var(--muted); }
.ty-over { color: var(--danger); font-weight: 700; }
.today-clear {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 40px; text-align: center; color: var(--muted); font-size: 15px;
}

.conv-row.pinned { background: linear-gradient(90deg, var(--accent-light), transparent 70%); }
.conv-pin { margin-right: 3px; }
#btn-pin.active { background: var(--accent); border-color: var(--accent); }
.conv-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.conv-tag {
  font-size: 10.5px; font-weight: 600; background: var(--accent-light);
  color: var(--accent-dark); border-radius: 5px; padding: 1px 6px; cursor: pointer;
}
.conv-tag:hover { background: var(--accent); color: #fff; }
.tag-filter-bar {
  display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600;
  color: var(--accent-dark); background: var(--accent-light);
  border-radius: 9px; padding: 6px 11px; margin-bottom: 8px;
}
.tag-clear { margin-left: auto; border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 13px; }
.tag-clear:hover { color: var(--danger); }

/* ---------------------------------------------------------------------------
   Formularios (JotForm embebidos)
--------------------------------------------------------------------------- */
.forms-layout { display: flex; flex-direction: column; gap: 12px; }
.forms-tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.form-tab {
  display: inline-flex; align-items: center; gap: 10px; font-family: inherit;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 7px 12px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--text);
}
.form-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.form-tab-actions { display: inline-flex; gap: 4px; opacity: .7; }
.form-tab-actions span { padding: 0 3px; border-radius: 4px; }
.form-edit:hover, .form-del:hover { background: rgba(0,0,0,.12); }
.forms-frame {
  position: relative; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--r-lg); overflow: hidden; min-height: 70vh;
}
.forms-frame iframe { width: 100%; height: 78vh; border: 0; display: block; }
.forms-frame .form-open { position: absolute; top: 10px; right: 12px; z-index: 2; text-decoration: none; }
.forms-empty { padding: 48px 24px; text-align: center; color: var(--muted); }

/* ---------------------------------------------------------------------------
   Vista previa de PDF + botón de PDF en el chat
--------------------------------------------------------------------------- */
.msg .msg-file.pdf-view {
  border: 0; font-family: inherit; cursor: pointer; text-align: left;
}
.pdf-eye { font-weight: 700; color: var(--accent-dark); margin-left: 4px; white-space: nowrap; }
.pdf-modal {
  position: fixed; inset: 0; z-index: 70; background: rgba(29,29,27,.55);
  display: flex; align-items: center; justify-content: center; padding: 3vh 2vw;
}
.pdf-modal.hidden { display: none; }
.pdf-box {
  background: var(--panel); width: min(900px, 96vw); height: 92vh;
  border-radius: 14px; overflow: hidden; display: flex; flex-direction: column;
  box-shadow: var(--shadow-3);
}
.pdf-bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.pdf-title { flex: 1; font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pdf-bar .btn { text-decoration: none; }
#pdf-frame { flex: 1; width: 100%; border: 0; background: #f0eef4; }

/* Bandeja de notificaciones de la Administración: semáforo del plazo. */
.sem { display:inline-block; padding:2px 8px; border-radius:999px; font-size:12px; font-weight:700; white-space:nowrap; }
.sem-verde { background:#e3f5e8; color:#1e6b36; }
.sem-ambar { background:#fff1cc; color:#8a5a00; }
.sem-rojo, .sem-vencido { background:#fde2e1; color:#a1221c; }
.sem-gris { background:var(--border); color:var(--muted); }
.notif-row { align-items:flex-start; flex-wrap:wrap; gap:8px; }
.notif-row .org { font-weight:700; color:var(--accent-deep); margin-right:6px; }
.notif-row .actions { display:flex; gap:6px; flex-wrap:wrap; width:100%; margin-top:6px; }
.notif-row.sospechoso { border-left:4px solid var(--danger); }
.notif-row .motivos { color:var(--danger); font-size:12.5px; margin-top:4px; }
.notif-row.done { opacity:.6; }
.notif-row .actions select { max-width: 100%; flex: 1 1 180px; min-width: 0; }


/* ---------------------------------------------------------------------------
   Contabilizar facturas
   --------------------------------------------------------------------------- */
.conta-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.conta-h2 { font-size: 16px; font-weight: 700; margin: 26px 0 6px; }
.conta-bar { display: flex; align-items: center; gap: 14px; margin: 10px 0; font-size: 13px; }
.conta-table { display: block; overflow-x: auto; }
.conta-table table { min-width: 1180px; }
.conta-table .rep-table th, .conta-table .rep-table td { padding: 8px 10px; vertical-align: top; }
.conta-table td.conta-col-estado { min-width: 230px; }
.conta-table td.conta-col-tercero { min-width: 150px; }
.conta-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.conta-table td.acciones { white-space: nowrap; }
.conta-table td.acciones .btn { margin-right: 4px; }
.conta-table select.conta-cuenta { max-width: 260px; font-size: 12.5px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 7px; background: var(--panel); }
.conta-motivo { display: block; color: var(--muted); font-size: 11.5px; margin-top: 3px; max-width: 260px; }
.conta-avisos { color: var(--accent-dark); font-size: 12px; }
.conta-avisos li { margin: 0; }
.conta-estado { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--accent-light); color: var(--accent-dark); white-space: nowrap; }
.conta-estado.confirmada { background: #e6f4ea; color: #1e7e34; }
.conta-estado.exportada { background: #eee; color: #555; }
.conta-estado.conciliado { background: #e6f4ea; color: #1e7e34; }
.conta-estado.pendiente { background: #fdf1e3; color: #a35c00; }
.conta-tercero { display: block; color: var(--muted); font-size: 11.5px; }
.conta-fila-aviso td { background: #fffaf0; }
.conta-lote { margin: 10px 0; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--panel); font-size: 13px; }
.conta-lote ul { margin: 4px 0 0 18px; }
