:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #1d2420;
  --muted: #5e6862;
  --border: #dcd9d0;
  --accent: #1f7a5c;
  --accent-soft: #e0f0e9;
  --accent-strong: #165a43;
  --line: #8a857a;
  --surface-soft: #faf9f6;
  --wa-bg: #efeae2;
  --danger-line: #d9a39b;
  --info: #1f4b80;
  --info-soft: #e3ecf8;
  --bubble: #d9fdd3;
  --bubble-text: #111b21;
  --accent-text: #ffffff;
  --warn: #9a5b00;
  --warn-soft: #fbefd9;
  --danger: #a33a2f;
  --danger-soft: #f8e3e0;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 4%);
  /* Marcas de los gráficos: validado con el validador de paletas (claro, superficie #fff). */
  --chart: #11875d;
  --chart-hover: #0b6c4a;
  --grid: #ecebe6;
  color-scheme: light;
}

/* Oscuro: si el sistema lo pide y no has elegido «Claro», o si has elegido «Oscuro» (Ajustes o botón ☀️/🌙). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141816;
    --surface: #1c211e;
    --surface-2: #252b27;
    --text: #e6ebe7;
    --muted: #9aa49e;
    --border: #333b36;
    --accent: #4cbf93;
    --accent-soft: #1e3a2f;
    --accent-strong: #7fd8b2;
    --line: #727d77;
    --surface-soft: #181d1a;
    --wa-bg: #0b141a;
    --danger-line: #7a3d36;
    --info: #9cc1f0;
    --info-soft: #1d2a3d;
    --bubble: #005c4b;
    --bubble-text: #e9edef;
    --accent-text: #0d1a14;
    --warn: #e8b25a;
    --warn-soft: #3a2f1c;
    --danger: #f08b7e;
    --danger-soft: #3d2420;
    --shadow: none;
    /* Validado contra la superficie oscura #1c211e. */
    --chart: #3aa77e;
    --chart-hover: #52bf95;
    --grid: #2a312d;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #141816;
  --surface: #1c211e;
  --surface-2: #252b27;
  --text: #e6ebe7;
  --muted: #9aa49e;
  --border: #333b36;
  --accent: #4cbf93;
  --accent-soft: #1e3a2f;
  --accent-strong: #7fd8b2;
  --line: #727d77;
  --surface-soft: #181d1a;
  --wa-bg: #0b141a;
  --danger-line: #7a3d36;
  --info: #9cc1f0;
  --info-soft: #1d2a3d;
  --bubble: #005c4b;
  --bubble-text: #e9edef;
  --accent-text: #0d1a14;
  --warn: #e8b25a;
  --warn-soft: #3a2f1c;
  --danger: #f08b7e;
  --danger-soft: #3d2420;
  --shadow: none;
  /* Validado contra la superficie oscura #1c211e. */
  --chart: #3aa77e;
  --chart-hover: #52bf95;
  --grid: #2a312d;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; margin-top: 1.25rem; }
a { color: var(--accent-strong); }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.5em; }
.small { font-size: .875rem; }

/* Controles grandes y con borde visible: es una herramienta de trabajo, se usa muchas horas. */
button, .button, input, textarea, select { font: inherit; color: inherit; }
button, .button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  min-height: 44px;
  padding: 0 1rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  font-weight: 600;
}
button:hover, .button:hover { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); padding: 0 1.25rem; }
button.primary:hover, .button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.danger-solid { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.ghost { background: none; border: none; color: var(--muted); padding: 0 .6rem; text-decoration: none; font-weight: 500; }
.ghost:hover { color: var(--text); }
button.small, .ghost.small { min-height: 36px; }
.icon-button { border: none; background: none; font-size: 1.3rem; padding: .2rem .5rem; }
input[type="text"], input[type="password"], input[type="search"], input[type="url"], input[type="tel"], input[type="datetime-local"], textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: .55rem .8rem;
}
textarea { resize: vertical; min-height: 5rem; line-height: 1.5; }
select {
  max-width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 0 .7rem;
}
input[type="checkbox"], input[type="radio"] { width: 1.15rem; height: 1.15rem; margin: 0; accent-color: var(--accent); flex: none; }
.field { display: grid; gap: .35rem; justify-items: start; }
input:focus, textarea:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: .55rem; color: var(--muted); font-size: .95rem; min-height: 36px; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: .6rem;
}

