:root {
  --bg: #f4f6f3;
  --panel: #ffffff;
  --panel-light: #dfe7dc;
  --text: #1c261c;
  --muted: #667a63;
  --accent: #7cb733;
  --accent-dark: #5e9226;
  --danger: #c0392b;
  --ok: #4caf50;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: var(--panel);
  border-bottom: 2px solid var(--accent);
}

header.topbar a {
  color: var(--text);
  text-decoration: none;
  margin-right: 1rem;
  font-weight: 600;
  padding-bottom: 0.2rem;
  border-bottom: 2px solid transparent;
}
header.topbar a:hover { border-bottom-color: var(--accent); }
header.topbar form { display: inline; }

.nav-toggle {
  display: none;
  background: none;
  border: 1px solid var(--panel-light);
  border-radius: 6px;
  color: var(--text);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
}

.nav-count { margin-left: 0.3rem; font-weight: 700; }

/* Del menú de admin, solo Clientes/Planificador/Pendientes quedan
   siempre a la vista (lo que se usa a diario) — el resto vive adentro de
   "Más", un desplegable simple que se abre/cierra con un clic, igual que
   el menú hamburguesa de celular. */
.nav-dropdown { position: relative; display: inline-block; }
.nav-dropdown-toggle {
  background: none;
  border: none;
  color: var(--text);
  font-weight: 600;
  font-size: 1rem;
  font-family: inherit;
  padding: 0 0 0.2rem;
  margin-right: 1rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.nav-dropdown-toggle:hover { border-bottom-color: var(--accent); }
.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 20;
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  padding: 0.4rem;
  min-width: 180px;
}
.nav-dropdown.open .nav-dropdown-menu { display: flex; flex-direction: column; }
.nav-dropdown-menu a { margin-right: 0; padding: 0.5rem 0.6rem; border-radius: 6px; }
.nav-dropdown-menu a:hover { background: var(--panel-light); border-bottom-color: transparent; }

/* En celular, el menú de arriba (hasta 10 links en admin) no entra en una
   fila: se junta con el resto de la pantalla y queda ilegible/imposible
   de tocar bien. Abajo de 768px se colapsa detrás de un botón "☰ Menú"
   que despliega los links apilados en columna. Ahí "Más" no hace falta
   (ya está todo apilado y visible al abrir el menú): el desplegable queda
   siempre expandido y su botón se oculta. */
@media (max-width: 768px) {
  header.topbar { flex-wrap: wrap; gap: 0.5rem; }
  .nav-toggle { display: block; order: 1; }
  header.topbar > div:last-child { order: 2; margin-left: auto; }
  .nav-links {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    order: 3;
  }
  .nav-links.open { display: flex; }
  .nav-links a {
    margin-right: 0;
    padding: 0.7rem 0.4rem;
    border-bottom: 1px solid var(--panel-light);
    font-size: 1rem;
  }
  .nav-dropdown-toggle { display: none; }
  .nav-dropdown-menu {
    display: flex;
    position: static;
    flex-direction: column;
    border: none;
    box-shadow: none;
    padding: 0;
    min-width: 0;
  }
  .nav-dropdown-menu a {
    padding: 0.7rem 0.4rem;
    border-bottom: 1px solid var(--panel-light);
    font-size: 1rem;
    border-radius: 0;
  }
}

main { max-width: min(1500px, 96vw); margin: 0 auto; padding: 1.5rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(28, 38, 28, 0.06);
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--panel-light); }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; text-transform: uppercase; }

input, select, textarea {
  width: 100%;
  padding: 0.5rem;
  margin-bottom: 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--panel-light);
  background: #ffffff;
  color: var(--text);
}

label { font-size: 0.85rem; color: var(--muted); }

button, .btn {
  background: var(--accent);
  color: #ffffff;
  border: none;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

button:hover, .btn:hover { background: var(--accent-dark); }
button.danger, .btn.danger { background: var(--danger); }
button.secondary, .btn.secondary { background: var(--panel-light); color: var(--text); }
button.secondary:hover, .btn.secondary:hover { background: #cddcc7; }

.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.75rem; background: var(--panel-light); }
.badge.ok { background: rgba(76, 175, 80, 0.15); color: var(--ok); }
.badge.warn { background: rgba(192, 57, 43, 0.12); color: var(--danger); }

.error { color: var(--danger); margin-bottom: 1rem; }

/* ---- Medidas de bajo costo contra copiado casual de datos sensibles ----
   No son infalibles (un usuario con acceso a devtools siempre puede leer
   el HTML), pero elevan la fricción y disuaden el "copiar y pegar todo".
   La protección real está en el servidor: cada asesor solo recibe los
   clientes que tiene asignados y vencidos hoy, nunca la base completa. */
.protected {
  -webkit-user-select: none;
  user-select: none;
}

.watermark {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.06;
  display: flex;
  flex-wrap: wrap;
  align-content: space-around;
  justify-content: space-around;
  transform: rotate(-25deg);
  font-size: 1.1rem;
  color: #1c261c;
}
.watermark span { margin: 2.5rem; white-space: nowrap; }

/* Sin esto, un elemento con la clase .qc-panel/.qc-chip/etc (que fija su
   propio "display") queda visible aunque JS le ponga el atributo
   "hidden": una regla de autor con la misma especificidad que compite
   por "display" siempre le gana a la hoja de estilos por defecto del
   navegador, que es la única que trae [hidden] { display: none }. Con
   esto, cualquier elemento oculto vía hidden queda realmente oculto sin
   tener que acordarse de excluir "display" de cada regla nueva. */
[hidden] { display: none !important; }

/* ---- Chat del equipo: composer flotante estilo chat donde se escribe
   "@" para elegir (opcionalmente) un cliente (ver public/quick-comment.js). ---- */
.qc-toggle {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(28, 38, 28, 0.25);
  z-index: 40;
  padding: 0;
}
.qc-toggle:hover { background: var(--accent-dark); }
.qc-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  border-radius: 10px;
  background: var(--danger);
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  border: 2px solid var(--bg);
}

