/* Parasolution dashboard navigation: sticky scrollable sidebar, search, folding
   categories, instant highlight and smoother mobile drawer. Shared by the admin
   panel and the user dashboard (.pal-user-nav); reuses the site's colour tokens. */

:is(.admin-panel-with-sidebar, .pal-user-nav) {
  --pal-admin-sticky-top: calc(var(--pal-admin-header-h, 88px) + 16px);
  --pal-admin-ease: cubic-bezier(.2, .8, .2, 1);
}

/* ---------- Sidebar shell ---------- */
:is(.admin-panel-with-sidebar, .pal-user-nav) > .admin-sidebar {
  width: 240px;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  top: var(--pal-admin-sticky-top);
  max-height: calc(100vh - var(--pal-admin-sticky-top) - 16px);
  overflow: hidden;
  padding: 14px 10px 10px;
}

:is(.admin-panel-with-sidebar, .pal-user-nav) > .admin-sidebar .admin-sidebar-header {
  padding: 0 6px 12px;
  margin-bottom: 12px;
}

:is(.admin-panel-with-sidebar, .pal-user-nav) > .admin-sidebar .admin-sidebar-nav {
  flex: 1 1 auto;
  min-height: 0;
  gap: 2px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  padding: 0 2px 4px;
  margin: 0 -2px;
}

:is(.admin-panel-with-sidebar, .pal-user-nav) > .admin-sidebar .admin-sidebar-nav::-webkit-scrollbar { width: 6px; }
:is(.admin-panel-with-sidebar, .pal-user-nav) > .admin-sidebar .admin-sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
}

/* ---------- Search ---------- */
.pal-admin-search {
  position: relative;
  display: flex;
  align-items: center;
  margin: 0 2px 12px;
  flex-shrink: 0;
}

.pal-admin-search .pal-admin-search-icon {
  position: absolute;
  left: 11px;
  color: var(--text-secondary);
  pointer-events: none;
}

.pal-admin-search-input {
  width: 100%;
  height: 36px;
  padding: 0 58px 0 33px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
  -webkit-appearance: none;
  appearance: none;
}

.pal-admin-search-input::-webkit-search-cancel-button { display: none; }
.pal-admin-search-input::placeholder { color: var(--text-secondary); opacity: .75; }

.pal-admin-search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb, 99, 102, 241), .18);
}

.pal-admin-search-kbd {
  position: absolute;
  right: 8px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font: 600 10px/1.4 inherit;
  font-family: inherit;
  pointer-events: none;
}

.pal-admin-search-input:focus ~ .pal-admin-search-kbd { opacity: 0; }

/* ---------- Return button ---------- */
:is(.admin-panel-with-sidebar, .pal-user-nav) .admin-menu-item.pal-admin-return {
  flex-shrink: 0;
  margin: 0 0 10px;
  border: 1px dashed var(--border);
}

/* ---------- Categories ---------- */
:is(.admin-panel-with-sidebar, .pal-user-nav) .admin-menu-category { margin-bottom: 6px; }

:is(.admin-panel-with-sidebar, .pal-user-nav) .pal-admin-cat-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin: 0;
  padding: 8px 10px 6px 12px;
  background: none;
  border: 0;
  border-radius: 6px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: color .15s ease;
}

:is(.admin-panel-with-sidebar, .pal-user-nav) .pal-admin-cat-toggle:hover:not(:disabled) { color: var(--text-primary); }
:is(.admin-panel-with-sidebar, .pal-user-nav) .pal-admin-cat-toggle:disabled { cursor: default; }

.pal-admin-cat-name { flex: 1; min-width: 0; }

.pal-admin-cat-count {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0;
  opacity: 0;
  transition: opacity .15s ease;
}

.pal-admin-cat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb, 99, 102, 241), .2);
}

.pal-admin-cat-chevron {
  flex-shrink: 0;
  opacity: .7;
  transition: transform .22s var(--pal-admin-ease);
}

.pal-admin-cat-toggle:disabled .pal-admin-cat-chevron { opacity: 0; }

.admin-menu-category.is-collapsed .pal-admin-cat-chevron { transform: rotate(-90deg); }
.admin-menu-category.is-collapsed .pal-admin-cat-count,
:is(.admin-panel-with-sidebar, .pal-user-nav) .pal-admin-cat-toggle:hover .pal-admin-cat-count { opacity: .8; }