/* Estructura: menú | lista de grupos (solo en la sección Grupos) | contenido */
.app {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  grid-template-areas: "nav main";
  height: 100%;
}
.app.with-groups { grid-template-columns: 232px 300px minmax(0, 1fr); grid-template-areas: "nav list main"; }

.nav {
  grid-area: nav;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 20px 14px 24px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.nav-brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px; }
.nav-logo { flex: none; width: 40px; height: 40px; border-radius: 10px; background: var(--accent); color: var(--accent-text); display: flex; align-items: center; justify-content: center; }
.nav-brand-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.nav .brand { font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; }
.wa-status { display: flex; align-items: center; gap: 6px; font-size: .875rem; color: var(--muted); line-height: 1.3; }
.wa-status::before { content: ''; flex: none; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.wa-status.ok { color: var(--accent-strong); }
.wa-status.warn { color: var(--warn); }
.nav-links { display: flex; flex-direction: column; gap: 4px; }
.nav-links a {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 0 12px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}
.nav-links a:hover { background: var(--surface-2); }
.nav-links a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-strong); font-weight: 650; }
.nav-foot { display: flex; flex-direction: column; gap: 4px; padding-top: 16px; border-top: 1px solid var(--border); }
.nav-foot-item, button.nav-foot-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font-size: .95rem;
  font-weight: 500;
  text-decoration: none;
}
.nav-foot-item:hover { background: var(--surface-2); color: var(--text); }
#theme-toggle .i-sun, #theme-toggle.is-dark .i-moon { display: none; }
#theme-toggle.is-dark .i-sun { display: inline; }

/* La barra de arriba solo la usa ya el gestor de comunidades (gestor/), que comparte esta hoja. */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
/* En pantallas estrechas, el nombre corto */
@media (max-width: 480px) { .brand-extra { display: none; } }
.top-actions { margin-left: auto; display: flex; gap: .25rem; }
.pill {
  font-size: .8rem;
  padding: .15rem .6rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

.sidebar {
  grid-area: list;
  display: none;
  flex-direction: column;
  gap: 14px;
  padding: 22px 16px 28px;
  background: var(--surface-soft);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.app.with-groups .sidebar { display: flex; }
.sidebar-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 0 6px; }
.sidebar-head h2 { margin: 0; font-size: 1.25rem; }
.segmented { display: flex; gap: 4px; padding: 4px; border-radius: 10px; background: var(--surface-2); }
.segmented button { flex: 1; min-height: 40px; padding: 0 .75rem; white-space: nowrap; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: .95rem; font-weight: 500; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / 12%); }
.chat-list { display: flex; flex-direction: column; gap: 2px; }
.group-heading { font-size: .875rem; font-weight: 650; color: var(--muted); margin: 1rem 10px .25rem; }
.chat-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-height: 46px;
  padding: 0 10px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 650; }
.chat-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item.unmonitored .name { color: var(--muted); }
.badge {
  font-size: .8125rem;
  min-width: 1.6rem;
  text-align: center;
  padding: 0 .45rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.chat-item .badge { background: none; color: var(--accent-strong); font-weight: 600; }
.dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--border); flex: none; }
.dot.on { background: var(--accent); }

.main { grid-area: main; overflow-y: auto; padding: 28px 36px 56px; --pad-top: 28px; container: main / inline-size; }
.main > * { max-width: 1120px; }

