/*
 * NextGen application shell and shared primitives.
 * All values reference variables in tokens.css.
 *
 * Layouts:
 *   .app-shell + .top-nav        — global frame, used on every authenticated page.
 *   .page-layout                  — content row beneath the top nav.
 *   .sidebar                      — left admin nav, used only inside Company Settings.
 *   .main-content                 — padded content area.
 *   .main-content--embedded       — zero-padding variant for full-bleed iframes.
 *
 * Primitives: .card, .table, .input, .select, .button, .status-pill, .modal, .segmented-control.
 * Feedback Loop: .feedback-row, .feedback-drawer, .feedback-drawer-grid, .feedback-drawer-section.
 */

/* ── Base ───────────────────────────────────────────────────────────────── */
html, body {
  margin: 0 !important;
  padding: 0 !important;
}

body {
  font-family: var(--font-sans);
  color: var(--color-text-primary);
  background: var(--color-page-bg);
  font-size: 14px;
  overflow-x: hidden;     /* never show a horizontal scrollbar on the main page */
}

main { display: block; margin: 0; padding: 0; }
.app-shell { margin: 0; padding: 0; }

/* Hide Django admin's sidebar-collapse button — our sidebar doesn't use it. */
#toggle-nav-sidebar { display: none !important; }

a {
  color: var(--color-brand-blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ── App shell ──────────────────────────────────────────────────────────── */
/* Fixed-height shell: the top nav is pinned and the <main> content pane is the
   only scroll region. Admin pages get the equivalent treatment on #container
   in admin/base_site.html. */
.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--color-page-bg);
}

/* The content pane — the single scroll region (both axes) on app pages. */
.app-shell > main {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.top-nav {
  flex: 0 0 auto;
  height: var(--top-nav-height);
  background: linear-gradient(180deg, var(--color-brand-navy), var(--color-brand-navy-dark));
  color: var(--color-text-inverse);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  z-index: 100;
}

.top-nav a.top-nav__brand,
.top-nav a.top-nav__brand:visited,
.top-nav a.top-nav__brand:hover {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--color-text-inverse) !important;
  font-weight: 700;
  font-size: 16px;
  text-decoration: none !important;
}

.top-nav__brand-logo {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.top-nav__links {
  display: flex;
  align-items: center;
  gap: 32px;
  margin-left: auto;
  margin-right: 32px;
}

.top-nav a.top-nav__link {
  color: rgba(255, 255, 255, 0.55) !important;
  text-decoration: none;
  font-weight: 600;
  height: var(--top-nav-height);
  display: flex;
  align-items: center;
  border-bottom: 3px solid transparent;
  padding: 0 2px;
  transition: color 0.15s ease;
}

.top-nav a.top-nav__link:hover {
  color: #ffffff !important;
  text-decoration: none;
}

.top-nav a.top-nav__link.active {
  color: #ffffff !important;
  border-bottom-color: #ffffff;
}

.top-nav__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-brand-blue);
  color: var(--color-text-inverse);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
}

.top-nav__avatar:hover {
  border-color: rgba(255, 255, 255, 0.55);
}

.top-nav__user {
  position: relative;
}

.top-nav__menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  max-width: 280px;
  background: var(--color-surface);
  color: var(--color-text-primary);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.15);
  padding: 8px 0;
  display: none;
  z-index: 200;
  box-sizing: border-box;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.top-nav__menu.open {
  display: block;
}

.top-nav__menu-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--color-border-subtle);
}

.top-nav__menu-header strong {
  display: block;
  font-size: 13px;
}

.top-nav__menu-header span {
  display: block;
  font-size: 12px;
  color: var(--color-text-muted);
}

.top-nav__menu a,
.top-nav__menu button {
  display: block;
  width: 100%;
  padding: 8px 16px;
  background: transparent;
  border: 0;
  text-align: left;
  font: inherit;
  color: var(--color-text-primary);
  cursor: pointer;
}

.top-nav__menu a:hover,
.top-nav__menu button:hover {
  background: var(--color-surface-subtle);
  text-decoration: none;
}

/* ── Page layout ────────────────────────────────────────────────────────── */
.page-layout {
  display: flex;
  min-height: calc(100vh - var(--top-nav-height));
}

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border-subtle);
  padding: 28px 16px;
  box-sizing: border-box;
  position: sticky;
  /* The content pane (<main>) is the scroll container now and already sits
     below the top nav, so stick to its top (0), not the nav height — otherwise
     a top-nav-height gap opens above the sidebar when the pane scrolls. */
  top: 0;
  align-self: flex-start;
  height: calc(100vh - var(--top-nav-height));
  overflow-y: auto;
}

.sidebar__heading {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  padding: 0 12px;
  margin: 0 0 12px;
}

.sidebar__section {
  margin-top: 16px;
}

.sidebar__section + .sidebar__section {
  border-top: 1px solid var(--color-border-subtle);
  padding-top: 16px;
}

.sidebar__section-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 12px;
  margin: 0 0 4px;
  background: transparent;
  border: 0;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  color: var(--color-brand-blue);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-align: left;
}

.sidebar__section-toggle:hover {
  background: var(--color-row-hover);
}

.sidebar__section-toggle .sidebar__section-icon {
  flex-shrink: 0;
}

.sidebar__section-toggle .sidebar__section-chevron {
  margin-left: auto;
  color: var(--color-text-muted);
  transition: transform 0.15s ease;
}

/* Chevron points up when expanded, down when collapsed (rotated 180°). */
.sidebar__section-toggle[aria-expanded="false"] .sidebar__section-chevron {
  transform: rotate(180deg);
}

.sidebar__section-items {
  padding-left: 4px;
  margin-top: 6px;
}

.sidebar__section-toggle[aria-expanded="false"] + .sidebar__section-items {
  display: none;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin: 3px 0;
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-size: 14px;
  text-decoration: none;
}

.sidebar__link .sidebar__link-icon {
  flex-shrink: 0;
  color: var(--color-text-muted);
}

.sidebar__link:hover {
  background: var(--color-row-hover);
  color: var(--color-text-primary);
  text-decoration: none;
}

.sidebar__link:hover .sidebar__link-icon { color: var(--color-text-secondary); }

.sidebar__link.active {
  background: var(--color-brand-blue-light);
  color: var(--color-brand-blue);
  font-weight: 600;
}

.sidebar__link.active .sidebar__link-icon {
  color: var(--color-brand-blue);
}

.main-content {
  flex: 1;
  padding: var(--page-padding-y) var(--page-padding-x);
  min-width: 0;
}

.main-content--embedded {
  padding: 0;
  overflow: hidden;
}

.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 4px;
}

.page-header p {
  margin: 0;
  color: var(--color-text-secondary);
  font-size: 14px;
}

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.card__body {
  padding: var(--card-padding);
}

/* Inside Django admin (#content), Django's own styles can leak onto our
   .card; re-assert the V2 surface + border + shadow so admin pages match
   custom-view pages exactly. */
#content .card {
  background: var(--color-surface) !important;
  border: 1px solid var(--color-border-subtle) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-card) !important;
  overflow: hidden;
}

/* ── Tables ─────────────────────────────────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
}

/* Canonical list-table shape: applies to every <table class="table"> in
   the app (Feedback Loop, Group Management, etc.) and is mirrored by the
   #result_list (Django admin) and #dm-table (Dashboard Management)
   overrides so all list views render with identical metrics. */
.table th {
  text-align: left;
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border-subtle);
  background: var(--color-surface);
}

.table td {
  padding: 10px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--color-border-subtle);
  vertical-align: middle;
}

.table tbody tr:hover {
  background: var(--color-row-hover);
}

/* Drag-to-resize column grip (static/js/table-resize.js): a small diagonal-
   lines grip icon in each header cell's lower-right corner — grab it to resize
   the column (like a textarea's resizer). Gray at rest, brand-blue on hover.
   The handle has a slightly larger transparent hit-pad around the visible icon
   so it's easy to grab. */
.col-resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: col-resize;
  user-select: none;
  z-index: 5;
}
/* The visible grip: a lower-right TRIANGLE of diagonal lines (the classic
   resize-corner look), pinned to the corner of the hit-pad. clip-path carves
   the striped box down to the bottom-right triangle. */
.col-resize-handle::before {
  content: "";
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 12px;
  height: 12px;
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  background: repeating-linear-gradient(
    135deg,
    var(--color-text-muted) 0 1.5px,
    transparent 1.5px 4px
  );
  opacity: 0.65;
  transition: opacity 0.12s ease;
}
.col-resize-handle:hover::before {
  opacity: 1;
  background: repeating-linear-gradient(
    135deg,
    var(--color-brand-blue) 0 1.5px,
    transparent 1.5px 4px
  );
}
/* While dragging, force the resize cursor everywhere and kill text selection. */
body.col-resizing,
body.col-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

