/* ============================================================
   ClinicaApp — styles.css
   Paleta: #522566 #7A3A8E #AD74C3 #EADFF0 #F8EDFB
   Tipografía: Fraunces (display) + DM Sans (cuerpo)
   ============================================================ */

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --color-primary:    #522566;
  --color-secondary:  #7A3A8E;
  --color-accent:     #AD74C3;
  --color-accent-light: #EADFF0;
  --color-bg:         #F8EDFB;
  --color-surface:    #FFFFFF;
  --color-border:     #E2D3EE;
  --color-text:       #2A1535;
  --color-text-muted: #8B6EA0;
  --color-danger:     #C0392B;
  --color-success:    #1E8449;
  --color-warning:    #D4AC0D;

  --sidebar-w:        250px;
  --header-h:         72px;
  --radius-sm:        6px;
  --radius-md:        12px;
  --radius-lg:        18px;
  --shadow-sm:        0 2px 8px rgba(82,37,102,.08);
  --shadow-md:        0 6px 24px rgba(82,37,102,.13);
  --shadow-lg:        0 16px 48px rgba(82,37,102,.18);

  --transition:       .22s cubic-bezier(.4,0,.2,1);

  --font-display: 'Fraunces', Georgia, serif;
  --font-body:    'DM Sans', system-ui, sans-serif;
}

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

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

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select { font-family: inherit; }

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--color-primary);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform var(--transition);
  overflow: hidden;
}

/* Decoración interior */
.sidebar::before {
  content: '';
  position: absolute;
  top: -80px; right: -80px;
  width: 220px; height: 220px;
  background: var(--color-secondary);
  border-radius: 50%;
  opacity: .35;
  pointer-events: none;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 28px 24px 24px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}

.sidebar__logo {
  font-size: 1.5rem;
  color: var(--color-accent);
  line-height: 1;
}

.sidebar__name {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  color: #fff;
  letter-spacing: -.01em;
}

.sidebar__name em {
  font-style: normal;
  color: var(--color-accent);
}

.sidebar__links {
  list-style: none;
  flex: 1;
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
  color: rgba(255,255,255,.72);
  transition: background var(--transition), color var(--transition);
}

.sidebar__link:hover {
  background: rgba(255,255,255,.10);
  color: #fff;
}

.sidebar__link.active {
  background: rgba(255,255,255,.15);
  color: #fff;
  font-weight: 600;
}

.sidebar__icon {
  font-size: 1rem;
  color: var(--color-accent);
  flex-shrink: 0;
}

.sidebar__footer {
  padding: 18px 24px;
  font-size: .72rem;
  color: rgba(255,255,255,.35);
  border-top: 1px solid rgba(255,255,255,.08);
}

/* ── Hamburger (móvil) ──────────────────────────────────────── */
.hamburger {
  display: none;
  position: fixed;
  top: 16px; left: 16px;
  z-index: 300;
  background: var(--color-primary);
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  flex-direction: column;
  gap: 5px;
}

.hamburger span {
  display: block;
  width: 20px; height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: transform var(--transition), opacity var(--transition);
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 190;
  opacity: 0;
  transition: opacity var(--transition);
}

.overlay.visible { opacity: 1; }

/* ── Main content ───────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px 36px;
  min-height: 100vh;
  position: relative;
}

/* ── Page header ────────────────────────────────────────────── */
.page-header {
  margin-bottom: 28px;
}

.page-header__inner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.page-title {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-primary);
  letter-spacing: -.03em;
  line-height: 1.1;
}

.page-subtitle {
  font-size: .9rem;
  color: var(--color-text-muted);
  margin-top: 4px;
}

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
  gap: 8px;
}

.card__title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-primary);
}

/* ── Stats grid ─────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 18px;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.stat-card::after {
  content: '';
  position: absolute;
  bottom: -20px; right: -20px;
  width: 80px; height: 80px;
  border-radius: 50%;
  background: var(--color-accent-light);
  opacity: .5;
}

.stat-card--accent { border-top: 3px solid var(--color-accent); }
.stat-card--light  { border-top: 3px solid var(--color-secondary); }
.stat-card--soft   { border-top: 3px solid var(--color-primary); }

.stat-card__icon {
  font-size: 1.4rem;
  color: var(--color-accent);
}

.stat-card__value {
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1;
}

.stat-card__label {
  font-size: .8rem;
  color: var(--color-text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ── Tabla ──────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
}

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

.table thead tr {
  background: var(--color-accent-light);
}

.table th {
  padding: 13px 20px;
  text-align: left;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--color-secondary);
  white-space: nowrap;
}

.table td {
  padding: 13px 20px;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  vertical-align: middle;
}

.table__row {
  transition: background var(--transition);
}

.table__row:hover {
  background: rgba(173,116,195,.06);
}

.table__row:last-child td {
  border-bottom: none;
}

.table__empty {
  text-align: center;
  color: var(--color-text-muted);
  padding: 48px !important;
  font-size: .9rem;
}

.td--name { font-weight: 500; }

.td--actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  background: var(--color-accent-light);
  color: var(--color-primary);
  font-size: .75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.badge--count {
  background: var(--color-primary);
  color: #fff;
  font-size: .78rem;
}

/* ── Botones ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 22px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 600;
  border: 2px solid transparent;
  transition: background var(--transition), color var(--transition),
              transform var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn--primary {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 4px 14px rgba(82,37,102,.3);
}

.btn--primary:hover {
  background: var(--color-secondary);
  box-shadow: 0 6px 20px rgba(82,37,102,.4);
}

.btn--secondary {
  background: var(--color-accent);
  color: #fff;
}

.btn--secondary:hover {
  background: var(--color-secondary);
}

.btn--ghost {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-border);
}

.btn--ghost:hover {
  background: var(--color-accent-light);
  border-color: var(--color-accent);
}

.btn--danger {
  background: var(--color-danger);
  color: #fff;
  border-color: transparent;
}

.btn--danger:hover { background: #a93226; }

.btn--sm {
  padding: 6px 14px;
  font-size: .82rem;
}

/* Botones icono (editar / eliminar en tabla) */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: .95rem;
  color: var(--color-text-muted);
  transition: all var(--transition);
}

