/* ============================================================
   Dermalux · estilos base, tema y layout
   ============================================================ */
:root {
  --brand: #a855f7;
  --brand-2: #ec4899;
  --brand-grad: linear-gradient(135deg, #a855f7, #ec4899);

  --ok: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(0, 0, 0, .06);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .12);
  --sidebar-w: 250px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --transition: .2s ease;
}

/* ---- Tema claro ---- */
[data-theme="light"] {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --text: #1f2430;
  --text-soft: #6b7280;
  --border: #e8eaf1;
  --sidebar-bg: #ffffff;
  --hover: #f3f0fb;
}

/* ---- Tema oscuro ---- */
[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #181b24;
  --surface-2: #1f232e;
  --text: #e7e9f0;
  --text-soft: #9aa1b1;
  --border: #262a36;
  --sidebar-bg: #14161e;
  --hover: #22262f;
  --shadow: 0 4px 20px rgba(0, 0, 0, .3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ============================================================
   Layout
   ============================================================ */
.app { display: flex; min-height: 100vh; }

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin-left: var(--sidebar-w);
}

.view { padding: 24px; animation: fade .3s ease; }

@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  transition: transform var(--transition);
}

.sidebar__brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 20px 16px;
}
.sidebar__logo { width: 40px; height: 40px; border-radius: 12px; }
.sidebar__brandtext { display: flex; flex-direction: column; line-height: 1.2; }
.sidebar__brandtext strong { font-size: 17px; }
.sidebar__brandtext span { font-size: 11px; color: var(--text-soft); }

.sidebar__nav { flex: 1; overflow-y: auto; padding: 8px 12px; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-soft); margin: 16px 12px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-soft); font-weight: 500;
  transition: var(--transition); margin-bottom: 2px;
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: var(--brand-grad); color: #fff; box-shadow: 0 4px 14px rgba(168,85,247,.35); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar__footer { padding: 14px; border-top: 1px solid var(--border); }
.userchip { display: flex; align-items: center; gap: 10px; }
.userchip__avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--brand-grad); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.userchip__info { display: flex; flex-direction: column; line-height: 1.2; }
.userchip__info strong { font-size: 13px; }
.userchip__info span { font-size: 11px; color: var(--text-soft); }

/* ============================================================
   Topbar
   ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar__menu { display: none; background: none; border: none; font-size: 22px; color: var(--text); }
.topbar__title { font-size: 18px; font-weight: 700; white-space: nowrap; }
.topbar__search { flex: 1; max-width: 420px; }
.topbar__search input {
  width: 100%; padding: 9px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  outline: none; transition: var(--transition);
}
.topbar__search input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(168,85,247,.15); }
.topbar__actions { display: flex; gap: 8px; margin-left: auto; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-size: 17px; display: grid; place-items: center; transition: var(--transition);
}
.iconbtn:hover { background: var(--hover); transform: translateY(-1px); }

/* ============================================================
   Componentes reutilizables
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card__title { font-size: 15px; font-weight: 700; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-head h2 { font-size: 20px; }
.page-head p { color: var(--text-soft); font-size: 13px; }

.grid { display: grid; gap: 18px; }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-weight: 600; font-size: 13px; transition: var(--transition);
}
.btn:hover { background: var(--hover); }
.btn--primary { background: var(--brand-grad); color: #fff; border: none; box-shadow: 0 4px 14px rgba(168,85,247,.3); }
.btn--primary:hover { filter: brightness(1.05); }
.btn--sm { padding: 6px 10px; font-size: 12px; }
.btn--ghost { background: transparent; }
.btn--danger { color: var(--danger); border-color: rgba(239,68,68,.3); }

/* Badges de estado */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge--confirmada { color: var(--info); background: rgba(59,130,246,.12); }
.badge--pendiente { color: var(--warn); background: rgba(245,158,11,.12); }
.badge--en_atencion { color: #8b5cf6; background: rgba(139,92,246,.14); }
.badge--finalizada { color: var(--ok); background: rgba(16,185,129,.12); }
.badge--cancelada { color: var(--danger); background: rgba(239,68,68,.12); }
.badge--no_show { color: #6b7280; background: rgba(107,114,128,.15); }
.badge--pagado { color: var(--ok); background: rgba(16,185,129,.12); }
.badge--parcial { color: var(--warn); background: rgba(245,158,11,.12); }
.badge--activo { color: var(--ok); background: rgba(16,185,129,.12); }
.badge--inactivo { color: #6b7280; background: rgba(107,114,128,.15); }

/* Tablas */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; padding: 11px 14px; color: var(--text-soft);
  font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 1px solid var(--border);
}
table.data td { padding: 12px 14px; border-bottom: 1px solid var(--border); }
table.data tbody tr { transition: var(--transition); }
table.data tbody tr:hover { background: var(--surface-2); }

.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select {
  padding: 8px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text); outline: none;
}
.toolbar input:focus, .toolbar select:focus { border-color: var(--brand); }
.toolbar .spacer { flex: 1; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--brand-grad); color: #fff;
  display: inline-grid; place-items: center; font-weight: 700; font-size: 12px; flex-shrink: 0;
}
.cell-user { display: flex; align-items: center; gap: 10px; }