.table tbody tr.selected {
  background: var(--color-row-selected);
}

/* ── Form controls ──────────────────────────────────────────────────────── */
.input,
.select,
.button,
.textarea {
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 14px;
  box-sizing: border-box;
}

.input,
.select {
  height: var(--control-height);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  padding: 0 12px;
  color: var(--color-text-primary);
}

.select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px;
  cursor: pointer;
}

.textarea {
  min-height: 90px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  padding: 10px 12px;
  color: var(--color-text-primary);
  resize: vertical;
  width: 100%;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--color-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.input--block,
.select--block {
  width: 100%;
}

/* Style the native file-input button (the dated grey "Choose File") to match
   the secondary button language — white shell, brand-blue label, rounded
   border. Applies to every <input type="file"> (config upload, bucket
   uploads, etc.). The "No file chosen" text keeps the muted body style. */
input[type="file"] {
  font-size: 13px;
  color: var(--color-text-secondary);
}
input[type="file"]::file-selector-button {
  height: 34px;
  padding: 0 14px;
  margin-right: 12px;
  background: var(--color-surface);
  color: var(--color-brand-blue);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
input[type="file"]::file-selector-button:hover {
  background: var(--color-row-hover);
  border-color: var(--color-text-muted);
}

.button {
  height: var(--control-height);
  border: 1px solid transparent;
  padding: 0 18px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.button-primary {
  background: var(--color-brand-blue);
  color: #ffffff;
}

.button-primary:hover:not(:disabled) {
  background-color: var(--color-brand-blue-hover);
}

.button-secondary {
  background: #ffffff;
  border-color: var(--color-border);
  color: var(--color-brand-blue);
}

/* Dropdown triggers reuse .button-secondary for their shell but are value
   selectors, not actions — keep their text neutral so they don't read as a
   link the way the blue cancel/secondary buttons now do. */
.button-secondary.dropdown__trigger {
  color: var(--color-text-primary);
}

.button-secondary:hover:not(:disabled) {
  background-color: var(--color-row-hover);
  border-color: var(--color-text-muted);
}

.button-danger {
  background: var(--color-danger-text);
  color: #ffffff;
}

.button-danger:hover:not(:disabled) {
  background-color: var(--color-danger-hover);
}

.button-success {
  background: var(--color-success-text);
  color: #ffffff;
}

.button-success:hover:not(:disabled) {
  background-color: var(--color-success-hover);
}

.button--link {
  background: transparent;
  border: 0;
  color: var(--color-brand-blue);
  padding: 0 4px;
  height: auto;
  font-weight: 600;
}

.button--link:hover:not(:disabled) {
  text-decoration: underline;
}

/* ── Status pills ───────────────────────────────────────────────────────── */
.status-pill {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill--success {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

.status-pill--warning {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
}

.status-pill--danger {
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
}

.status-pill--info {
  background: var(--color-info-bg);
  color: var(--color-info-text);
}

.status-pill--neutral {
  background: var(--color-surface-subtle);
  color: var(--color-text-secondary);
}

/* ── Tooltip ────────────────────────────────────────────────────────────── *
 *
 * Usage:
 *
 *   <span class="tooltip-anchor">
 *     <a class="button">Trigger</a>
 *     <div class="tooltip-bubble" role="tooltip">Explanation text…</div>
 *   </span>
 *
 * The anchor span establishes the positioning context. Wrap the trigger
 * (button, link, icon) and the bubble together inside it.
 *
 * Why an explicit anchor span (and not, say, position: relative on the
 * trigger itself): some containers — notably Django admin's `.object-tools li`
 * — have a constrained height (`height: 1em`), so positioning relative to
 * the trigger's parent drops the bubble into the trigger instead of below
 * it. The span anchor inherits the trigger's actual height.
 *
 * Default placement is bottom-right (right-aligned with the trigger). For
 * left-aligned or center placement, add a modifier (TODO when needed).
 * Reveal is hover OR keyboard focus, with a 300 ms delay so casual cursor
 * passes don't trigger the bubble.
 */
.tooltip-anchor {
  position: relative;
  display: inline-block;
}

.tooltip-bubble {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: max-content;
  max-width: 300px;
  background: #1f2937;
  color: #f9fafb;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-2px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s linear 0.15s;
  pointer-events: none;
  z-index: 1000;
  white-space: normal;
  /* Both edges flush; the last line of each paragraph stays naturally
     left-aligned (CSS standard), so the trailing words of each sentence
     aren't over-stretched. Wrap each sentence in <p> for paragraph behavior. */
  text-align: justify;
}

/* Each sentence in a tooltip is its own <p>. Strip browser defaults and
   add a small gap between paragraphs to make sentence breaks visible. */
.tooltip-bubble p {
  margin: 0;
}
.tooltip-bubble p + p {
  margin-top: 8px;
}

.tooltip-bubble::before {
  content: '';
  position: absolute;
  top: -5px;
  right: 16px;
  width: 10px;
  height: 10px;
  background: #1f2937;
  transform: rotate(45deg);
}

.tooltip-anchor:hover .tooltip-bubble,
.tooltip-anchor:focus-within .tooltip-bubble {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity 0.15s ease 0.3s, transform 0.15s ease 0.3s, visibility 0s linear 0.3s;
}

/* Placement modifier: open the bubble ABOVE the trigger. Use when the trigger
   sits at the bottom of a clipping container (e.g. an .card with
   overflow:hidden), where the default below-placement would be clipped. */
.tooltip-bubble--above {
  top: auto;
  bottom: calc(100% + 10px);
}
.tooltip-bubble--above::before {
  top: auto;
  bottom: -5px;
}

/* ── Modal ──────────────────────────────────────────────────────────────── */
/* Modal entrance: backdrop fades, dialog pops in. Animations replay whenever
   a modal is shown (display:none → flex). Shared by every modal. */
@keyframes modalBackdropIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes modalPopIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.52);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: modalBackdropIn 0.18s ease;
}

.modal {
  width: 600px;
  max-width: calc(100vw - 48px);
  background: #ffffff;
  border-radius: 16px;
  box-shadow: var(--shadow-modal);
  padding: 32px;
  animation: modalPopIn 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
  .modal-backdrop,
  .modal { animation: none; }
}

/* Page-content entrance: the content pane eases in on each navigation, so
   clicking a sidebar item (or any nav) transitions the new page in instead of
   snapping. Scoped to the content body (#content on admin, .main-content on
   app) so the top nav + sidebar don't move. No animation-fill is used, so the
   element keeps no lingering transform (which would otherwise create a
   containing block and break position:fixed modals / slide-outs). */
@keyframes pageContentIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
#content,
.main-content {
  animation: pageContentIn 0.22s ease;
}
@media (prefers-reduced-motion: reduce) {
  #content,
  .main-content { animation: none; }
}

.modal__title {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 700;
}

.modal__subtitle {
  margin: 0 0 16px;
  color: var(--color-text-secondary);
  font-size: 13px;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* Modal action buttons render outside #content, where Django admin's generic
   `.button { background: var(--button-bg) }` (navy) competes with our variant
   colors at equal specificity and wins at rest — so the primary button only
   looked blue on hover. Pin the variant colors here with higher specificity. */
.modal-backdrop .modal__actions .button-primary {
  background: var(--color-brand-blue);
  color: #ffffff;
}
.modal-backdrop .modal__actions .button-primary:hover {
  background: var(--color-brand-blue-hover);
}
.modal-backdrop .modal__actions .button-danger {
  background: var(--color-danger-text);
  color: #ffffff;
}
.modal-backdrop .modal__actions .button-danger:hover {
  background: var(--color-danger-hover);
}
.modal-backdrop .modal__actions .button-secondary {
  background: #ffffff;
  color: var(--color-brand-blue);
  border-color: var(--color-border);
}

.segmented-control {
  display: flex;
  gap: 8px;
  margin: 20px 0;
  flex-wrap: wrap;
}

.segmented-control button {
  height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: #ffffff;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  color: var(--color-text-secondary);
}

.segmented-control button.active {
  color: var(--color-brand-blue);
  border-color: var(--color-brand-blue);
  background: var(--color-brand-blue-light);
}

/* ── Field grid (used in modals/drawers) ────────────────────────────────── */
.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

@media (max-width: 720px) {
  .field-grid {
    grid-template-columns: 1fr;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  font-weight: 700;
}

.field__value {
  font-size: 14px;
  color: var(--color-text-primary);
}

/* ── Feedback Loop expandable rows ──────────────────────────────────────── */
/* table-layout: fixed locks column widths to the header row so an expanded
   row's drawer (which lives in a colspan=7 cell) can't shift them. */
.fb-loop-shell .table {
  table-layout: fixed;
}

.feedback-row {
  cursor: pointer;
}

.feedback-row > td {
  /* Inherits padding/font-size/border from .table td above so all list
     views render rows at the same height. The override is only for the
     overflow:hidden needed by the ellipsis wrappers below. */
  vertical-align: middle;
  overflow: hidden;
}

/* Single-line truncation on the cell text via a wrapper span so the
   <td> can keep display:table-cell (otherwise row borders break). */
.feedback-row > td > .cell-ellipsis {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Feedback column: two-line clamp via a div wrapper. */
.feedback-row > td > .cell-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.feedback-row__expand {
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 4px;
  color: var(--color-text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.feedback-row__expand svg {
  width: 14px;
  height: 14px;
  transition: transform 0.15s ease;
}

.feedback-row.expanded .feedback-row__expand svg {
  transform: rotate(90deg);
}

.feedback-row.expanded {
  background: var(--color-row-selected);
}

.feedback-detail-row {
  background: var(--color-surface-subtle);
}

.feedback-detail-row > td {
  padding: 0 !important;
  border-bottom: 1px solid var(--color-border-subtle);
}

/* Expand animation — plays whenever a drawer becomes visible (hidden removed,
   or the detail row is inserted into the DOM). Shared by every expandable
   drawer (Group Management, Feedback Loop, Users, Upload Packages). */
@keyframes feedbackDrawerIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.feedback-drawer {
  animation: feedbackDrawerIn 0.2s ease both;
  margin: 0 16px 16px;
  padding: 24px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.feedback-drawer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 900px) {
  .feedback-drawer-grid {
    grid-template-columns: 1fr;
  }
}

.feedback-drawer-section {
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  background: #ffffff;
}

.feedback-drawer-section h4 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 700;
}

.feedback-drawer-section dl {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 6px 12px;
  margin: 0;
  font-size: 13px;
}

.feedback-drawer-section dt {
  color: var(--color-text-muted);
}

.feedback-drawer-section dd {
  margin: 0;
  color: var(--color-text-primary);
  word-break: break-word;
}

/* Data Point: 3-column grid of label/value pairs (matches V2 mockup). */
.dp-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 32px;
  font-size: 13px;
}

@media (max-width: 1100px) {
  .dp-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .dp-grid { grid-template-columns: 1fr; }
}

.dp-field {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 4px 12px;
  align-items: start;
}

.dp-label {
  color: var(--color-text-muted);
}

.dp-value {
  color: var(--color-text-primary);
  word-break: break-word;
}

/* ── Filter bar (legacy top-row variant) ────────────────────────────────── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.filter-bar .input,
.filter-bar .select {
  min-width: 160px;
}

.filter-bar .filter-bar__spacer {
  flex: 1;
}

.filter-bar__search {
  flex: 1;
  min-width: 240px;
  max-width: 360px;
}

/* ── Filters panel (right-side, per V2 Feedback Loop spec) ──────────────── */
.with-filters {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

.with-filters__main {
  flex: 1;
  min-width: 0;
}

/* Feedback Loop fixed-viewport shell: page = exactly viewport height,
   table area scrolls internally, filter panel and table share the same
   available vertical space. Responsive: nothing is hard-coded in pixels. */
.fb-loop-shell {
  /* Fill the <main> content pane (which is already viewport-minus-nav). Using
     100% — not calc(100vh - nav) — keeps it correct if a messages banner ever
     shrinks <main>. */
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}

.fb-loop-shell .page-header {
  flex-shrink: 0;
  margin-bottom: 16px;
}

.fb-loop-shell .with-filters {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 24px;
  overflow: hidden;
}

.fb-loop-shell .with-filters__main {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.fb-loop-shell .with-filters__main > .card {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
}

.fb-loop-shell .with-filters__main > .pagination {
  flex-shrink: 0;
  flex-grow: 0;
  margin-top: 12px;
}

/* The card is the only scroll surface. The drawer renders at its natural
   height (no internal scrollbar); contents are compressed so it fits
   within the card alongside following rows. */
.fb-loop-shell .feedback-drawer {
  gap: 10px;
  padding: 16px;
}

.fb-loop-shell .feedback-drawer-section {
  padding: 12px 14px;
}

.fb-loop-shell .feedback-drawer-section h4 {
  margin: 0 0 8px;
  font-size: 13px;
}

.fb-loop-shell .feedback-drawer-section dl,
.fb-loop-shell .dp-grid,
.fb-loop-shell .dp-field {
  font-size: 12px;
}

.fb-loop-shell .feedback-drawer-section dl {
  grid-template-columns: 110px 1fr;
  gap: 4px 10px;
}

.fb-loop-shell .dp-grid {
  gap: 6px 24px;
}

.fb-loop-shell .dp-field {
  grid-template-columns: 120px 1fr;
  gap: 2px 10px;
}

.fb-loop-shell .feedback-drawer .textarea {
  min-height: 60px;
  font-size: 12px;
  padding: 8px 10px;
}

.fb-loop-shell .feedback-drawer-grid {
  gap: 10px;
}

/* ── Pagination ─────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.pagination__info {
  color: var(--color-text-muted);
  font-size: 13px;
}

.pagination__nav {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.pagination__btn,
.pagination__page {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-primary);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}

.pagination__btn:hover,
.pagination__page:hover {
  background: var(--color-row-hover);
  text-decoration: none;
}

.pagination__btn--disabled {
  opacity: 0.4;
  pointer-events: none;
}

.pagination__page--active {
  background: var(--color-brand-blue);
  border-color: var(--color-brand-blue);
  color: #fff;
}

.pagination__page--active:hover {
  background: var(--color-brand-blue);
  color: #fff;
}

.pagination__ellipsis {
  display: inline-flex;
  align-items: center;
  padding: 0 4px;
  color: var(--color-text-muted);
}

.fb-loop-shell .filters-panel {
  position: static;
  align-self: stretch;
  max-height: 100%;
  overflow-y: auto;
}

.filters-panel {
  width: 260px;
  flex-shrink: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 12px 14px;
  font-size: 13px;
  position: sticky;
  /* Sticks within the content pane (already below the top nav), so offset is
     just a small gap from the pane's top — not the nav height. */
  top: 16px;
  align-self: flex-start;
}

.filters-panel[hidden] { display: none; }

.filters-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border-subtle);
  margin-bottom: 8px;
}

.filters-panel__header h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.filters-panel__hide,
.filters-panel__show {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--color-brand-blue);
  font-size: 13px;
  font-weight: 600;
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 4px;
  font-family: var(--font-sans);
}

.filters-panel__hide:hover,
.filters-panel__show:hover { text-decoration: underline; }

.filters-show-btn {
  display: none;
  margin-bottom: 12px;
  align-self: flex-end;
}

.with-filters.hidden .filters-show-btn { display: inline-flex; }

.filters-toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  margin-bottom: 0;
  border-bottom: 1px solid var(--color-border-subtle);
}

.filters-toggle-row__label {
  color: var(--color-text-primary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.filters-toggle-row__spacer { flex: 1; }

.filters-panel__section {
  padding-top: 6px;
  margin-top: 6px;
  border-top: 1px solid var(--color-border-subtle);
}

.filters-panel__section:first-of-type {
  border-top: 0;
  padding-top: 6px;
  margin-top: 0;
}

.filters-section-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 0;
  padding: 4px 0;
  width: 100%;
  text-align: left;
  font-size: 14px;
  font-weight: 700;
  color: var(--color-brand-blue);
  cursor: pointer;
  font-family: var(--font-sans);
}

.filters-section-toggle .filters-section-chevron {
  transition: transform 0.15s ease;
  color: var(--color-brand-blue);
}

.filters-section-toggle[aria-expanded="false"] .filters-section-chevron {
  transform: rotate(-90deg);
}

.filters-section-toggle[aria-expanded="false"] + .filters-section-items {
  display: none;
}

.filters-section-items {
  margin-top: 6px;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 3px 10px;
  margin: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--color-text-primary);
  line-height: 1.4;
}

.filter-item:hover {
  background: var(--color-row-hover);
}

.filter-item input {
  accent-color: var(--color-brand-blue);
  margin: 0;
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.filter-item--checked {
  background: var(--color-brand-blue-light);
  color: var(--color-brand-blue);
  font-weight: 600;
}

.filter-item__count {
  margin-left: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  padding: 1px 8px;
  font-size: 12px;
  color: var(--color-text-muted);
  min-width: 28px;
  text-align: center;
  font-weight: 500;
}

.filters-panel--no-counts .filter-item__count { display: none; }

/* ── Django admin changelist — restyle to match Group Management card ────
   Targets the changelist body on /admin/.../changelist/ pages (Invitations,
   Users, File Uploads, etc.). Functionality unchanged; visual only.
   ────────────────────────────────────────────────────────────────────────── */

/* Title row: <h1> on the left, .object-tools (Add ... +) on the right. */
.admin-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 24px;
  position: relative;
  z-index: 1;
}

.admin-page-header__title {
  flex: 1;
  min-width: 0;
}

.admin-page-header__title h1 {
  margin: 0 !important;
  line-height: 1.2 !important;
  font-size: 22px !important;
  font-weight: 700 !important;
  color: var(--color-text-primary) !important;
}

.admin-page-header__title .page-subtitle,
.page-subtitle {
  margin: 4px 0 0;
  color: var(--color-text-secondary);
  font-size: 14px;
  line-height: 1.4;
}

/* Make h1 inside #content match the Group Management title style even
   when there's no .admin-page-header wrapper yet (e.g., add/change form). */
#content > h1 {
  font-size: 22px !important;
  font-weight: 700 !important;
  color: var(--color-text-primary) !important;
  margin: 0 0 16px !important;
}

/* Defensive: kill Django admin's -3em margin-top on object-tools that
   would otherwise pull it up into the card area below. */
.admin-page-header .object-tools {
  margin-top: 0 !important;
}

/* Changelist + its content fills full width inside #content. */
#content > #content-main,
#content #changelist,
#content #changelist .changelist-form-container {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* "Add X +" button (top-right object-tools). Moved to .admin-page-header via JS. */
#content .object-tools {
  margin: 0 !important;
  padding: 0 !important;
  display: flex !important;
  gap: 8px !important;
  flex-shrink: 0;
}

#content .object-tools li,
#content .object-tools a.addlink {
  list-style: none !important;
  background: none !important;
}