.pal-admin-cat-items {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows .24s var(--pal-admin-ease);
}

.admin-menu-category.is-collapsed .pal-admin-cat-items { grid-template-rows: 0fr; }

.pal-admin-cat-inner {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ---------- Items ---------- */
:is(.admin-panel-with-sidebar, .pal-user-nav) .admin-menu-item {
  padding: 9px 12px;
  transition: background-color .15s ease, color .15s ease, box-shadow .2s ease;
  -webkit-tap-highlight-color: transparent;
}

:is(.admin-panel-with-sidebar, .pal-user-nav) .admin-menu-item:hover { transform: none; }

:is(.admin-panel-with-sidebar, .pal-user-nav) .admin-menu-item:not(.active):hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

:is(.admin-panel-with-sidebar, .pal-user-nav) .admin-menu-item:not(.active):active { background: rgba(var(--accent-rgb, 99, 102, 241), .12); }

:is(.admin-panel-with-sidebar, .pal-user-nav) .admin-menu-item:focus-visible,
:is(.admin-panel-with-sidebar, .pal-user-nav) .pal-admin-cat-toggle:focus-visible,
.pal-admin-mobilebar button:focus-visible {
  outline: 2px solid rgba(var(--accent-rgb, 99, 102, 241), .75);
  outline-offset: 1px;
}

:is(.admin-panel-with-sidebar, .pal-user-nav) .admin-menu-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

:is(.admin-panel-with-sidebar, .pal-user-nav) .admin-menu-item[hidden],
:is(.admin-panel-with-sidebar, .pal-user-nav) .admin-menu-category[hidden] { display: none; }

.pal-admin-empty {
  padding: 18px 12px;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
}

/* Loaders / Remboursements injected by admin-loader-ui.js & admin-refund-ui.js */
.pal-tools-category { display: flex; flex-direction: column; gap: 2px; }

/* ---------- Content transitions ---------- */
:is(.admin-panel-with-sidebar, .pal-user-nav) > .admin-content > * {
  /* backwards, not both: a filled opacity animation keeps a stacking context that
     would trap the tab's modals under the sticky header. */
  animation: pal-admin-enter .22s var(--pal-admin-ease) backwards;
}

/* Opacity only: a transform would make each tab the containing block of its
   position: fixed modals (feedback form, ban dialog…) and crop them. */
@keyframes pal-admin-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* .dashboard and .dashboard-content use `contain: content`, which also makes
   them the containing block of fixed elements: modals, the mobile drawer and
   its overlay would follow the page and get clipped instead of covering the screen. */
.dashboard:has(.admin-panel-with-sidebar),
.dashboard-content:has(> .admin-content > .admin-panel-with-sidebar),
.dashboard:has(> .dashboard-content.pal-user-nav),
.dashboard-content.pal-user-nav { contain: none; }

.pal-admin-progress {
  position: absolute;
  top: -12px;
  left: 0;
  right: 0;
  height: 2px;
  overflow: hidden;
  border-radius: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
}

.pal-admin-progress::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 40%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: pal-admin-progress 1s ease-in-out infinite;
}

.admin-panel-with-sidebar.is-navigating > .pal-admin-progress {
  opacity: 1;
  transition-delay: .12s;
}

@keyframes pal-admin-progress {
  from { transform: translateX(-100%); }
  to { transform: translateX(250%); }
}

/* ---------- Mobile bar (hidden on desktop) ---------- */
.pal-admin-mobilebar { display: none; }

