/* ===== Variables ===== */
:root {
  --primary: #e63946;
  --primary-dark: #c1121f;
  --primary-light: #ff6b6b;
  --secondary: #1d3557;
  --accent: #457b9d;
  --success: #2a9d8f;
  --warning: #e9c46a;
  --danger: #e63946;
  --bg: #f8f9fa;
  --card: #ffffff;
  --text: #212529;
  --text-muted: #6c757d;
  --border: #dee2e6;
  --sidebar-w: 260px;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
  --transition: all 0.25s ease;
}

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

body {
  font-family: 'Poppins', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* ===== Login ===== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1d3557 0%, #e63946 100%);
  padding: 20px;
}

.login-card {
  background: white;
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
  text-align: center;
  margin-bottom: 30px;
}

.logo-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

.login-logo h1 {
  font-size: 32px;
  font-weight: 700;
  color: var(--secondary);
}

.login-logo h1 .red { color: var(--primary); }

.login-logo p {
  color: var(--text-muted);
  font-size: 14px;
}

.login-hint {
  margin-top: 20px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--secondary);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.logo-mini {
  font-size: 28px;
  background: white;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.sidebar-header small {
  opacity: 0.7;
  font-size: 11px;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  border-radius: 10px;
  margin-bottom: 4px;
  transition: var(--transition);
  font-size: 14px;
  font-weight: 500;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255,255,255,0.12);
  color: white;
}

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

.nav-item i {
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.doctor-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.doctor-info i {
  font-size: 20px;
  opacity: 0.8;
}

.doctor-info small {
  display: block;
  opacity: 0.6;
  font-size: 11px;
}

.btn-logout {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  font-size: 16px;
  padding: 8px;
  border-radius: 8px;
  transition: var(--transition);
}

.btn-logout:hover {
  background: rgba(255,255,255,0.1);
  color: white;
}

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

.topbar {
  background: white;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  position: sticky;
  top: 0;
  z-index: 50;
}

.btn-menu {
  display: none;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--secondary);
}

.topbar h1 {
  font-size: 20px;
  font-weight: 600;
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.fecha {
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== Views ===== */
.views {
  padding: 24px 28px;
  flex: 1;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Stats ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: white;
}

.stat-icon.blue { background: #457b9d; }
.stat-icon.green { background: #2a9d8f; }
.stat-icon.orange { background: #e9c46a; color: #333; }
.stat-icon.red { background: #e63946; }

.stat-card h3 {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
}

.stat-card p {
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== Cards ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body {
  padding: 16px 20px;
}

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 220px;
  position: relative;
}

.search-box i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.search-box input {
  width: 100%;
  padding: 10px 14px 10px 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(230,57,70,0.15);
}

/* ===== Tables ===== */
.table-container {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th {
  background: #f1f3f5;
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  white-space: nowrap;
}

.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background: #f8f9fa;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-activo { background: #d8f3dc; color: #2d6a4f; }
.badge-inactivo { background: #f8d7da; color: #842029; }
.badge-pendiente { background: #fff3cd; color: #664d03; }
.badge-completada { background: #d1e7dd; color: #0f5132; }
.badge-cancelada { background: #f8d7da; color: #842029; }

.actions {
  display: flex;
  gap: 6px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: #f1f3f5;
  cursor: pointer;
  color: var(--secondary);
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

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

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

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

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

.btn-outline {
  background: white;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

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

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.btn-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ===== Forms ===== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(230,57,70,0.12);
}

.form-group small {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

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

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal-content {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.modal-content.modal-lg {
  max-width: 680px;
}

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

.modal-header h3 {
  font-size: 17px;
  font-weight: 600;
}

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

.modal-body,
.modal form {
  padding: 20px 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 8px;
}

/* ===== Servicios / Tratamientos ===== */
.servicios-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}

.servicio-card {
  background: white;
  border-radius: var(--radius);
  padding: 24px 20px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: var(--transition);
  border: 2px solid transparent;
}

.servicio-card:hover {
  border-color: var(--primary);
  transform: translateY(-3px);
}

.servicio-card .icon {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin: 0 auto 14px;
}

.servicio-card h4 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
}

.servicio-card p {
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== ChatBot ===== */
.chatbot-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  min-height: 520px;
}

.chatbot-info {
  background: white;
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.chatbot-info h3 {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chatbot-info > p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.info-box {
  background: #f1f5f9;
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 20px;
  font-size: 13px;
}

.info-box h4 {
  margin-bottom: 8px;
  font-size: 14px;
}

.info-box ol {
  padding-left: 18px;
}

.info-box a {
  color: var(--primary);
}

.chat-window {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 14px 18px;
  background: var(--secondary);
  color: white;
  font-weight: 500;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header .badge {
  margin-left: auto;
  background: rgba(255,255,255,0.2);
  color: white;
}

.chat-messages {
  flex: 1;
  padding: 18px;
  overflow-y: auto;
  background: #f8f9fa;
  min-height: 320px;
  max-height: 400px;
}

.message {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  animation: fadeIn 0.3s ease;
}

.message.user {
  flex-direction: row-reverse;
}

.message .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.message .bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.45;
}

.message.bot .bubble {
  background: white;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.message.user .bubble {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-input {
  display: flex;
  padding: 12px;
  border-top: 1px solid var(--border);
  gap: 8px;
}

.chat-input input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-family: inherit;
  font-size: 13px;
}

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

.chat-input button {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== Config ===== */
.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 24px;
}

/* ===== Lista simple ===== */
.lista-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.lista-item:last-child {
  border-bottom: none;
}

.lista-item .avatar-sm {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}

.lista-item .info {
  flex: 1;
}

.lista-item .info strong {
  display: block;
  font-size: 14px;
}

.lista-item .info small {
  color: var(--text-muted);
  font-size: 12px;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .btn-menu {
    display: block;
  }
  .dashboard-grid,
  .chatbot-layout {
    grid-template-columns: 1fr;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .views {
    padding: 16px;
  }
  .topbar {
    padding: 12px 16px;
  }
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Botpress container */
.botpress-box {
  margin-top: 24px;
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.botpress-box h4 {
  margin-bottom: 12px;
  font-size: 15px;
}
.botpress-box iframe {
  background: #f8f9fa;
}

/* Login hint multi-user */
.login-hint p {
  margin: 4px 0;
  font-size: 12px;
}
