:root {
  --primary: #3B82F6;
  --primary-hover: #2563EB;
  --primary-light: #EFF6FF;
  --danger: #EF4444;
  --danger-light: #FEF2F2;
  --warning: #F59E0B;
  --warning-light: #FFFBEB;
  --success: #10B981;
  --success-light: #ECFDF5;
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --text: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;
  --border: #E2E8F0;
  --border-light: #F1F5F9;
  --sidebar-bg: #FFFFFF;
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1), 0 4px 10px rgba(0,0,0,0.06);
  --transition: 0.2s ease;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app-view {
  min-height: 100vh;
  background: var(--bg);
}

.bg-primary-light { background: var(--primary-light) !important; }
.bg-danger-light { background: var(--danger-light) !important; }
.bg-success-light { background: var(--success-light) !important; }

.fw-medium { font-weight: 500; }

.btn {
  border-radius: 8px;
  font-weight: 500;
  padding: 0.5rem 1.2rem;
  transition: all var(--transition);
}
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59,130,246,0.3);
}

.form-control {
  border-radius: 8px;
  border: 1.5px solid var(--border);
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.form-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.modal-content {
  border-radius: var(--radius-lg);
}

/* Topbar */
#topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: var(--topbar-h);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  z-index: 100;
  transition: left 0.3s ease;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-toggle {
  color: var(--text) !important;
  font-size: 1.2rem;
  padding: 4px 8px;
  text-decoration: none;
}
.topbar-toggle:hover {
  background: var(--border-light);
  border-radius: 8px;
}
.topbar-brand {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text);
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.btn-topbar-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.btn-topbar-icon:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-light);
  transform: translateY(-1px);
}

/* Sidebar */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: transform 0.3s ease;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  min-height: var(--topbar-h);
}
.sidebar-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  line-height: 1.2;
}
.sidebar-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0;
}
.sidebar-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: 0.75rem 1.25rem 0.4rem;
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0.6rem 1.25rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 450;
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
}
.sidebar-item:hover {
  background: var(--border-light);
  color: var(--text);
  border-left-color: var(--primary);
  padding-left: 1.5rem;
}
.sidebar-item.active {
  background: var(--primary-light);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 500;
}
.sidebar-item-icon {
  width: 20px;
  text-align: center;
  font-size: 0.95rem;
  flex-shrink: 0;
}
.sidebar-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  text-align: center;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 150;
}

/* Main content */
#main-content {
  margin-left: var(--sidebar-w);
  margin-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h));
  padding: 1.5rem;
  transition: margin-left 0.3s ease;
}

.welcome-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--topbar-h) - 3rem);
}
.welcome-title {
  font-weight: 700;
  font-size: 1.6rem;
  color: var(--text);
}

/* Toast */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  max-width: 420px;
  width: calc(100% - 40px);
}
.toast-custom {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: slideInRight 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  border-left: 4px solid;
  position: relative;
}
.toast-custom.removing {
  animation: slideOutRight 0.3s ease forwards;
}
@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOutRight {
  to { transform: translateX(120%); opacity: 0; }
}
.toast-success { background: var(--success-light); border-color: var(--success); }
.toast-error { background: var(--danger-light); border-color: var(--danger); }
.toast-info { background: var(--primary-light); border-color: var(--primary); }
.toast-warning { background: var(--warning-light); border-color: var(--warning); }
.toast-icon { font-size: 1.2rem; flex-shrink: 0; }
.toast-text { flex: 1; font-size: 0.9rem; color: var(--text); line-height: 1.4; }
.toast-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 2px 0 0 8px; font-size: 1.2rem;
  transition: color 0.15s; line-height: 1; flex-shrink: 0;
}
.toast-close:hover { color: var(--text); }

/* Panel card */
.panel-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

/* Custom table */
.table-custom thead th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  padding: 0.75rem 1rem;
  background: var(--bg);
  white-space: nowrap;
}
.table-custom tbody td {
  padding: 0.7rem 1rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.88rem;
}
.table-custom tbody tr:last-child td {
  border-bottom: none;
}
.table-custom tbody tr:hover {
  background: var(--primary-light);
}

