html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

html {
  position: relative;
  min-height: 100%;
}

/* AI Helper Button - Global Styles */
.ai-helper-btn {
    position: absolute;
    bottom: 10px;
    right: 10px;
    z-index: 10;
    border-radius: 20px;
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(4px);
}

.ai-helper-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    background-color: rgba(255, 255, 255, 1);
}

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

.ai-helper-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

body.dark-theme .ai-helper-btn {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--primary);
}

body.dark-theme .ai-helper-btn:hover {
    background-color: var(--bg-tertiary);
    border-color: var(--primary-light);
}

.ai-helper-btn i {
    color: var(--primary);
}

body.dark-theme .ai-helper-btn i {
    color: var(--primary-light);
}

/* Ensure textareas have room for AI button */
.position-relative textarea {
    padding-right: 100px;
}

@media (max-width: 576px) {
    .ai-helper-btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
        bottom: 5px;
        right: 5px;
    }
    
    .position-relative textarea {
        padding-right: 80px;
    }
}

body {
  margin-bottom: 60px;
  transition: background-color 0.3s ease, color 0.3s ease;
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

/* Sticky Header */
header {
  position: sticky;
  top: 0;
  z-index: 1020;
  background: var(--bg-secondary);
  transition: background-color 0.3s ease;
}

header .navbar {
  box-shadow: var(--shadow-md);
  background-color: var(--bg-secondary);
}

/* Light Mode */
body:not(.dark-theme) {
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

body:not(.dark-theme) .card {
  background-color: var(--bg-secondary);
  border-color: var(--bg-tertiary);
  box-shadow: var(--shadow-sm);
}

body:not(.dark-theme) .card-header {
  background-color: var(--bg-tertiary);
  border-bottom-color: var(--bg-tertiary);
  color: var(--text-primary);
}

body:not(.dark-theme) .card-header.bg-white {
  background-color: var(--bg-tertiary) !important;
}

body:not(.dark-theme) .card-body {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

body:not(.dark-theme) .stat-card,
body:not(.dark-theme) .dashboard-topbar {
  background-color: var(--bg-secondary) !important;
  border-color: var(--bg-tertiary);
}

body:not(.dark-theme) .table-light {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}

body:not(.dark-theme) .table thead th {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border-bottom-color: var(--bg-tertiary);
}

body:not(.dark-theme) .text-muted {
  color: var(--text-muted) !important;
}

body:not(.dark-theme) .dashboard-sidebar {
  background-color: var(--bg-secondary);
  border-right-color: var(--bg-tertiary);
}

body:not(.dark-theme) .sidebar-header {
  background-color: var(--bg-tertiary);
  border-bottom-color: var(--bg-tertiary);
}

body:not(.dark-theme) .sidebar-footer {
  background-color: var(--bg-tertiary);
  border-top-color: var(--bg-tertiary);
}

body:not(.dark-theme) .navbar-light {
  background-color: var(--bg-secondary) !important;
}

body:not(.dark-theme) .navbar-light .navbar-brand,
body:not(.dark-theme) .navbar-light .nav-link {
  color: var(--text-primary) !important;
}

body:not(.dark-theme) .form-control {
  background-color: var(--bg-secondary);
  border-color: var(--bg-tertiary);
  color: var(--text-primary);
}

body:not(.dark-theme) .form-control:focus {
  background-color: var(--bg-secondary);
  border-color: var(--primary);
  color: var(--text-primary);
}

body:not(.dark-theme) .border,
body:not(.dark-theme) .border-bottom {
  border-color: var(--bg-tertiary) !important;
}

body:not(.dark-theme) .dashboard-header {
  border-bottom-color: var(--bg-tertiary);
}

body:not(.dark-theme) .table-hover tbody tr:hover {
  background-color: var(--bg-tertiary);
}

/* Dark Theme Styles */
body.dark-theme {
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

body.dark-theme header {
  background-color: var(--bg-secondary);
  border-bottom-color: var(--bg-tertiary);
}

body.dark-theme header .navbar {
  box-shadow: var(--shadow-md);
}

body.dark-theme .navbar-light {
  background-color: var(--bg-secondary) !important;
}

body.dark-theme .navbar-light .navbar-brand,
body.dark-theme .navbar-light .nav-link {
  color: var(--text-primary) !important;
}

body.dark-theme .navbar-light #themeToggleBtn {
  color: var(--text-primary) !important;
}

body.dark-theme .navbar-light #themeToggleBtn:hover {
  color: var(--primary) !important;
}

body.dark-theme .card {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--bg-tertiary);
}

body.dark-theme .card-header {
  background-color: var(--bg-tertiary) !important;
  border-bottom-color: var(--bg-tertiary);
  color: var(--text-primary);
}

body.dark-theme .card-header.bg-white {
  background-color: var(--bg-tertiary) !important;
}

body.dark-theme .card-header .card-title,
body.dark-theme .card-header h5,
body.dark-theme .card-header h6 {
  color: var(--text-primary) !important;
}

body.dark-theme .card-header p,
body.dark-theme .card-header .text-muted,
body.dark-theme .card-header small {
  color: var(--text-secondary) !important;
}

body.dark-theme .card-body {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

body.dark-theme .card-body * {
  color: inherit;
}

body.dark-theme .card-body h1,
body.dark-theme .card-body h2,
body.dark-theme .card-body h3,
body.dark-theme .card-body h4,
body.dark-theme .card-body h5,
body.dark-theme .card-body h6,
body.dark-theme .card-body .fw-bold,
body.dark-theme .card-body .fw-semibold {
  color: var(--text-primary) !important;
}

body.dark-theme .stat-card,
body.dark-theme .dashboard-topbar {
  background-color: var(--bg-secondary) !important;
  color: var(--text-primary);
}

body.dark-theme .stat-card .card-body,
body.dark-theme .stat-card .card-body h3,
body.dark-theme .stat-card .card-body .fw-bold {
  color: var(--text-primary) !important;
}

body.dark-theme .stat-card .card-body h6,
body.dark-theme .stat-card .card-body .text-muted {
  color: var(--text-secondary) !important;
}

body.dark-theme .stat-card .card-body small {
  color: var(--success) !important;
}

body.dark-theme .dashboard-sidebar {
  background-color: var(--bg-secondary);
  border-right-color: var(--bg-tertiary);
}

body.dark-theme .sidebar-header {
  background-color: var(--bg-tertiary);
  border-bottom-color: var(--bg-tertiary);
}

body.dark-theme .sidebar-nav .nav-link {
  color: var(--text-primary);
}

body.dark-theme .sidebar-nav .nav-link:hover {
  background-color: var(--bg-tertiary);
  color: var(--primary);
}

body.dark-theme .sidebar-nav .nav-link.active {
  background-color: rgba(37, 99, 235, 0.2);
  color: var(--primary);
}

body.dark-theme .sidebar-footer {
  background-color: var(--bg-tertiary);
  border-top-color: var(--bg-tertiary);
}

body.dark-theme .table {
  color: var(--text-primary);
}

body.dark-theme .table-light {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}

body.dark-theme .table thead th {
  background-color: var(--bg-tertiary);
  color: var(--text-primary) !important;
  border-bottom-color: var(--bg-tertiary);
}

body.dark-theme .table thead th,
body.dark-theme .table thead td {
  color: var(--text-primary) !important;
}

body.dark-theme .table tbody td {
  color: var(--text-primary) !important;
}

body.dark-theme .table tbody .fw-semibold {
  color: var(--text-primary) !important;
}

body.dark-theme .table tbody small,
body.dark-theme .table tbody .text-muted {
  color: var(--text-secondary) !important;
}

body.dark-theme .table-hover tbody tr:hover {
  background-color: var(--bg-tertiary);
}

body.dark-theme .table-hover tbody tr:hover td,
body.dark-theme .table-hover tbody tr:hover .fw-semibold {
  color: var(--text-primary) !important;
}

body.dark-theme .form-control {
  background-color: var(--bg-tertiary);
  border-color: var(--bg-tertiary);
  color: var(--text-primary);
}

body.dark-theme .form-control:focus {
  background-color: var(--bg-tertiary);
  border-color: var(--primary);
  color: var(--text-primary);
}

body.dark-theme .text-muted {
  color: var(--text-secondary) !important;
}

body.dark-theme .border,
body.dark-theme .border-bottom {
  border-color: var(--bg-tertiary) !important;
}

body.dark-theme .dropdown-menu {
  background-color: var(--bg-secondary);
  border-color: var(--bg-tertiary);
}

body.dark-theme .dropdown-item {
  color: var(--text-primary);
}

body.dark-theme .dropdown-item:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}

body.dark-theme .dropdown-header {
  color: var(--text-secondary);
}

body.dark-theme .dashboard-header {
  border-bottom-color: var(--bg-tertiary);
}

body.dark-theme .dashboard-header h1,
body.dark-theme .dashboard-header .display-5,
body.dark-theme .dashboard-header .display-4 {
  color: var(--text-primary) !important;
}

body.dark-theme .dashboard-header p {
  color: var(--text-secondary) !important;
}

/* Ensure all text in card headers is visible */
body.dark-theme .card-header * {
  color: inherit;
}

body.dark-theme .card-header .fw-bold {
  color: #e0e0e0 !important;
}

/* Chart container headers */
body.dark-theme .card .card-header h5,
body.dark-theme .card .card-header .card-title {
  color: #e0e0e0 !important;
}

/* Additional card text elements */
body.dark-theme .card-body .fw-semibold,
body.dark-theme .card-body .fw-bold {
  color: #e0e0e0 !important;
}

body.dark-theme .card-body small,
body.dark-theme .card-body .small {
  color: #a0a0a0 !important;
}

/* Buttons and badges in dark mode */
body.dark-theme .btn-link {
  color: var(--text-primary) !important;
}

body.dark-theme .btn-link:hover {
  color: var(--primary) !important;
}

body.dark-theme .btn-outline-primary {
  color: var(--primary);
  border-color: var(--primary);
}

body.dark-theme .btn-outline-primary:hover {
  background-color: var(--primary);
  color: #fff;
}

/* Badge colors in dark mode */
body.dark-theme .badge {
  color: #fff !important;
}

/* Progress bars in dark mode */
body.dark-theme .progress {
  background-color: var(--bg-tertiary);
}

body.dark-theme .progress-bar {
  color: #fff;
}

/* All headings in cards */
body.dark-theme .card h1,
body.dark-theme .card h2,
body.dark-theme .card h3,
body.dark-theme .card h4,
body.dark-theme .card h5,
body.dark-theme .card h6 {
  color: #e0e0e0 !important;
}

/* Text content in cards */
body.dark-theme .card p,
body.dark-theme .card span:not(.badge),
body.dark-theme .card div:not(.bg-):not(.stat-icon) {
  color: #e0e0e0;
}

body.dark-theme .card .text-success {
  color: var(--success) !important;
}

body.dark-theme .card .text-primary {
  color: var(--primary) !important;
}

body.dark-theme .card .text-info {
  color: var(--info) !important;
}

body.dark-theme .card .text-warning {
  color: var(--warning) !important;
}

body.dark-theme .card .text-danger {
  color: var(--error) !important;
}

/* Display classes */
body.dark-theme .display-1,
body.dark-theme .display-2,
body.dark-theme .display-3,
body.dark-theme .display-4,
body.dark-theme .display-5,
body.dark-theme .display-6 {
  color: #e0e0e0 !important;
}

/* Override Bootstrap container for dashboard page only */
body .container:has(.dashboard-wrapper) {
  max-width: 100% !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
}

body .container:has(.dashboard-wrapper) > main {
  max-width: 100% !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
}

/* Dashboard Styles */
.dashboard-container {
  padding: 0;
  width: 100%;
  max-width: 100%;
}

.dashboard-header {
  padding-bottom: 20px;
  border-bottom: 2px solid var(--bg-tertiary);
}

body:not(.dark-theme) .dashboard-header {
  border-bottom-color: var(--bg-tertiary);
}

.stat-card {
  transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

.stat-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
}

.stat-icon {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.avatar-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  font-size: 14px;
}

.card {
  transition: box-shadow 0.2s ease-in-out;
}

.card:hover {
  box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.1) !important;
}

