/* ============================================================
   ARMONIA ESPACIO DE PSICOLOGIA - Estilos Principales
   Color corporativo: #704d9b
   ============================================================ */

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

:root {
  --primary:        #704d9b;
  --primary-dark:   #5a3a80;
  --primary-light:  #9370bb;
  --primary-pale:   #f0eaf7;
  --primary-subtle: #e8dff4;
  --accent:         #c9a227;
  --accent-light:   #f5e6b0;

  --bg:             #f7f5fb;
  --surface:        #ffffff;
  --surface2:       #f3eff9;
  --border:         #e2d9ef;
  --border-strong:  #c4b3db;

  --text-primary:   #1a1025;
  --text-secondary: #5b4d6e;
  --text-muted:     #9589a8;

  --success:        #2a9d6f;
  --success-bg:     #e6f7f1;
  --warning:        #d97706;
  --warning-bg:     #fef3cd;
  --danger:         #c0392b;
  --danger-bg:      #fdecea;
  --info:           #2563eb;
  --info-bg:        #eff6ff;

  --sidebar-w:      260px;
  --header-h:       64px;
  --radius:         10px;
  --radius-lg:      16px;
  --radius-xl:      24px;
  --shadow:         0 2px 12px rgba(112,77,155,.10);
  --shadow-md:      0 4px 24px rgba(112,77,155,.15);
  --shadow-lg:      0 8px 40px rgba(112,77,155,.20);
  --transition:     .2s cubic-bezier(.4,0,.2,1);
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* ---- TIPOGRAFÍA ---- */
h1, h2, h3 { font-family: 'Lora', serif; font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p  { line-height: 1.7; }

/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
  box-shadow: var(--shadow);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 18px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo img {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: contain;
}

.sidebar-logo-text {
  font-family: 'Lora', serif;
  font-size: .82rem;
  font-weight: 600;
  color: var(--primary);
  line-height: 1.2;
  letter-spacing: .01em;
}

.sidebar-section {
  padding: 16px 12px 4px;
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-muted);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  margin: 2px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: .9rem;
  font-weight: 400;
  text-decoration: none;
  transition: all var(--transition);
  position: relative;
}

.nav-item:hover {
  background: var(--primary-pale);
  color: var(--primary);
}

.nav-item.active {
  background: var(--primary-pale);
  color: var(--primary);
  font-weight: 600;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: -8px; top: 20%; bottom: 20%;
  width: 3px;
  background: var(--primary);
  border-radius: 2px;
}

.nav-item svg, .nav-item i {
  width: 18px; height: 18px; min-width: 18px;
  opacity: .8;
}

.nav-item .badge-count {
  margin-left: auto;
  background: var(--primary);
  color: white;
  font-size: .68rem;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--primary-pale);
  cursor: pointer;
  transition: background var(--transition);
}

.user-card:hover { background: var(--primary-subtle); }

.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem;
  font-weight: 600;
  flex-shrink: 0;
}

.user-name { font-size: .85rem; font-weight: 600; color: var(--text-primary); }
.user-role { font-size: .72rem; color: var(--text-muted); }

/* ---- MAIN CONTENT ---- */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- TOP HEADER ---- */
.top-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 4px rgba(112,77,155,.06);
}

.header-title { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); }
.header-breadcrumb { font-size: .8rem; color: var(--text-muted); }

.header-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.header-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 14px;
  font-size: .875rem;
  color: var(--text-secondary);
  min-width: 220px;
  cursor: text;
  transition: border var(--transition);
}

.header-search:focus-within {
  border-color: var(--primary-light);
  background: var(--surface);
}

.header-search input {
  border: none; background: transparent; outline: none;
  font-size: .875rem; color: var(--text-primary); width: 100%;
  font-family: 'DM Sans', sans-serif;
}

