/**
 * OpenThink SAS — Bootstrap 5 (Tabler) overrides
 *
 * This file ensures Tabler/BS5 styles co-exist with legacy Bootstrap 2.x
 * classes that are still present in un-migrated templates.
 *
 * Strategy:
 * - Namespace modern styles under .ots-modern or body.ots-modern
 * - Legacy classes (.row-fluid, .span*, .btn-navbar, etc.) remain untouched
 * - Only activate BS5 overrides inside .ots-modern context
 */

/* ===== GLOBAL RESETS for MODERN layout ===== */
body.ots-modern {
  font-family: var(--ots-font-family);
  font-size: var(--ots-font-size-base);
  line-height: var(--ots-line-height);
  background-color: var(--ots-bg-body);
  color: var(--ots-text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== SIDEBAR ===== */
.ots-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--ots-sidebar-width);
  background: var(--ots-bg-sidebar);
  z-index: 1040;
  transition: width var(--ots-transition-speed) var(--ots-transition-fn),
              transform var(--ots-transition-speed) var(--ots-transition-fn);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.ots-sidebar::-webkit-scrollbar {
  width: 4px;
}

.ots-sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.ots-sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

/* Sidebar Brand */
.ots-sidebar-brand {
  display: flex;
  align-items: center;
  padding: 1rem 1.25rem;
  min-height: var(--ots-header-height);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  text-decoration: none;
  flex-shrink: 0;
}

.ots-sidebar-brand img {
  height: var(--ots-logo-sidebar-height);
  width: auto;
  flex-shrink: 0;
}

.ots-sidebar-brand-text {
  margin-left: 0.75rem;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sidebar profile */
.ots-sidebar-profile {
  display: flex;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.ots-sidebar-profile-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ots-brand-primary);
  flex-shrink: 0;
  object-fit: cover;
}

.ots-sidebar-profile-info {
  margin-left: 0.75rem;
  overflow: hidden;
}

.ots-sidebar-profile-name {
  color: #fff;
  font-weight: 600;
  font-size: var(--ots-font-size-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ots-sidebar-profile-role {
  color: var(--ots-text-sidebar);
  font-size: var(--ots-font-size-xs);
}

/* Sidebar Navigation */
.ots-sidebar-nav {
  padding: 0.75rem 0;
  flex: 1;
  overflow-y: auto;
}

.ots-sidebar-nav-label {
  padding: 0.75rem 1.25rem 0.375rem;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.35);
}

.ots-sidebar-nav-item {
  list-style: none;
}

.ots-sidebar-nav-link {
  display: flex;
  align-items: center;
  padding: 0.5rem 1.25rem;
  color: var(--ots-text-sidebar);
  text-decoration: none;
  font-size: var(--ots-font-size-sm);
  font-weight: 400;
  transition: all 0.15s ease;
  border-radius: 0;
  position: relative;
}

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

.ots-sidebar-nav-link.active {
  color: var(--ots-text-sidebar-active);
  background: rgba(var(--ots-brand-primary-rgb), 0.15);
  font-weight: 500;
}

.ots-sidebar-nav-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--ots-brand-primary);
  border-radius: 0 3px 3px 0;
}

.ots-sidebar-nav-link i {
  width: 1.5rem;
  margin-right: 0.75rem;
  font-size: 1.125rem;
  text-align: center;
  flex-shrink: 0;
  opacity: 0.75;
}

.ots-sidebar-nav-link:hover i,
.ots-sidebar-nav-link.active i {
  opacity: 1;
}

.ots-sidebar-nav-link .nav-chevron {
  margin-left: auto;
  transition: transform 0.2s ease;
  font-size: 0.75rem;
  opacity: 0.5;
}

.ots-sidebar-nav-link[aria-expanded="true"] .nav-chevron {
  transform: rotate(90deg);
}

/* Sidebar submenu — custom JS toggle (no BS5 collapse dependency) */
.ots-sidebar-submenu {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s ease;
}

.ots-sidebar-submenu.ots-submenu-open {
  max-height: none;
}

.ots-sidebar-nav-link.ots-submenu-expanded .nav-chevron {
  transform: rotate(90deg);
}

.ots-sidebar-submenu .ots-sidebar-nav-link {
  padding-left: 3.25rem;
  font-size: var(--ots-font-size-xs);
}

.ots-sidebar-submenu .ots-sidebar-submenu .ots-sidebar-nav-link {
  padding-left: 4.5rem;
}

/* Sidebar Footer */
.ots-sidebar-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

/* ===== HEADER / TOP NAV ===== */
.ots-header {
  position: fixed;
  top: 0;
  right: 0;
  left: var(--ots-sidebar-width);
  height: var(--ots-header-height);
  background: var(--ots-bg-header);
  border-bottom: 1px solid var(--ots-border-color);
  z-index: 1030;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  transition: left var(--ots-transition-speed) var(--ots-transition-fn);
  box-shadow: var(--ots-shadow-sm);
}

