:root, [data-bs-theme="light"] {
  --primary-color: #1e56a0;
  --primary-hover: #163172;
  --accent-green: #16a34a;
  --sidebar-bg: #091a2f;
  --sidebar-hover: #132b4b;
  --sidebar-text: #94a3b8;
  --sidebar-active: #1e56a0;
  --topbar-bg: #ffffff;
  --card-bg: #ffffff;
  --body-bg: #f8fafc;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --table-th-bg: #f8fafc;
  --login-bg: radial-gradient(circle at 10% 20%, rgb(238, 242, 255) 0%, rgb(248, 250, 252) 90%);
}

[data-bs-theme="dark"] {
  --primary-color: #3b82f6;
  --primary-hover: #60a5fa;
  --accent-green: #22c55e;
  --sidebar-bg: #060e1a;
  --sidebar-hover: #0f1c30;
  --sidebar-text: #94a3b8;
  --sidebar-active: #1d4ed8;
  --topbar-bg: #0c1524;
  --card-bg: #111c2e;
  --body-bg: #080e18;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --border-color: #1e2d42;
  --table-th-bg: #142034;
  --login-bg: radial-gradient(circle at 10% 20%, rgb(15, 23, 42) 0%, rgb(7, 13, 24) 90%);
}

body {
  background-color: var(--body-bg);
  color: var(--text-main);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  transition: background-color 0.25s ease, color 0.25s ease;
}

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

/* Sidebar */
.app-sidebar {
  width: 260px;
  background-color: var(--sidebar-bg);
  color: #fff;
  flex-shrink: 0;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 1.25rem 1.5rem;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: #fff;
  text-decoration: none;
}

.sidebar-menu {
  list-style: none;
  padding: 1rem 0.75rem;
  margin: 0;
  flex-grow: 1;
}

.sidebar-header {
  font-size: 0.72rem;
  text-transform: uppercase;
  font-weight: 700;
  color: #64748b;
  padding: 0.75rem 0.75rem 0.35rem 0.75rem;
  letter-spacing: 0.8px;
}

.sidebar-item {
  margin-bottom: 0.25rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 0.5rem;
  font-size: 0.92rem;
  font-weight: 500;
  transition: all 0.2s;
}

.sidebar-link:hover {
  background-color: var(--sidebar-hover);
  color: #fff;
}

.sidebar-link.active {
  background-color: var(--sidebar-active);
  color: #fff;
}

.sidebar-link i {
  font-size: 1.15rem;
}

/* Main Content Area */
.app-main {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background-color: var(--body-bg);
}

/* Topbar */
.app-topbar {
  background-color: var(--topbar-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

/* Content Container */
.app-content {
  padding: 1.75rem;
  flex-grow: 1;
}

/* Cards & Widgets */
.stat-card {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 0.85rem;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
  transition: transform 0.2s, box-shadow 0.2s, background-color 0.25s, border-color 0.25s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
}

.card-custom {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 0.85rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  transition: background-color 0.25s, border-color 0.25s;
}

.card-header-custom {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--card-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top-left-radius: 0.85rem;
  border-top-right-radius: 0.85rem;
}

/* Status Badges */
.badge-status {
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 2rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.badge-activo { background-color: #dcfce7; color: #15803d; }
.badge-suspendido { background-color: #fef3c7; color: #b45309; }
.badge-bloqueado { background-color: #fee2e2; color: #b91c1c; }
.badge-gracia { background-color: #ffedd5; color: #c2410c; }
.badge-perpetua { background-color: #f3e8ff; color: #7e22ce; }
.badge-vencido { background-color: #f1f5f9; color: #475569; }
.badge-nuevo { background-color: #e2e8f0; color: #334155; }
.badge-demo { background-color: #e0f2fe; color: #0369a1; }

[data-bs-theme="dark"] .badge-activo { background-color: rgba(34, 197, 94, 0.18); color: #4ade80; border: 1px solid rgba(34, 197, 94, 0.3); }
[data-bs-theme="dark"] .badge-suspendido { background-color: rgba(245, 158, 11, 0.18); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
[data-bs-theme="dark"] .badge-bloqueado { background-color: rgba(239, 68, 68, 0.18); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.3); }
[data-bs-theme="dark"] .badge-gracia { background-color: rgba(249, 115, 22, 0.18); color: #fb923c; border: 1px solid rgba(249, 115, 22, 0.3); }
[data-bs-theme="dark"] .badge-perpetua { background-color: rgba(168, 85, 247, 0.18); color: #c084fc; border: 1px solid rgba(168, 85, 247, 0.3); }
[data-bs-theme="dark"] .badge-vencido { background-color: rgba(148, 163, 184, 0.18); color: #cbd5e1; border: 1px solid rgba(148, 163, 184, 0.3); }
[data-bs-theme="dark"] .badge-nuevo { background-color: rgba(148, 163, 184, 0.2); color: #cbd5e1; border: 1px solid rgba(148, 163, 184, 0.3); }
[data-bs-theme="dark"] .badge-demo { background-color: rgba(56, 189, 248, 0.18); color: #38bdf8; border: 1px solid rgba(56, 189, 248, 0.3); }

/* Table styling */
.table-custom th {
  background-color: var(--table-th-bg);
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
  border-top: none;
  border-bottom-color: var(--border-color);
}

.table-custom td {
  vertical-align: middle;
  font-size: 0.92rem;
  border-bottom-color: var(--border-color);
  color: var(--text-main);
}

[data-bs-theme="dark"] .table-hover tbody tr:hover td {
  background-color: rgba(255, 255, 255, 0.03);
}

/* Emergency Code Box */
.emergency-code-box {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  color: #38bdf8;
  font-family: 'Courier New', Courier, monospace;
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: 6px;
  padding: 1.25rem;
  border-radius: 0.75rem;
  text-align: center;
  border: 2px dashed #0284c7;
  user-select: all;
}

[data-bs-theme="dark"] .bg-light {
  background-color: #142034 !important;
}

[data-bs-theme="dark"] .text-dark {
  color: #f1f5f9 !important;
}

[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
  background-color: #0f1827;
  border-color: #1e2d42;
  color: #f1f5f9;
}

[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus {
  background-color: #131f32;
  border-color: #3b82f6;
  color: #ffffff;
}

[data-bs-theme="dark"] .input-group-text {
  background-color: #142034 !important;
  border-color: #1e2d42;
  color: #94a3b8;
}

/* Mobile responsive */
@media (max-width: 992px) {
  .app-sidebar {
    position: fixed;
    z-index: 1040;
    height: 100vh;
    left: -260px;
  }
  .app-sidebar.show {
    left: 0;
  }
}