/* ---- PAGE CONTENT ---- */
.page-content {
  padding: 28px 28px;
  flex: 1;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title { font-size: 1.5rem; color: var(--text-primary); margin-bottom: 2px; }
.page-subtitle { font-size: .875rem; color: var(--text-muted); font-family: 'DM Sans', sans-serif; }

/* ============================================================
   COMPONENTES UI
   ============================================================ */

/* ---- BOTONES ---- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: .875rem; font-weight: 500;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer; border: none;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dark); box-shadow: var(--shadow); transform: translateY(-1px); }

.btn-secondary {
  background: var(--primary-pale);
  color: var(--primary);
  border: 1px solid var(--primary-subtle);
}
.btn-secondary:hover { background: var(--primary-subtle); }

.btn-ghost {
  background: transparent; color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); color: var(--text-primary); }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #a93226; }

.btn-success { background: var(--success); color: white; }

.btn-sm { padding: 5px 12px; font-size: .8rem; }
.btn-icon { padding: 8px; border-radius: var(--radius); }

/* ---- CARDS ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}

.card-title { font-size: 1rem; font-weight: 600; color: var(--text-primary); font-family: 'Lora', serif; }
.card-body { padding: 22px; }

/* ---- STATS CARDS ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
  transition: box-shadow var(--transition);
}

.stat-card:hover { box-shadow: var(--shadow-md); }

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--primary);
}

.stat-card.accent::before { background: var(--accent); }
.stat-card.success::before { background: var(--success); }
.stat-card.info::before { background: var(--info); }

.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); line-height: 1; margin-bottom: 4px; }
.stat-label { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-icon {
  position: absolute; top: 16px; right: 16px;
  width: 40px; height: 40px;
  background: var(--primary-pale);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--primary); font-size: 1.1rem;
}

/* ---- TABLAS ---- */
.table-wrap { overflow-x: auto; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

.data-table thead th {
  padding: 11px 14px;
  text-align: left;
  font-weight: 600;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.data-table tbody tr:hover { background: var(--primary-pale); }
.data-table tbody tr:last-child { border-bottom: none; }

.data-table tbody td {
  padding: 12px 14px;
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table .actions { display: flex; gap: 6px; }

/* ---- BADGES / PILLS ---- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 20px;
  font-size: .75rem; font-weight: 600;
}

.badge-active    { background: var(--success-bg); color: var(--success); }
.badge-inactive  { background: var(--danger-bg);  color: var(--danger); }
.badge-suspended { background: var(--warning-bg); color: var(--warning); }
.badge-derived   { background: var(--info-bg);    color: var(--info); }

.badge-admin    { background: var(--primary-pale); color: var(--primary); }
.badge-therapist{ background: var(--accent-light); color: #7a5a00; }
.badge-admin-staff { background: var(--bg); color: var(--text-secondary); border: 1px solid var(--border); }

/* ---- FORMULARIOS ---- */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block; margin-bottom: 6px;
  font-size: .825rem; font-weight: 500; color: var(--text-secondary);
}
.form-label .required { color: var(--danger); }

.form-control {
  width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: 'DM Sans', sans-serif;
  color: var(--text-primary);
  background: var(--surface);
  transition: border var(--transition), box-shadow var(--transition);
  outline: none;
  line-height: 1.5;
}

.form-control:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(112,77,155,.1);
}

.form-control:disabled {
  background: var(--bg);
  color: var(--text-muted);
  cursor: not-allowed;
}

textarea.form-control { min-height: 100px; resize: vertical; }

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

.form-section-title {
  font-family: 'Lora', serif;
  font-size: 1rem; font-weight: 600;
  color: var(--primary);
  margin: 28px 0 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}

/* ---- MODAL ---- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 10, 35, .45);
  backdrop-filter: blur(2px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn .15s ease;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  width: 100%; max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp .2s ease;
}

.modal-lg { max-width: 980px; }
.modal-sm { max-width: 460px; }

.modal-header {
  padding: 22px 26px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; justify-content: space-between;
  position: sticky; top: 0; background: var(--surface);
  z-index: 1;
}

.modal-header h2 { font-size: 1.2rem; }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 1.4rem; line-height: 1;
  padding: 4px; border-radius: 6px;
  transition: color var(--transition), background var(--transition);
}
.modal-close:hover { color: var(--text-primary); background: var(--bg); }

.modal-body { padding: 22px 26px; }
.modal-footer {
  padding: 16px 26px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
  position: sticky; bottom: 0; background: var(--surface);
}

/* ---- TABS ---- */
.tabs { border-bottom: 1px solid var(--border); margin-bottom: 24px; display: flex; gap: 0; }

.tab-btn {
  padding: 12px 20px;
  font-size: .875rem; font-weight: 500;
  color: var(--text-muted);
  background: none; border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  font-family: 'DM Sans', sans-serif;
  display: flex; align-items: center; gap: 7px;
}

.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- ALERTS ---- */
.alert {
  padding: 12px 16px; border-radius: var(--radius);
  font-size: .875rem; display: flex; align-items: flex-start; gap: 10px;
  margin-bottom: 16px;
}
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #a8dfc9; }
.alert-danger   { background: var(--danger-bg);  color: var(--danger);  border: 1px solid #f5bcb6; }
.alert-warning  { background: var(--warning-bg); color: var(--warning); border: 1px solid #fcd887; }
.alert-info     { background: var(--info-bg);    color: var(--info);    border: 1px solid #bcd3f8; }

/* ---- LOADER / SPINNER ---- */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

/* ---- EMPTY STATE ---- */
.empty-state {
  text-align: center; padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 12px; opacity: .4; }
.empty-state p { font-size: .9rem; margin-top: 6px; }

/* ---- PAGINATION ---- */
.pagination {
  display: flex; align-items: center; gap: 4px;
  padding: 16px 22px; border-top: 1px solid var(--border);
  justify-content: space-between; flex-wrap: wrap; gap: 12px;
}
.pagination-info { font-size: .8rem; color: var(--text-muted); }
.pagination-btns { display: flex; gap: 4px; }
.page-btn {
  min-width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-secondary); font-size: .825rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all var(--transition); font-family: 'DM Sans', sans-serif;
}
.page-btn:hover, .page-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---- LOGIN PAGE ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #4a2d70 0%, #704d9b 50%, #9b6fcc 100%);
}

.login-left {
  background: linear-gradient(145deg, #4a2d70 0%, #704d9b 50%, #9b6fcc 100%);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px;
  position: relative; overflow: hidden;
}

.login-left::before {
  content: '';
  position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.login-brand {
  text-align: center; z-index: 1;
}

.login-brand img { width: 80px; margin-bottom: 20px; filter: drop-shadow(0 4px 12px rgba(0,0,0,.3)); }
.login-brand-name { font-family: 'Lora', serif; font-size: 1.6rem; color: white; line-height: 1.2; font-weight: 600; }
.login-brand-sub  { color: rgba(255,255,255,.7); font-size: .9rem; margin-top: 8px; }

.login-decor {
  margin-top: 48px; z-index: 1;
  text-align: center; color: rgba(255,255,255,.5); font-size: .8rem;
}

.login-right {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 48px 40px;
  background: var(--bg);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 64px rgba(0,0,0,.25);
  width: 100%; max-width: 460px;
}

.login-form-wrap { width: 100%; max-width: 400px; }
.login-title { font-size: 1.6rem; margin-bottom: 6px; }
.login-subtitle { color: var(--text-muted); font-size: .875rem; margin-bottom: 32px; }

/* ---- FICHA PACIENTE ---- */
.patient-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex; align-items: center; gap: 20px;
  margin-bottom: 24px;
}

.patient-avatar {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--primary);
  color: white; font-size: 1.4rem; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.patient-info h2 { margin-bottom: 4px; }
.patient-meta { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.patient-meta-item { font-size: .8rem; color: var(--text-muted); display: flex; align-items: center; gap: 4px; }

/* ---- TOAST NOTIFICACIONES ---- */
#toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 9999; display: flex; flex-direction: column; gap: 8px;
}

.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
  font-size: .875rem; box-shadow: var(--shadow-md);
  display: flex; align-items: center; gap: 10px;
  min-width: 280px; max-width: 380px;
  animation: slideInRight .25s ease;
}

.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--danger);  }
.toast-info    { border-left: 3px solid var(--primary);  }

/* ---- FILTROS ---- */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 16px;
}