.ots-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.ots-header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

.ots-sidebar-toggle {
  display: none;
  border: none;
  background: transparent;
  padding: 0.375rem;
  color: var(--ots-text-secondary);
  font-size: 1.25rem;
  cursor: pointer;
  border-radius: var(--ots-border-radius);
}

.ots-sidebar-toggle:hover {
  background: var(--ots-bg-surface-secondary);
  color: var(--ots-text-primary);
}

/* ===== CONTENT AREA ===== */
.ots-content-wrapper {
  margin-left: var(--ots-sidebar-width);
  padding-top: var(--ots-header-height);
  min-height: 100vh;
  transition: margin-left var(--ots-transition-speed) var(--ots-transition-fn);
}

.ots-content {
  padding: var(--ots-content-padding);
}

/* ===== FOOTER ===== */
.ots-footer {
  padding: 1rem var(--ots-content-padding);
  border-top: 1px solid var(--ots-border-color);
  color: var(--ots-text-muted);
  font-size: var(--ots-font-size-xs);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 991.98px) {
  .ots-sidebar {
    transform: translateX(-100%);
  }

  .ots-sidebar.show {
    transform: translateX(0);
  }

  .ots-header {
    left: 0;
  }

  .ots-content-wrapper {
    margin-left: 0;
  }

  .ots-sidebar-toggle {
    display: flex;
  }

  /* Overlay */
  .ots-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1035;
    backdrop-filter: blur(2px);
  }

  .ots-sidebar-overlay.show {
    display: block;
  }
}

/* ===== SIDEBAR COLLAPSED (Desktop) ===== */
body.ots-sidebar-collapsed .ots-sidebar {
  width: var(--ots-sidebar-collapsed-width);
}

body.ots-sidebar-collapsed .ots-sidebar .ots-sidebar-brand-text,
body.ots-sidebar-collapsed .ots-sidebar .ots-sidebar-profile-info,
body.ots-sidebar-collapsed .ots-sidebar .ots-sidebar-nav-label,
body.ots-sidebar-collapsed .ots-sidebar .ots-sidebar-nav-link span,
body.ots-sidebar-collapsed .ots-sidebar .ots-sidebar-nav-link .nav-chevron {
  display: none;
}

body.ots-sidebar-collapsed .ots-sidebar .ots-sidebar-nav-link {
  justify-content: center;
  padding: 0.65rem;
}

body.ots-sidebar-collapsed .ots-sidebar .ots-sidebar-nav-link i {
  margin-right: 0;
  font-size: 1.25rem;
}

body.ots-sidebar-collapsed .ots-header {
  left: var(--ots-sidebar-collapsed-width);
}

body.ots-sidebar-collapsed .ots-content-wrapper {
  margin-left: var(--ots-sidebar-collapsed-width);
}

body.ots-sidebar-collapsed .ots-sidebar .ots-sidebar-submenu {
  display: none !important;
}

/* ===== UTILITY CLASSES ===== */
.ots-modern .hover-shadow {
  transition: box-shadow var(--ots-transition-speed) var(--ots-transition-fn),
              transform var(--ots-transition-speed) var(--ots-transition-fn);
}

.ots-modern .hover-shadow:hover {
  box-shadow: var(--ots-shadow-md);
  transform: translateY(-1px);
}

/* ===== DARK MODE TOGGLE ===== */
.ots-theme-toggle {
  border: none;
  background: transparent;
  padding: 0.375rem 0.5rem;
  color: var(--ots-text-secondary);
  font-size: 1.125rem;
  cursor: pointer;
  border-radius: var(--ots-border-radius);
  transition: all 0.15s ease;
}

.ots-theme-toggle:hover {
  background: var(--ots-bg-surface-secondary);
  color: var(--ots-text-primary);
}

[data-bs-theme="dark"] .ots-theme-toggle .ti-sun {
  display: inline;
}

[data-bs-theme="dark"] .ots-theme-toggle .ti-moon {
  display: none;
}

[data-bs-theme="light"] .ots-theme-toggle .ti-sun,
:root:not([data-bs-theme]) .ots-theme-toggle .ti-sun {
  display: none;
}

[data-bs-theme="light"] .ots-theme-toggle .ti-moon,
:root:not([data-bs-theme]) .ots-theme-toggle .ti-moon {
  display: inline;
}

/* ===== BREADCRUMB ===== */
.ots-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: var(--ots-font-size-sm);
  color: var(--ots-text-muted);
  margin: 0;
  padding: 0;
  list-style: none;
}

.ots-breadcrumb a {
  color: var(--ots-text-secondary);
  text-decoration: none;
}

.ots-breadcrumb a:hover {
  color: var(--ots-brand-primary);
}
