/* ============================================================
   SmartFisio — Componentes UI (estilo iOS)
   ============================================================ */

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: var(--fs-base); font-weight: 600;
  transition: transform var(--t-fast) var(--ease-spring),
              background var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease),
              opacity var(--t-fast) var(--ease);
  user-select: none; white-space: nowrap;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn svg { width: 17px; height: 17px; flex-shrink: 0; }

.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--primary-soft); color: var(--primary-soft-text); }
.btn-secondary:hover { filter: brightness(0.97); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-outline { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--surface-hover); }
.btn-sm { padding: 6px 12px; font-size: var(--fs-sm); border-radius: var(--radius-sm); }
.btn-lg { padding: 14px 26px; font-size: var(--fs-md); border-radius: var(--radius-lg); }
.btn-block { width: 100%; }

.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: var(--radius-md);
  color: var(--text-2);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease-spring);
}
.btn-icon:hover { background: var(--surface-hover); color: var(--text); }
.btn-icon:active { transform: scale(0.9); }
.btn-icon svg { width: 19px; height: 19px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--t-base) var(--ease), transform var(--t-base) var(--ease),
              background var(--t-base) var(--ease), border-color var(--t-base) var(--ease);
}
.card-pad { padding: var(--sp-5); }
.card-hover:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.card-header h3 { font-size: var(--fs-md); }
.card-body { padding: var(--sp-5); }

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.field > label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.field .hint { font-size: var(--fs-xs); color: var(--text-3); }
.field .error-msg { font-size: var(--fs-xs); color: var(--danger); font-weight: 500; }

.input, .select, .textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-sunken);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: var(--fs-base);
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; background: var(--surface);
  border-color: var(--primary); box-shadow: var(--shadow-focus);
}
.input.invalid, .select.invalid { border-color: var(--danger); }
.textarea { resize: vertical; min-height: 84px; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238E8E93' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 36px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
@media (max-width: 560px) { .form-row { grid-template-columns: 1fr; } }

/* Búsqueda */
.search-box { position: relative; }
.search-box svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--text-3); pointer-events: none;
}
.search-box .input { padding-left: 38px; }

/* ---------- Switch iOS ---------- */
.switch { position: relative; display: inline-block; width: 50px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--gray-300); border-radius: var(--radius-full);
  transition: background var(--t-base) var(--ease);
}
[data-theme="dark"] .switch .track { background: var(--gray-800); }
.switch .track::before {
  content: ""; position: absolute; height: 26px; width: 26px; left: 2px; top: 2px;
  background: #fff; border-radius: 50%;
  box-shadow: 0 2px 5px rgba(0,0,0,0.25);
  transition: transform var(--t-base) var(--ease-spring);
}
.switch input:checked + .track { background: var(--success); }
.switch input:checked + .track::before { transform: translateX(20px); }
.switch input:focus-visible + .track { box-shadow: var(--shadow-focus); }

/* ---------- Segmented control iOS ---------- */
.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--bg-sunken);
  border-radius: var(--radius-md);
}
.segmented button {
  padding: 6px 16px;
  border-radius: 9px;
  font-size: var(--fs-sm); font-weight: 600; color: var(--text-2);
  transition: all var(--t-fast) var(--ease);
  white-space: nowrap;
}
.segmented button:hover { color: var(--text); }
.segmented button.active {
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ---------- Badges de estado ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: var(--fs-xs); font-weight: 600;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-pendiente   { background: var(--warning-soft); color: var(--warning); }
.badge-confirmada  { background: var(--success-soft); color: var(--success); }
.badge-completada  { background: var(--info-soft); color: var(--info); }
.badge-cancelada   { background: var(--danger-soft); color: var(--danger); }
.badge-no-show     { background: var(--purple-soft); color: var(--purple); }
.badge-neutral     { background: var(--bg-sunken); color: var(--text-2); }
.badge-primary     { background: var(--primary-soft); color: var(--primary-soft-text); }

/* ---------- Chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-full);
  background: var(--bg-sunken);
  border: 1px solid transparent;
  font-size: var(--fs-sm); font-weight: 600; color: var(--text-2);
  cursor: pointer;
  transition: all var(--t-fast) var(--ease);
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.active { background: var(--primary); color: #fff; }
.chip:active { transform: scale(0.95); }
.chip:disabled { opacity: 0.35; cursor: not-allowed; }
.eva-chip { padding: 7px 0; min-width: 32px; text-align: center; font-family: var(--font-mono); }

/* ---------- Avatar ---------- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 50%;
  font-size: var(--fs-sm); font-weight: 700; color: #fff;
  background: var(--primary);
  flex-shrink: 0; user-select: none;
}
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.avatar-lg { width: 56px; height: 56px; font-size: var(--fs-lg); }

/* ---------- Tabla ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
.table th {
  text-align: left; padding: 10px 16px;
  font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background var(--t-fast) var(--ease); }
.table tbody tr:hover { background: var(--surface-hover); }
.table tbody tr:last-child td { border-bottom: none; }
.table .row-actions { display: flex; gap: 2px; justify-content: flex-end; opacity: 0.55; transition: opacity var(--t-fast); }
.table tbody tr:hover .row-actions { opacity: 1; }

/* ---------- Lista agrupada estilo iOS ---------- */
.ios-list { background: var(--surface); border-radius: var(--radius-lg); border: 1px solid var(--border); overflow: hidden; }
.ios-list-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  transition: background var(--t-fast) var(--ease);
}
.ios-list-item:last-child { border-bottom: none; }
.ios-list-item.clickable { cursor: pointer; }
.ios-list-item.clickable:hover { background: var(--surface-hover); }