.table-hover tbody tr:hover {
  background-color: rgba(0, 0, 0, 0.02);
}

/* Override container for dashboard */
body > .container > main > .dashboard-wrapper {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
}

/* Dashboard Wrapper */
.dashboard-wrapper {
  display: flex;
  min-height: calc(100vh - 60px);
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
}

/* Dashboard Sidebar */
.dashboard-sidebar {
  width: 280px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--bg-tertiary);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  z-index: 1010;
  transition: transform 0.3s ease, left 0.3s ease;
  box-shadow: var(--shadow-md);
}

.dashboard-sidebar.sidebar-closed {
  left: -280px;
}

/* Desktop: Ensure sidebar is visible by default */
@media (min-width: 992px) {
  .dashboard-sidebar {
    left: 0 !important;
  }

  .dashboard-sidebar.sidebar-closed {
    left: -280px !important;
  }
}

.sidebar-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--bg-tertiary);
  background: var(--bg-tertiary);
}

.sidebar-logo {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(37, 99, 235, 0.1);
  border-radius: 8px;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
}

.sidebar-nav .nav-link {
  color: var(--text-secondary);
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
  text-decoration: none;
}

.sidebar-nav .nav-link:hover {
  background-color: var(--bg-tertiary);
  color: var(--primary);
  border-left-color: var(--primary);
}

