/* Base de página: header arriba, footer abajo, contenido flexible en medio */
html, body { height: 100%; }
body { display: flex; flex-direction: column; min-height: 100%; }
main, #notifications { flex: 1 1 auto; min-height: 0; } /* clave para scroll interno */
/* === Grid de notificaciones (dos columnas) === */
.notif-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
  width: 100%;
  align-items: start;
}

/* === Opciones de mensaje === */
.message-options {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}
.message-options button {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: var(--border-radius);
  background-color: var(--light);
  color: var(--dark);
  cursor: pointer;
  transition: var(--transition);
  font-weight: 500;
}
.message-options button.active { background-color: var(--primary); color: white; }
.message-options button:hover:not(.active) { background-color: var(--light-gray); }

/* === Textarea === */
textarea {
  width: 100%;
  min-height: 120px;
  flex: 1;
  padding: 15px;
  border: 1px solid var(--light-gray);
  border-radius: var(--border-radius);
  resize: vertical;
  margin-bottom: 20px;
  outline: none;
  transition: var(--transition);
}
textarea:focus { border-color: var(--primary); }

/* === Mensajes guardados === */
.saved-messages { margin-top: 10px; flex: 1; overflow-y: auto; }
.saved-message {
  padding: 12px 15px;
  border: 1px solid var(--light-gray);
  border-radius: var(--border-radius);
  margin-bottom: 10px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.saved-message:hover { background-color: var(--light); border-color: var(--primary); }
.saved-message-content { flex: 1; min-width: 0; }   /* clave para ellipsis */
.saved-message-actions { display: flex; gap: 10px; }

/* Vista previa de mensajes guardados (resumida con ...) */
.saved-message-content .message-title {
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.saved-message-content .message-preview {
  font-size: 13px;
  color: #6c757d;
  white-space: nowrap;      /* 1 sola línea */
  overflow: hidden;         /* oculta exceso */
  text-overflow: ellipsis;  /* agrega los ... */
  display: block;
  max-width: 100%;
}

/* Contenedor de guardados con scroll interno */
#savedMessagesSection {
  max-height: 50vh;
  overflow: auto;
  border: 1px solid var(--light-gray);
  border-radius: 12px;
  padding: 8px;
}

/* === Grid de tarjetas de destinatarios === */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

/* === Tarjeta de destinatario === */
.recipient-card {
  position: relative;
  background: #fff;
  border: 1px solid var(--light-gray);
  border-radius: 16px;
  padding: 16px 14px 14px 14px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.06);
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
  display: grid;
  grid-template-columns: 56px 1fr;
  grid-template-areas:
    "check check"
    "avatar main"
    "meta meta";
  row-gap: 10px;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.recipient-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 22px rgba(0,0,0,0.08);
  border-color: var(--primary);
}
.card-check { grid-area: check; display: flex; justify-content: flex-end; }
.card-avatar {
  grid-area: avatar;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #ffd86b);
  color: #111;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: .5px;
  user-select: none;
}
.card-main { grid-area: main; display: flex; flex-direction: column; justify-content: center; padding-left: 8px; min-width: 0; }
.card-name { font-weight: 700; font-size: 16px; color: var(--dark); line-height: 1.2; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-email { font-size: 13px; color: #333; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-email.muted { color: #8a8a8a; }
.card-meta { grid-area: meta; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--light);
  color: var(--dark);
  border: 1px solid var(--light-gray);
}
.chip-apv { background: #eef6ff; border-color: #cfe6ff; color: #0b63b6; font-weight: 600; }
.chip-warn { background: #fff4e5; border-color: #ffd9a8; color: #9a5b00; font-weight: 600; }


/* Altura visible = alto ventana real - header - footer */
#notifications .notif-grid {
  height: calc(100svh - var(--header-h, 0px) - var(--footer-h, 0px));
  grid-template-columns: 1.25fr 0.85fr;
  align-items: stretch;
  overflow: hidden; /* evita que el contenido empuje el footer */
}

#notifications .card { display: flex; flex-direction: column; min-height: 0; }
#recipientsList {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--light-gray);
  border-radius: 12px;
  padding: 10px;
}
#notifications .card .search-box,
#notifications .card .select-all {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 2;
}
#notifications .notif-grid > .card:nth-child(2) {
  position: static;
  top: auto;
  align-self: stretch;
  height: auto;
}