.search-input-wrap {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 14px;
  flex: 1; min-width: 220px; max-width: 360px;
}
.search-input-wrap:focus-within { border-color: var(--primary-light); }
.search-input-wrap input { border: none; outline: none; background: transparent; font-family: 'DM Sans', sans-serif; font-size: .875rem; width: 100%; color: var(--text-primary); }

/* ---- RESPONSIVE ---- */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .form-grid-3 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
  .login-wrap { padding: 20px; }
  .login-right { padding: 32px 24px; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .page-content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ---- ANIMACIONES ---- */
@keyframes fadeIn    { from { opacity: 0; }    to { opacity: 1; } }
@keyframes slideUp   { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes slideInRight { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes spin      { to { transform: rotate(360deg); } }

/* ---- UTILIDADES ---- */
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.text-primary-color { color: var(--primary); }
.fw-600      { font-weight: 600; }
.mt-4        { margin-top: 4px; }
.mt-8        { margin-top: 8px; }
.mt-16       { margin-top: 16px; }
.mt-24       { margin-top: 24px; }
.mb-16       { margin-bottom: 16px; }
.mb-24       { margin-bottom: 24px; }
.gap-8       { gap: 8px; }
.flex        { display: flex; }
.items-center{ align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap   { flex-wrap: wrap; }
.d-none      { display: none !important; }
.w-100       { width: 100%; }

/* Decorative dot badge for session number */
.session-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary-pale); color: var(--primary);
  font-size: .78rem; font-weight: 700;
}

/* Print styles */
@media print {
  .sidebar, .top-header, .btn, .actions, #toast-container { display: none !important; }
  .main-content { margin-left: 0; }
  .card { border: 1px solid #ccc; }
}
