:root {
  --sidebar-width: 260px;
  --topbar-height: 64px;

  --lms-primary: #4f46e5;
  --lms-primary-dark: #4338ca;
  --lms-primary-darker: #3730a3;
  --lms-primary-light: #eef2ff;
  --lms-primary-rgb: 79, 70, 229;

  --lms-body-bg: #f6f7fb;
  --lms-text: #1f2333;
  --lms-text-muted: #667085;
  --lms-border-color: #e7e9f1;

  --lms-gray-50: #f8fafc;
  --lms-gray-100: #f1f5f9;
  --lms-gray-200: #e2e8f0;

  --lms-radius-sm: 0.45rem;
  --lms-radius: 0.7rem;
  --lms-radius-lg: 1rem;

  --lms-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --lms-shadow: 0 2px 8px -2px rgba(16, 24, 40, 0.08), 0 1px 3px rgba(16, 24, 40, 0.05);
  --lms-shadow-md: 0 8px 20px -6px rgba(16, 24, 40, 0.12), 0 2px 6px -1px rgba(16, 24, 40, 0.06);
  --lms-shadow-lg: 0 20px 40px -12px rgba(16, 24, 40, 0.22), 0 6px 16px -4px rgba(16, 24, 40, 0.1);

  --lms-gradient-primary: linear-gradient(135deg, var(--lms-primary), var(--lms-primary-dark));
  --lms-gradient-primary-hover: linear-gradient(135deg, var(--lms-primary-dark), var(--lms-primary-darker));

  --lms-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

/* Belt-and-braces against any stray fixed-width element on a narrow viewport — every
   scrollable table already opts back in via its own .table-responsive wrapper below. */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: var(--lms-font);
  background-color: var(--lms-body-bg);
  color: var(--lms-text);
  font-size: 0.9375rem;
  line-height: 1.55;
}

img, svg {
  max-width: 100%;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--lms-font);
  font-weight: 700;
  letter-spacing: -0.015em;
  color: #111827;
}

.text-muted {
  color: var(--lms-text-muted) !important;
}

/* Re-tints Bootstrap's baked-in blue (#0d6efd) to the app's indigo accent everywhere
   .btn-primary/.btn-outline-primary/links/checked-switches are used — this stock
   Bootstrap build has the primary color compiled directly into each component's own
   --bs-btn-* custom properties (not sourced from a root --bs-primary variable), so a
   root-level override alone wouldn't reach these; each component needs its own reset. */
.btn-primary {
  --bs-btn-bg: var(--lms-primary);
  --bs-btn-border-color: var(--lms-primary);
  --bs-btn-hover-bg: var(--lms-primary-dark);
  --bs-btn-hover-border-color: var(--lms-primary-dark);
  --bs-btn-active-bg: var(--lms-primary-darker);
  --bs-btn-active-border-color: var(--lms-primary-darker);
  --bs-btn-disabled-bg: var(--lms-primary);
  --bs-btn-disabled-border-color: var(--lms-primary);
  --bs-btn-focus-shadow-rgb: 99, 102, 241;
  background-image: var(--lms-gradient-primary);
  border: none;
  box-shadow: 0 2px 6px -1px rgba(var(--lms-primary-rgb), 0.4);
}

.btn-primary:hover, .btn-primary:focus {
  background-image: var(--lms-gradient-primary-hover);
}

.btn-primary:active {
  background-image: none;
}

.btn-outline-primary {
  --bs-btn-color: var(--lms-primary);
  --bs-btn-border-color: var(--lms-primary);
  --bs-btn-hover-bg: var(--lms-primary);
  --bs-btn-hover-border-color: var(--lms-primary);
  --bs-btn-active-bg: var(--lms-primary);
  --bs-btn-active-border-color: var(--lms-primary);
  --bs-btn-focus-shadow-rgb: 99, 102, 241;
}

.btn-outline-primary:hover {
  box-shadow: 0 2px 6px -1px rgba(var(--lms-primary-rgb), 0.3);
}

a {
  color: var(--lms-primary);
  text-decoration: none;
}
a:hover {
  color: var(--lms-primary-dark);
}

/* ---- Buttons & form controls: shared radius, weight and touch-friendly sizing ---- */
.btn {
  border-radius: var(--lms-radius-sm);
  font-weight: 600;
  letter-spacing: 0.005em;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background-image 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-sm {
  border-radius: 0.4rem;
}

.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
  outline: none;
}

.form-control, .form-select {
  border-radius: var(--lms-radius-sm);
  border-color: var(--lms-border-color);
}

.form-control:focus, .form-select:focus {
  border-color: var(--lms-primary);
  box-shadow: 0 0 0 0.2rem rgba(var(--lms-primary-rgb), 0.15);
}

