/* ============================================
   THEME SYSTEM - CSS Custom Properties
   ============================================ */

:root {
  /* Light Theme Colors */
  --bg-primary: #f9fafb;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f3f4f6;
  --bg-sidebar: #14532d;
  --bg-sidebar-hover: #166534;
  --bg-sidebar-active: #15803d;
  --bg-card: #ffffff;
  --bg-input: #ffffff;

  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --text-sidebar: #ffffff;
  --text-sidebar-muted: #86efac;

  --border-color: #e5e7eb;
  --border-sidebar: #166534;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1),
    0 4px 6px -4px rgb(0 0 0 / 0.1);

  /* Accent Colors (remain same in both themes) */
  --color-green-600: #16a34a;
  --color-green-700: #15803d;
  --color-green-800: #166534;
  --color-green-900: #14532d;
}

/* Dark Theme Colors */
html.dark-theme {
  --bg-primary: #111827;
  --bg-secondary: #1f2937;
  --bg-tertiary: #374151;
  --bg-sidebar: #0f172a;
  --bg-sidebar-hover: #1e293b;
  --bg-sidebar-active: #334155;
  --bg-card: #1f2937;
  --bg-input: #374151;

  --text-primary: #f9fafb;
  --text-secondary: #d1d5db;
  --text-tertiary: #9ca3af;
  --text-sidebar: #f1f5f9;
  --text-sidebar-muted: #94a3b8;

  --border-color: #374151;
  --border-sidebar: #1e293b;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3),
    0 4px 6px -4px rgb(0 0 0 / 0.3);
}

/* ============================================
   APPLY THEME COLORS TO ELEMENTS
   ============================================ */

/* Body and Main Content */
body {
  background-color: var(--bg-primary) !important;
  color: var(--text-primary);
}

main {
  background-color: var(--bg-primary) !important;
}

/* Override Tailwind bg-gray-50, bg-gray-100 */
.bg-gray-50 {
  background-color: var(--bg-primary) !important;
}

.bg-gray-100 {
  background-color: var(--bg-tertiary) !important;
}

/* White backgrounds (cards, modals, sections) */
.bg-white {
  background-color: var(--bg-card) !important;
}

/* Text colors */
.text-gray-800,
.text-gray-900 {
  color: var(--text-primary) !important;
}

.text-gray-700 {
  color: var(--text-primary) !important;
}

.text-gray-600 {
  color: var(--text-secondary) !important;
}

.text-gray-500 {
  color: var(--text-secondary) !important;
}

.text-gray-400 {
  color: var(--text-tertiary) !important;
}

/* Borders */
.border-gray-300,
.border-gray-200 {
  border-color: var(--border-color) !important;
}

/* Tables */
table thead,
.bg-gray-50 {
  background-color: var(--bg-tertiary) !important;
}

table tbody tr {
  border-color: var(--border-color) !important;
}

table tbody tr:hover {
  background-color: var(--bg-tertiary) !important;
}

/* Input fields */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="tel"],
select,
textarea {
  background-color: var(--bg-input) !important;
  color: var(--text-primary) !important;
  border-color: var(--border-color) !important;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-tertiary) !important;
}

/* Sidebar specific */
#sidebar {
  background-color: var(--bg-sidebar) !important;
}

#sidebar .border-green-800 {
  border-color: var(--border-sidebar) !important;
}

#sidebar .bg-green-950 {
  background-color: var(--bg-sidebar) !important;
}

/* Dropdown menus */
#userMenu {
  background-color: var(--bg-sidebar-hover) !important;
  border-color: var(--border-sidebar) !important;
}

/* Cards and sections with shadows */
.shadow-md,
.shadow-lg {
  box-shadow: var(--shadow-md);
}

/* Smooth transitions for theme switching */
body,
#sidebar,
.bg-white,
.bg-gray-50,
.bg-gray-100,
.text-gray-800,
.text-gray-700,
.text-gray-600,
.text-gray-500 {
  transition: background-color 0.3s ease, color 0.3s ease,
    border-color 0.3s ease;
}

/* Theme Toggle Button Styles */
.theme-toggle {
  position: relative;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.375rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.theme-toggle:hover {
  background-color: var(--bg-sidebar-hover);
}

.theme-toggle svg {
  width: 1.25rem;
  height: 1.25rem;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.theme-toggle .sun-icon {
  position: absolute;
}

.theme-toggle .moon-icon {
  position: absolute;
}

html:not(.dark-theme) .theme-toggle .moon-icon {
  opacity: 0;
  transform: rotate(180deg);
}

html:not(.dark-theme) .theme-toggle .sun-icon {
  opacity: 1;
  transform: rotate(0deg);
}

html.dark-theme .theme-toggle .sun-icon {
  opacity: 0;
  transform: rotate(-180deg);
}

html.dark-theme .theme-toggle .moon-icon {
  opacity: 1;
  transform: rotate(0deg);
}

/* ============================================
   SIDEBAR STYLES
   ============================================ */

/* Sidebar Transitions */
#sidebar {
  transition: width 0.3s ease-in-out;
}

#sidebar .menu-text,
#sidebar .user-details,
#sidebar .sidebar-title {
  transition: opacity 0.2s ease-in-out;
  white-space: nowrap;
  overflow: hidden;
}

