@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=Fraunces:wght@400;600&display=swap');

:root {
  --bg:            #F7F5F2;
  --sidebar-bg:    #393c8a;
  --sidebar-hover: #3D2580;
  --primary:       #7C3AED;
  --primary-light: #EDE9FE;
  --primary-dark:  #6D28D9;
  --text:          #1F2937;
  --text-muted:    #6B7280;
  --white:         #FFFFFF;
  --success:       #10B981;
  --border:        #E5E0D8;
  --card-shadow:   0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(124,58,237,.06);
  --danger:        #EF4444;
}

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

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── SIDEBAR ── */
.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}
.sidebar::before {
  content: '';
  position: absolute;
  top: -60px; right: -60px;
  width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(124,58,237,.3) 0%, transparent 70%);
  pointer-events: none;
}
.sidebar-logo {
  padding: 28px 24px 24px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.logo-text {
  font-family: 'Fraunces', serif;
  font-size: 18px; font-weight: 600;
  color: #fff; letter-spacing: -0.3px;
}
.logo-text span { color: #A78BFA; }

.sidebar-user {
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.user-name { font-size: 13px; font-weight: 600; color: #fff; margin-bottom: 2px; }
.user-role {
  font-size: 11px; color: #A78BFA;
  text-transform: uppercase; letter-spacing: .8px; font-weight: 500;
}

.sidebar-nav { padding: 16px 12px; flex: 1; }

.nav-label {
  font-size: 10px; text-transform: uppercase;
  letter-spacing: 1px; color: rgba(255,255,255,.3);
  padding: 0 12px; margin-bottom: 8px; margin-top: 16px; font-weight: 500;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  cursor: pointer; transition: all .15s ease;
  margin-bottom: 2px; color: rgba(255,255,255,.65);
  font-size: 14px; font-weight: 400;
  text-decoration: none;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 500; }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.btn-footer {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 9px 12px; border-radius: 8px;
  border: none; background: rgba(255,255,255,.07);
  color: rgba(255,255,255,.6); font-size: 13px;
  cursor: pointer; font-family: 'DM Sans', sans-serif;
  transition: all .15s; margin-bottom: 6px; text-decoration: none;
}
.btn-footer:hover { background: rgba(255,255,255,.12); color: #fff; }
.btn-footer.danger { color: #FCA5A5; }
.btn-footer.danger:hover { background: rgba(239,68,68,.15); color: #FCA5A5; }

/* ── MAIN ── */
.main {
  flex: 1; overflow-y: auto;
  padding: 40px 48px;
}
.main::-webkit-scrollbar { width: 6px; }
.main::-webkit-scrollbar-track { background: transparent; }
.main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.page-header { margin-bottom: 32px; }
.page-title {
  font-family: 'Fraunces', serif;
  font-size: 28px; font-weight: 600;
  color: var(--text); letter-spacing: -.5px; margin-bottom: 4px;
}
.page-subtitle { font-size: 14px; color: var(--text-muted); }

/* ── TABS ── */
.tabs {
  display: flex; gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 32px;
}
.tab {
  padding: 10px 20px; font-size: 14px; font-weight: 500;
  color: var(--text-muted); cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: all .15s;
  background: none; border-top: none; border-left: none; border-right: none;
  font-family: 'DM Sans', sans-serif;
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── CARDS ── */
.card {
  background: var(--white); border-radius: 16px;
  padding: 32px; box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
}
.card-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 24px; }

/* ── GRUPOS GRID ── */
.grupos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px; max-width: 960px;
}
.grupo-card {
  background: var(--white); border-radius: 14px;
  padding: 20px 22px; border: 1.5px solid var(--border);
  box-shadow: var(--card-shadow); cursor: pointer; transition: all .2s;
}
.grupo-card:hover {
  border-color: var(--primary); transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(124,58,237,.12);
}
.grupo-card.selected { border-color: var(--primary); background: #FDFCFF; }

.grupo-header {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 12px;
}
.grupo-icon {
  width: 36px; height: 36px; background: var(--primary-light);
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
}
.grupo-badge {
  font-size: 11px; font-weight: 600;
  padding: 3px 8px; border-radius: 20px;
  background: #D1FAE5; color: #065F46;
}
.grupo-badge.inactivo { background: #FEE2E2; color: #991B1B; }

.grupo-nombre { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.grupo-desc { font-size: 12px; color: var(--text-muted); line-height: 1.5; margin-bottom: 14px; }
.grupo-meta { display: flex; align-items: center; gap: 14px; font-size: 12px; color: var(--text-muted); }
.grupo-meta span { display: flex; align-items: center; gap: 4px; }

.grupo-add-card {
  border: 2px dashed var(--border); background: transparent;
  box-shadow: none; display: flex; align-items: center;
  justify-content: center; flex-direction: column;
  gap: 8px; min-height: 160px; color: var(--text-muted);
  border-radius: 14px; cursor: pointer; transition: all .2s;
}
.grupo-add-card:hover { border-color: var(--primary); color: var(--primary); }

/* ── DETAIL PANEL ── */
.detail-panel {
  background: var(--white); border-radius: 16px;
  border: 1.5px solid var(--primary-light);
  box-shadow: var(--card-shadow);
  margin-top: 24px; max-width: 960px;
  overflow: hidden;
}
.detail-header {
  padding: 20px 28px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.detail-title { font-size: 17px; font-weight: 600; color: var(--text); }
.detail-body { padding: 24px 28px; }

/* ── PACIENTES TABLE ── */
.pacientes-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 20px; }
.pacientes-table th {
  text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-muted); padding: 0 12px 10px; border-bottom: 1px solid var(--border);
}
.pacientes-table td { padding: 12px; border-bottom: 1px solid var(--border); }
.pacientes-table tr:last-child td { border-bottom: none; }
.pacientes-table tr:hover td { background: var(--bg); }

.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.badge.activo  { background: #D1FAE5; color: #065F46; }
.badge.inactivo{ background: #FEE2E2; color: #991B1B; }

/* ── FORMS ── */
.form-group { margin-bottom: 20px; }
.form-label {
  display: block; font-size: 13px; font-weight: 500;
  color: var(--text); margin-bottom: 7px;
}
.form-label .optional { color: var(--text-muted); font-weight: 400; font-size: 12px; margin-left: 4px; }
.form-input {
  width: 100%; padding: 11px 14px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 14px; font-family: 'DM Sans', sans-serif;
  color: var(--text); background: var(--bg); transition: all .15s; outline: none;
}
.form-input:focus {
  border-color: var(--primary); background: #fff;
  box-shadow: 0 0 0 3px rgba(124,58,237,.08);
}
.form-input::placeholder { color: #C4BCAC; }
textarea.form-input { resize: vertical; min-height: 90px; }
select.form-input { cursor: pointer; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-radius: 10px;
  font-size: 14px; font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer; border: none; transition: all .15s;
}
.btn-primary {
  background: var(--primary); color: #fff;
}
.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(124,58,237,.3);
}
.btn-secondary {
  background: var(--white); color: var(--text);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 7px; }
.btn-ghost {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 6px 10px; border-radius: 7px; font-family: 'DM Sans', sans-serif;
  font-size: 13px; transition: all .15s;
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: #FEE2E2; color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

/* ── PREGUNTA BUILDER ── */
.pregunta-item {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
}
.pregunta-item input { flex: 1; }
.pregunta-remove {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 6px; border-radius: 6px; transition: all .15s;
}
.pregunta-remove:hover { background: #FEE2E2; color: var(--danger); }

/* ── SESIONES TABLE ── */
.sesiones-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.sesiones-table th {
  text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-muted); padding: 0 12px 12px; border-bottom: 1px solid var(--border);
}
.sesiones-table td {
  padding: 14px 12px; border-bottom: 1px solid var(--bg);
  vertical-align: middle;
}
.sesiones-table tr:hover td { background: #FDFCFF; }

/* ── HISTORIAL EDITOR ── */
.historial-card {
  background: var(--white); border-radius: 14px;
  border: 1.5px solid var(--border); margin-bottom: 12px;
  overflow: hidden; transition: all .2s;
}
.historial-card-header {
  padding: 16px 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
}
.historial-card-header:hover { background: var(--bg); }
.historial-card-body { padding: 20px; border-top: 1px solid var(--border); }
.historial-textarea {
  width: 100%; min-height: 200px; padding: 14px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-family: 'DM Sans', sans-serif; font-size: 14px;
  color: var(--text); background: var(--bg); resize: vertical; outline: none;
}
.historial-textarea:focus { border-color: var(--primary); background: #fff; }

/* ── NOTAS LOG ── */
.nota-entry {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.nota-entry:last-child { border-bottom: none; }
.nota-fecha { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; font-weight: 500; }
.nota-texto { font-size: 14px; color: var(--text); line-height: 1.6; }

/* ── ALERTS ── */
.alert {
  padding: 12px 16px; border-radius: 10px;
  font-size: 14px; margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}
.alert-success { background: #D1FAE5; color: #065F46; }
.alert-error   { background: #FEE2E2; color: #991B1B; }
.alert-info    { background: var(--primary-light); color: var(--primary-dark); }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--white); border-radius: 20px;
  padding: 36px; width: 100%; max-width: 480px;
  box-shadow: 0 24px 48px rgba(0,0,0,.15);
  transform: translateY(12px); transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-title { font-family: 'Fraunces', serif; font-size: 20px; font-weight: 600; margin-bottom: 24px; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }

/* ── TOKENS LIST ── */
.token-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.token-row:last-child { border-bottom: none; }
.token-link {
  font-size: 11px; color: var(--primary); word-break: break-all;
  max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── SPINNER ── */
.spinner {
  width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite;
  display: none;
}
.spinner.visible { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── LOGIN ── */
.login-wrap {
  min-height: 100vh; width: 100%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--white); border-radius: 20px;
  padding: 48px 40px; width: 400px;
  box-shadow: 0 8px 40px rgba(0,0,0,.08);
  border: 1px solid var(--border);
}
.login-logo {
  font-family: 'Fraunces', serif; font-size: 22px; font-weight: 600;
  color: var(--sidebar-bg); margin-bottom: 32px; text-align: center;
}
.login-logo span { color: var(--primary); }

/* ── FORMULARIO PÚBLICO ── */
.form-publ-wrap {
  min-height: 100vh; background: var(--bg);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 20px;
}
.form-publ-card {
  background: var(--white); border-radius: 20px;
  padding: 40px; width: 100%; max-width: 640px;
  box-shadow: var(--card-shadow); border: 1px solid var(--border);
}

/* ── TOAST ── */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  background: #1F2937; color: #fff;
  padding: 12px 20px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.2);
  transform: translateY(80px); opacity: 0;
  transition: all .3s ease; z-index: 200;
}
#toast.show { transform: translateY(0); opacity: 1; }
#toast.success { background: var(--success); }
#toast.error   { background: var(--danger); }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { padding: 24px 20px; }
  .grupos-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}
