/* ============================================================
   MesaOS · Sistema de diseño v2 (con sidebar)
   ============================================================ */

:root {
  --mesa-primary: #2563eb;
  --mesa-primary-hover: #1d4ed8;
  --mesa-primary-light: #eff6ff;
  --mesa-success: #16a34a;
  --mesa-danger: #dc2626;
  --mesa-warning: #f59e0b;
  --mesa-dark: #1e293b;
  --mesa-light: #f8fafc;
  --mesa-border: #e2e8f0;
  --mesa-text: #1e293b;
  --mesa-text-muted: #64748b;
  --mesa-radius: 10px;
  --mesa-shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --mesa-shadow-lg: 0 10px 25px rgba(0,0,0,.1), 0 4px 10px rgba(0,0,0,.05);
  --mesa-transition: all .2s ease;
  --sidebar-width: 250px;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: var(--mesa-text);
  overflow-x: hidden;
}

/* ============================================================
   SIDEBAR LAYOUT
   ============================================================ */
.mesa-layout {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.mesa-sidebar {
  width: var(--sidebar-width);
  background: #fff;
  border-right: 1px solid var(--mesa-border);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform .3s ease;
}
.mesa-sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid var(--mesa-border);
}
.mesa-sidebar-brand {
  display: flex; align-items: center; gap: 10px;
}
.mesa-sidebar-brand .brand-avatar {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--mesa-primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
  flex-shrink: 0;
}
.mesa-sidebar-brand .brand-avatar img {
  width: 100%; height: 100%;
  object-fit: cover; border-radius: 10px;
}
.mesa-sidebar-brand .brand-info {
  overflow: hidden;
}
.mesa-sidebar-brand .brand-name {
  font-weight: 600; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--mesa-text);
}
.mesa-sidebar-brand .brand-role {
  font-size: 12px; color: var(--mesa-text-muted);
}

/* Navigation */
.mesa-sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}
.mesa-sidebar-nav .nav-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--mesa-text-muted);
  font-weight: 600;
  padding: 16px 20px 6px;
}
.mesa-sidebar-nav .nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  color: var(--mesa-text-muted);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: var(--mesa-transition);
  border-radius: 0;
  margin: 1px 8px;
  border-radius: 8px;
}
.mesa-sidebar-nav .nav-link:hover {
  background: var(--mesa-primary-light);
  color: var(--mesa-primary);
}
.mesa-sidebar-nav .nav-link.active {
  background: var(--mesa-primary);
  color: #fff;
}
.mesa-sidebar-nav .nav-link i {
  font-size: 18px; width: 22px; text-align: center;
}

.mesa-sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--mesa-border);
}

/* ---- Topbar ---- */
.mesa-topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: 56px;
  background: #fff;
  border-bottom: 1px solid var(--mesa-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 1030;
}
.mesa-topbar-title {
  font-size: 16px; font-weight: 600; color: var(--mesa-text);
}
.mesa-topbar-actions {
  display: flex; align-items: center; gap: 12px;
}
.mesa-topbar-user {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--mesa-text-muted);
}

/* ---- Main content ---- */
.mesa-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding-top: 56px;
  min-height: 100vh;
  background: var(--mesa-light);
}
.mesa-content {
  padding: 24px;
}

/* ---- Mobile sidebar toggle ---- */
.mesa-sidebar-toggle {
  display: none;
  background: none; border: none;
  font-size: 22px; color: var(--mesa-text);
  padding: 4px 8px; cursor: pointer;
}
.mesa-sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 1039;
}

/* ---- Responsive ---- */
@media (max-width: 991px) {
  .mesa-sidebar {
    transform: translateX(-100%);
  }
  .mesa-sidebar.open {
    transform: translateX(0);
  }
  .mesa-sidebar-overlay.open {
    display: block;
  }
  .mesa-sidebar-toggle {
    display: block;
  }
  .mesa-topbar {
    left: 0;
  }
  .mesa-main {
    margin-left: 0;
  }
  :root {
    --sidebar-width: 260px;
  }
}

@media (max-width: 575px) {
  .mesa-content {
    padding: 16px 12px;
  }
}

/* ============================================================
   COMPONENTES
   ============================================================ */