#content .object-tools a.addlink {
  display: inline-flex !important;
  align-items: center !important;
  gap: 6px !important;
  height: var(--control-height) !important;
  padding: 0 18px !important;
  border-radius: var(--radius-md) !important;
  background: var(--color-brand-blue) !important;
  color: #ffffff !important;
  font-weight: 600 !important;
  font-size: 14px !important;
  text-decoration: none !important;
  border: 0 !important;
  transition: background 0.15s ease;
}

#content .object-tools a.addlink:hover {
  background: var(--color-brand-blue-hover) !important;
}

#content .object-tools a.addlink::before {
  content: '+';
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}

/* Search bar at top of the changelist (inside the .card). */
#content #toolbar {
  background: var(--color-surface) !important;
  padding: 14px 16px !important;
  border: 0 !important;
  border-bottom: 1px solid var(--color-border-subtle) !important;
  margin: 0 !important;
}

#content #toolbar form#changelist-search {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
}

#content #toolbar label[for="searchbar"] {
  display: none !important;
}

#content #toolbar #searchbar {
  height: var(--control-height) !important;
  width: 280px !important;
  padding: 0 12px 0 32px !important;
  border: 1px solid var(--color-border) !important;
  border-radius: var(--radius-md) !important;
  background: var(--color-surface) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><path d='m21 21-4.3-4.3'/></svg>") 10px center / 14px no-repeat !important;
  font-size: 14px !important;
  font-family: var(--font-sans) !important;
  color: var(--color-text-primary) !important;
}