/* Collapsed State */
#sidebar.collapsed {
  width: 5rem; /* w-20 */
}

#sidebar.collapsed .menu-text,
#sidebar.collapsed .user-details,
#sidebar.collapsed .sidebar-title {
  opacity: 0;
  width: 0;
  display: none; /* Ensure they don't take up space */
}

#sidebar.collapsed .logo {
  width: 2rem;
  height: 2rem;
}

#sidebar.collapsed .sidebar-header {
  flex-direction: column;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem;
}

#sidebar.collapsed #sidebarToggle {
  margin-left: 0;
}

#sidebar.collapsed .menu-link {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

#sidebar.collapsed .user-section {
  padding: 1rem 0.5rem;
  justify-content: center;
}

#sidebar.collapsed #userMenuChevron {
  display: none;
}

#sidebar.collapsed .theme-toggle {
  margin: 0.25rem auto;
}

/* Tooltips */
.menu-link {
  position: relative;
}

#sidebar.collapsed .menu-link:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  background-color: #1f2937; /* gray-800 */
  color: white;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 50;
  margin-left: 0.5rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* ============================================
   PAGINATION STYLES
   ============================================ */

/* Pagination container */
.pagination,
nav[aria-label="Pagination"] {
  display: flex;
  gap: 0.25rem;
}

/* Pagination links - Light Theme */
.pagination a,
.pagination span,
nav[aria-label="Pagination"] a,
nav[aria-label="Pagination"] span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  height: 2.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  text-decoration: none;
  transition: all 0.2s ease;
  cursor: pointer;
}

/* Pagination hover state */
.pagination a:hover,
nav[aria-label="Pagination"] a:hover {
  background-color: var(--bg-tertiary);
  border-color: var(--border-color);
}

/* Active pagination page - Both themes */
.pagination a.bg-blue-600,
.pagination a.bg-green-600,
nav[aria-label="Pagination"] a.bg-blue-600,
nav[aria-label="Pagination"] a.bg-green-600 {
  background-color: #16a34a !important;
  color: #ffffff !important;
  border-color: #16a34a !important;
  font-weight: 600;
}

/* Active page hover */
.pagination a.bg-blue-600:hover,
.pagination a.bg-green-600:hover,
nav[aria-label="Pagination"] a.bg-blue-600:hover,
nav[aria-label="Pagination"] a.bg-green-600:hover {
  background-color: #15803d !important;
  border-color: #15803d !important;
}

/* Ellipsis */
.pagination span,
nav[aria-label="Pagination"] span {
  cursor: default;
  border-color: transparent;
  background-color: transparent;
}

/* Dark Theme Pagination Overrides */
html.dark-theme .pagination a,
html.dark-theme .pagination span,
html.dark-theme nav[aria-label="Pagination"] a,
html.dark-theme nav[aria-label="Pagination"] span {
  background-color: var(--bg-secondary);
  border-color: var(--border-color);
  color: var(--text-primary);
}

html.dark-theme .pagination a:hover,
html.dark-theme nav[aria-label="Pagination"] a:hover {
  background-color: var(--bg-tertiary);
  border-color: #4b5563;
}

/* Active page in dark theme stays green */
html.dark-theme .pagination a.bg-blue-600,
html.dark-theme .pagination a.bg-green-600,
html.dark-theme nav[aria-label="Pagination"] a.bg-blue-600,
html.dark-theme nav[aria-label="Pagination"] a.bg-green-600 {
  background-color: #16a34a !important;
  color: #ffffff !important;
  border-color: #16a34a !important;
}

html.dark-theme .pagination a.bg-blue-600:hover,
.pagination a.bg-green-600:hover,
html.dark-theme nav[aria-label="Pagination"] a.bg-blue-600:hover,
html.dark-theme nav[aria-label="Pagination"] a.bg-green-600:hover {
  background-color: #15803d !important;
  border-color: #15803d !important;
}

/* Ellipsis in dark theme */
html.dark-theme .pagination span,
html.dark-theme nav[aria-label="Pagination"] span {
  background-color: transparent;
  border-color: transparent;
}

/* Disabled state */
.pagination a[disabled],
.pagination a.disabled,
nav[aria-label="Pagination"] a[disabled],
nav[aria-label="Pagination"] a.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