.qc-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 5.5rem;
  width: 340px;
  max-width: calc(100vw - 2rem);
  max-height: min(520px, calc(100vh - 7rem));
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(28, 38, 28, 0.22);
  display: flex;
  flex-direction: column;
  z-index: 40;
  overflow: hidden;
}
.qc-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--accent);
  color: #ffffff;
}
.qc-panel-header-actions { display: flex; align-items: center; gap: 0.25rem; }
.qc-close {
  background: none;
  border: none;
  color: #ffffff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  text-decoration: none;
  display: inline-block;
}
.qc-hint { margin: 0.4rem 1rem 0; font-size: 0.72rem; line-height: 1.3; color: var(--muted); }
/* De página completa hay lugar de sobra: se puede dejar la explicación
   larga sin que le robe espacio al feed/composer (ver .qc-panel--fullpage
   .qc-hint más abajo, que la vuelve a agrandar). En el panel flotante,
   chico de por sí, se recorta a una sola línea. */
.qc-hint { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.qc-feed { flex: 1; overflow-y: auto; padding: 0.5rem 1rem 0; min-height: 0; max-height: 220px; }
.qc-bubble {
  background: var(--accent);
  color: #ffffff;
  border-radius: 12px 12px 2px 12px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
  max-width: 90%;
  margin-left: auto;
  font-size: 0.88rem;
}
/* Mensaje de otra persona: alineado a la izquierda y sin el color de
   acento, para distinguir de un vistazo quién escribió qué en un feed
   compartido entre varios perfiles. */
.qc-bubble--other {
  background: var(--panel-light);
  color: var(--text);
  border-radius: 12px 12px 12px 2px;
  margin-left: 0;
  margin-right: auto;
}
.qc-bubble-meta { font-weight: 700; font-size: 0.75rem; opacity: 0.85; margin-bottom: 0.15rem; display: flex; gap: 0.4rem; align-items: center; }
.qc-bubble-text { white-space: pre-wrap; word-break: break-word; }
.qc-bubble-edit, .qc-bubble-delete {
  background: none;
  border: none;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
  padding: 0;
  font-size: 0.75rem;
}
.qc-bubble-edit { margin-left: auto; }
.qc-bubble-edit:hover, .qc-bubble-delete:hover { opacity: 1; }

/* Separador de día, estilo WhatsApp: una etiqueta centrada entre los
   mensajes de un día y los del siguiente. */
.qc-day-sep { text-align: center; margin: 0.6rem 0; }
.qc-day-sep span {
  display: inline-block;
  background: var(--panel-light);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
}

/* Panel de página completa (ver /chat): mismo widget, pero ocupando el
   ancho normal del contenido en vez de flotar fijo abajo a la derecha. */
.qc-panel--fullpage {
  position: static;
  width: 100%;
  max-width: none;
  height: calc(100vh - 230px);
  min-height: 420px;
  max-height: none;
  box-shadow: none;
  border-radius: 12px;
}
.qc-panel--fullpage .qc-feed { max-height: none; }
.qc-panel--fullpage .qc-hint { white-space: normal; overflow: visible; text-overflow: clip; font-size: 0.8rem; }

.qc-search { padding: 0.5rem 1rem 0; }
.qc-search input { margin: 0; }

.qc-error { margin: 0 1rem 0.5rem; color: var(--danger); font-size: 0.82rem; }

.qc-chip {
  margin: 0 1rem 0.5rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--panel-light);
  border-radius: 999px;
  padding: 0.25rem 0.5rem 0.25rem 0.7rem;
  font-size: 0.82rem;
  width: fit-content;
}
.qc-chip button { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0 0.2rem; font-size: 0.85rem; }

.qc-compose { display: flex; align-items: flex-end; gap: 0.5rem; padding: 0.75rem 1rem; border-top: 1px solid var(--panel-light); }
.qc-mentions-wrap { position: relative; flex: 1; }
.qc-compose textarea { margin: 0; resize: none; max-height: 96px; }
.qc-mentions {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  margin-bottom: 0.35rem;
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(28, 38, 28, 0.15);
  max-height: 200px;
  overflow-y: auto;
}
.qc-mention-item { padding: 0.5rem 0.7rem; cursor: pointer; font-size: 0.88rem; }
.qc-mention-item.active, .qc-mention-item:hover { background: var(--panel-light); }
.qc-mention-empty { padding: 0.5rem 0.7rem; color: var(--muted); font-size: 0.85rem; }

.qc-send { border-radius: 50%; width: 40px; height: 40px; padding: 0; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

@media (max-width: 480px) {
  .qc-panel { right: 0.5rem; left: 0.5rem; width: auto; bottom: 4.75rem; }
  .qc-toggle { right: 1rem; bottom: 1rem; }
}

@media print {
  .protected, .no-print { display: none !important; }
  body::before {
    content: "Documento confidencial - impresión no autorizada";
    display: block;
    text-align: center;
    font-weight: bold;
  }
}