#content #toolbar input[type="submit"] {
  height: var(--control-height) !important;
  padding: 0 16px !important;
  background: var(--color-brand-blue) !important;
  color: #ffffff !important;
  border: 0 !important;
  border-radius: var(--radius-md) !important;
  font-weight: 600 !important;
  font-size: 14px !important;
  cursor: pointer !important;
  transition: background 0.15s ease;
}

#content #toolbar input[type="submit"]:hover {
  background: var(--color-brand-blue-hover) !important;
}

/* Card wrapper around the changelist table. */
#content #changelist {
  background: transparent !important;
  border: 0 !important;
  padding: 0 !important;
}

#content #changelist .changelist-form-container {
  background: var(--color-surface) !important;
  border: 1px solid var(--color-border-subtle) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-card);
  padding: 0 !important;
  overflow: hidden;
}

#content #changelist form#changelist-form {
  background: transparent !important;
  padding: 0 !important;
}

/* Bulk-action bar (Action / Go / X of Y selected). */
#content #changelist .actions {
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  padding: 12px 16px !important;
  margin: 0 !important;
  background: transparent !important;
  border-bottom: 1px solid var(--color-border-subtle) !important;
  font-size: 13px !important;
}

#content #changelist .actions label {
  font-size: 13px !important;
  color: var(--color-text-secondary) !important;
  font-weight: 500 !important;
}

#content #changelist .actions select {
  height: 36px !important;
  padding: 0 32px 0 12px !important;
  border: 1px solid var(--color-border) !important;
  border-radius: var(--radius-md) !important;
  background: var(--color-surface) !important;
  color: var(--color-text-primary) !important;
  font-family: var(--font-sans) !important;
  font-size: 13px !important;
  appearance: none !important;
  -webkit-appearance: none !important;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>") !important;
  background-repeat: no-repeat !important;
  background-position: right 10px center !important;
  background-size: 12px !important;
}

#content #changelist .actions button[type="submit"],
#content #changelist .actions input[type="submit"] {
  height: 36px !important;
  padding: 0 16px !important;
  background: var(--color-brand-blue) !important;
  color: #ffffff !important;
  border: 0 !important;
  border-radius: var(--radius-md) !important;
  font-weight: 600 !important;
  font-size: 13px !important;
  cursor: pointer !important;
  transition: background 0.15s ease;
}

#content #changelist .actions button[type="submit"]:hover,
#content #changelist .actions input[type="submit"]:hover {
  background: var(--color-brand-blue-hover) !important;
}

/* JS-built bulk-action dropdown — fixed dimensions so the trigger width is
   constant regardless of the selected option's text length. */
.admin-action-dropdown .dropdown__trigger {
  height: 36px !important;
  font-size: 13px !important;
  width: 240px !important;
  min-width: 240px;
}

.admin-action-dropdown .dropdown__current {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-action-dropdown .dropdown__menu {
  min-width: 240px;
}

#content #changelist .actions .action-counter {
  color: var(--color-text-secondary) !important;
  font-size: 13px !important;
}

#content #changelist .actions .question {
  color: var(--color-text-secondary) !important;
}

/* The table. */
#content #result_list {
  width: 100% !important;
  border-collapse: collapse !important;
  background: var(--color-surface) !important;
  border: 0 !important;
  margin: 0 !important;
}

#content #result_list thead th {
  background: var(--color-surface) !important;
  color: var(--color-text-muted) !important;
  text-transform: uppercase !important;
  letter-spacing: 0.04em !important;
  font-size: 12px !important;
  font-weight: 700 !important;
  padding: 14px 16px !important;
  border-bottom: 1px solid var(--color-border-subtle) !important;
  border-top: 0 !important;
  text-align: left !important;
}

#content #result_list thead th a {
  color: var(--color-text-muted) !important;
  text-decoration: none !important;
  font-weight: 700 !important;
}

/* Zero out the inner padding inside Django admin's column-header wrappers
   so the header text aligns vertically with the cell content. Django adds
   8px/10px padding on .text span (non-sortable) and .text a (sortable),
   plus display:block on the <a> which throws vertical alignment off.
   Forcing display:inline lines USERNAME up on the same row as the other
   header labels. */
#content #result_list thead th .text {
  padding: 0 !important;
  margin: 0 !important;
  display: inline !important;
}

#content #result_list thead th .text span,
#content #result_list thead th .text a,
#content #result_list thead th > a,
#content #result_list thead th > span {
  padding: 0 !important;
  margin: 0 !important;
  display: inline !important;
  line-height: inherit !important;
  vertical-align: baseline !important;
}

/* Sortable columns show a static double-chevron icon next to the label.
   The label itself is rendered as non-clickable (cursor:default,
   pointer-events:none); only the .sort-handle icon is clickable. The
   sort URL is mirrored from Django's <a> into a JS-injected handle in
   admin/base_site.html. */
