:root {
  --bg: #F7F5FB;
  --white: #FFFFFF;
  --primary: #623D86;
  --primary-hover: #4E2F6C;
  --primary-light: #DDBFF1;
  --primary-lighter: #F2E9FA;
  --text-dark: #1E2333;
  --text-gray: #8992A6;
  --border: #E7E2EF;
  --danger: #E24A4A;
  --radius: 12px;
}

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

body {
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text-dark);
}

button, input {
  font-family: inherit;
}

a { text-decoration: none; color: inherit; }

/* ---------- Login ---------- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 4px 24px rgba(30, 35, 51, 0.06);
}

.login-logo {
  margin-bottom: 28px;
}

.login-logo-img {
  display: block;
  height: 40px;
  width: auto;
  object-fit: contain;
  margin-bottom: 8px;
}

.login-title {
  font-size: 15px;
  color: var(--text-gray);
  margin-bottom: 24px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-gray);
  margin-bottom: 6px;
}

.field input,
.field textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-dark);
  font-family: inherit;
  resize: vertical;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.readonly-copy {
  display: flex;
  gap: 8px;
}
.readonly-copy input {
  flex: 1;
  background: #FAFAFC;
  color: var(--text-gray);
}

.copy-btn {
  flex-shrink: 0;
  background: var(--primary-lighter);
  color: var(--primary);
  border: none;
  padding: 0 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.copy-btn:hover { background: var(--primary-light); }
.copy-btn.copied { background: #DDF3E4; color: #2E9E5B; }

.btn-primary {
  width: 100%;
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: 8px;
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}

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

.login-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin-top: 12px;
}

.login-hint {
  margin-top: 20px;
  font-size: 12px;
  color: var(--text-gray);
  line-height: 1.5;
}

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

.sidebar {
  width: 240px;
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
  margin-bottom: 28px;
}

.brand-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-name { font-weight: 700; font-size: 14px; line-height: 1.3; }
.brand-sub { font-size: 12px; color: var(--primary); }

.nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-dark);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.nav-item.active {
  background: var(--primary-lighter);
  color: var(--primary);
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.avatar-lg { width: 64px; height: 64px; font-size: 20px; }

.sidebar-user-name { font-size: 13px; font-weight: 600; }
.sidebar-user-role { font-size: 12px; color: var(--text-gray); }

.logout-link {
  margin-left: auto;
  color: var(--text-gray);
  cursor: pointer;
  display: flex;
  align-items: center;
}
.logout-link svg { width: 16px; height: 16px; }
.logout-link:hover { color: var(--danger); }

.mobile-topbar { display: none; }

.main {
  flex: 1;
  padding: 32px 40px;
}

.view { display: none; }
.view.active { display: block; }

/* ---------- Header ---------- */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header-left { display: flex; align-items: center; gap: 14px; }

.greeting-title { font-size: 20px; font-weight: 700; }
.greeting-sub { font-size: 14px; color: var(--text-gray); margin-top: 2px; }

.bell-btn {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--white);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.bell-btn svg { width: 18px; height: 18px; color: var(--text-dark); }
.bell-dot {
  position: absolute;
  top: 8px;
  right: 9px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--white);
}

/* ---------- Tabs ---------- */
.tabs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.tabs {
  display: inline-flex;
  gap: 4px;
}

.refresh-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--white);
  border: 1px solid var(--border);
  color: var(--text-dark);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.refresh-btn svg { width: 14px; height: 14px; }
.refresh-btn:hover { background: var(--primary-lighter); color: var(--primary); }
.refresh-btn:disabled { opacity: 0.6; cursor: default; }
.refresh-btn.spinning svg { animation: spin 0.7s linear infinite; }

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

.tab-btn {
  border: none;
  background: var(--white);
  color: var(--text-gray);
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--primary);
  color: var(--white);
}

/* ---------- Table ---------- */
.card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow-x: auto;
}

.card table { min-width: 560px; }
.card.compact table { min-width: 0; }

table { width: 100%; border-collapse: collapse; }

thead th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-gray);
  font-weight: 600;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

tbody tr:last-child td { border-bottom: none; }

.patient-cell { display: flex; align-items: center; gap: 12px; }
.patient-name { font-weight: 600; }
.patient-sub { font-size: 12px; color: var(--text-gray); }

.time-cell { font-weight: 700; }
.date-cell { color: var(--text-gray); }