/* Bloques */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.row.spread { justify-content: space-between; }
.stack { display: grid; gap: .85rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin: 0 0 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.15rem; }
.stat b { display: block; font-size: 1.75rem; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat span { color: var(--text); font-size: .95rem; }
.section-title { margin: 2rem 0 .75rem; font-size: 1.25rem; }

/* Pestañas: dentro de un grupo y en Personas. */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin: 1rem 0 1.5rem; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  min-height: 48px;
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: none;
  color: var(--muted);
  padding: 0 1rem;
  font-weight: 500;
  white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--accent-strong); border-bottom-color: var(--accent); font-weight: 650; }

/* Escribir: tres pasos numerados (para quién, mensaje, cuándo) y, al lado, cómo se verá y los envíos. */
.write-layout { display: grid; grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr); gap: 1.25rem; align-items: start; }
@container main (max-width: 760px) { .write-layout { grid-template-columns: minmax(0, 1fr); } }
.write-side { display: grid; gap: 1.25rem; min-width: 0; }
.write-side .card, .write-main .card { margin: 0; }
.composer { display: grid; gap: 1.75rem; scroll-margin-top: 12rem; }
.step { margin: 0; padding: 0; border: 0; min-width: 0; display: grid; gap: .75rem; }
.step-title { display: flex; align-items: center; gap: .6rem; padding: 0; margin: 0 0 .1rem; font-size: 1.1rem; font-weight: 650; }
.step-num { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-text); display: inline-flex; align-items: center; justify-content: center; font-size: .9rem; font-weight: 700; }
.choice-row { display: flex; flex-wrap: wrap; gap: .6rem; }
.choice { display: flex; align-items: center; gap: .6rem; min-height: 48px; padding: 0 1rem; border: 2px solid var(--border); border-radius: 10px; background: var(--surface); cursor: pointer; font-weight: 500; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); font-weight: 650; }
.choice .muted { font-weight: 400; }
.choice:has(input:checked) .muted { color: var(--accent-strong); }
.hint { margin: 0; color: var(--muted); font-size: .95rem; }
.when-at { display: grid; gap: .35rem; max-width: 300px; font-size: .95rem; font-weight: 600; }
.composer textarea { font-size: 1.05rem; line-height: 1.55; min-height: 9rem; }
.composer-foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem; padding-top: 1.25rem; border-top: 1px solid var(--grid); }
.composer-foot .summary { flex: 1 1 220px; margin: 0; font-size: .95rem; }
.composer-foot .row { justify-content: flex-end; }
.wa-frame { background: var(--wa-bg); border-radius: 10px; padding: 1rem; }
.wa-frame .wa-bubble { justify-self: end; border-radius: 10px 10px 2px 10px; }
.ai-help { border-style: dashed; border-color: var(--line); }
.card.danger-zone { border: 2px solid var(--danger-line); }
.card.danger-zone h3 { color: var(--danger); }

