/* ==========================================================================
   Componentes reutilizables
   ========================================================================== */

/* ---------- Tarjetas ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 20px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head > * { min-width: 0; }
.card-head h2, .card-head h3 { flex: 1; }
.card-body { padding: 20px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-lg { display: flex; flex-direction: column; gap: 24px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 800px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 520px) { .grid-4 { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Indicadores ---------- */
.stat { display: flex; align-items: center; gap: 16px; padding: 18px 20px; }
.stat .ico { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.stat .num { font-size: 1.9rem; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.stat .lbl { color: var(--muted); font-size: 0.88rem; margin-top: 4px; }
.tone-teal { background: var(--brand-100); color: var(--brand-700); }
.tone-blue { background: var(--blue-bg); color: var(--blue); }
.tone-amber { background: var(--amber-bg); color: var(--amber); }
.tone-red { background: var(--red-bg); color: var(--red); }
.tone-green { background: var(--green-bg); color: var(--green); }
.tone-slate { background: var(--slate-bg); color: var(--slate); }
.tone-purple { background: var(--purple-bg); color: var(--purple); }

/* ---------- Insignias y chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; line-height: 1.4; white-space: nowrap; background: var(--slate-bg); color: var(--slate); }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge.confirmada { background: var(--green-bg); color: #166534; }
.badge.atendida { background: var(--blue-bg); color: #1e40af; }
.badge.cancelada { background: var(--red-bg); color: #991b1b; }
.badge.no_asistio { background: #cbd5e1; color: #1e293b; }
.badge.pendiente { background: var(--amber-bg); color: #92400e; }
.badge.en_proceso { background: var(--blue-bg); color: #1e40af; }
.badge.realizado { background: var(--green-bg); color: #166534; }
.badge.brand { background: var(--brand-100); color: var(--brand-800); }
.badge.warn { background: var(--amber-bg); color: #92400e; }
.badge.danger { background: var(--red-bg); color: #991b1b; }
.badge.ok { background: var(--green-bg); color: #166534; }
.dot-status { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot-status.confirmada { background: var(--green); }
.dot-status.atendida { background: var(--blue); }
.dot-status.cancelada { background: var(--red); }
.dot-status.no_asistio { background: #1e293b; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 14px; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface); color: var(--text-2); font-size: 0.86rem; font-weight: 500; cursor: pointer; user-select: none; }
.chip:hover { border-color: var(--muted); }
.chip.active { background: var(--brand-700); border-color: var(--brand-700); color: #fff; }
.chip .n { font-size: 0.75rem; opacity: 0.8; }

.segmented { display: inline-flex; padding: 4px; gap: 4px; border-radius: 10px; background: var(--slate-bg); max-width: 100%; overflow-x: auto; }
.segmented button { min-height: 36px; padding: 0 16px; border: 0; border-radius: 8px; background: transparent; color: var(--text-2); font-weight: 600; font-size: 0.9rem; cursor: pointer; white-space: nowrap; }
.segmented button:hover { background: rgba(255, 255, 255, 0.6); }
.segmented button.active { background: var(--surface); color: var(--brand-800); box-shadow: var(--shadow-sm); }

/* ---------- Pestañas del paciente ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 0 2px; margin-bottom: 20px; border-bottom: 1px solid var(--border); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; display: inline-flex; align-items: center; gap: 8px; padding: 12px 14px; color: var(--muted); font-weight: 600; font-size: 0.9rem; border-bottom: 3px solid transparent; margin-bottom: -1px; text-decoration: none; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand-700); border-bottom-color: var(--brand-600); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th { padding: 11px 16px; text-align: left; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--brand-50); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions.wrap { white-space: normal; min-width: 150px; }
.cell-title { font-weight: 600; }
.cell-sub { font-size: 0.82rem; color: var(--muted); }

/* Tablas que pasan a tarjetas en pantallas pequeñas */
@media (max-width: 720px) {
  .table.responsive thead { display: none; }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .table.responsive tr:last-child { border-bottom: 0; }
  .table.responsive td { padding: 3px 0; border: 0; display: flex; gap: 12px; justify-content: space-between; align-items: baseline; }
  .table.responsive td::before { content: attr(data-label); flex: none; color: var(--muted); font-size: 0.78rem; font-weight: 600; }
  .table.responsive td.no-label::before { display: none; }
  .table.responsive td.actions { justify-content: flex-end; padding-top: 8px; }
  .table.responsive .num { text-align: right; }
}

/* ---------- Listas de registros ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 14px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item.clickable { cursor: pointer; }
.list-item.clickable:hover { background: var(--brand-50); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .time { flex: none; width: 74px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 0.9rem; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Datos en dos columnas ---------- */
.dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px 24px; margin: 0; }
.dl dt { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.dl dd { margin: 0; font-weight: 500; word-break: break-word; }
.dl dd.empty { color: #94a3b8; font-weight: 400; }
.pre { white-space: pre-wrap; word-break: break-word; }

/* ---------- Avisos ---------- */
.alert { display: flex; gap: 12px; padding: 12px 16px; border-radius: var(--radius-sm); border: 1px solid; font-size: 0.92rem; }
.alert svg { flex: none; margin-top: 2px; }
.alert.info { background: var(--blue-bg); border-color: #bfdbfe; color: #1e3a8a; }
.alert.warn { background: var(--amber-bg); border-color: #fde68a; color: #78350f; }
.alert.danger { background: var(--red-bg); border-color: #fecaca; color: #7f1d1d; }
.alert.ok { background: var(--green-bg); border-color: #bbf7d0; color: #14532d; }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 44px 20px; color: var(--muted); }
.empty .ico { width: 60px; height: 60px; border-radius: 50%; background: var(--slate-bg); color: var(--muted); display: grid; place-items: center; margin-bottom: 4px; }
.empty h3 { color: var(--text-2); }
.empty p { max-width: 380px; margin: 0 0 8px; }

/* ---------- Ventanas (modales) ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 160; display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow-y: auto; background: rgba(15, 23, 42, 0.55); animation: fade 0.15s ease; }
.modal { width: 100%; max-width: 640px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); animation: pop 0.18s ease; display: flex; flex-direction: column; margin: auto 0; }
.modal.wide { max-width: 860px; }
.modal.narrow { max-width: 460px; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; font-size: 1.15rem; }
.modal-body { padding: 22px; }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 16px 16px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@media (max-width: 640px) {
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { max-width: none; border-radius: 18px 18px 0 0; margin: 0; max-height: 96vh; overflow-y: auto; }
  .modal-foot { position: sticky; bottom: 0; border-radius: 0; }
  .modal-foot .btn { flex: 1 1 auto; }
}

/* ---------- Avisos emergentes ---------- */
.toasts { position: fixed; z-index: 200; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; max-width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; align-items: flex-start; gap: 10px; padding: 12px 16px; border-radius: 10px; background: #0f172a; color: #fff; box-shadow: var(--shadow-lg); animation: pop 0.2s ease; font-size: 0.92rem; }
.toast.success svg { color: #4ade80; }
.toast.error { background: #7f1d1d; }
.toast.error svg { color: #fecaca; }
.toast svg { flex: none; margin-top: 1px; }
@media (max-width: 640px) { .toasts { left: 16px; right: 16px; bottom: 16px; max-width: none; } }

/* ---------- Buscador de pacientes (autocompletar) ---------- */
.picker { position: relative; }
.picker-list { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); max-height: 280px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow); }
.picker-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; background: none; text-align: left; cursor: pointer; }
.picker-item:hover, .picker-item.focus { background: var(--brand-50); }
.picker-item .exp { font-family: var(--mono); font-size: 0.78rem; color: var(--brand-700); font-weight: 600; flex: none; }
.picker-empty { padding: 12px; color: var(--muted); font-size: 0.9rem; }
.picked { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--brand-200); border-radius: var(--radius-sm); background: var(--brand-50); min-height: 42px; }
.picked .exp { font-family: var(--mono); font-size: 0.8rem; font-weight: 700; color: var(--brand-700); }
.picked .grow { flex: 1; min-width: 0; }

/* ---------- Selector de archivos ---------- */
.dropzone { display: flex; flex-direction: column; gap: 12px; padding: 16px; border: 2px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2); }
.dropzone.drag { border-color: var(--brand-600); background: var(--brand-50); }
.dropzone .buttons { display: flex; flex-wrap: wrap; gap: 10px; }
.picked-files { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.picked-file { position: relative; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); overflow: hidden; }
.picked-file .thumb { aspect-ratio: 4 / 3; display: grid; place-items: center; background: var(--slate-bg); color: var(--muted); overflow: hidden; }
.picked-file .thumb img { width: 100%; height: 100%; object-fit: cover; }
.picked-file .meta { padding: 6px 8px; font-size: 0.75rem; line-height: 1.3; }
.picked-file .meta b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picked-file .rm { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border: 0; border-radius: 50%; background: rgba(15, 23, 42, 0.75); color: #fff; cursor: pointer; display: grid; place-items: center; }
.picked-file .pg { position: absolute; top: 4px; left: 4px; padding: 1px 8px; border-radius: 999px; background: rgba(15, 23, 42, 0.75); color: #fff; font-size: 0.7rem; font-weight: 700; }

.progress { height: 8px; border-radius: 999px; background: var(--slate-bg); overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: var(--brand-600); transition: width 0.15s; }

/* ---------- Otros ---------- */
.divider { height: 1px; background: var(--border); margin: 20px 0; border: 0; }
.section-title { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font-size: 1.02rem; }
.section-title svg { color: var(--brand-600); }
.kbd { font-family: var(--mono); background: var(--slate-bg); padding: 1px 6px; border-radius: 4px; font-size: 0.85em; }
.credentials { padding: 16px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px dashed var(--border-strong); font-family: var(--mono); font-size: 0.92rem; line-height: 1.9; word-break: break-all; }
.credentials b { font-family: var(--font); color: var(--muted); font-weight: 600; display: inline-block; min-width: 110px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--brand-700); cursor: pointer; font-weight: 600; }
.link-btn:hover { text-decoration: underline; }
.load-more { display: flex; justify-content: center; padding: 16px; }