/* ---------- Modal / Sheet ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--overlay);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-5);
  animation: fadeIn var(--t-fast) var(--ease) both;
}
.modal {
  width: 100%; max-width: 560px; max-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
  background: var(--bg-elevated);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  animation: scaleIn var(--t-base) var(--ease-spring) both;
  overflow: hidden;
}
.modal-lg { max-width: 720px; }
.modal-sm { max-width: 420px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-head h3 { font-size: var(--fs-md); }
.modal-body { padding: var(--sp-5); overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
/* En móvil el modal se vuelve bottom-sheet */
@media (max-width: 640px) {
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%; max-height: 92vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    animation: slideUpSheet var(--t-slow) var(--ease-spring) both;
  }
  .modal::before {
    content: ""; display: block; width: 40px; height: 4px;
    background: var(--border-strong); border-radius: 4px;
    margin: 10px auto 0;
  }
}

/* ---------- Toasts ---------- */
.toast-zone {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 20px;
  background: var(--gray-900); color: #fff;
  border-radius: var(--radius-full);
  font-size: var(--fs-sm); font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn var(--t-base) var(--ease-spring) both;
  pointer-events: auto;
}
[data-theme="dark"] .toast { background: var(--gray-100); color: var(--gray-900); }
.toast.leaving { opacity: 0; transform: translateY(8px); transition: all var(--t-base) var(--ease); }
.toast svg { width: 16px; height: 16px; flex-shrink: 0; }
.toast-success svg { color: var(--success); }
.toast-error svg { color: var(--danger); }
.toast-info svg { color: var(--info); }
.toast-undo { padding-right: 8px; }
.toast-undo [data-undo] {
  margin-left: 4px; padding: 5px 12px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.16);
  color: inherit; font-weight: 700; font-size: var(--fs-xs);
  transition: background var(--t-fast) var(--ease);
  flex-shrink: 0;
}
[data-theme="dark"] .toast-undo [data-undo] { background: rgba(0, 0, 0, 0.1); }
.toast-undo [data-undo]:hover { background: rgba(255, 255, 255, 0.28); }
[data-theme="dark"] .toast-undo [data-undo]:hover { background: rgba(0, 0, 0, 0.18); }

/* ---------- Banner de instalación (PWA) ---------- */
.install-banner {
  position: fixed; left: 16px; bottom: 16px; z-index: 190;
  display: flex; align-items: center; gap: 12px;
  max-width: 380px; padding: 14px 14px 14px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: toastIn var(--t-base) var(--ease-spring) both;
}
.install-banner-icon {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700)); color: #fff;
}
.install-banner-icon svg { width: 22px; height: 22px; }
.install-banner-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.install-banner-copy strong { font-size: var(--fs-sm); }
.install-banner-copy span { font-size: var(--fs-xs); color: var(--text-3); }
.install-banner [data-dismiss] { flex-shrink: 0; width: 28px; height: 28px; }
@media (max-width: 480px) {
  .install-banner { left: 12px; right: 12px; max-width: none; }
  .install-banner-copy span { display: none; }
}

/* ---------- Empty state ---------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-3); padding: var(--sp-12) var(--sp-5);
  text-align: center; color: var(--text-2);
}
.empty-state svg { width: 44px; height: 44px; color: var(--text-3); }
.empty-state h4 { color: var(--text); font-size: var(--fs-md); }
.empty-state p { font-size: var(--fs-sm); max-width: 320px; }

/* ---------- Tooltips de conflicto / alertas inline ---------- */
.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  margin-bottom: var(--sp-4);
}
.alert svg { width: 17px; height: 17px; flex-shrink: 0; margin-top: 1px; }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-warning { background: var(--warning-soft); color: #B36D00; }
[data-theme="dark"] .alert-warning { color: var(--warning); }
.alert-info { background: var(--info-soft); color: var(--info); }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert ul { padding-left: 16px; list-style: disc; }

/* ---------- Dot de color (recursos) ---------- */
.color-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; display: inline-block; }