#content #result_list thead th .sortoptions,
#content #result_list thead th .sortpriority {
  display: none !important;
}

#content #result_list thead th.sorted .text {
  padding-right: 0 !important;
}

/* Disable click on the column label (kept inside <a> by Django admin). */
#content #result_list thead th.sortable .text a {
  pointer-events: none !important;
  cursor: default !important;
}

/* The JS-injected clickable sort handle (double-chevron). Has to override
   the earlier rule that forces th > a to display:inline — without
   !important here the SVG escapes the box and renders at default size. */
#content #result_list thead th a.sort-handle {
  display: inline-block !important;
  width: 12px !important;
  height: 12px !important;
  margin-left: 6px !important;
  vertical-align: middle !important;
  line-height: 1 !important;
  background: transparent !important;
  border: 0 !important;
  padding: 0 !important;
  cursor: pointer !important;
  color: var(--color-text-secondary) !important;
  opacity: 0.75;
  text-decoration: none !important;
  transition: opacity 0.15s ease, color 0.15s ease;
  position: relative;
  top: -1px;
}

#content #result_list thead th a.sort-handle:hover {
  opacity: 1;
  color: var(--color-brand-blue) !important;
}

#content #result_list thead th a.sort-handle svg {
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  stroke: currentColor !important;
  fill: none !important;
  stroke-width: 2.5 !important;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#content #result_list tbody tr {
  background: var(--color-surface) !important;
}

#content #result_list tbody tr:hover,
#content #result_list tbody tr:hover > th,
#content #result_list tbody tr:hover > td {
  background: var(--color-row-hover) !important;
  color: var(--color-text-primary) !important;
}

/* Same fix for Django admin's "selected row" state (action checkbox checked). */
#content #result_list tbody tr.selected,
#content #result_list tbody tr.selected > th,
#content #result_list tbody tr.selected > td {
  background: var(--color-row-selected) !important;
  color: var(--color-text-primary) !important;
}

#content #result_list tbody td {
  padding: 10px 16px !important;
  border-bottom: 1px solid var(--color-border-subtle) !important;
  border-top: 0 !important;
  color: var(--color-text-primary) !important;
  font-size: 13px !important;
  vertical-align: middle !important;
  /* Force consistent row height: every cell stays single-line and truncates
     with an ellipsis when content overflows its column. */
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  max-width: 1px;
}

/* Status pills inside cells shouldn't be truncated — they're fixed-width. */
#content #result_list tbody td .status-pill {
  max-width: none;
  overflow: visible;
}

#content #result_list tbody tr:last-child td {
  border-bottom: 0 !important;
}

#content #result_list tbody td a {
  color: var(--color-brand-blue) !important;
  text-decoration: none !important;
}

#content #result_list tbody td a:hover {
  text-decoration: underline !important;
}

/* Selection checkboxes — keep them but tone down their bg. */
#content #result_list .action-checkbox,
#content #result_list .action-checkbox-column {
  width: 32px !important;
  padding-left: 16px !important;
  padding-right: 0 !important;
  text-align: left !important;
}

/* Result count line below the table. */
#content .paginator,
#content p.paginator {
  padding: 10px 16px !important;
  margin: 0 !important;
  background: var(--color-surface) !important;
  border-top: 1px solid var(--color-border-subtle) !important;
  color: var(--color-text-secondary) !important;
  font-size: 13px !important;
  text-align: left !important;
}

#content .paginator a {
  color: var(--color-brand-blue) !important;
}

/* Hide Django admin's date hierarchy strip — it's noisy and the right-panel
   filter already covers temporal slicing. */
#content .xfull,
#content .date-hierarchy {
  display: none !important;
}

/* ── Generic form buttons (delete confirmation, add/change form, etc.) ──
   Split into GEOMETRY/FONT (shared by link-buttons AND native <button>s, so a
   "Create" <button> and a "Cancel" <a> render identically) and VARIANT COLORS
   (primary = blue, secondary = white, danger = red). Django admin's own button
   CSS overrides raw elements, hence the !important. The bulk-action dropdown
   trigger is excluded — it carries its own height + space-between layout. */
#content input[type="submit"].default,
#content button[type="submit"].default,
#content a.button,
#content button.button:not(.dropdown__trigger) {
  height: var(--control-height) !important;
  padding: 0 18px !important;
  border: 1px solid transparent !important;
  border-radius: var(--radius-md) !important;
  font-family: var(--font-sans) !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  line-height: normal !important;
  cursor: pointer !important;
  text-decoration: none !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: background 0.15s ease;
}

/* Primary — Django's default submit (Save) + explicit .button-primary. */
#content input[type="submit"].default,
#content button[type="submit"].default,
#content a.button.button-primary,
#content button.button.button-primary {
  background: var(--color-brand-blue) !important;
  color: #ffffff !important;
}
#content input[type="submit"].default:hover,
#content button[type="submit"].default:hover,
#content a.button.button-primary:hover,
#content button.button.button-primary:hover {
  background: var(--color-brand-blue-hover) !important;
}

/* Secondary — Cancel and other neutral buttons: white bg, dark text, border
   (NOT blue). Applies to both <a> and <button> so all cancels match. */
#content a.button.button-secondary,
#content button.button.button-secondary:not(.dropdown__trigger) {
  background: var(--color-surface) !important;
  color: var(--color-brand-blue) !important;
  border-color: var(--color-border) !important;
}
#content a.button.button-secondary:hover,
#content button.button.button-secondary:not(.dropdown__trigger):hover {
  background: var(--color-row-hover) !important;
  border-color: var(--color-text-muted) !important;
}

/* Danger — delete actions. */
#content a.button.button-danger,
#content button.button.button-danger {
  background: var(--color-danger-text) !important;
  color: #ffffff !important;
}
#content a.button.button-danger:hover,
#content button.button.button-danger:hover {
  background: var(--color-danger-hover) !important;
}

#content input.deletelink,
#content input[type="submit"].deletelink {
  height: var(--control-height) !important;
  padding: 0 18px !important;
  background: var(--color-danger-text) !important;
  color: #ffffff !important;
  border: 1px solid transparent !important;
  border-radius: var(--radius-md) !important;
  font-family: var(--font-sans) !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  line-height: 1 !important;
  transition: background 0.15s ease;
}

#content input.deletelink:hover,
#content input[type="submit"].deletelink:hover {
  background: var(--color-danger-hover) !important;
}

#content a.cancel-link,
#content .submit-row a.cancel-link {
  height: var(--control-height) !important;
  padding: 0 18px !important;
  background: var(--color-surface) !important;
  color: var(--color-text-primary) !important;
  border: 1px solid var(--color-border) !important;
  border-radius: var(--radius-md) !important;
  font-weight: 600 !important;
  font-size: 14px !important;
  font-family: var(--font-sans) !important;
  cursor: pointer !important;
  text-decoration: none !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: background 0.15s ease;
}

#content a.cancel-link:hover {
  background: var(--color-surface-subtle) !important;
}

/* Non-default submit-row buttons ("Save and add another", "Save and continue
   editing"), Django's view-only "Close" link, plus the injected Cancel link are
   secondary actions — white shell, brand-blue label — so only the primary SAVE
   (.default) stays filled. :not(.deletelink) leaves the red Delete alone. */
#content .submit-row input[type="submit"]:not(.default):not(.deletelink),
#content .submit-row a.admin-cancel-link,
#content .submit-row a.closelink {
  height: var(--control-height) !important;
  padding: 0 18px !important;
  background: var(--color-surface) !important;
  color: var(--color-brand-blue) !important;
  border: 1px solid var(--color-border) !important;
  border-radius: var(--radius-md) !important;
  font-family: var(--font-sans) !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  cursor: pointer !important;
  text-decoration: none !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: background 0.15s ease, border-color 0.15s ease;
}
#content .submit-row input[type="submit"]:not(.default):not(.deletelink):hover,
#content .submit-row a.admin-cancel-link:hover,
#content .submit-row a.closelink:hover {
  background: var(--color-row-hover) !important;
  border-color: var(--color-text-muted) !important;
}

/* Submit-row gap so buttons don't touch. */
#content .submit-row,
#content form .submit-row {
  display: flex !important;
  gap: 8px !important;
  align-items: center !important;
  background: transparent !important;
  padding: 16px 0 !important;
  border: 0 !important;
  margin: 16px 0 0 !important;
}

