/* Admin components and tokens - non-invasive presentation-only rules */
:root {
  --admin-bg-gradient-start: #0a2546;
  --admin-bg-gradient-end: #18b9b6;
  --admin-primary: #2563eb;
  --admin-accent: #d63384;
  --admin-card-bg: #ffffff;
  --admin-muted: #6b7280;
  --space-xxs: 0.25rem;
  --space-xs: 0.5rem;
  --space-sm: 0.75rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --radius-sm: 4px;
  --radius-md: 10px;
  --card-shadow: 0 6px 24px rgba(16, 24, 40, 0.08);
}

/* Responsive container padding */
.content-wrapper,
.main-content {
  padding: clamp(0.75rem, 2vw, 1.5rem);
}

/* Off-canvas sidebar for mobile */
.admin-sidebar {
  transition:
    transform 0.25s ease,
    opacity 0.2s ease;
}
@media (max-width: 767.98px) {
  .admin-sidebar {
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    width: 280px !important;
    transform: translateX(-110%) !important;
    z-index: 1050 !important;
    margin: 0 !important;
    padding: 1.25rem !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1) !important;
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(10px) !important;
  }

  .admin-sidebar.show {
    transform: translateX(0) !important;
  }

  .admin-sidebar-overlay,
  .admin-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1040;
  }

  .admin-sidebar-overlay.show,
  .admin-overlay.show {
    display: block;
  }

  /* Show the hamburger toggle on small screens */
  .admin-sidebar-toggle {
    display: inline-flex !important;
    border: none;
    background: transparent;
    color: white;
    margin-right: 0.5rem;
  }
}

/* Table responsive helper */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Ensure touch targets meet 44px minimum */
.admin-btn,
.btn-admin-outline,
.admin-sidebar .list-group-item {
  min-height: 44px;
  min-width: 44px;
  padding: 0.5rem 1rem;
}

/* Priority-based column helpers (requires data-priority attrs) */
@media (max-width: 575.98px) {
  table thead th[data-priority="3"],
  table td[data-priority="3"] {
    display: none;
  }
}
@media (max-width: 767.98px) {
  table thead th[data-priority="2"],
  table td[data-priority="2"] {
    display: none;
  }
}

/* Small utility */
.hidden-on-mobile {
  display: none;
}

/* Card and badge tokens */
.admin-card {
  background: var(--admin-card-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--card-shadow);
}
.admin-badge {
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-weight: 600;
}

/* Minor focus outline for keyboard users */
.admin-sidebar a:focus,
.admin-sidebar button:focus,
.admin-sidebar .list-group-item:focus {
  outline: 3px solid rgba(37, 99, 235, 0.25);
  outline-offset: 2px;
}

/* Details control for table rows (mobile) */
.row-details-toggle {
  cursor: pointer;
  color: var(--admin-primary);
  font-weight: 600;
}

/* Table row details for mobile */
.row-details {
  background: #f8f9fa;
  border-top: 1px solid #dee2e6;
}
.row-details td {
  padding: 1rem;
  font-size: 0.875rem;
}

/* Prevent tables from clipping action controls (override page-specific rules) */
.table {
  overflow: visible !important;
}
.table td,
.table th {
  overflow: visible !important;
}
.table-responsive {
  overflow-x: auto !important;
}

/* Ensure delete / action buttons remain visible and tappable on small screens */
.delete-user {
  position: relative;
  z-index: 20;
  min-width: 44px;
  white-space: nowrap;
}
.delete-user .btn-text {
  display: inline-block;
}

@media (max-width: 576px) {
  /* Keep the icon visible and make the label optional, but ensure the button itself remains present */
  .delete-user {
    padding: 0.35rem 0.5rem !important;
    min-width: 40px !important;
  }
  .delete-user .btn-text {
    display: none;
  }
  /* Allow selects to shrink more on narrow screens so actions don't get pushed out */
  .table td .form-control {
    min-width: 90px !important;
    max-width: 160px !important;
  }
}

/* Sticky actions column so buttons remain visible when table scrolls */
.table thead th.actions-column,
.table tbody td.actions-column {
  position: -webkit-sticky !important;
  position: sticky !important;
  right: 0 !important;
  z-index: 40 !important;
  background: rgba(255, 255, 255, 0.95) !important;
  white-space: nowrap !important;
  box-shadow: -6px 0 12px rgba(0, 0, 0, 0.06) !important;
}

@media (max-width: 767.98px) {
  /* Ensure the sticky action column doesn't block touch on very small screens */
  .table thead th.actions-column,
  .table tbody td.actions-column {
    box-shadow: none !important;
  }
}

/* Prevent overlapping text in admin tables: truncate long values and avoid layout shifts */
.main-content .table {
  table-layout: fixed; /* allow columns to respect available space and enable text-overflow */
}
.main-content .table th,
.main-content .table td {
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
  max-width: 1% !important; /* collapse to fit available space when table-layout:fixed */
}

/* Allow controls inside cells to behave normally (not truncated) */
.main-content .table td .form-control,
.main-content .table td .btn,
.main-content .table td .btn-group,
.main-content .table td .admin-actions,
.main-content .table td .delete-user {
  overflow: visible !important;
  white-space: nowrap !important;
}

/* Responsive: on very small screens let the name/title column wrap instead of truncating so it doesn't overlap actions */
@media (max-width: 575.98px) {
  .main-content .table th:nth-child(2),
  .main-content .table td:nth-child(2),
  .main-content .table th:nth-child(3),
  .main-content .table td:nth-child(3) {
    white-space: normal !important;
    overflow-wrap: anywhere !important;
  }

  /* Slightly reduce cell padding to fit more content */
  .main-content .table td,
  .main-content .table th {
    padding: 0.45rem 0.5rem !important;
  }
}

/* Navbar: prevent brand/buttons from overlapping */
.admin-navbar .navbar-brand {
  flex-shrink: 0;
}
.admin-navbar .btn-admin-outline {
  flex-shrink: 0;
}

/* Keep overlay out of print */
@media print {
  .admin-sidebar,
  .admin-sidebar-overlay,
  .admin-overlay {
    display: none !important;
  }
}