.sidebar-nav .nav-link.active {
  background-color: rgba(37, 99, 235, 0.1);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}

.sidebar-nav .nav-link i {
  width: 20px;
  text-align: center;
}

.sidebar-divider {
  margin: 0.5rem 1.25rem;
  opacity: 0.25;
}

.sidebar-footer {
  border-top: 1px solid var(--bg-tertiary);
  background: var(--bg-tertiary);
}

.user-profile {
  border-top: 1px solid #e9ecef;
}

.user-profile .avatar-circle {
  width: 35px;
  height: 35px;
  font-size: 12px;
}

/* Dashboard Main Content */
.dashboard-main {
  flex: 1;
  width: calc(100% - 280px);
  margin-left: 280px;
  padding: 1.5rem;
  margin-right: 0;
  transition: margin-left 0.3s ease, width 0.3s ease;
}

.dashboard-sidebar.sidebar-closed + .dashboard-main {
  margin-left: 0;
  width: 100%;
}

.dashboard-topbar {
  display: flex;
  align-items: center;
  background: var(--bg-secondary);
  padding: 1rem;
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

.dashboard-topbar .form-control {
  width: 300px;
}

/* Sidebar Overlay - All Screen Sizes */
body.sidebar-overlay-active::before {
  content: '';
  position: fixed;
  top: 60px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1005;
}

/* Mobile adjustments */
@media (max-width: 991.98px) {
  .dashboard-sidebar {
    left: -280px;
  }

  .dashboard-sidebar.sidebar-open {
    left: 0;
  }

  .dashboard-main {
    margin-left: 0 !important;
    width: 100% !important;
  }

  .dashboard-sidebar.sidebar-closed + .dashboard-main {
    margin-left: 0 !important;
    width: 100% !important;
  }

  .dashboard-topbar .form-control {
    width: 200px;
  }
}

@media (max-width: 768px) {
  .dashboard-container {
    padding: 10px;
  }
  
  .stat-icon {
    width: 50px;
    height: 50px;
  }

  .dashboard-main {
    padding: 1rem;
  }

  .dashboard-topbar .form-control {
    width: 150px;
  }
}

/* Smooth scrolling for sidebar */
.sidebar-nav {
  scrollbar-width: thin;
  scrollbar-color: #dee2e6 #f8f9fa;
}

.sidebar-nav::-webkit-scrollbar {
  width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: #f8f9fa;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: #dee2e6;
  border-radius: 3px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
  background: #adb5bd;
}

/* Alert Info Styling - Fix Text Visibility */
.alert-info {
  background-color: #e7f3ff;
  border-color: #b8daff;
  color: #004085;
}

.alert-info strong {
  color: #002752;
  font-weight: 600;
}

.alert-info i {
  color: #0056b3;
}

body.dark-theme .alert-info {
  background-color: rgba(6, 182, 212, 0.1);
  border-color: var(--info);
  color: var(--text-primary);
}

body.dark-theme .alert-info strong {
  color: var(--text-primary);
  font-weight: 600;
}

body.dark-theme .alert-info i {
  color: var(--info);
}