/* Submit-row "Delete" link — Django 5.2 renders it as <a class="deletelink">
   directly in .submit-row (no <p.deletelink-box> wrapper), so its own
   forms.css rule otherwise wins: filled red but with a 4px radius, a stubby
   height (15px + 10px/15px padding), and 15px font from a different family.
   Align it with the rest of the button language (filled red kept). */
#content .submit-row a.deletelink {
  margin-left: auto !important;
  height: var(--control-height) !important;
  padding: 0 18px !important;
  background: var(--color-danger-text) !important;
  color: #ffffff !important;
  border: 1px solid transparent !important;
  border-radius: var(--radius-md) !important;
  font-family: var(--font-sans) !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  line-height: 1 !important;
  text-decoration: none !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: background 0.15s ease;
}

#content .submit-row a.deletelink:hover,
#content .submit-row a.deletelink:focus,
#content .submit-row a.deletelink:active {
  background: var(--color-danger-hover) !important;
  color: #ffffff !important;
}

/* ── Add / Change form layout — V2 card + field styling ──────────────── */

/* Fieldsets render as cards stacked vertically. */
#content #content-main form > div > fieldset.module,
#content form fieldset.module {
  background: var(--color-surface) !important;
  border: 1px solid var(--color-border-subtle) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-card);
  padding: 0 !important;
  margin: 0 0 16px !important;
  font-family: var(--font-sans) !important;
  overflow: hidden;   /* clip inner rows to the rounded corners */
}

/* Section heading inside a fieldset card. */
#content form fieldset.module h2,
#content form fieldset.module .module-header {
  border: none;
  background: var(--color-surface) !important;
  color: var(--color-text-primary) !important;
  font-size: 14px !important;
  font-weight: 700 !important;
  padding: 14px 20px !important;
  margin: 0 !important;
  border-bottom: 1px solid var(--color-border-subtle) !important;
  text-transform: none !important;
  letter-spacing: normal !important;
}

/* Body of each fieldset (where the form rows live). */
#content form fieldset.module > .form-row,
#content form fieldset.module > .description {
  padding: 16px 20px !important;
  border: 0 !important;
  border-bottom: 1px solid var(--color-border-subtle) !important;
  background: var(--color-surface) !important;
  margin: 0 !important;
}

#content form fieldset.module > .form-row:last-of-type,
#content form fieldset.module > .description:last-of-type {
  border-bottom: 0 !important;
}

/* Inside a form-row: label on top, field below. */
#content form fieldset.module .form-row > div {
  margin: 0 !important;
}

#content form .form-row label,
#content form .form-row .form-row label {
  display: block !important;
  font-size: 12px !important;
  font-weight: 700 !important;
  color: var(--color-text-secondary) !important;
  text-transform: uppercase !important;
  letter-spacing: 0.04em !important;
  margin: 0 0 6px !important;
  padding: 0 !important;
  float: none !important;
  width: auto !important;
  line-height: 1.4 !important;
}

/* Put each field's label and value on one line, vertically centered, with a
   fixed-width label column so values line up across rows. Django wraps the
   label+widget in .flex-container; the help text is a sibling after it, so it
   stays below. Checkbox rows keep their own (checkbox + inline label) layout. */
#content form fieldset.module .form-row:not(.checkbox-row) .flex-container {
  display: flex !important;
  flex-flow: row nowrap !important;
  align-items: center !important;
  gap: 16px !important;
}
#content form fieldset.module .form-row:not(.checkbox-row) .flex-container > label {
  flex: 0 0 200px !important;
  margin: 0 !important;
  text-align: left !important;
  align-self: center !important;
}
#content form fieldset.module .form-row:not(.checkbox-row) .flex-container > input:not([type="checkbox"]),
#content form fieldset.module .form-row:not(.checkbox-row) .flex-container > select,
#content form fieldset.module .form-row:not(.checkbox-row) .flex-container > textarea,
#content form fieldset.module .form-row:not(.checkbox-row) .flex-container > .readonly {
  flex: 1 1 auto !important;
  margin: 0 !important;
}

/* Date/datetime field: the date input is wrapped in <p class="date"> and
   Django's JS appends the "Today | 📅" shortcut after it. Lay them out as an
   inline row so the shortcut sits to the RIGHT of a compact input, not below.
   p.date shrinks to its content (input + shortcut) — NOT flex:1 — so there's
   no empty filler between the input and the shortcut. */
#content form .flex-container > p.date,
#content form .flex-container > p.datetime {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  flex: 0 1 auto !important;
  margin: 0 !important;
  min-width: 0 !important;
}
#content form .flex-container p.date input.vDateField,
#content form .flex-container p.datetime input.vDateField,
#content form .flex-container p.datetime input.vTimeField {
  width: 160px !important;
  max-width: 160px !important;
  flex: 0 0 auto !important;
}
#content form .flex-container .datetimeshortcuts {
  display: inline-flex !important;
  align-items: center !important;
  gap: 6px !important;
  white-space: nowrap !important;
  margin: 0 !important;
}

/* Form inputs adopt the V2 input style. */
#content form input[type="text"],
#content form input[type="email"],
#content form input[type="password"],
#content form input[type="url"],
#content form input[type="number"],
#content form input[type="search"],
#content form input[type="tel"],
#content form input[type="date"],
#content form input[type="datetime-local"],
#content form input[type="time"],
#content form textarea,
#content form select:not([name="action"]):not(.dropdown-trigger-select) {
  height: var(--control-height) !important;
  width: 100% !important;
  max-width: 480px !important;
  padding: 0 12px !important;
  font-size: 14px !important;
  font-family: var(--font-sans) !important;
  color: var(--color-text-primary) !important;
  background: var(--color-surface) !important;
  border: 1px solid var(--color-border) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: none !important;
  box-sizing: border-box !important;
}

/* Textareas: variable height, more padding. */
#content form textarea {
  height: auto !important;
  min-height: 90px !important;
  padding: 10px 12px !important;
  line-height: 1.5 !important;
  resize: vertical !important;
}

#content form input:focus,
#content form textarea:focus,
#content form select:focus {
  outline: none !important;
  border-color: var(--color-focus) !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15) !important;
}

/* Readonly-field rendering (e.g., display_username on CustomUserAdmin). */
#content form .form-row .readonly,
#content form p.readonly {
  display: block !important;
  margin: 0 !important;
  padding: 9px 0 !important;
  font-size: 14px !important;
  color: var(--color-text-primary) !important;
  font-family: var(--font-sans) !important;
}

/* Help text below a field. */
#content form .help,
#content form div.help,
#content form .form-row .help {
  font-size: 12px !important;
  color: var(--color-text-muted) !important;
  margin: 6px 0 0 !important;
  padding: 0 !important;
  background: transparent !important;
  font-weight: 400 !important;
}

/* Error states. */
#content form .errornote,
#content form p.errornote {
  background: var(--color-danger-bg) !important;
  color: var(--color-danger-text) !important;
  border: 1px solid rgba(185, 28, 28, 0.25) !important;
  border-radius: var(--radius-md) !important;
  padding: 12px 16px !important;
  margin: 0 0 16px !important;
  font-size: 14px !important;
  font-weight: 500 !important;
}

#content form ul.errorlist {
  list-style: none !important;
  margin: 6px 0 0 !important;
  padding: 0 !important;
  background: transparent !important;
  border: 0 !important;
  color: var(--color-danger-text) !important;
  font-size: 12px !important;
}

#content form ul.errorlist li {
  padding: 0 !important;
  margin: 0 !important;
  background: transparent !important;
}

/* Inline form-row variant Django uses when fields are checkboxes. */
#content form .form-row.checkbox-row label,
#content form .form-row label.vCheckboxLabel {
  display: inline !important;
  text-transform: none !important;
  letter-spacing: normal !important;
  font-size: 14px !important;
  color: var(--color-text-primary) !important;
  font-weight: 500 !important;
  margin: 0 0 0 6px !important;
}

#content form input[type="checkbox"],
#content form input[type="radio"] {
  margin: 0 !important;
  accent-color: var(--color-brand-blue);
}

/* "Filtered" multi-select widget used by the Roles/Groups field. Keep its
   default Django styling — themed with our colors instead of being fully
   replaced. */
#content form .selector {
  width: 100% !important;
  max-width: 720px !important;
}

#content form .selector .selector-available h2,
#content form .selector .selector-chosen h2 {
  background: var(--color-surface-subtle) !important;
  color: var(--color-text-secondary) !important;
  border: 1px solid var(--color-border-subtle) !important;
  font-size: 12px !important;
  text-transform: uppercase !important;
  letter-spacing: 0.04em !important;
}

