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

:root {
  --primary:       #2563eb;
  --primary-dark:  #1d4ed8;
  --primary-light: #eff6ff;
  --accent:        #60a5fa;
  --bg:            #f0f7ff;
  --white:         #ffffff;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --border:        #e2e8f0;
  --success:       #059669;
  --warning:       #d97706;
  --danger:        #dc2626;
  --shadow-sm:     0 2px 8px rgba(0,0,0,.07);
  --shadow-md:     0 4px 16px rgba(0,0,0,.11);
  --radius:        20px;
}

html, body { height: 100%; font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); overflow-x: hidden; -webkit-tap-highlight-color: transparent; }
button, a, [onclick] { touch-action: manipulation; }

/* ── App shell ─────────────────────────────────────────────────────────────── */

.app {
  display: flex; flex-direction: column; height: 100dvh; width: 100%;
  background: var(--bg);
  overflow: hidden;
}

/* ── Header ────────────────────────────────────────────────────────────────── */

.header { background: var(--primary); padding: calc(14px + env(safe-area-inset-top)) 18px 14px; flex-shrink: 0; z-index: 10; position: relative; }
.header-content { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; row-gap: 8px; }
.bot-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.bot-info { flex: 1; min-width: 0; }
.bot-info h1 { font-size: 16px; font-weight: 700; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 12px; color: #bfdbfe; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.admin-link {
  color: rgba(255,255,255,.7); font-size: 18px; text-decoration: none;
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.admin-link:hover { color: #fff; }
.btn-logout { background: rgba(255,255,255,.15); border: none; border-radius: 8px; color: #fff; padding: 6px 12px; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; flex-shrink: 0; }
.btn-logout:hover { background: rgba(255,255,255,.25); }
.btn-switch-mode { background: rgba(255,255,255,.22); border: 1.5px solid rgba(255,255,255,.5); border-radius: 8px; color: #fff; padding: 6px 12px; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; flex-shrink: 0; }
.btn-switch-mode:hover { background: rgba(255,255,255,.35); }
.btn-more-menu { display: none; }

/* ── Guardia strip ─────────────────────────────────────────────────────────── */
.guardia-strip {
  background: #1e293b; border-bottom: 1px solid #334155; padding: 10px 16px;
  display: flex; align-items: center; gap: 10px; flex-shrink: 0; flex-wrap: wrap;
}
.gs-label { font-size: 11px; font-weight: 700; color: #94a3b8; text-transform: uppercase; letter-spacing: .05em; }
.guardia-input { padding: 7px 11px; border-radius: 8px; border: 1.5px solid #334155; background: #0f172a; color: #f1f5f9; font-size: 16px; width: 130px; }
.guardia-input::placeholder { color: #475569; }
.guardia-input:focus { outline: none; border-color: var(--primary); }
.btn-guardia-on  { background: #059669; color: #fff; border: none; border-radius: 8px; padding: 7px 13px; font-size: 13px; font-weight: 700; cursor: pointer; }
.btn-guardia-off { background: #334155; color: #f1f5f9; border: none; border-radius: 8px; padding: 7px 13px; font-size: 13px; font-weight: 600; cursor: pointer; }
.guardia-badge { display:inline-flex; align-items:center; gap:6px; background:#dc2626; color:#fff; border-radius:20px; padding:3px 10px; font-size:12px; font-weight:700; animation: gpulse 2s infinite; }
.guardia-precio { font-size:13px; color:#4ade80; font-weight:700; }
@keyframes gpulse { 0%,100%{opacity:1} 50%{opacity:.7} }

/* ── Llamada entrante ──────────────────────────────────────────────────────── */
.call-alert {
  position: fixed; top: 0; left: 0; right: 0; z-index: 999;
  background: #0f172a; border-bottom: 3px solid #059669;
  padding: calc(14px + env(safe-area-inset-top)) 18px 14px; display: flex; align-items: center; gap: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,.5);
}
.ca-icon { font-size: 28px; animation: shake .5s infinite alternate; }
@keyframes shake { from{transform:rotate(-10deg)} to{transform:rotate(10deg)} }
.ca-info { flex:1; }
.ca-title  { font-size:13px; font-weight:700; color:#f1f5f9; }
.ca-patient{ font-size:12px; color:#94a3b8; margin-top:2px; }
.ca-accept { background:#059669; color:#fff; border:none; border-radius:8px; padding:9px 16px; font-size:13px; font-weight:700; cursor:pointer; }
.ca-reject { background:#334155; color:#f1f5f9; border:none; border-radius:8px; padding:9px 12px; font-size:13px; font-weight:600; cursor:pointer; }

/* ── Email card (modo médico) ──────────────────────────────────────────────── */
.email-card { background:#eff6ff; border:1.5px solid #bfdbfe; border-radius:12px; padding:14px 16px; margin-top:8px; }
.email-card .ec-label { font-size:11px; font-weight:700; color:var(--primary); text-transform:uppercase; letter-spacing:.05em; margin-bottom:8px; }
.email-card .ec-row   { font-size:13px; color:var(--text); margin-bottom:4px; }
.email-card .ec-row span { color:var(--text-muted); }
.email-card .ec-actions { display:flex; gap:8px; margin-top:12px; }
.ec-send   { flex:1; padding:9px; background:var(--success); color:#fff; border:none; border-radius:8px; font-size:13px; font-weight:700; cursor:pointer; }
.ec-cancel { flex:1; padding:9px; background:#fff; color:var(--text-muted); border:1.5px solid var(--border); border-radius:8px; font-size:13px; font-weight:600; cursor:pointer; }
.ec-result { font-size:13px; font-weight:600; padding:8px 0 0; }
.ec-result.ok  { color:var(--success); }
.ec-result.err { color:var(--danger); }

/* ── Messages area ─────────────────────────────────────────────────────────── */

.chat-container { flex: 1; overflow-y: auto; padding: 16px; scroll-behavior: smooth; }
.messages { display: flex; flex-direction: column; gap: 12px; }

/* ── Bubbles ───────────────────────────────────────────────────────────────── */

.message { display: flex; flex-direction: column; max-width: 84%; animation: fadeSlideIn .22s ease both; }
.message.user  { align-self: flex-end; }
.message.bot   { align-self: flex-start; }
.message.wide  { max-width: 100%; width: 100%; }

.bubble {
  padding: 11px 15px; border-radius: var(--radius);
  font-size: 14px; line-height: 1.55;
  box-shadow: var(--shadow-sm); word-break: break-word;
}
.message.user .bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 5px; }
.message.bot  .bubble { background: var(--white); color: var(--text); border-bottom-left-radius: 5px; }
.message.wide .bubble { background: transparent; box-shadow: none; padding: 0; }
.message-time { font-size: 11px; color: var(--text-muted); margin-top: 3px; padding: 0 4px; }
.message.user .message-time { text-align: right; }

/* ── Professional cards ────────────────────────────────────────────────────── */

.prof-cards { display: flex; flex-direction: column; gap: 8px; width: 100%; }

.prof-card {
  background: var(--white); border-radius: 14px;
  border-left: 4px solid var(--accent);
  padding: 14px 16px; box-shadow: var(--shadow-sm);
  cursor: pointer; transition: box-shadow .15s, border-color .15s;
}
.prof-card:hover { box-shadow: var(--shadow-md); border-color: var(--primary); }

.prof-card-name { font-size: 15px; font-weight: 700; margin-bottom: 3px; }
.prof-card-esp  { font-size: 12px; color: var(--primary); font-weight: 600; margin-bottom: 6px; }
.prof-card-meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; color: var(--text-muted); }
.prof-card-address { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600;
}
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-green  { background: #d1fae5; color: #065f46; }
.badge-gray   { background: #f1f5f9; color: #475569; }
.badge-yellow { background: #fef3c7; color: #92400e; }

/* ── Service cards ─────────────────────────────────────────────────────────── */

.svc-cards { display: flex; flex-direction: column; gap: 8px; width: 100%; }

.svc-card {
  background: var(--white); border-radius: 14px;
  border: 2px solid var(--border); padding: 14px 16px;
  box-shadow: var(--shadow-sm); cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  transition: border-color .15s, background .15s;
}
.svc-card:hover { border-color: var(--primary); background: var(--primary-light); }
.svc-card-name  { font-size: 14px; font-weight: 700; }
.svc-card-desc  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.svc-card-meta  { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.svc-card-price { font-size: 18px; font-weight: 800; color: var(--primary); white-space: nowrap; margin-left: 12px; }

/* ── Slot grid ─────────────────────────────────────────────────────────────── */

.slot-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: 8px; width: 100%;
}
.slot-btn {
  background: var(--white); border: 2px solid var(--border); border-radius: 10px;
  padding: 10px 6px; text-align: center; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all .15s; min-height: 44px; touch-action: manipulation;
}
.slot-btn:hover { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
/* colores para slots del médico */
.slot-confirmed { border-color: #059669; background: #d1fae5; color: #065f46; }
.slot-confirmed:hover { background: #a7f3d0; border-color: #059669; color: #064e3b; }
.slot-pending   { border-color: #f59e0b; background: #fef3c7; color: #92400e; }
.slot-pending:hover   { background: #fde68a; border-color: #d97706; color: #78350f; }
.slot-cancelado { border-color: #cbd5e1; background: #f8fafc; color: #94a3b8; text-decoration: line-through; }
.slot-cancelado:hover { background: #f1f5f9; border-color: #94a3b8; }

/* ── Calendar ──────────────────────────────────────────────────────────────── */

.calendar-wrap { background: var(--white); border-radius: 14px; padding: 16px; box-shadow: var(--shadow-sm); width: 100%; }
.cal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-weight: 700; }
.cal-nav { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 14px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-day-label { text-align: center; font-size: 10px; font-weight: 600; color: var(--text-muted); padding: 4px 0; }
.cal-day {
  text-align: center; padding: 7px 2px; border-radius: 8px; font-size: 13px;
  cursor: pointer; transition: all .15s; border: 2px solid transparent;
  font-weight: 600; color: var(--text);
  min-height: 38px; display: flex; align-items: center; justify-content: center;
  touch-action: manipulation;
}
.cal-day:hover:not(.disabled):not(.no-avail):not(.empty) { background: var(--primary-light); border-color: var(--primary); }
.cal-day.selected  { background: var(--primary); color: #fff; border-color: var(--primary); }
.cal-day.today:not(.selected) { border-color: var(--primary); color: var(--primary); }
.cal-day.disabled  { color: #cbd5e1; cursor: not-allowed; font-weight: 400; }
.cal-day.no-avail  { color: #cbd5e1; cursor: not-allowed; font-weight: 400; }
.cal-day.empty     { cursor: default; }
/* días con turnos (modo médico) */
.cal-day.ag-confirmed { background: #d1fae5; color: #065f46; border-color: #059669; font-weight: 700; cursor: pointer; }
.cal-day.ag-confirmed:hover { background: #a7f3d0; border-color: #047857; }
.cal-day.ag-pending   { background: #fef3c7; color: #92400e; border-color: #f59e0b; font-weight: 700; cursor: pointer; }
.cal-day.ag-pending:hover   { background: #fde68a; border-color: #d97706; }
.cal-day.ag-cancelado { background: #f1f5f9; color: #94a3b8; border-color: #cbd5e1; font-weight: 500; cursor: pointer; text-decoration: line-through; }
.cal-day.ag-cancelado:hover { background: #e2e8f0; border-color: #94a3b8; }
.cal-legend { display: flex; gap: 14px; margin-top: 12px; font-size: 11px; color: var(--text-muted); flex-wrap: wrap; }
.cal-legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; }
.cal-legend-avail    { background: var(--text); }
.cal-legend-no-avail { background: #cbd5e1; }
.cal-legend-today    { background: transparent; border: 2px solid var(--primary); }

/* ── Guardia matrix (selector de horarios por arrastre) ───────────────────── */

.guardia-matrix-wrap {
  width: 100%; overflow: auto; max-height: 360px;
  border: 1.5px solid var(--border); border-radius: 12px;
}
.guardia-matrix {
  display: grid; grid-template-columns: 42px repeat(7, minmax(34px, 1fr));
  width: 100%; min-width: 300px; user-select: none; -webkit-user-select: none; touch-action: none;
}
.gm-corner, .gm-day-label {
  position: sticky; top: 0; z-index: 2; background: var(--white);
  font-size: 11px; font-weight: 700; color: var(--text-muted); text-align: center;
  padding: 6px 2px; border-bottom: 1.5px solid var(--border);
}
.gm-corner { left: 0; z-index: 3; }
.gm-hour-label {
  position: sticky; left: 0; z-index: 1; background: var(--white);
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  border-right: 1.5px solid var(--border); border-bottom: 1px solid #f1f5f9;
}
.gm-cell {
  height: 26px; border-bottom: 1px solid #f1f5f9; border-right: 1px solid #f1f5f9;
  cursor: pointer; transition: background .08s;
}
.gm-cell:hover { background: var(--primary-light); }
.gm-cell.gm-existing-virtual { background: #a7f3d0; }
.gm-cell.gm-existing-virtual:hover { background: #6ee7b7; }
.gm-cell.gm-existing-presencial { background: #fde68a; }
.gm-cell.gm-existing-presencial:hover { background: #fbbf24; }
.gm-cell.selected { background: var(--primary); }

/* ── Guardia matrix (solo lectura, con detalle al click) ──────────────────── */

.gm-cell-view { cursor: default; }
.gm-cell.gm-cell-view:hover        { background: transparent; }
.gm-cell-view.gm-virtual           { background: #6ee7b7; cursor: pointer; }
.gm-cell-view.gm-virtual:hover     { background: #34d399; }
.gm-cell-view.gm-presencial        { background: #fbbf24; cursor: pointer; }
.gm-cell-view.gm-presencial:hover  { background: #f59e0b; }

.gm-legend { display: flex; gap: 14px; margin-bottom: 10px; font-size: 12px; color: var(--text-muted); flex-wrap: wrap; }
.gm-legend-item { display: flex; align-items: center; }
.gm-legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.gm-legend-virtual    { background: #6ee7b7; border: 1px solid #059669; }
.gm-legend-presencial { background: #fbbf24; border: 1px solid #d97706; }
.gm-legend-existing-virtual    { background: #a7f3d0; border: 1px solid #059669; }
.gm-legend-existing-presencial { background: #fde68a; border: 1px solid #d97706; }
.gm-hint { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

/* ── Modal de detalle de horario de guardia ───────────────────────────────── */

.gh-modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.gh-modal {
  background: var(--white); border-radius: 16px; padding: 20px;
  width: 100%; max-width: 340px; box-shadow: var(--shadow-md);
}
.gh-modal-header { font-size: 15px; margin-bottom: 10px; }

/* ── Upload box ────────────────────────────────────────────────────────────── */

.upload-box {
  background: var(--white); border: 2px dashed var(--border); border-radius: 14px;
  padding: 20px; text-align: center; cursor: pointer;
  transition: border-color .15s; width: 100%;
}
.upload-box:hover { border-color: var(--primary); }
.upload-box input { display: none; }

.alias-box {
  background: var(--primary-light); border: 2px solid var(--primary); border-radius: 14px;
  padding: 18px; text-align: center; width: 100%;
}
.alias-box .alias-amount { font-size: 2rem; font-weight: 800; color: var(--primary); margin: 6px 0; }
.alias-box .alias-value  { font-size: 1.1rem; font-weight: 700; letter-spacing: .04em; margin-top: 4px; }
.alias-box p { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.tracking-box {
  background: var(--primary-light); border: 2px solid var(--primary); border-radius: 14px;
  padding: 16px; text-align: center; width: 100%;
}
.tracking-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.tracking-code {
  font-family: monospace; font-size: 13px; font-weight: 700; color: var(--primary);
  word-break: break-all; margin-bottom: 12px; letter-spacing: .03em;
}

.alias-copy-btn {
  padding: 8px 20px; border-radius: 20px;
  border: 2px solid var(--primary); background: #fff; color: var(--primary);
  font-size: 13px; font-weight: 700; cursor: pointer; font-family: inherit;
  transition: all .15s;
}
.alias-copy-btn:hover { background: var(--primary); color: #fff; }

/* ── Manage-turno cards ─ */
.manage-card {
  background: #f8fafc; border: 1.5px solid #e2e8f0; border-radius: 12px;
  padding: 12px 14px; margin-bottom: 10px;
}
.manage-card:last-child { margin-bottom: 0; }
.mc-row { font-size: 13px; color: #1e293b; margin-bottom: 4px; }
.mc-row strong { color: #0f172a; }
.mc-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.mc-btn {
  padding: 11px 14px; border-radius: 20px; font-size: 12px; font-weight: 700;
  cursor: pointer; border: none; font-family: inherit; transition: opacity .15s;
  min-height: 40px; touch-action: manipulation;
}
.mc-btn:hover { opacity: .85; }
.mc-reschedule { background: #eff6ff; color: #2563eb; border: 1.5px solid #2563eb; }
.mc-cancel     { background: #fef2f2; color: #dc2626; border: 1.5px solid #dc2626; }
.alias-mp-btn {
  padding: 8px 20px; border-radius: 20px; text-decoration: none;
  background: #009ee3; color: #fff; font-size: 13px; font-weight: 700;
  border: 2px solid #009ee3; transition: all .15s; display: inline-flex; align-items: center;
}
.alias-mp-btn:hover { background: #007bbf; border-color: #007bbf; }

/* ── Appointment status ────────────────────────────────────────────────────── */

.status-card {
  background: var(--white); border-radius: 14px; padding: 16px;
  box-shadow: var(--shadow-sm); width: 100%;
}
.status-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.status-row:last-child { border-bottom: none; }
.status-row .lbl { color: var(--text-muted); }

/* ── Action buttons (dentro del chat) ─────────────────────────────────────── */

.chat-btn {
  display: inline-flex; align-items: center; margin: 4px 4px 0 0;
  padding: 11px 16px; border-radius: 20px; border: none;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all .15s; min-height: 40px; touch-action: manipulation;
}
.chat-btn-primary { background: var(--primary); color: #fff; }
.chat-btn-primary:hover { background: var(--primary-dark); }
.chat-btn-outline { background: var(--white); color: var(--primary); border: 2px solid var(--primary); }
.chat-btn-outline:hover { background: var(--primary-light); }
.chat-btn-success { background: var(--success); color: #fff; }

/* ── OS selector (multi-select obra social) ────────────────────────────────── */

.os-selector { width: 100%; }
.os-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.os-chip {
  padding: 8px 16px; border-radius: 24px; border: 2px solid var(--primary);
  color: var(--primary); background: #fff; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .15s; font-family: inherit;
}
.os-chip:hover    { background: var(--primary-light); }
.os-chip.selected { background: var(--primary); color: #fff; }
.os-continue {
  display: block; width: 100%; padding: 11px; border-radius: 10px;
  background: var(--primary); color: #fff; border: none;
  font-size: 14px; font-weight: 700; cursor: pointer; font-family: inherit;
  transition: background .15s;
}
.os-continue:hover { background: var(--primary-dark); }
.os-continue:disabled { background: #93c5fd; cursor: not-allowed; }

/* ── Typing indicator ──────────────────────────────────────────────────────── */

.typing-indicator {
  display: flex; gap: 5px; padding: 12px 15px;
  background: var(--white); border-radius: var(--radius); border-bottom-left-radius: 5px;
  width: fit-content; box-shadow: var(--shadow-sm);
}
.dot { width: 7px; height: 7px; background: var(--primary); border-radius: 50%; animation: bounce 1.3s infinite ease-in-out; }
.dot:nth-child(2) { animation-delay: .18s; }
.dot:nth-child(3) { animation-delay: .36s; }

/* ── Quick buttons ─────────────────────────────────────────────────────────── */

.quick-buttons {
  padding: 6px 14px 10px; display: flex; flex-wrap: wrap; gap: 7px;
  flex-shrink: 0; min-height: 10px; max-height: 170px; overflow-y: auto;
}
.quick-btn {
  background: var(--white); border: 2px solid var(--primary); color: var(--primary);
  border-radius: 24px; padding: 11px 16px; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: background .18s, color .18s; font-family: inherit;
  min-height: 40px; touch-action: manipulation;
}
.quick-btn:hover  { background: var(--primary); color: #fff; }
.quick-btn:active { transform: scale(.97); }
.quick-btn-back {
  border-color: #cbd5e1; color: #64748b; background: #f8fafc;
}
.quick-btn-back:hover { background: #e2e8f0; color: #334155; }

/* ── Input area ────────────────────────────────────────────────────────────── */

.input-area {
  display: flex; gap: 9px; align-items: center;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: var(--white);
  border-top: 1px solid var(--border); flex-shrink: 0;
}
.input-area input {
  flex: 1; border: 2px solid var(--border); border-radius: 24px;
  padding: 9px 16px; font-size: 16px; font-family: inherit; outline: none;
  transition: border-color .2s; background: #f8fafc;
}
.input-area input:focus { border-color: var(--primary); background: #fff; }
.input-area input:disabled { background: #f1f5f9; color: #94a3b8; cursor: not-allowed; }
.eye-btn {
  width: 44px; height: 44px; border-radius: 50%; border: none;
  background: transparent; color: #94a3b8;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; transition: color .2s;
  padding: 0; touch-action: manipulation;
}
.eye-btn:hover { color: var(--primary); }
.send-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--primary); border: none; color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; transition: background .2s, transform .1s;
  touch-action: manipulation;
}
.send-btn:hover  { background: var(--primary-dark); }
.send-btn:active { transform: scale(.94); }
.send-btn:disabled { background: #cbd5e1; cursor: not-allowed; }

/* ── Toast ─────────────────────────────────────────────────────────────────── */

.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(10px);
  background: #1e293b; color: #fff; border-radius: 24px;
  padding: 8px 20px; font-size: 13px; font-weight: 500;
  opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; z-index: 999;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Animations ────────────────────────────────────────────────────────────── */

@keyframes fadeSlideIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

.chat-container::-webkit-scrollbar       { width: 4px; }
.chat-container::-webkit-scrollbar-track { background: transparent; }
.chat-container::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* ── Inbox button ──────────────────────────────────────────────────────────── */

.btn-inbox {
  position: relative; background: rgba(255,255,255,.15); border: none; border-radius: 8px;
  color: #fff; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; transition: background .2s; touch-action: manipulation;
}
.btn-inbox:hover { background: rgba(255,255,255,.28); }
.inbox-badge {
  position: absolute; top: -5px; right: -5px;
  background: #ef4444; color: #fff; border-radius: 10px;
  font-size: 10px; font-weight: 700; min-width: 17px; height: 17px;
  display: flex; align-items: center; justify-content: center; padding: 0 3px;
  border: 2px solid var(--primary);
}

/* ── Inbox panel ───────────────────────────────────────────────────────────── */

.inbox-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50;
}
.inbox-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(400px, 100vw);
  background: #fff; z-index: 51; display: flex; flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,.15);
  animation: slideInRight .22s ease;
}
@keyframes slideInRight { from { transform: translateX(100%); } to { transform: translateX(0); } }
.inbox-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(16px + env(safe-area-inset-top)) 20px 16px; background: var(--primary); color: #fff; flex-shrink: 0;
}
.inbox-title { font-size: 16px; font-weight: 700; }
.inbox-close {
  background: rgba(255,255,255,.2); border: none; color: #fff; width: 30px; height: 30px;
  border-radius: 6px; cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center;
}
.inbox-close:hover { background: rgba(255,255,255,.35); }
.inbox-body { flex: 1; overflow-y: auto; padding: 0; }
.inbox-loading { padding: 32px; text-align: center; color: var(--text-muted); font-size: 14px; }
.inbox-empty   { padding: 40px 20px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* ── Inbox conversation threads ────────────────────────────────────────────── */

.inbox-thread {
  border-bottom: 1px solid var(--border); cursor: pointer;
  transition: background .15s;
}
.inbox-thread:hover { background: #f8fafc; }
.inbox-thread-header {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px 6px;
}
.inbox-thread-name { font-weight: 700; font-size: 14px; flex: 1; }
.inbox-thread-date { font-size: 11px; color: var(--text-muted); }
.inbox-thread-apt  { font-size: 12px; color: var(--text-muted); padding: 0 16px 4px; }
.inbox-thread-preview { font-size: 13px; color: #475569; padding: 0 16px 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-thread.unread .inbox-thread-name { color: var(--primary); }
.inbox-thread.unread .inbox-thread-preview { color: #1e293b; font-weight: 500; }
.inbox-unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); flex-shrink: 0; }

/* ── Inbox message view ────────────────────────────────────────────────────── */

.inbox-msg-view { display: flex; flex-direction: column; height: 100%; }
.inbox-msg-back {
  display: flex; align-items: center; gap: 8px; padding: 12px 16px;
  border-bottom: 1px solid var(--border); cursor: pointer; font-size: 13px;
  color: var(--primary); font-weight: 600; flex-shrink: 0;
}
.inbox-msg-back:hover { background: #f8fafc; }
.inbox-msg-apt-info {
  padding: 10px 16px; background: #f8fafc; border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted); flex-shrink: 0;
}
.inbox-messages-list { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.inbox-msg-bubble {
  max-width: 85%; padding: 10px 14px; border-radius: 14px;
  font-size: 13px; line-height: 1.5;
}
.inbox-msg-bubble.from-doctor   { background: var(--primary); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.inbox-msg-bubble.from-patient  { background: #f1f5f9; color: #1e293b; align-self: flex-start; border-bottom-left-radius: 4px; }
.inbox-msg-meta { font-size: 11px; margin-top: 4px; opacity: .7; }
.inbox-msg-compose {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); flex-shrink: 0; display: flex; flex-direction: column; gap: 8px;
}
.inbox-compose-textarea {
  width: 100%; border: 1.5px solid var(--border); border-radius: 10px;
  padding: 9px 12px; font-size: 16px; font-family: inherit; resize: none; outline: none;
  transition: border-color .2s;
}
.inbox-compose-textarea:focus { border-color: var(--primary); }
.inbox-send-btn {
  align-self: flex-end; background: var(--primary); color: #fff; border: none;
  border-radius: 8px; padding: 8px 18px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.inbox-send-btn:hover { background: var(--primary-dark); }
.inbox-send-btn:disabled { opacity: .5; cursor: default; }

/* ── Cancel with message form ──────────────────────────────────────────────── */

.cancel-msg-form {
  background: #fff; border: 1.5px solid var(--border); border-radius: 12px;
  padding: 16px; margin-top: 10px; display: flex; flex-direction: column; gap: 10px;
}
.cancel-msg-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.cancel-msg-textarea {
  width: 100%; border: 1.5px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 16px; font-family: inherit; resize: vertical; outline: none;
  min-height: 80px; transition: border-color .2s;
}
.cancel-msg-textarea:focus { border-color: var(--danger); }
.cancel-msg-actions { display: flex; gap: 8px; }
.cancel-msg-confirm { flex: 1; background: #dc2626; color: #fff; border: none; border-radius: 8px; padding: 10px 14px; font-size: 13px; font-weight: 700; cursor: pointer; min-height: 42px; }
.cancel-msg-cancel  { flex: 1; background: #f1f5f9; color: #64748b; border: none; border-radius: 8px; padding: 10px 14px; font-size: 13px; font-weight: 600; cursor: pointer; min-height: 42px; }

/* ── Mobile (≤480px) ───────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  .header { padding-left: 14px; padding-right: 14px; }
  .header-content { gap: 8px; }
  .bot-avatar { width: 38px; height: 38px; font-size: 19px; }
  .bot-info h1 { font-size: 14.5px; }

  /* Los botones de acción (admin, mensajes, cambiar modo, salir) no entran
     en una sola fila junto al avatar+título en pantallas angostas: se
     esconden detrás de un botón "⋮" y se muestran como desplegable
     de ancho completo, para no robarle alto a la pantalla del chat. */
  .header-actions {
    display: none;
    position: absolute;
    top: 100%; left: 0; right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    background: var(--primary-dark);
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    box-shadow: 0 8px 20px rgba(0,0,0,.25);
    z-index: 20;
  }
  .header-actions.open { display: flex; }
  .header-actions > * {
    width: 100%;
    justify-content: center;
  }
  .admin-link, .btn-inbox { height: 40px; }
  .btn-switch-mode, .btn-logout { padding: 11px 10px; font-size: 13px; }

  .btn-more-menu {
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border-radius: 8px; flex-shrink: 0;
    background: rgba(255,255,255,.15); border: none; color: #fff;
    font-size: 20px; line-height: 1; cursor: pointer; touch-action: manipulation;
  }
  .btn-more-menu.open, .btn-more-menu:active { background: rgba(255,255,255,.32); }

  /* La franja de guardia se apila para no desbordar en pantallas angostas */
  .guardia-strip { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 12px; }
  .guardia-strip .guardia-input { width: 100%; }
  .guardia-strip .btn-guardia-on,
  .guardia-strip .btn-guardia-off { width: 100%; padding: 11px 13px; }

  .chat-container { padding: 12px 10px; }
  .message { max-width: 92%; }
  .bubble { padding: 10px 13px; font-size: 14px; }

  .quick-buttons { padding: 6px 10px 10px; }
  .input-area { padding-left: 10px; padding-right: 10px; }

  .slot-grid { grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); }

  .prof-card, .svc-card, .status-card, .calendar-wrap { padding: 12px 13px; }
  .svc-card-price { font-size: 16px; }

  .inbox-panel { width: 100vw; }
}