.call-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-lighter);
  color: var(--primary);
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.call-btn svg { width: 14px; height: 14px; }
.call-btn:hover { background: var(--primary-light); }

.empty-state {
  padding: 40px 24px;
  text-align: center;
  color: var(--text-gray);
  font-size: 14px;
}

.error-state { color: var(--danger); }

.retry-btn {
  display: inline;
  background: none;
  border: none;
  padding: 0;
  margin-left: 6px;
  color: var(--primary);
  font-weight: 600;
  font-size: 14px;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- Configuración ---------- */
.config-card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 20px;
}

.config-card h3 {
  font-size: 15px;
  margin-bottom: 4px;
}

.config-card .config-desc {
  font-size: 13px;
  color: var(--text-gray);
  margin-bottom: 18px;
}

.profile-row { display: flex; align-items: center; gap: 16px; }
.profile-avatar-wrap { position: relative; }
.lock-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #B7BECD;
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--white);
}
.lock-badge svg { width: 11px; height: 11px; }

.profile-name { font-weight: 700; font-size: 15px; }
.profile-role { font-size: 13px; color: var(--text-gray); }
.profile-note { font-size: 12px; color: var(--text-gray); font-style: italic; margin-top: 4px; }

.day-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 12px;
}
.day-row:last-child { margin-bottom: 0; }

.day-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.day-name { font-weight: 700; font-size: 14px; }

.day-shifts { display: flex; gap: 32px; flex-wrap: wrap; }
.shift-group { display: flex; align-items: center; gap: 8px; }
.shift-label { font-size: 13px; color: var(--text-gray); width: 52px; }

.time-input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text-dark);
}
.time-input:disabled { color: var(--text-gray); background: #FAFBFD; }

.shift-sep { color: var(--text-gray); }

/* toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #D6DAE5;
  border-radius: 999px;
  transition: 0.15s;
}
.slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: var(--white);
  border-radius: 50%;
  transition: 0.15s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.config-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}

.btn-save {
  background: var(--primary);
  color: var(--white);
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-save:hover { background: var(--primary-hover); }
.btn-save:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-save:disabled:hover { background: var(--primary); }

.config-error {
  background: #FCEAEA;
  border: 1px solid #F3C6C6;
  color: var(--danger);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 14px;
  margin-bottom: 20px;
}

.save-status {
  font-size: 13px;
  color: var(--text-gray);
}
.save-status.ok { color: #2E9E5B; }
.save-status.error { color: var(--danger); }

/* ---------- Estadísticas ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}

.stat-label {
  font-size: 13px;
  color: var(--text-gray);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-dark);
}
.stat-value.positive { color: #2E9E5B; }
.stat-value.negative { color: var(--danger); }

.stat-sub {
  font-size: 11px;
  color: var(--text-gray);
  margin-top: 4px;
}

.chart-empty {
  padding: 24px 0;
  text-align: center;
  color: var(--text-gray);
  font-size: 14px;
}

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
  .app-shell {
    flex-direction: column;
  }

  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
  }
  .mobile-topbar .brand { margin-bottom: 0; }
  .mobile-topbar .logout-link svg { width: 20px; height: 20px; }

  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 64px;
    flex-direction: row;
    padding: 0;
    border-right: none;
    border-top: 1px solid var(--border);
    z-index: 30;
  }

  .sidebar .brand,
  .sidebar .sidebar-footer {
    display: none;
  }

  .nav {
    flex: 1;
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    gap: 0;
  }

  .nav-item {
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    width: auto;
    padding: 8px 18px;
  }

  .nav-label { display: none; }

  .main {
    padding: 16px;
    padding-bottom: 88px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ---------- Panel administrador ---------- */
.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.status-badge.activo { background: #DDF3E4; color: #2E9E5B; }
.status-badge.inactivo { background: #F1F1F4; color: var(--text-gray); }

.row-actions { display: flex; gap: 8px; }

.action-btn {
  background: var(--primary-lighter);
  color: var(--primary);
  border: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.action-btn:hover { background: var(--primary-light); }
.action-btn.danger { background: #FCEAEA; color: var(--danger); }
.action-btn.danger:hover { background: #F8D3D3; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 20, 45, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h3 { font-size: 18px; }

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--text-gray);
  cursor: pointer;
}
.modal-close:hover { color: var(--text-dark); }