.btn-action {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  cursor: pointer;
  margin: 0 2px;
}
.btn-action i { font-size: 0.85rem; }
.btn-action-ver { background: rgba(59,130,246,0.1); color: #3B82F6; }
.btn-action-ver:hover { background: #3B82F6; color: #fff; transform: translateY(-2px) scale(1.1); box-shadow: 0 4px 12px rgba(59,130,246,0.35); }
.btn-action-editar { background: rgba(245,158,11,0.12); color: #D97706; }
.btn-action-editar:hover { background: #F59E0B; color: #fff; transform: translateY(-2px) scale(1.1); box-shadow: 0 4px 12px rgba(245,158,11,0.3); }
.btn-action-eliminar { background: rgba(239,68,68,0.1); color: #DC2626; }
.btn-action-eliminar:hover { background: #EF4444; color: #fff; transform: translateY(-2px) scale(1.1); box-shadow: 0 4px 12px rgba(239,68,68,0.3); }

.badge-activo {
  background: rgba(16,185,129,0.12);
  color: #059669;
  font-weight: 500;
  padding: 0.3em 0.7em;
  border-radius: 20px;
  font-size: 0.75rem;
  display: inline-block;
}
.badge-inactivo {
  background: rgba(148,163,184,0.12);
  color: #64748B;
  font-weight: 500;
  padding: 0.3em 0.7em;
  border-radius: 20px;
  font-size: 0.75rem;
  display: inline-block;
}

.acciones-cell { white-space: nowrap; text-align: right; }

.table-info-text { font-size: 0.82rem; color: var(--text-muted); }

.pagination-custom { display: flex; gap: 3px; }
.pagination-custom .page-item .page-link {
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.82rem;
  padding: 0.35rem 0.7rem;
  border-radius: 6px !important;
  transition: all 0.15s ease;
  background: var(--surface);
}
.pagination-custom .page-item .page-link:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}
.pagination-custom .page-item.active .page-link {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}
.pagination-custom .page-item.disabled .page-link {
  opacity: 0.4;
  pointer-events: none;
}

.loading-row td { padding: 3rem 0; }
.spinner-table {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state-icon { font-size: 3rem; color: var(--text-muted); opacity: 0.4; }

/* Responsive */
@media (max-width: 991.98px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.sidebar-open { transform: translateX(0); }
  .sidebar-overlay.active { display: block; }
  #topbar { left: 0; }
  #main-content { margin-left: 0; }
}
@media (max-width: 575.98px) {
  #topbar { padding: 0 1rem; }
  #main-content { padding: 1rem; }
}

/* Calendar Styles */
.calendar-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 1rem;
}
.calendar-header .form-select {
  min-width: 180px;
}
.calendar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
.calendar-nav button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
}
.calendar-nav button:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}
.calendar-nav span {
  font-weight: 600;
  font-size: 0.95rem;
  min-width: 220px;
  text-align: center;
}

.calendar-grid {
  display: grid;
  grid-template-columns: 60px repeat(7, 1fr);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
}
.calendar-grid.animate-in {
  animation: calendarFadeIn 0.3s ease-out;
}
@keyframes calendarFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.calendar-grid .time-col {
  border-right: 1px solid var(--border);
  background: var(--bg);
}

.calendar-grid .day-col {
  border-right: 1px solid var(--border);
  min-height: 600px;
  position: relative;
}
.calendar-grid .day-col:last-child {
  border-right: none;
}

.calendar-grid .day-header {
  text-align: center;
  padding: 8px 4px;
  font-weight: 600;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
.calendar-grid .day-header .day-num {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}
.calendar-grid .time-slot {
  height: 40px;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.7rem;
  color: var(--text-muted);
  padding: 2px 6px;
  display: flex;
  align-items: start;
  justify-content: end;
}

.day-slots {
  position: relative;
  height: 100%;
  min-height: 640px;
}

.day-slots .slot {
  height: 40px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 0.1s;
}
.day-slots .slot:hover {
  background: rgba(59,130,246,0.05);
}

.calendar-card {
  position: absolute;
  left: 4px;
  right: 4px;
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.75rem;
  cursor: grab;
  z-index: 10;
  overflow: hidden;
  user-select: none;
  touch-action: none;
  transition: box-shadow 0.15s;
  min-height: 28px;
}
.calendar-card:active {
  cursor: grabbing;
}
.calendar-card.dragging {
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  opacity: 0.9;
}
.calendar-card.confirmed {
  background: #DBEAFE;
  border-left: 3px solid #3B82F6;
  color: #1E40AF;
}
.calendar-card.unconfirmed {
  background: #FEF3C7;
  border: 2px dashed #F59E0B;
  color: #92400E;
}
.calendar-card .card-title {
  font-weight: 600;
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.calendar-card .card-sub {
  font-size: 0.65rem;
  opacity: 0.8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.calendar-card .card-time {
  font-size: 0.65rem;
  font-weight: 500;
}
.calendar-card .btn-confirm {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: #10B981;
  color: #fff;
  font-size: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s;
}
.calendar-card .btn-confirm:hover {
  transform: scale(1.2);
}
.calendar-card .btn-delete {
  position: absolute;
  top: 4px;
  right: 30px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: #EF4444;
  color: #fff;
  font-size: 0.55rem;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s;
}
.calendar-card:hover .btn-delete {
  display: flex;
}
.calendar-card .btn-delete:hover {
  transform: scale(1.2);
}

.sala-color-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

/* Searchable Select */
.searchable-wrapper {
  position: relative;
}
.searchable-original {
  display: none !important;
}
.searchable-input {
  cursor: pointer;
}
.searchable-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1060;
  max-height: 220px;
  overflow-y: auto;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  margin-top: 2px;
}
.searchable-dropdown.show {
  display: block;
}
.searchable-option {
  padding: 0.55rem 1rem;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.12s ease;
  border-bottom: 1px solid var(--border-light);
}
.searchable-option:last-child {
  border-bottom: none;
}
.searchable-option:hover {
  background: var(--primary-light);
}
.searchable-option.disabled {
  color: var(--text-muted);
  cursor: default;
  font-style: italic;
}

/* Tablet optimizations */
@media (min-width: 576px) and (max-width: 991.98px) {
  .calendar-grid .time-slot {
    height: 44px;
    font-size: 0.75rem;
  }
  .day-slots .slot {
    height: 44px;
  }
  .calendar-grid .day-header {
    font-size: 0.7rem;
    padding: 6px 2px;
  }
  .calendar-grid .day-header .day-num {
    font-size: 1rem;
  }
  .calendar-card {
    padding: 4px 6px;
    font-size: 0.65rem;
  }
  .calendar-card .card-title {
    font-size: 0.7rem;
  }
  .calendar-card .btn-confirm,
  .calendar-card .btn-delete {
    width: 28px;
    height: 28px;
    font-size: 0.7rem;
  }
  .calendar-card .btn-delete {
    right: 34px;
  }
}

/* Touch devices: always show delete button */
@media (hover: none) {
  .calendar-card .btn-delete {
    display: flex;
  }
  .calendar-card .btn-confirm {
    width: 28px;
    height: 28px;
  }
  .calendar-card .btn-delete {
    width: 28px;
    height: 28px;
  }
}

/* Small mobile */
@media (max-width: 575.98px) {
  .calendar-grid {
    grid-template-columns: 40px repeat(7, 1fr);
    font-size: 0.7rem;
    overflow-x: auto;
  }
  .calendar-grid .time-slot {
    height: 36px;
    font-size: 0.6rem;
    padding: 1px 3px;
  }
  .day-slots .slot {
    height: 36px;
  }
  .calendar-grid .day-header {
    font-size: 0.6rem;
    padding: 4px 2px;
  }
  .calendar-grid .day-header .day-num {
    font-size: 0.85rem;
    width: 24px;
    height: 24px;
    line-height: 24px;
  }
  .calendar-nav span {
    font-size: 0.8rem;
    min-width: 140px;
  }
  .calendar-card {
    padding: 3px 4px;
    font-size: 0.6rem;
    left: 2px;
    right: 2px;
  }
  .calendar-card .card-title {
    font-size: 0.65rem;
  }
  .calendar-card .card-time {
    font-size: 0.55rem;
  }
  .calendar-card .btn-confirm,
  .calendar-card .btn-delete {
    width: 24px;
    height: 24px;
    font-size: 0.6rem;
  }
  .calendar-card .btn-delete {
    right: 28px;
  }
}