/* === Header del buscador de guardados === */
.saved-messages-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0 12px;
}
.icon-btn {
  background: #fff;
  border: 1px solid var(--light-gray);
  border-radius: var(--border-radius);
  padding: 8px 10px;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn i { font-size: 16px; color: var(--gray); }
.icon-btn:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(67,97,238,.08);
}
.icon-btn.active i { color: var(--primary); }

#savedSearchInput {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--light-gray);
  border-radius: var(--border-radius);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
}
#savedSearchInput:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(67,97,238,.08);
}

/* Responsive (notificaciones) */
@media (max-width: 980px) {
  #notifications .notif-grid { grid-template-columns: 1fr; height: auto; }
  #notifications .notif-grid > .card:nth-child(2) { position: static; }
  #recipientsList { max-height: 50vh; }
}

/* ===== Historial — estilo timeline ===== */
.history-list {
  padding: 4px 8px 8px 18px;
  position: relative;
  max-height: 60vh; /* scroll suave */
  overflow: auto;
  border: 1px solid var(--light-gray);
  border-radius: 12px;
  background: #fff;
}
.history-list::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 10px;
  bottom: 10px;
  width: 2px;
  background: linear-gradient(180deg, var(--light-gray), #dfe3ea);
  border-radius: 2px;
}
.h-item {
  position: relative;
  margin: 12px 0 14px 18px;
  padding: 12px 14px;
  border: 1px solid var(--light-gray);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,.05);
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.h-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(0,0,0,.07);
  border-color: var(--primary);
}
.h-bullet {
  position: absolute;
  left: -26px;
  top: 16px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--primary);
  box-shadow: 0 0 0 4px rgba(67,97,238,.12);
}

/* Cabecera compacta */
.h-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px 12px;
  align-items: center;
}
.h-avatar {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--secondary), var(--primary));
  color: #fff; font-weight: 800; display:flex; align-items:center; justify-content:center;
  letter-spacing:.3px;
}
.h-title {
  font-weight: 800; color: var(--ink); line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.h-actions .btn { padding: 8px 10px; border-radius: 10px; }

/* Meta y preview */
.h-meta {
  display:flex; flex-wrap:wrap; gap:8px; margin-top:8px;
}
.h-chip {
  display:inline-flex; align-items:center; gap:6px;
  padding:6px 10px; border-radius:999px; font-size:12px;
  background:#f7f8fc; border:1px solid var(--light-gray); color:#374151;
}
.h-chip--sender { background:#eef6ff; border-color:#cfe6ff; color:#0b63b6; font-weight:600; }
.h-chip--date   { background:#fff; }
.h-chip--apv    { background:#fff4e5; border-color:#ffd9a8; color:#9a5b00; font-weight:600; }

.h-preview {
  font-size: 13px; color:#6b7280; margin-top:6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;  /* 1 línea con ... */
}

/* Responsive (historial) */
@media (max-width: 720px){
  .h-head { grid-template-columns: auto 1fr; }
  .h-actions { grid-column: 1 / -1; justify-self: end; }
}

/* ====== Modales (única definición) ====== */
.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  justify-content: center;
  align-items: center;
  z-index: 1000;
}
.modal-content {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  width: 600px;          /* ancho cómodo para leer */
  max-width: 95%;
  max-height: 80vh;      /* altura contenida */
  display: flex;
  flex-direction: column;
  box-shadow: 0 5px 20px rgba(0,0,0,0.2);
}
.modal-header {
  display:flex; align-items:center; justify-content:space-between;
  margin-bottom: 10px;
}
.modal-header .close { cursor: pointer; font-size: 22px; line-height: 1; }
.modal-body {
  overflow: auto;        /* scroll interno para textos largos */
  flex: 1 1 auto;
  border: 1px solid var(--light-gray);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}
.modal-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Texto largo en modales: que haga wrap y scroll */
#viewSavedContent,
#hDetContent {
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 720px){
  .modal-content { width: 95%; }
}