.btn-icon--edit:hover  { background: var(--color-accent-light); color: var(--color-primary); border-color: var(--color-accent); }
.btn-icon--delete:hover { background: #fdecea; color: var(--color-danger); border-color: var(--color-danger); }

/* ── Inputs ──────────────────────────────────────────────────── */
.input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  color: var(--color-text);
  background: var(--color-surface);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(173,116,195,.18);
}

.input::placeholder { color: var(--color-text-muted); opacity: .7; }

.input-file {
  font-size: .88rem;
  color: var(--color-text-muted);
}

/* ── Filtros ─────────────────────────────────────────────────── */
.filters-card { padding: 20px 24px; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 160px;
}

.filter-group--actions {
  flex-direction: row;
  align-items: flex-end;
  flex: 0;
  gap: 8px;
}

.filter-label {
  font-size: .78rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ── CSV ─────────────────────────────────────────────────────── */
.csv-card { padding: 0; }

.csv-details summary { list-style: none; }
.csv-details summary::-webkit-details-marker { display: none; }

.csv-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  cursor: pointer;
  font-weight: 600;
  color: var(--color-secondary);
  font-size: .9rem;
  transition: background var(--transition);
}

.csv-summary:hover { background: var(--color-accent-light); }
.csv-toggle-icon   { font-size: 1.1rem; transition: transform var(--transition); }
.csv-details[open] .csv-toggle-icon { transform: rotate(180deg); }

.csv-body {
  padding: 20px 24px;
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.csv-hint {
  font-size: .84rem;
  color: var(--color-text-muted);
}

.csv-hint code {
  background: var(--color-accent-light);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  color: var(--color-primary);
}

.csv-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.csv-resultado {
  font-size: .88rem;
  padding: 12px 16px;
  background: var(--color-accent-light);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--color-accent);
}

.csv-ok  { color: var(--color-success); }
.csv-err { color: var(--color-danger); margin-top: 4px; }

/* ── Formulario ──────────────────────────────────────────────── */
.form-container {
  max-width: 680px;
}

.form-card { padding: 32px 36px; }

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

.form-group { display: flex; flex-direction: column; gap: 7px; }
.form-group--full { grid-column: 1 / -1; }

.form-label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.form-error {
  font-size: .78rem;
  color: var(--color-danger);
  min-height: 1em;
}

.input.input--error {
  border-color: var(--color-danger);
  box-shadow: 0 0 0 3px rgba(192,57,43,.12);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--color-border);
}

.form-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 48px;
  color: var(--color-text-muted);
  font-size: .9rem;
}

.form-error-global {
  text-align: center;
  color: var(--color-danger);
  padding: 32px;
}

/* ── Modal ───────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden { display: none; }

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(2px);
}

.modal__box {
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 36px 40px;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: modalIn .22s ease;
}

@keyframes modalIn {
  from { transform: scale(.92); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.modal__icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  color: var(--color-danger);
}

.modal__title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--color-primary);
  margin-bottom: 8px;
}

.modal__body {
  font-size: .9rem;
  color: var(--color-text-muted);
  margin-bottom: 24px;
  line-height: 1.5;
}

.modal__actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

/* ── Toasts ──────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 600;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--color-text);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: .88rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toastIn .28s ease;
  max-width: 340px;
}

@keyframes toastIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.toast--success { background: var(--color-success); }
.toast--error   { background: var(--color-danger); }
.toast--warning { background: var(--color-warning); color: #2c2c2c; }

.toast__icon { font-size: 1.1rem; flex-shrink: 0; }

/* ── Spinner ─────────────────────────────────────────────────── */
.spinner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(248,237,251,.6);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner-overlay.hidden { display: none; }

.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--color-accent-light);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── No resultados ───────────────────────────────────────────── */
.no-resultados {
  text-align: center;
  padding: 56px 24px;
  color: var(--color-text-muted);
}

.no-resultados.hidden { display: none; }

.no-resultados__icon {
  font-size: 2.5rem;
  color: var(--color-accent);
  display: block;
  margin-bottom: 12px;
}

/* ── Utilidades ──────────────────────────────────────────────── */
.hidden  { display: none !important; }
.mt-sm   { margin-top: 14px; }
.mt-lg   { margin-top: 24px; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .overlay { display: block; }
  .hamburger { display: flex; }
  .main-content {
    margin-left: 0;
    padding: 80px 20px 28px;
  }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr; }
  .form-grid  { grid-template-columns: 1fr; }
  .form-group--full { grid-column: auto; }
  .page-header__inner { flex-direction: column; align-items: flex-start; }
  .filters { flex-direction: column; }
  .filter-group { min-width: 100%; }
  .filter-group--actions { flex-direction: row; }
  .form-card { padding: 24px 20px; }
  .table th, .table td { padding: 10px 12px; }
}

/* ── Btn loading state ───────────────────────────────────────── */
.btn .btn__loading { display: none; }
.btn.is-loading .btn__text    { display: none; }
.btn.is-loading .btn__loading { display: inline; }
.btn.is-loading { opacity: .75; pointer-events: none; }