/* Formularios */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-soft); }
.field input, .field select, .field textarea {
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); outline: none;
  transition: var(--transition);
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(168,85,247,.13);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

/* Modal */
.modal-root { position: fixed; inset: 0; z-index: 60; display: none; }
.modal-root.open { display: block; }
.modal__overlay { position: absolute; inset: 0; background: rgba(0,0,0,.45); backdrop-filter: blur(2px); animation: fade .2s; }
.modal__box {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(640px, 92vw); max-height: 90vh; overflow-y: auto;
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg);
  padding: 24px; animation: pop .22s ease;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, -46%) scale(.97); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
.modal__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal__head h3 { font-size: 17px; }
.modal__close { background: none; border: none; font-size: 22px; color: var(--text-soft); }
.modal__foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* Toast */
.toast-root { position: fixed; bottom: 22px; right: 22px; z-index: 80; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--brand);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  padding: 13px 18px; min-width: 240px; animation: slidein .25s ease; font-size: 13px;
}
.toast--ok { border-left-color: var(--ok); }
.toast--warn { border-left-color: var(--warn); }
.toast--danger { border-left-color: var(--danger); }
@keyframes slidein { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }

.muted { color: var(--text-soft); }
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-soft); }
.empty-state .big { font-size: 42px; margin-bottom: 8px; }

/* ============================================================
   Pantalla de login
   ============================================================ */
.login-screen {
  min-height: 100vh; display: grid; place-items: center;
  background: var(--bg);
  background-image: radial-gradient(circle at 20% 20%, rgba(168,85,247,.12), transparent 45%),
                     radial-gradient(circle at 80% 80%, rgba(236,72,153,.12), transparent 45%);
}
.login-card {
  width: min(380px, 90vw); background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--shadow-lg); padding: 34px 30px; text-align: center;
}
.login-card__logo { width: 56px; height: 56px; border-radius: 16px; margin-bottom: 10px; }
.login-card h1 { font-size: 22px; margin-bottom: 2px; }
.login-card .field { text-align: left; margin-top: 16px; margin-bottom: 0; }
.login-card .btn { width: 100%; margin-top: 20px; justify-content: center; padding: 11px; }
.login-card__error {
  color: var(--danger); font-size: 12.5px; margin-top: 10px; min-height: 16px;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1100px) { .cols-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .main { margin-left: 0; }
  .topbar__menu { display: block; }
  /* El z-index de un hijo no puede superar al de otro árbol si el padre (.topbar)
     ya crea su propio contexto de apilamiento — hay que subir el del padre. */
  .topbar { z-index: 41; }
  .sidebar-backdrop.show { display: block; }
  .cols-3, .cols-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 39; /* debajo del sidebar (40) y del botón ☰ (45), encima de todo lo demás */
}
@media (max-width: 560px) {
  .cols-4 { grid-template-columns: 1fr; }
  .topbar__search { display: none; }
  .view { padding: 16px; }
}