/* ---------- Stat tiles ---------- */
.stat-tile { display: flex; flex-direction: column; gap: 2px; padding: var(--sp-5); }
.stat-tile .stat-label {
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--text-3);
}
.stat-tile .stat-value { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.03em; }
.stat-tile .stat-sub { font-size: var(--fs-sm); color: var(--text-2); }

/* ---------- Barra de progreso ---------- */
.progress { height: 6px; background: var(--bg-sunken); border-radius: var(--radius-full); overflow: hidden; }
.progress > span {
  display: block; height: 100%; background: var(--primary); border-radius: var(--radius-full);
  transition: width var(--t-slow) var(--ease);
}

/* ---------- Paginación de fechas (strip) ---------- */
.date-strip { display: flex; gap: var(--sp-2); overflow-x: auto; padding: 2px; scroll-snap-type: x mandatory; }
.date-strip::-webkit-scrollbar { display: none; }
.date-pill {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  min-width: 58px; padding: 9px 6px;
  border-radius: var(--radius-lg);
  background: var(--surface); border: 1px solid var(--border);
  cursor: pointer; scroll-snap-align: start;
  transition: all var(--t-fast) var(--ease);
}
.date-pill:hover { border-color: var(--primary); }
.date-pill .dow { font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; color: var(--text-3); }
.date-pill .day { font-size: var(--fs-md); font-weight: 700; }
.date-pill.active { background: var(--primary); border-color: var(--primary); }
.date-pill.active .dow, .date-pill.active .day { color: #fff; }
.date-pill:disabled { opacity: 0.35; cursor: not-allowed; }
.date-pill:active { transform: scale(0.95); }

/* ---------- Command palette (⌘K) ---------- */
.palette-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: var(--overlay);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 12vh 20px 20px;
  animation: fadeIn var(--t-fast) var(--ease) both;
}
.palette {
  width: 100%; max-width: 580px; max-height: 70vh;
  display: flex; flex-direction: column;
  background: var(--bg-elevated);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: scaleIn var(--t-fast) var(--ease-spring) both;
}
.palette-input-row {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  color: var(--text-3);
}
.palette-input-row svg { width: 19px; height: 19px; flex-shrink: 0; }
.palette-input {
  flex: 1; border: none; background: none; outline: none;
  font-size: var(--fs-md); color: var(--text);
}
.palette-input::placeholder { color: var(--text-3); }
.palette-kbd, .shortcut-key {
  font-family: var(--font-mono); font-size: var(--fs-xs); font-weight: 600;
  padding: 3px 8px; border-radius: var(--radius-sm);
  background: var(--bg-sunken); color: var(--text-2);
  border: 1px solid var(--border); flex-shrink: 0;
}
.palette-results { overflow-y: auto; padding: 8px; }
.palette-group + .palette-group { margin-top: 4px; }
.palette-group-label {
  padding: 8px 10px 4px;
  font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-3);
}
.palette-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 9px 10px;
  border-radius: var(--radius-md);
  text-align: left;
  transition: background var(--t-fast) var(--ease);
}
.palette-item-icon {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: var(--radius-sm);
  background: var(--bg-sunken); color: var(--text-2); flex-shrink: 0;
}
.palette-item-icon svg { width: 16px; height: 16px; }
.palette-item.active .palette-item-icon { background: var(--primary); color: #fff; }
.palette-item.active { background: var(--primary-soft); }
.palette-item-body { min-width: 0; display: flex; flex-direction: column; }
.palette-item-title { font-size: var(--fs-sm); font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-item-title mark { background: var(--warning-soft); color: inherit; border-radius: 3px; padding: 0 1px; }
.palette-item-subtitle { font-size: var(--fs-xs); color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 40px 20px; color: var(--text-3); }
.palette-empty svg { width: 30px; height: 30px; }
.palette-empty p { font-size: var(--fs-sm); }

@media (max-width: 640px) {
  .palette-overlay { padding: 5vh 10px 10px; }
  .palette { max-height: 80vh; }
}

/* ---------- Mapa corporal ---------- */
.bodymap { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); }
.bodymap-toggle { align-self: center; }
.bodymap-svg-wrap { width: 100%; max-width: 220px; }
.bodymap-figure { width: 100%; height: auto; display: block; overflow: visible; }
.bodymap-hint { text-align: center; }

.bm-region {
  fill: var(--bg-sunken);
  stroke: var(--border-strong);
  stroke-width: 1.5;
  transition: fill var(--t-fast) var(--ease), stroke var(--t-fast) var(--ease), transform var(--t-fast) var(--ease-spring);
  transform-box: fill-box;
  transform-origin: center;
}
.bm-region:hover { stroke: var(--primary); cursor: pointer; }
.bm-region.is-on { fill: var(--primary); stroke: var(--primary-hover); transform: scale(1.04); }
.bm-region.has-freq {
  fill: color-mix(in srgb, var(--primary) var(--fill-pct, 40%), var(--bg-sunken));
  stroke: color-mix(in srgb, var(--primary) var(--fill-pct, 40%), var(--border-strong));
}