/* History/View-on-site link in object-tools on change pages. */
#content .object-tools a.historylink,
#content .object-tools a.viewsitelink {
  display: inline-flex !important;
  align-items: center !important;
  height: var(--control-height) !important;
  padding: 0 16px !important;
  background: var(--color-surface) !important;
  color: var(--color-text-primary) !important;
  border: 1px solid var(--color-border) !important;
  border-radius: var(--radius-md) !important;
  font-weight: 600 !important;
  font-size: 14px !important;
  text-decoration: none !important;
  transition: background 0.15s ease;
}

#content .object-tools a.historylink:hover,
#content .object-tools a.viewsitelink:hover {
  background: var(--color-surface-subtle) !important;
}

#content .object-tools a.historylink::before,
#content .object-tools a.viewsitelink::before {
  content: none !important;
}

/* Shrink the Client.qs_dataset_arns JSONField textarea so its row height
   matches the other form fields. User can still drag-resize if a large
   JSON blob needs editing. */
#content .field-qs_dataset_arns textarea {
  min-height: var(--control-height) !important;
  height: var(--control-height) !important;
  padding: 8px 12px !important;
  font-family: var(--font-mono, ui-monospace, "SFMono-Regular", Menlo, monospace);
  font-size: 13px;
  line-height: 1.4;
  resize: vertical;
}

/* ── Django admin's filter sidebar — restyled to match .filters-panel ──── */
#changelist-filter {
  width: 260px !important;
  background: var(--color-surface) !important;
  border: 1px solid var(--color-border-subtle) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-card);
  padding: 12px 14px !important;
  font-size: 13px !important;
  font-family: var(--font-sans) !important;
  color: var(--color-text-primary) !important;
  box-sizing: border-box !important;
}

#changelist-filter h2 {
  margin: 0 0 8px !important;
  padding: 0 0 8px !important;
  font-size: 13px !important;
  font-weight: 700 !important;
  letter-spacing: 0.04em !important;
  color: var(--color-text-primary) !important;
  background: transparent !important;
  border-bottom: 1px solid var(--color-border-subtle) !important;
  text-transform: uppercase !important;
}

#changelist-filter h3 {
  margin: 8px 0 4px !important;
  padding: 6px 0 !important;
  font-size: 14px !important;
  font-weight: 700 !important;
  color: var(--color-brand-blue) !important;
  background: transparent !important;
  border-top: 1px solid var(--color-border-subtle) !important;
  padding-top: 8px !important;
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
}

#changelist-filter h3:first-of-type {
  border-top: 0 !important;
  padding-top: 6px !important;
  margin-top: 0 !important;
}

#changelist-filter h3 a {
  color: var(--color-brand-blue) !important;
  text-decoration: none !important;
}

/* <details>/<summary> variant used by Django 5.x admin filters. */
#changelist-filter details {
  margin: 8px 0 0 !important;
  padding-top: 8px !important;
  border-top: 1px solid var(--color-border-subtle) !important;
}

#changelist-filter details:first-of-type {
  border-top: 0 !important;
  padding-top: 6px !important;
  margin-top: 0 !important;
}

#changelist-filter details > summary {
  list-style: none !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  padding: 4px 0 !important;
  font-size: 14px !important;
  font-weight: 700 !important;
  color: var(--color-brand-blue) !important;
}

#changelist-filter details > summary::-webkit-details-marker { display: none !important; }
#changelist-filter details > summary::marker { content: '' !important; }

#changelist-filter details > summary::before {
  content: '';
  width: 12px;
  height: 12px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><polyline points='6,9 12,15 18,9' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/></svg>") center / contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><polyline points='6,9 12,15 18,9' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/></svg>") center / contain no-repeat;
  transition: transform 0.15s ease;
}

#changelist-filter details:not([open]) > summary::before {
  transform: rotate(-90deg);
}

#changelist-filter ul {
  list-style: none !important;
  padding: 0 !important;
  margin: 4px 0 0 !important;
}

#changelist-filter li {
  margin: 2px 0 !important;
  padding: 0 !important;
  background: transparent !important;
  border: 0 !important;
  border-radius: var(--radius-sm) !important;
}

#changelist-filter li a {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 10px !important;
  border-radius: var(--radius-sm) !important;
  color: var(--color-text-primary) !important;
  font-size: 13px !important;
  line-height: 1.5 !important;
  text-decoration: none !important;
  background: transparent !important;
}

#changelist-filter li a:hover {
  background: var(--color-row-hover) !important;
}

/* Count pill — populated by the JS in admin/base_site.html that strips
   the "(N)" suffix from Django's facet rendering and wraps it. */
#changelist-filter .ca-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#changelist-filter .ca-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  padding: 1px 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 500;
  flex-shrink: 0;
}

#changelist-filter li.selected a .ca-count {
  border-color: var(--color-brand-blue);
  color: var(--color-brand-blue);
}

/* Show / Hide counts toggle row (Django's <h3><a class="viewlink"> / hidelink). */
#changelist-filter-extra-actions {
  padding: 0 0 8px;
  margin: 0 0 8px;
  border-bottom: 1px solid var(--color-border-subtle);
}

#changelist-filter-extra-actions h3 {
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  font-size: 13px !important;
  font-weight: 600 !important;
}

#changelist-filter-extra-actions h3 a.viewlink,
#changelist-filter-extra-actions h3 a.hidelink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--color-brand-blue) !important;
  text-decoration: none !important;
  font-weight: 600;
}

#changelist-filter-extra-actions h3 a.viewlink::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z'/><circle cx='12' cy='12' r='3'/></svg>") center / contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z'/><circle cx='12' cy='12' r='3'/></svg>") center / contain no-repeat;
}

#changelist-filter-extra-actions h3 a.hidelink::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M9.88 9.88a3 3 0 1 0 4.24 4.24'/><path d='M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68'/><path d='M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61'/><line x1='2' x2='22' y1='2' y2='22'/></svg>") center / contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M9.88 9.88a3 3 0 1 0 4.24 4.24'/><path d='M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68'/><path d='M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61'/><line x1='2' x2='22' y1='2' y2='22'/></svg>") center / contain no-repeat;
}

#changelist-filter li.selected {
  background: transparent !important;
  border: 0 !important;
}

#changelist-filter li.selected a {
  background: var(--color-brand-blue-light) !important;
  color: var(--color-brand-blue) !important;
  font-weight: 600 !important;
}

#changelist-filter .filter-choice-clear,
#changelist-filter #changelist-filter-clear { display: none !important; }

/* ── Custom dropdown (button trigger + popup menu) ──────────────────────── */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown__trigger {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 160px;
}

.dropdown__trigger .dropdown__chevron {
  transition: transform 0.15s ease;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.dropdown.open .dropdown__trigger .dropdown__chevron {
  transform: rotate(180deg);
}

.dropdown__menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 4px 0;
  display: none;
  z-index: 50;
  overflow: hidden;
}

.dropdown.open .dropdown__menu {
  display: block;
}

.dropdown__menu a,
.dropdown__menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 14px;
  font-size: 14px;
  color: var(--color-text-primary);
  text-decoration: none;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-family: var(--font-sans);
}

.dropdown__menu a:hover,
.dropdown__menu button:hover {
  background: var(--color-row-hover);
  color: var(--color-text-primary);
}

.dropdown__menu a.active,
.dropdown__menu button.active {
  background: var(--color-brand-blue-light);
  color: var(--color-brand-blue);
  font-weight: 600;
}

/* Field-style dropdown: a JS-enhanced <select> on an admin form. The trigger
   mirrors #content form inputs/selects (white, bordered, full width up to
   480px) so it sits flush with the surrounding fields, while the open menu
   uses the styled .dropdown__menu instead of the OS-native popup. */
.dropdown--field {
  display: block;
  width: 100%;
  max-width: 480px;
}
.dropdown__trigger--field {
  width: 100%;
  height: var(--control-height);
  min-width: 0;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 400;
  font-family: var(--font-sans);
  color: var(--color-text-primary);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-sizing: border-box;
}
.dropdown__trigger--field:hover {
  background: var(--color-surface);
  border-color: var(--color-text-muted);
}
.dropdown.open .dropdown__trigger--field {
  border-color: var(--color-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
/* The field menu is positioned with fixed viewport coords (set by JS on open)
   so it escapes the form card's `overflow: hidden` — which would otherwise
   clip the menu at the card edge. z-index above modals/cards.
   min-width is reset to 0 because the base .dropdown__menu uses
   `min-width: 100%`, which under fixed positioning resolves to 100% of the
   VIEWPORT (full page width). JS sets an explicit px width = trigger width. */
.dropdown--field .dropdown__menu {
  position: fixed;
  z-index: 1200;
  min-width: 0;
}
/* Items never wrap — the menu grows to fit the longest label on one line
   (JS sets min-width = trigger width, so it's at least trigger-aligned). */
.dropdown--field .dropdown__menu a,
.dropdown--field .dropdown__menu button {
  white-space: nowrap;
}

/* ── Toggle switch ──────────────────────────────────────────────────────── */
.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch__slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--color-border);
  border-radius: 999px;
  transition: 0.2s;
}