/* Enviar: editor, listas para elegir personas, etiquetas y envíos */
.file-chip { display: inline-flex; align-items: center; gap: .4rem; max-width: 100%; background: var(--surface-2); border-radius: 10px; padding: .25rem .3rem .25rem .8rem; font-size: .95rem; }
.file-chip button { min-height: 36px; }
.pick-list { display: grid; gap: .15rem; max-height: 16rem; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: .5rem .7rem; }
.pick-list.tall { max-height: 28rem; }
.pick-list .check { color: var(--text); }
.person-row { display: grid; grid-template-columns: minmax(11rem, 1.4fr) auto minmax(8rem, 1.3fr) minmax(6rem, 1fr) auto; align-items: center; gap: .5rem; padding: .3rem 0; border-bottom: 1px solid var(--border); }
.person-row .check { flex-wrap: wrap; }
.group-chips .tag { max-width: 11rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
/* Formato de WhatsApp: botones y vista previa */
.fmt-bar { gap: .35rem; }
.fmt-bar .fmt { min-width: 44px; padding: 0; border-color: var(--border); }
.fmt-sep { width: 1px; height: 28px; margin: 0 .25rem; background: var(--border); }
.wa-preview { display: grid; gap: .3rem; }
.wa-bubble { justify-self: start; max-width: 32rem; background: var(--bubble); color: var(--bubble-text); border-radius: 10px 10px 10px 2px; padding: .5rem .7rem; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.wa-bubble code { font-size: .9em; }
/* Barra de acciones de las personas marcadas: se queda abajo mientras te mueves por la lista */
.bulk-bar { position: sticky; bottom: 0; z-index: 2; display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; padding: .6rem .7rem; margin: 0 -.2rem; background: var(--accent-soft); border-radius: 10px; box-shadow: 0 -4px 12px rgba(0, 0, 0, .08); }
.person-row:last-child { border-bottom: none; }
.tag-row { padding: .35rem 0; border-bottom: 1px solid var(--border); }
.tag-pick { color: var(--text); }
.tagc::before { content: ''; display: inline-block; width: .55rem; height: .55rem; border-radius: 50%; margin-right: .35rem; background: var(--dot, #8a938e); }
.tagc.verde { --dot: #2e9d6a; }
.tagc.azul { --dot: #3b7dd8; }
.tagc.morado { --dot: #8a5cd0; }
.tagc.rosa { --dot: #d65a8f; }
.tagc.naranja { --dot: #e0803a; }
.tagc.amarillo { --dot: #c9a227; }
.tagc.gris { --dot: #8a938e; }
.job .quote { white-space: pre-wrap; }

/* Cabecera de cada grupo (nombre y pestañas): se queda arriba al desplazarse por la página. */
.chat-head {
  position: sticky;
  top: calc(-1 * var(--pad-top)); /* pegada al borde de arriba, por encima del relleno de .main */
  z-index: 3;
  background: var(--bg);
  margin: -.75rem 0 1.5rem;
  padding: .75rem 0 0;
  display: grid;
  gap: 1rem;
}
.chat-head-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.chat-head h1 { margin: .15rem 0 0; }
.chat-head .meta { margin: .25rem 0 0; color: var(--muted); font-size: .95rem; }
.crumb { font-size: .95rem; font-weight: 600; text-decoration: none; }
.crumb:hover { text-decoration: underline; }
.chat-head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; }
.follow-toggle { display: flex; align-items: center; gap: .6rem; min-height: 48px; padding: 0 1rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); font-size: .95rem; cursor: pointer; }
.chat-head .tabs { margin: 0; }

.list { margin: .25rem 0 0; padding-left: 1.2rem; }
.list li { margin: .3rem 0; }
.tag {
  display: inline-block;
  font-size: .8125rem;
  padding: .05rem .55rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  margin-right: .35rem;
}
.tag.alta, .tag.conflicto, .tag.queja, .tag.spam, .tag.datos_sensibles { background: var(--danger-soft); color: var(--danger); }
.tag.media, .tag.normas, .tag.baja_actividad, .tag.privado { background: var(--warn-soft); color: var(--warn); }
.tag.respuesta, .tag.dinamizacion, .tag.anuncio { background: var(--accent-soft); color: var(--accent); }

.quote {
  border-left: 3px solid var(--border);
  padding: .1rem .7rem;
  margin: .4rem 0;
  color: var(--muted);
  font-size: .9rem;
}
.suggestion textarea { min-height: 6rem; margin: .5rem 0; }

.messages { display: flex; flex-direction: column; gap: .6rem; }
.msg { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .55rem .85rem; max-width: 85%; }
.msg.mine { align-self: flex-end; background: var(--accent-soft); border-color: transparent; }
.msg .meta { font-size: .875rem; color: var(--muted); }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }

pre.digest {
  white-space: pre-wrap;
  font: inherit;
  margin: 0;
  overflow-wrap: anywhere;
}
.qr { display: grid; justify-items: center; gap: .75rem; text-align: center; }
.qr img { width: 280px; max-width: 100%; background: #fff; padding: 8px; border-radius: 8px; }
.empty { color: var(--muted); padding: 1rem 0; }
.spinner {
  width: 1rem; height: 1rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: .6rem 1rem;
  border-radius: 8px;
  max-width: calc(100% - 32px);
  z-index: 10;
}

.only-mobile { display: none; }

/* Comunidades en la lista de grupos (solo ahí: el gestor usa .community para otra cosa) */
.chat-list .community {
  display: flex;
  align-items: center;
  gap: .25rem;
  min-height: 46px;
  padding: 0 .5rem 0 0;
  border-radius: 10px;
}
.chat-list .community:hover, .chat-list .community.active { background: var(--surface-2); }
.chat-list .community .caret {
  width: 40px;
  min-height: 40px;
  border: none;
  background: none;
  padding: 0;
  color: var(--muted);
  font-size: .95rem;
}
.community-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge.on { background: var(--accent-soft); color: var(--accent-strong); }
.community-groups { margin: 0 0 .35rem 1.25rem; padding-left: .35rem; border-left: 1px solid var(--border); }

/* Cabeceras y avisos */
.eyebrow { margin: 0 0 .2rem; font-size: .8125rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.description { white-space: pre-wrap; max-height: 9em; overflow-y: auto; }
.notice { background: var(--warn-soft); border-color: transparent; color: var(--text); }
.issues { margin: .35rem 0; font-size: .95rem; }
.stat small { display: block; color: var(--muted); font-size: .875rem; margin-top: .15rem; }

/* Portada: tarjetas de comunidades y grupos */
.ov-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.ov-card { display: flex; flex-direction: column; gap: .2rem; color: var(--text); text-decoration: none; margin: 0; }
.ov-card:hover { border-color: var(--accent); }
.ov-card .issues { margin: .2rem 0 0; }

/* Gráficos de columnas */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.chart-grid > .card { margin-bottom: 1rem; }
figure.chart { margin: 0 0 1rem; }
.chart figcaption { display: flex; flex-direction: column; margin-bottom: .75rem; }
.cc-plot { position: relative; height: 150px; margin-left: 2rem; border-bottom: 1px solid var(--border); }
.cc-grid { position: absolute; left: 0; right: 0; border-top: 1px solid var(--grid); }
.cc-tick {
  position: absolute;
  right: calc(100% + .4rem);
  top: -.6em;
  font-size: .72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.cc-cols { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 2px; }
.cc-col {
  position: relative;
  flex: 1;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  outline-offset: 0;
}
.cc-bar { width: 100%; max-width: 24px; min-height: 0; background: var(--chart); border-radius: 4px 4px 0 0; transition: background .1s; }
.cc-col:hover .cc-bar, .cc-col:focus .cc-bar { background: var(--chart-hover); }
.cc-peak { position: absolute; transform: translateY(-.2rem); font-size: .75rem; color: var(--text); font-weight: 600; }
.cc-x { display: flex; gap: 2px; margin: .3rem 0 .5rem 2rem; }
.cc-x span { flex: 1; text-align: center; font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: visible; }
.chart details summary { cursor: pointer; }
.data-table { border-collapse: collapse; margin-top: .4rem; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { text-align: left; padding: .15rem .8rem .15rem 0; border-bottom: 1px solid var(--grid); }
.chart-tip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .35rem .6rem;
  box-shadow: 0 4px 16px rgb(0 0 0 / 15%);
  display: flex;
  flex-direction: column;
  font-size: .85rem;
}
.chart-tip span { color: var(--muted); font-size: .78rem; }

/* Personas y datos del grupo */
.people { margin: 0; padding-left: 1.3rem; }
.people li { margin: .25rem 0; }
.people li span:first-child { margin-right: .4rem; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: .5rem 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

/* Tabla de grupos de una comunidad */
.group-table { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.group-row {
  display: grid;
  grid-template-columns: 2rem minmax(0, 2.2fr) minmax(140px, 1.4fr) 5.5rem 8.5rem;
  gap: .75rem;
  align-items: center;
  padding: .6rem .8rem;
  border-bottom: 1px solid var(--grid);
}
.group-row:last-child { border-bottom: none; }
.group-head { font-size: .75rem; color: var(--muted); padding-top: .45rem; padding-bottom: .45rem; }
.group-row.unmonitored .gr-name a { color: var(--muted); }
.gr-name { display: flex; flex-direction: column; min-width: 0; }
.gr-name a { font-weight: 600; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gr-label { display: none; }
.gr-metric { font-size: .9rem; font-variant-numeric: tabular-nums; }
.inline-bar { display: flex; align-items: center; gap: .5rem; }
.ib-track { flex: 1; height: 8px; background: var(--grid); border-radius: 4px; overflow: hidden; }
.ib-fill { display: block; height: 100%; background: var(--chart); border-radius: 0 4px 4px 0; }
.ib-value { min-width: 2.5rem; text-align: right; }

/* Móvil: arriba el nombre y el estado; abajo, una barra con las cinco secciones. En «Grupos», la lista ocupa la pantalla. */
@media (max-width: 800px) {
  .app, .app.with-groups {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "nav" "main";
  }
  .nav { flex-direction: row; align-items: center; gap: .5rem; padding: 8px 6px 8px 12px; border-right: 0; border-bottom: 1px solid var(--border); overflow: visible; }
  .nav-brand { flex: 1; min-width: 0; padding: 0; gap: 10px; }
  .nav-logo { width: 34px; height: 34px; }
  .nav-links {
    position: fixed;
    z-index: 6;
    left: 0;
    right: 0;
    bottom: 0;
    flex-direction: row;
    gap: 0;
    padding: 4px 4px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
  }
  .nav-links a { flex: 1; flex-direction: column; justify-content: center; gap: 2px; min-height: 56px; padding: 0 2px; font-size: .8125rem; }
  .nav-links a[aria-current="page"] { background: none; }
  .nav-foot { flex-direction: row; gap: 2px; padding: 0; border: 0; }
  .nav-foot-item, button.nav-foot-item { min-width: 44px; padding: 0 10px; justify-content: center; }
  .nav-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .sidebar { grid-area: main; padding: 18px 16px 96px; border-right: 0; }
  .app.with-groups .sidebar { display: none; }
  .app.list-view .sidebar { display: flex; }
  .app.list-view .main { display: none; }
  .main { padding: 18px 16px 96px; --pad-top: 18px; }
  .toast { bottom: 84px; }
  .chat-head { position: static; margin-top: 0; padding-top: 0; }
  .chat-head h1 { font-size: 1.4rem; }
  .person-row { grid-template-columns: 1fr auto; }
  .person-row > :nth-child(3), .person-row > :nth-child(4) { grid-column: 1 / -1; }
  .top-actions .ghost { padding: .4rem .35rem; font-size: .9rem; }
  .topbar { gap: .4rem; padding: .5rem .5rem; flex-wrap: wrap; }
  .msg { max-width: 100%; }
  .group-row { grid-template-columns: 2rem repeat(3, minmax(0, 1fr)); row-gap: .35rem; }
  .group-row .gr-follow { grid-row: 1 / span 2; }
  .group-row .gr-name { grid-column: 2 / -1; }
  .gr-metric { font-size: .85rem; }
  .gr-label { display: block; font-size: .72rem; color: var(--muted); }
  .group-head { display: none; }
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dd { margin-bottom: .4rem; }
}

/* Opciones de Ajustes (motor de IA, tema) */
.ai-options { display: grid; gap: .35rem; }
.ai-option {
  display: flex;
  align-items: flex-start;
  gap: .55rem;
  padding: .5rem .65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.ai-option:hover { border-color: var(--accent); }
.ai-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.ai-option input { margin-top: .3rem; }
.ai-option .tag { margin-left: .4rem; }
.ai-options + .stack input[type="text"] { flex: 1; min-width: 12rem; }
#theme-toggle { font-size: 1.05rem; }

/* Páginas web conectadas */
.web-url { display: block; overflow-wrap: anywhere; color: var(--muted); }
.web-text { max-height: 18rem; overflow-y: auto; background: var(--surface-2); padding: .6rem .75rem; border-radius: 8px; margin-top: .5rem; }

/* Importar una hoja de cálculo */
input.short { width: 5rem; }
.table-wrap { overflow-x: auto; max-height: 22rem; border: 1px solid var(--border); border-radius: 8px; }
.import-table { border-collapse: collapse; width: 100%; font-size: .85rem; }
.import-table th, .import-table td { text-align: left; padding: .35rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.import-table th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; }

/* Columna de al lado del editor: sin huecos vacíos y envíos en forma de lista. */
.write-side > :empty { display: none; }
.write-side .job { box-shadow: none; border: 0; border-bottom: 1px solid var(--grid); border-radius: 0; padding: .75rem 0; margin: 0; }
.write-side .job:last-child { border-bottom: 0; }
.write-side .suggestion { box-shadow: none; }

/* Inicio: cabecera con la acción principal, «Pendiente de ti» y la tabla de comunidades. */
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: .5rem; }
.button.primary { min-height: 48px; }
.todo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.todo-card { display: flex; flex-direction: column; gap: .75rem; margin: 0; }
.todo-card > :last-child:is(div) { margin-top: auto; }
.todo-card a { font-weight: 600; }
.todo-head { display: flex; align-items: center; gap: .75rem; }
.todo-head h3 { margin: 0; font-size: 1.1rem; }
.todo-icon { flex: none; width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.15rem; background: var(--accent-soft); color: var(--accent-strong); }
.todo-card.pendientes .todo-icon, .todo-card.silencio .todo-icon { background: var(--warn-soft); color: var(--warn); }
.todo-card.envios .todo-icon { background: var(--info-soft); color: var(--info); }
.todo-list { margin: 0; padding-left: 1.1rem; display: grid; gap: .35rem; }
.table-box { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.home-table { width: 100%; min-width: 620px; border-collapse: collapse; }
.home-table th, .home-table td { padding: .9rem 1.1rem; text-align: left; border-bottom: 1px solid var(--grid); }
.home-table thead th { font-size: .875rem; font-weight: 600; color: var(--muted); border-bottom-color: var(--border); }
.home-table tbody tr:last-child > * { border-bottom: 0; }
.home-table tbody th a { font-weight: 600; text-decoration: none; }
.home-table tbody th a:hover { text-decoration: underline; }
.home-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Ajustes: submenú a la izquierda y una sección cada vez. En pantallas estrechas, el submenú va en una fila deslizable. */
.settings-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 2rem; align-items: start; }
.settings-nav { display: grid; gap: 1.25rem; }
.settings-group { display: grid; gap: 2px; }
.settings-group-label { padding: 0 12px 6px; font-size: .875rem; font-weight: 650; color: var(--muted); }
.settings-nav button { justify-content: flex-start; min-height: 46px; padding: 0 12px; border: 0; border-radius: 10px; background: none; color: var(--text); font-weight: 500; text-align: left; }
.settings-nav button:hover { background: var(--surface-2); }
.settings-nav button[aria-current="page"] { background: var(--accent-soft); color: var(--accent-strong); font-weight: 650; }
.settings-content { display: grid; gap: 1.25rem; min-width: 0; }
.settings-content .card { margin: 0; }
@container main (max-width: 700px) {
  .settings-layout { grid-template-columns: minmax(0, 1fr); gap: 1rem; }
  .settings-nav { display: flex; gap: .5rem; overflow-x: auto; scrollbar-width: none; padding-bottom: .25rem; }
  .settings-group { display: flex; gap: .35rem; }
  .settings-group-label { display: none; }
  .settings-nav button { white-space: nowrap; border: 1px solid var(--border); min-height: 44px; }
}

/* Resúmenes en Inicio: con las negritas y cursivas de WhatsApp ya aplicadas. */
div.digest { overflow-wrap: anywhere; line-height: 1.55; }

/* Aviso en la vista previa: a algunas personas les falta un dato de la hoja (@barrio…). */
.note-warn { margin: .5rem 0 0; padding: .5rem .75rem; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: .95rem; font-weight: 600; }
