/* Collapsible Admin Sidebar — Django 5.2 Riqroll Admin */

/* ── Reduce gap between app sections (Django default is 30px) ── */

#nav-sidebar .module {
  margin-bottom: 5px;
}

/* ── Theme-aware sidebar colours ── */

/* Light mode (explicit or auto with light preference) */
html[data-theme="light"] #nav-sidebar .module caption a.section,
html[data-theme="light"] #nav-sidebar .module caption {
  color: #1a2c35;
}

html[data-theme="light"] #nav-sidebar .module:not(.expanded):not(.active) caption a.section {
  color: #1a2c35;
}

html[data-theme="light"] #nav-sidebar .module caption:hover {
  background-color: rgba(0, 0, 0, 0.15);
}

html[data-theme="light"] #nav-sidebar .module.active {
  background-color: rgba(0, 120, 180, 0.08);
}

html[data-theme="light"] #nav-sidebar .module.active caption a.section {
  color: #0a1f2a;
  font-weight: bold;
}

html[data-theme="light"] #nav-sidebar .module .current-model {
  background: rgba(0, 120, 180, 0.12);
}

html[data-theme="light"] #nav-sidebar .module .current-model th a {
  color: #0a1f2a;
  font-weight: bold;
}

html[data-theme="light"] #nav-sidebar .module tbody tr:hover {
  background-color: rgba(0, 0, 0, 0.04);
}

html[data-theme="light"] #nav-sidebar .module caption::after {
  color: #1a2c35;
}

html[data-theme="light"] #nav-sidebar .module th a {
  color: #1e3a4a;
}

html[data-theme="light"] #nav-sidebar .module td a {
  color: #1e3a4a;
}

/* Dark mode (explicit) */
html[data-theme="dark"] #nav-sidebar .module caption:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

html[data-theme="dark"] #nav-sidebar .module.active {
  background-color: rgba(100, 200, 255, 0.06);
}

html[data-theme="dark"] #nav-sidebar .module .current-model {
  background: rgba(100, 200, 255, 0.12);
}

html[data-theme="dark"] #nav-sidebar .module tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.04);
}

html[data-theme="dark"] #nav-sidebar .module .current-model th a {
  color: #79aec8;
  font-weight: bold;
}

/* Auto mode — match system preference */
@media (prefers-color-scheme: light) {
  html[data-theme="auto"] #nav-sidebar .module caption a.section,
  html[data-theme="auto"] #nav-sidebar .module caption {
    color: #1a2c35;
  }

  html[data-theme="auto"] #nav-sidebar .module:not(.expanded):not(.active) caption a.section {
    color: #1a2c35;
  }

  html[data-theme="auto"] #nav-sidebar .module caption:hover {
    background-color: rgba(0, 0, 0, 0.15);
  }

  html[data-theme="auto"] #nav-sidebar .module.active {
    background-color: rgba(0, 120, 180, 0.08);
  }

  html[data-theme="auto"] #nav-sidebar .module .current-model {
    background: rgba(0, 120, 180, 0.12);
  }

  html[data-theme="auto"] #nav-sidebar .module tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.04);
  }

  html[data-theme="auto"] #nav-sidebar .module caption::after {
    color: #1a2c35;
  }

  html[data-theme="auto"] #nav-sidebar .module th a {
    color: #1e3a4a;
  }

  html[data-theme="auto"] #nav-sidebar .module .current-model th a {
    color: #0a1f2a;
    font-weight: bold;
  }

  html[data-theme="auto"] #nav-sidebar .module.active caption a.section {
    color: #0a1f2a;
    font-weight: bold;
  }

  html[data-theme="auto"] #nav-sidebar .module td a {
    color: #1e3a4a;
  }
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] #nav-sidebar .module caption:hover {
    background-color: rgba(255, 255, 255, 0.05);
  }

  html[data-theme="auto"] #nav-sidebar .module.active {
    background-color: rgba(100, 200, 255, 0.06);
  }

  html[data-theme="auto"] #nav-sidebar .module .current-model {
    background: rgba(100, 200, 255, 0.12);
  }

  html[data-theme="auto"] #nav-sidebar .module tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.04);
  }

  html[data-theme="auto"] #nav-sidebar .module .current-model th a {
    color: #79aec8;
    font-weight: bold;
  }
}

/* ── Caption (app header) — clickable toggle ── */

#nav-sidebar .module caption {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 28px;
  padding-top: 8px;
  padding-bottom: 8px;
  transition: background-color 0.2s ease;
  background-color: rgba(65, 118, 144, 0.4);
}

#nav-sidebar .module caption::after {
  content: '\203A';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.2rem;
  font-weight: bold;
  color: #1a2c35;
  transition: transform 0.3s ease;
}

#nav-sidebar .module.expanded caption::after,
#nav-sidebar .module.active caption::after {
  transform: translateY(-50%) rotate(90deg);
}

/* ── Collapse/expand animation on tbody ── */

#nav-sidebar .module tbody {
  display: block;
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease;
}

#nav-sidebar .module.expanded tbody,
#nav-sidebar .module.active tbody {
  max-height: 2000px;
  transition: max-height 0.4s ease-in;
}

/* Keep table rows as table display when visible */
#nav-sidebar .module tbody tr {
  display: table-row;
}

#nav-sidebar .module thead {
  display: none;
}

/* Ensure table and caption still render properly */
#nav-sidebar .module table {
  width: 100%;
  border-collapse: collapse;
}

#nav-sidebar .module caption {
  display: table-caption;
}

/* ── Active section highlight ── */

#nav-sidebar .module.active {
  border-left: 3px solid var(--primary);
}

[dir="rtl"] #nav-sidebar .module.active {
  border-left: none;
  border-right: 3px solid var(--primary);
}

/* ── Filter active state — expand all when searching ── */

#nav-sidebar.filtering .module tbody {
  max-height: 2000px;
  transition: max-height 0.2s ease-in;
}

#nav-sidebar.filtering .module caption::after {
  transform: translateY(-50%) rotate(90deg);
}

/* ── Smooth scroll for auto-focus ── */

#nav-sidebar {
  scroll-behavior: smooth;
}