.switch__slider:before {
  position: absolute;
  content: '';
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}

.switch input:checked + .switch__slider {
  background: var(--color-brand-blue);
}

.switch input:checked + .switch__slider:before {
  transform: translateX(16px);
}

/* ── QuickSight embedded container ──────────────────────────────────────── */
.quicksight-container {
  width: 100%;
  /* Fill the <main> content pane (already viewport-minus-nav); 100% adapts if
     a messages banner shrinks <main>. */
  height: 100%;
  overflow: hidden;
  background: var(--color-page-bg);
  position: relative;
}

.quicksight-container iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

/* Edge handle on the AI panel's left border — collapses/expands the panel.
   Always visible; the icon flips by state (» collapse / « expand). Sits at the
   embed area's right edge, i.e. flush against the panel's left border. */
/* Status message shown in the AI panel when there's no real QS content yet
   (account not registered / company not provisioned). */
.ai-panel__status {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 28px 24px;
  text-align: center;
  color: var(--color-text-muted);
}
.ai-panel__status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--color-brand-blue-subtle, rgba(37, 99, 235, 0.1));
  color: var(--color-brand-blue);
}
.ai-panel__status-title {
  margin: 2px 0 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-primary);
}
.ai-panel__status-detail {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  max-width: 260px;
}
.ai-panel__checklist {
  list-style: none;
  margin: 8px 0 0;
  padding: 12px;
  width: 100%;
  max-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--color-surface-subtle, rgba(0, 0, 0, 0.02));
  border: 1px solid var(--color-border-subtle);
  border-radius: 8px;
  text-align: left;
}
.ai-panel__check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  line-height: 1.3;
}
.ai-panel__check svg {
  flex-shrink: 0;
}
.ai-panel__check.is-met {
  color: var(--color-text-primary);
}
.ai-panel__check.is-met svg {
  color: var(--color-success-text, #16a34a);
}
.ai-panel__check.is-missing {
  color: var(--color-text-muted);
}
.ai-panel__check.is-missing svg {
  color: var(--color-warning-text, #d97706);
}

.ai-panel-toggle {
  position: absolute;
  top: 12px;       /* same y as the AI panel header padding-top */
  right: 0;
  display: inline-flex;
  width: 20px;
  height: 36px;
  padding: 0;
  background: var(--color-brand-blue);
  border: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  color: #ffffff;
  cursor: pointer;
  z-index: 20;
  box-shadow: -2px 0 6px rgba(15, 23, 42, 0.12);
  transition: background 0.15s ease;
  align-items: center;
  justify-content: center;
}

.ai-panel-toggle:hover {
  background: var(--color-brand-blue-hover);
}

.ai-panel-toggle svg {
  stroke: #ffffff;
  transition: transform 0.2s ease;
}

/* Collapsed: flip the » chevron to « (expand affordance). */
.ai-panel-toggle--collapsed svg {
  transform: rotate(180deg);
}

/* ── Auth pages (login / invite / profile) ──────────────────────────────── */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-page-bg);
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 32px;
}

.auth-card h1 {
  font-size: 22px;
  margin: 0 0 4px;
}

.auth-card p.subtitle {
  margin: 0 0 20px;
  color: var(--color-text-secondary);
  font-size: 14px;
}

.auth-card .form-row {
  margin-bottom: 14px;
}

.auth-card label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.auth-card .form-errors {
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* ── Toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: var(--color-text-primary);
  color: var(--color-text-inverse);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-modal);
  font-size: 14px;
  z-index: 1100;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* App-toast: structured toast with body + progress bar; shown via window.showAppToast(message, duration). */
#appToast {
  min-width: 280px;
  max-width: 420px;
  padding: 0;
  overflow: hidden;
}

#appToast .toast__body {
  padding: 12px 18px;
  font-size: 14px;
  line-height: 1.4;
}

#appToast .toast__progress {
  height: 3px;
  background: rgba(255, 255, 255, 0.15);
}

#appToast .toast__progress-fill {
  height: 100%;
  background: var(--color-brand-blue);
  transform-origin: left;
  transform: scaleX(1);
  will-change: transform;
}

#appToast.show .toast__progress-fill {
  animation: toast-progress var(--toast-duration, 3000ms) linear forwards;
}

@keyframes toast-progress {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

/* Variant tints — only the progress bar color changes so the dark toast
   surface stays readable. */
#appToast.toast--success .toast__progress-fill { background: #22c55e; }
#appToast.toast--error   .toast__progress-fill { background: #ef4444; }
#appToast.toast--warning .toast__progress-fill { background: #f59e0b; }

/* ── Messages (Django messages framework) ───────────────────────────────── */
.messages {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
}

.messages li {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: 14px;
}

.messages li.success {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

.messages li.error {
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
}

.messages li.warning {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
}

.messages li.info {
  background: var(--color-info-bg);
  color: var(--color-info-text);
}

/* ── History sidebar (slide-in from right on admin change pages) ──────── */
.history-sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 90;
}

.history-sidebar-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.history-sidebar {
  position: fixed;
  top: var(--top-nav-height);
  right: 0;
  width: 420px;
  max-width: 90vw;
  height: calc(100vh - var(--top-nav-height));
  background: var(--color-surface);
  border-left: 1px solid var(--color-border-subtle);
  box-shadow: -8px 0 24px rgba(15, 23, 42, 0.12);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 100;
  display: flex;
  flex-direction: column;
  font-family: var(--font-sans);
}

.history-sidebar.open {
  transform: translateX(0);
}

.history-sidebar__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--color-border-subtle);
}

.history-sidebar__title-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.history-sidebar__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text-primary);
  margin: 0;
}

.history-sidebar__subtitle {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-sidebar__close {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  cursor: pointer;
  flex-shrink: 0;
}

.history-sidebar__close:hover {
  background: var(--color-row-hover);
  color: var(--color-text-primary);
}

.history-sidebar__body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px 20px;
}

.history-sidebar__empty,
.history-sidebar__loading {
  padding: 24px 4px;
  font-size: 13px;
  color: var(--color-text-secondary);
  text-align: center;
}

.history-entry {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border-subtle);
}

.history-entry:last-child {
  border-bottom: 0;
}

.history-entry__top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--color-text-secondary);
}

.history-entry__action {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--color-info-bg);
  color: var(--color-info-text);
}

.history-entry__action--created { background: var(--color-success-bg); color: var(--color-success-text); }
.history-entry__action--changed { background: var(--color-info-bg);    color: var(--color-info-text); }
.history-entry__action--deleted { background: var(--color-danger-bg);  color: var(--color-danger-text); }

.history-entry__user {
  font-weight: 600;
  color: var(--color-text-primary);
  font-size: 13px;
}

.history-entry__time {
  font-size: 12px;
  color: var(--color-text-secondary);
}

.history-entry__message {
  font-size: 13px;
  color: var(--color-text-primary);
  line-height: 1.45;
}

/* ── FileUploadBucket detail: configuration chip toggles ──────────────── */
/* Wraps a native <input type="checkbox" name="configurations"> + label so
   Django's form-processing contract stays untouched. The hidden checkbox
   drives the visual state via :has(). */
.config-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.config-chip:hover {
  background: var(--color-row-hover);
  border-color: var(--color-brand-blue);
}

.config-chip input[type="checkbox"] {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.config-chip:has(input[type="checkbox"]:checked) {
  background: var(--color-brand-blue);
  border-color: var(--color-brand-blue);
  color: #ffffff;
}

.config-chip:has(input[type="checkbox"]:checked):hover {
  background: var(--color-brand-blue-hover);
  border-color: var(--color-brand-blue-hover);
}

.config-chip__label { line-height: 1; }

/* ── Status badge shim ────────────────────────────────────────────────
   The bucket_detail packages table renders <span class="status-badge"
   style="color: ...; background: ..."> server-side, and the live poller
   re-emits the same shape. Apply V2 pill geometry/typography while
   leaving the inline color overrides intact. */
.bucket-detail .status-badge,
#claim-packages-tbody .status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1.4;
}