.form-label {
  font-weight: 600;
  font-size: 0.85rem;
  color: #344054;
  margin-bottom: 0.4rem;
}

/* ---- Inline help — see views/partials/helpIcon.ejs ---- */
.help-icon {
  color: var(--lms-text-muted);
  font-size: 0.85em;
  cursor: help;
  margin-left: 0.3rem;
  vertical-align: 0.02em;
  transition: color 0.15s ease;
}
.help-icon:hover, .help-icon:focus-visible {
  color: var(--lms-primary);
  outline: none;
}
.tooltip .tooltip-inner {
  max-width: 260px;
  font-size: 0.8rem;
  padding: 0.45rem 0.65rem;
  border-radius: var(--lms-radius-sm);
  box-shadow: var(--lms-shadow-md);
}

.form-check-input:checked {
  background-color: var(--lms-primary);
  border-color: var(--lms-primary);
}
.form-check-input:focus {
  box-shadow: 0 0 0 0.25rem rgba(var(--lms-primary-rgb), 0.25);
}

.input-group-text {
  background-color: var(--lms-gray-50);
  border-color: var(--lms-border-color);
}

.text-bg-primary, .badge.bg-primary {
  background: var(--lms-gradient-primary) !important;
}
.text-primary {
  color: var(--lms-primary) !important;
}

/* ---- Cards ---- */
.card {
  border: 1px solid var(--lms-border-color);
  border-radius: var(--lms-radius);
  box-shadow: var(--lms-shadow);
  transition: box-shadow 0.2s ease;
}

/* !important: ~40 views pair `card-header` with Bootstrap's own `.bg-white` utility class
   (predating this gradient), which sets `background-color` with its own !important and
   would otherwise silently win over this rule on every one of them. */