/* ---- Loader overlay ---- */
#mesaLoader {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(255,255,255,.7);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center; justify-content: center;
  transition: opacity .2s;
}
#mesaLoader.show { display: flex; }
#mesaLoader .loader-content {
  text-align: center;
  animation: loaderFadeIn .3s ease;
}
#mesaLoader .spinner {
  width: 44px; height: 44px;
  border: 3px solid var(--mesa-border);
  border-top-color: var(--mesa-primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 12px;
}
#mesaLoader .loader-text {
  font-size: 14px; color: var(--mesa-text-muted); font-weight: 500;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes loaderFadeIn { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } }

/* ---- Toast notifications ---- */
#mesaToasts {
  position: fixed; top: 20px; right: 20px; z-index: 9998;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.mesa-toast {
  pointer-events: auto;
  padding: 12px 20px; border-radius: var(--mesa-radius);
  font-size: 14px; font-weight: 500;
  box-shadow: var(--mesa-shadow-lg);
  animation: toastIn .35s ease, toastOut .3s ease 3.2s forwards;
  display: flex; align-items: center; gap: 8px;
  max-width: 380px;
}
.mesa-toast.success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.mesa-toast.error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.mesa-toast.warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.mesa-toast.info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
@keyframes toastIn  { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(40px); } }

/* ---- Botones ---- */
.btn { transition: var(--mesa-transition); position: relative; border-radius: 8px; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--mesa-primary); border-color: var(--mesa-primary); }
.btn-primary:hover { background: var(--mesa-primary-hover); border-color: var(--mesa-primary-hover); }
.btn.loading { pointer-events: none; opacity: .7; }
.btn.loading::after {
  content: ''; display: inline-block; width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  border-radius: 50%; animation: spin .6s linear infinite;
  margin-left: 8px; vertical-align: middle;
}
.btn-outline-primary.loading::after,
.btn-outline-secondary.loading::after,
.btn-outline-danger.loading::after {
  border-color: rgba(0,0,0,.15);
  border-top-color: currentColor;
}

/* ---- Cards ---- */
.card {
  border: 1px solid var(--mesa-border);
  border-radius: var(--mesa-radius);
  box-shadow: var(--mesa-shadow);
}
.card-header {
  background: #fff;
  border-bottom: 1px solid var(--mesa-border);
  font-weight: 600;
}

/* ---- Tables ---- */
.table { font-size: 14px; }
.table thead th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--mesa-text-muted); font-weight: 600; border-bottom-width: 1px;
}

/* ---- Forms ---- */
.form-control, .form-select {
  border-radius: 8px; border-color: var(--mesa-border);
  transition: var(--mesa-transition);
}
.form-control:focus, .form-select:focus {
  border-color: var(--mesa-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-label { font-size: 13px; font-weight: 500; color: var(--mesa-text-muted); }
.form-check-input:checked { background-color: var(--mesa-primary); border-color: var(--mesa-primary); }

/* ---- Modales ---- */
.modal-content {
  border: none; border-radius: 14px;
  box-shadow: var(--mesa-shadow-lg); overflow: hidden;
}
.modal-header {
  background: var(--mesa-light);
  border-bottom: 1px solid var(--mesa-border);
  padding: 16px 20px;
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-footer {
  background: var(--mesa-light);
  border-top: 1px solid var(--mesa-border);
  padding: 12px 20px;
}
.modal-backdrop.show { opacity: .35; }

/* ---- Badges ---- */
.badge {
  font-weight: 500; font-size: 11px;
  padding: 4px 10px; border-radius: 6px;
}

/* ---- Alerts ---- */
.alert { border-radius: var(--mesa-radius); font-size: 14px; }

/* ---- Stat cards ---- */
.stat-card {
  background: #fff;
  border: 1px solid var(--mesa-border);
  border-radius: var(--mesa-radius);
  padding: 16px 20px;
  box-shadow: var(--mesa-shadow);
}
.stat-card .stat-label {
  font-size: 12px; color: var(--mesa-text-muted);
  text-transform: uppercase; letter-spacing: .5px; font-weight: 600;
}
.stat-card .stat-value {
  font-size: 28px; font-weight: 700; margin-top: 4px;
}

/* ---- Animations ---- */
.fade-in { animation: fadeIn .35s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---- Skeleton loading ---- */
.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px; min-height: 20px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }