/* =====================================================================
   Vistas especiales de módulos (citas, seguimiento, chat, plantillas, contraseña)
   ===================================================================== */

/* ---------- Calendario de citas ---------- */
.cal-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.cal-toolbar h2 { margin: 0 8px 0 4px; font-size: 19px; font-weight: 600; }
.cal-toolbar .grow { flex: 1; }
.cal-toolbar .ctl { width: 230px; }
.cal-toolbar .ctl select { height: 36px; }
.seg-sm { display: inline-flex; padding: 3px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.seg-sm button { padding: 5px 12px; font-size: 14px; color: var(--ink-soft); background: none; border: 0; border-radius: 6px; cursor: pointer; }
.seg-sm button[aria-pressed="true"] { background: #fff; color: var(--navy); font-weight: 600; box-shadow: 0 1px 2px rgba(20,30,50,.1); }
.cal-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; font-size: 13px; color: var(--ink-soft); }
.cal-legend span { display: inline-flex; align-items: center; gap: 6px; }
.cal-legend i { width: 10px; height: 10px; border-radius: 3px; }
.cal-legend i.cat-1 { background: #2f5fa8; }
.cal-legend i.cat-2 { background: #c98a00; }
.cal-legend i.cat-3 { background: #6d4fc2; }
.cal-legend i.cat-4 { background: #1f8a78; }

.cal { --slot: 44px; margin-top: 16px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.cal-head, .cal-body { display: grid; grid-template-columns: 60px repeat(5, minmax(0, 1fr)); }
.cal-head { background: #fafbfc; border-bottom: 1px solid var(--line); }
.cal-head div { padding: 10px 8px; text-align: center; font-size: 13px; color: var(--muted); }
.cal-head div b { display: block; font-size: 20px; font-weight: 600; color: var(--ink); line-height: 1.1; }
.cal-head div.today { color: var(--navy); font-weight: 600; }
.cal-head div.today b { display: grid; place-items: center; width: 32px; height: 32px; margin: 0 auto; border-radius: 50%; background: var(--navy); color: #fff; font-size: 17px; }
.cal-body { position: relative; max-height: 600px; overflow-y: auto; }
.cal-times div { height: var(--slot); padding-right: 8px; font-size: 12px; color: var(--muted); text-align: right; transform: translateY(-7px); }
.cal-times div:first-child { transform: none; padding-top: 2px; }
.cal-day { position: relative; border-left: 1px solid var(--line-soft); }
.cal-day .slot { height: var(--slot); border-bottom: 1px dashed var(--line-soft); cursor: pointer; }
.cal-day .slot:nth-child(3n) { border-bottom-style: solid; border-bottom-color: var(--line); }
.cal-day .slot:hover { background: var(--info-bg); }
.cal-day .slot.off { background: repeating-linear-gradient(135deg, #f7f8fa, #f7f8fa 6px, #f1f2f5 6px, #f1f2f5 12px); cursor: not-allowed; }
.appt {
  position: absolute;
  left: 4px; right: 4px;
  padding: 4px 8px;
  overflow: hidden;
  font-size: 12.5px;
  line-height: 1.3;
  border-left: 3px solid;
  border-radius: 6px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.appt:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(20,30,50,.12); z-index: 2; }
.appt b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt small { color: inherit; opacity: .85; }
.cat-1 { background: #e9f0fa; border-color: #2f5fa8; color: #1d3f75; }
.cat-2 { background: #fdf1dc; border-color: #c98a00; color: #6b4700; }
.cat-3 { background: #efeafa; border-color: #6d4fc2; color: #47318a; }
.cat-4 { background: #e3f4f1; border-color: #1f8a78; color: #135c50; }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--crit); z-index: 3; pointer-events: none; }
.now-line::before { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--crit); }

/* ---------- Seguimiento a pacientes ---------- */
.svc-list { display: flex; flex-wrap: wrap; gap: 6px; }
.svc {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px 3px 7px;
  font-size: 12.5px;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.svc svg { width: 13px; height: 13px; stroke-width: 2.2; }
.svc--done { background: var(--good-bg); color: var(--good); }
.svc--doing { background: var(--info-bg); color: var(--info); }
.svc--doing svg { animation: spin 2.4s linear infinite; }
.svc--pending { background: var(--neutral-bg); color: var(--neutral); }
.svc--wait { background: var(--warn-bg); color: var(--warn); }
.conv-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 12px; font-size: 13px; color: var(--ink-soft); }
.patient { display: flex; align-items: center; gap: 10px; }
.patient .av { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--neutral-bg); color: var(--navy); font-size: 12.5px; font-weight: 700; }
.patient b { display: block; font-weight: 500; }
.patient small { color: var(--muted); font-size: 12.5px; }
.progress-cell { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.progress-cell .bar { flex: 1; }
.progress-cell small { font-size: 12.5px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

/* ---------- Chat ---------- */
.chat { display: grid; grid-template-columns: 320px minmax(0, 1fr); height: calc(100vh - 220px); min-height: 520px; overflow: hidden; }
.chat-list { display: flex; flex-direction: column; border-right: 1px solid var(--line); min-height: 0; }
.chat-list .ctl { margin: 14px; }
.chat-list ul { flex: 1; margin: 0; padding: 0 8px 8px; list-style: none; overflow-y: auto; }
.chat-list li { display: flex; gap: 10px; padding: 10px; border-radius: 8px; cursor: pointer; }
.chat-list li:hover { background: var(--surface); }
.chat-list li.is-active { background: var(--info-bg); }
.chat-list .av { flex: none; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--yellow-soft); color: var(--navy); font-size: 13px; font-weight: 700; }
.chat-list .tx { min-width: 0; flex: 1; }
.chat-list .tx b { display: flex; justify-content: space-between; gap: 8px; font-size: 14.5px; font-weight: 500; }
.chat-list .tx b em { font-style: normal; font-size: 12px; font-weight: 400; color: var(--muted); }
.chat-list .tx small { display: block; font-size: 13px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list .unread { align-self: center; display: grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--yellow); color: var(--navy); font-size: 11.5px; font-weight: 700; }
.chat-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-top { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.chat-top b { display: block; font-size: 16px; }
.chat-top small { color: var(--good); font-size: 13px; }
.chat-top .grow { flex: 1; }
.msgs { flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 18px; overflow-y: auto; background: #fafbfc; }
.day-sep { align-self: center; padding: 2px 10px; font-size: 12px; color: var(--muted); background: #fff; border: 1px solid var(--line); border-radius: 999px; }
.msg { max-width: 70%; padding: 9px 12px; font-size: 14.5px; line-height: 1.45; border-radius: 12px; }
.msg small { display: block; margin-top: 4px; font-size: 11.5px; opacity: .7; text-align: right; }
.msg.them { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.me { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 4px; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; min-height: 42px; max-height: 120px; padding: 10px 12px; font-size: 15px; border: 1px solid var(--line); border-radius: 10px; resize: none; }
.composer textarea:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(31, 58, 102, 0.12); }

/* ---------- Editor de plantillas ---------- */
.ed { margin-top: 16px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.ed-toolbar { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; background: #fafbfc; border-bottom: 1px solid var(--line); }
.ed-toolbar button { min-width: 32px; height: 32px; padding: 0 8px; font-size: 14px; color: var(--ink-soft); background: none; border: 0; border-radius: 6px; cursor: pointer; }
.ed-toolbar button:hover { background: #fff; color: var(--navy); }
.ed-toolbar .sep { width: 1px; margin: 4px 4px; background: var(--line); }
.ed-area { min-height: 240px; padding: 16px; font-size: 15px; line-height: 1.6; outline: none; }
.ed-area:focus { box-shadow: inset 0 0 0 2px rgba(31, 58, 102, 0.15); }
.var-chip { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--yellow-soft); color: var(--navy); font-weight: 500; }
.vars { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.vars button { padding: 4px 10px; font-size: 13px; color: var(--navy); background: var(--yellow-soft); border: 1px solid #f1e2a6; border-radius: 999px; cursor: pointer; }
.vars button:hover { background: var(--yellow); }
.mail-preview { margin-top: 16px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; font-size: 14px; }
.mail-preview header { padding: 12px 14px; background: #fafbfc; border-bottom: 1px solid var(--line); color: var(--ink-soft); line-height: 1.6; }
.mail-preview header b { color: var(--ink); }
.mail-preview .mp-brand { display: flex; align-items: center; gap: 10px; padding: 14px; background: var(--navy); color: #fff; font-weight: 600; }
.mail-preview .mp-brand img { width: 34px; }
.mail-preview .mp-body { padding: 16px; line-height: 1.6; }
.mail-preview .mp-body .btn { margin-top: 8px; height: 36px; pointer-events: none; }

/* ---------- Cambiar contraseña ---------- */
.pw-wrap { display: grid; grid-template-columns: minmax(0, 520px) minmax(0, 1fr); gap: 20px; align-items: start; margin-top: 24px; }
.pw-field { margin-top: 16px; }
.pw-field label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 500; }
.pw-field .ctl input { padding-right: 80px; }
.pw-field .show { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); padding: 4px 8px; font-size: 13.5px; color: var(--ink-soft); background: none; border: 0; cursor: pointer; }
.pw-meter { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 10px; }
.pw-meter i { height: 4px; border-radius: 2px; background: var(--line); transition: background .2s ease; }
.pw-meter.s1 i:nth-child(-n+1) { background: var(--crit); }
.pw-meter.s2 i:nth-child(-n+2) { background: var(--warn); }
.pw-meter.s3 i:nth-child(-n+3) { background: var(--info); }
.pw-meter.s4 i { background: var(--good); }
.pw-label { margin-top: 6px; font-size: 13px; color: var(--muted); }
.rules { margin: 14px 0 0; padding: 0; list-style: none; }
.rules li { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 14.5px; color: var(--ink-soft); }
.rules li svg { width: 16px; height: 16px; color: #b5bcc7; }
.rules li.ok { color: var(--ink); }
.rules li.ok svg { color: var(--good); }

@media (max-width: 1100px) {
  .chat { grid-template-columns: 1fr; height: auto; }
  .chat-list { border-right: 0; border-bottom: 1px solid var(--line); max-height: 260px; }
  .msgs { min-height: 360px; }
  .pw-wrap { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .cal-head, .cal-body { grid-template-columns: 48px repeat(5, minmax(90px, 1fr)); }
  .cal { overflow-x: auto; }
  .cal-toolbar .ctl { width: 100%; }
  .msg { max-width: 88%; }
}