.card-header {
  background: linear-gradient(180deg, #fff 0%, #fbfbfe 100%) !important;
  border-bottom: 1px solid var(--lms-border-color);
  font-weight: 600;
  padding: 0.9rem 1.1rem;
}

.card-footer {
  background-color: #fff;
  border-top: 1px solid var(--lms-border-color);
}

.card-body {
  padding: 1.15rem;
}

@media (min-width: 768px) {
  .card-body {
    padding: 1.35rem;
  }
}

/* ---- Badges & alerts ---- */
.badge {
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 0.4em 0.65em;
}

.alert {
  border: 1px solid transparent;
  border-radius: var(--lms-radius-sm);
  border-left-width: 4px;
}

.alert-danger {
  border-left-color: #dc2626;
}
.alert-success {
  border-left-color: #16a34a;
}
.alert-warning {
  border-left-color: #d97706;
}
.alert-info {
  border-left-color: #0891b2;
}

/* ---- Tables ---- */
.table-responsive {
  border-radius: var(--lms-radius);
  border: 1px solid var(--lms-border-color);
  -webkit-overflow-scrolling: touch;
}

.table-responsive > .table {
  margin-bottom: 0;
}

.table {
  font-size: 0.9rem;
  vertical-align: middle;
}

.table thead th {
  background-color: var(--lms-gray-50);
  color: #475569;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--lms-border-color);
  white-space: nowrap;
  padding: 0.75rem 1rem;
}

.table tbody td {
  padding: 0.75rem 1rem;
  border-bottom-color: var(--lms-border-color);
}

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

.table-hover tbody tr:hover {
  background-color: var(--lms-primary-light);
}

/* ---- Dropdowns, modals, pagination ---- */
.dropdown-menu {
  border: 1px solid var(--lms-border-color);
  border-radius: var(--lms-radius-sm);
  box-shadow: var(--lms-shadow-lg);
  max-width: calc(100vw - 2rem);
}

.dropdown-item:active {
  background: var(--lms-gradient-primary);
}

.modal-content {
  border: none;
  border-radius: var(--lms-radius);
  box-shadow: var(--lms-shadow-lg);
}

.modal-header {
  border-bottom: 1px solid var(--lms-border-color);
}

.modal-footer {
  border-top: 1px solid var(--lms-border-color);
}

.pagination .page-link {
  color: var(--lms-primary);
  border-color: var(--lms-border-color);
}

.pagination .page-item.active .page-link {
  background: var(--lms-gradient-primary);
  border-color: var(--lms-primary);
  box-shadow: 0 2px 6px -1px rgba(var(--lms-primary-rgb), 0.4);
}

.nav-tabs .nav-link {
  color: var(--lms-text-muted);
  font-weight: 600;
  border: none;
  border-bottom: 2px solid transparent;
}
.nav-tabs .nav-link.active {
  color: var(--lms-primary);
  background: none;
  border-color: var(--lms-primary);
}

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

.sidebar {
  width: var(--sidebar-width);
  /* !important is required here: Bootstrap's responsive-offcanvas CSS forces
     `background-color: transparent !important` on .offcanvas-lg at the >=992px
     breakpoint (this element is both .offcanvas-lg and .sidebar), which otherwise
     silently wins over this rule regardless of source order or selector specificity. */
  background: #111827 !important;
  color: #e5e7eb !important;
  border: none;
}

@media (min-width: 992px) {
  .sidebar {
    flex-shrink: 0;
  }
}

@media (max-width: 991.98px) {
  .sidebar {
    width: min(var(--sidebar-width), 82vw);
  }
}

.sidebar-brand {
  height: var(--topbar-height);
  padding: 0 1.25rem;
  color: #fff;
  font-weight: 700;
  letter-spacing: -0.01em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-nav {
  padding: 0.75rem 0.5rem;
  overflow-y: auto;
}

.sidebar .nav-link {
  color: #cbd5e1;
  border-radius: 0.5rem;
  padding: 0.6rem 0.85rem;
  margin-bottom: 2px;
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar .nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.sidebar .nav-link.active {
  background: var(--lms-gradient-primary);
  color: #fff;
  box-shadow: 0 4px 14px -2px rgba(var(--lms-primary-rgb), 0.5);
}

.sidebar .offcanvas-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: #fff;
}

.sidebar .btn-close {
  filter: invert(1) grayscale(100%) brightness(200%);
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  min-height: var(--topbar-height);
  background: linear-gradient(180deg, #ffffff 0%, #fbfbfe 100%);
  border-bottom: 1px solid var(--lms-border-color);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.02);
}

.app-topbar .container-fluid {
  min-height: var(--topbar-height);
  flex-wrap: nowrap;
  gap: 0.5rem;
}

.tenant-name {
  color: #4b5563;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex-shrink: 1;
  max-width: 38vw;
}

.avatar-circle {
  width: 36px;
  height: 36px;
  min-width: 36px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--lms-gradient-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  box-shadow: 0 2px 6px -1px rgba(var(--lms-primary-rgb), 0.45);
}

.app-content {
  flex: 1;
  min-width: 0;
}

.app-content .container-fluid {
  max-width: 100%;
}

@media (max-width: 575.98px) {
  .app-content .container-fluid.py-4 {
    padding-top: 1rem !important;
    padding-bottom: 1rem !important;
    padding-left: 0.85rem !important;
    padding-right: 0.85rem !important;
  }
}

.app-footer {
  border-top: 1px solid var(--lms-border-color);
  background: #fff;
}

/* ---- Dashboard stat cards ---- */
.stat-card {
  border: 1px solid var(--lms-border-color);
  border-top: 3px solid var(--lms-primary);
  border-radius: var(--lms-radius);
  box-shadow: var(--lms-shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--lms-shadow-md);
}

.stat-card .stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.2;
}

@media (min-width: 768px) {
  .stat-card .stat-value {
    font-size: 1.85rem;
  }
}

/* ---- Auth pages ---- */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1100px circle at 12% -10%, rgba(255, 255, 255, 0.14), transparent 45%),
    radial-gradient(800px circle at 92% 108%, rgba(129, 140, 248, 0.35), transparent 45%),
    linear-gradient(135deg, #4f46e5, #111827);
  padding: 1rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  border: none;
  border-radius: var(--lms-radius-lg);
  position: relative;
  overflow: hidden;
  box-shadow: var(--lms-shadow-lg);
}

.auth-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--lms-primary), #818cf8, var(--lms-primary-dark));
}

/* ---- Small-screen touch targets & overflow guards ---- */
@media (max-width: 575.98px) {
  .btn {
    min-height: 2.5rem;
  }

  h1, .h1 { font-size: 1.6rem; }
  h2, .h2 { font-size: 1.4rem; }
  h3, .h3 { font-size: 1.2rem; }

  .card-body {
    padding: 1rem;
  }

  /* Page-header rows (title + action buttons) and inline filter/action bars are built
     app-wide with plain `.d-flex` utility rows. Bootstrap's default is nowrap, which on a
     narrow phone either squeezes controls unreadably or gets silently clipped by the
     html/body overflow-x guard above. Wrapping is the safer default everywhere inside the
     page body; `.flex-nowrap` remains available as an explicit opt-out where a row must
     stay on one line. */
  .app-content .d-flex {
    flex-wrap: wrap;
  }
  .app-content .d-flex.flex-nowrap {
    flex-wrap: nowrap;
  }
}

.text-nowrap-ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