@media (max-width: 1024px) {
  :is(.admin-panel-with-sidebar, .pal-user-nav) { flex-direction: column; gap: 16px; }

  .pal-admin-mobilebar {
    position: sticky;
    top: calc(var(--pal-admin-header-h, 68px) + 8px);
    z-index: 90;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  }

  :is(.admin-panel-with-sidebar, .pal-user-nav) .pal-admin-mobilebar .admin-menu-toggle {
    position: static;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 10px;
    box-shadow: none;
  }

  :is(.admin-panel-with-sidebar, .pal-user-nav) .pal-admin-mobilebar .admin-menu-toggle:hover { transform: none; }

  .pal-admin-mobilebar-title {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 0;
    background: none;
    border: 0;
    color: var(--text-primary);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
  }

  .pal-admin-mobilebar-title span {
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
  }

  .pal-admin-mobilebar-title strong {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 15px;
  }

  .pal-admin-mobilebar-search {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    cursor: pointer;
  }

  :is(.admin-panel-with-sidebar, .pal-user-nav) > .admin-sidebar,
  :is(.admin-panel-with-sidebar, .pal-user-nav) > .admin-sidebar.open {
    width: min(320px, 86vw);
    min-width: 0;
    top: 0;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    padding: calc(14px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom));
    border-radius: 0 16px 16px 0;
    transition: transform .3s var(--pal-admin-ease), visibility 0s linear .3s;
    visibility: hidden;
    will-change: transform;
  }

  :is(.admin-panel-with-sidebar, .pal-user-nav) > .admin-sidebar.open {
    visibility: visible;
    box-shadow: 24px 0 60px rgba(0, 0, 0, .45);
    transition: transform .3s var(--pal-admin-ease), visibility 0s;
  }

  :is(.admin-panel-with-sidebar, .pal-user-nav) > .admin-sidebar .admin-sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
  }

  :is(.admin-panel-with-sidebar, .pal-user-nav) > .admin-sidebar .admin-menu-item { padding: 11px 12px; font-size: 14px; }

  :is(.admin-panel-with-sidebar, .pal-user-nav) > .admin-sidebar-overlay {
    display: block;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .25s ease, visibility 0s linear .25s;
  }

  :is(.admin-panel-with-sidebar, .pal-user-nav) > .admin-sidebar-overlay.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity .25s ease, visibility 0s;
  }

  .pal-admin-search-kbd { display: none; }
  .pal-admin-search-input { height: 40px; padding-right: 12px; font-size: 16px; }

  body.pal-admin-nav-locked { overflow: hidden; }

  /* Fallback for browsers without :has(): lift containment while the drawer is open. */
  body.pal-admin-nav-locked .dashboard,
  body.pal-admin-nav-locked .dashboard-content { contain: none; }

  .pal-admin-progress { top: -8px; }
}

@media (prefers-reduced-motion: reduce) {
  :is(.admin-panel-with-sidebar, .pal-user-nav) > .admin-content > *,
  .pal-admin-progress::after { animation: none; }
  :is(.admin-panel-with-sidebar, .pal-user-nav) > .admin-sidebar,
  .pal-admin-cat-items,
  .pal-admin-cat-chevron { transition: none; }
}

/* ---------- Tables: pinned Actions column ---------- */
.admin-panel-with-sidebar .admin-table.pal-sticky-actions thead th:last-child,
.admin-panel-with-sidebar .admin-table.pal-sticky-actions tbody td:last-child:not(.admin-empty) {
  position: sticky;
  right: 0;
  z-index: 2;
  background: var(--bg-secondary);
  box-shadow: -14px 0 16px -14px rgba(0, 0, 0, .75);
  border-left: 1px solid var(--border);
}

.admin-panel-with-sidebar .admin-table.pal-sticky-actions thead th:last-child { background: var(--bg-tertiary); }
.admin-panel-with-sidebar .admin-table.pal-sticky-actions tbody tr:hover td:last-child:not(.admin-empty) { background: var(--bg-tertiary); }
.admin-panel-with-sidebar .admin-table.pal-sticky-actions tbody tr.editing td:last-child {
  background: linear-gradient(rgba(var(--accent-rgb, 99, 102, 241), .08), rgba(var(--accent-rgb, 99, 102, 241), .08)), var(--bg-secondary);
}

.admin-panel-with-sidebar .admin-table.pal-sticky-actions .admin-actions { flex-wrap: nowrap; }
.admin-panel-with-sidebar .admin-table.pal-sticky-actions .admin-actions .admin-btn { white-space: nowrap; }

/* ---------- Users: click the balance to edit it ---------- */
.pal-credits-edit {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: -6px -8px;
  padding: 6px 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease;
}

.pal-credits-edit-icon {
  color: var(--text-secondary);
  opacity: 0;
  transition: opacity .15s ease, color .15s ease;
}

.pal-credits-edit:hover,
.pal-credits-edit:focus-visible {
  background: var(--bg-primary);
  border-color: var(--border);
  outline: none;
}

.admin-table tbody tr:hover .pal-credits-edit-icon,
.pal-credits-edit:focus-visible .pal-credits-edit-icon { opacity: 1; }
.pal-credits-edit:hover .pal-credits-edit-icon { color: var(--accent); }

@media (hover: none) {
  .pal-credits-edit-icon { opacity: .6; }
}
