/* Orange theme admin CSS — focuses on readable sidebar headings */

/* =====================
   Global CSS Variables
   ===================== */
:root {
  /* Brand palette (anchored to provided shade) */
  --orange: #E26830;              /* primary orange */
  --orange-dark: #C75A2A;         /* press/active state */
  --orange-soft: #FFE4D6;         /* soft background tint */
  --orange-soft-border: #F7BFA8;  /* soft border tint */
  --hairline-color: #F3C7B4;      /* hairline divider */
  --text-default: #333333;
  /* High-contrast pair for headings (AA compliant) */
  --orange-contrast: #B64C1E;     /* stronger contrast block */
  --orange-contrast-text: #ffffff;

  /* Branding title (left header) */
  /* Set to green; change to #ffffff if you prefer white */
  --brand-title-color: #ffffff;           /* title text color (green) */
  --brand-title-hover-bg: rgba(255, 255, 255, 0.15);
  --brand-title-focus-ring: rgba(250, 250, 250, 0.45);

  /* Header and user-tools */
  --header-bg: var(--orange);
  --header-text: #ffffff;
  --hover-bg: rgba(0, 0, 0, 0.22); /* darker overlay to keep white text readable */
  --hover-ring: 0 0 0 2px rgba(0, 0, 0, 0.20);

  /* Icon styling */
  --theme-icon-color: #ffffff; /* icon white to match header text */
  /* Accent for theme toggle */
  --accent-orange: #E26830;
  --accent-orange-hover: #EE7A47;
  --accent-orange-active: #C75A2A;
  --green: #16a34a;
  --green-dark: #15803d;
  --breadcrumbs-bg: var(--green);
  --breadcrumbs-fg: #ffffff;

  /* Motion */
  --transition-med: 240ms;
  --transition-fast: 200ms;
}

[data-theme="dark"] {
  /* Maintain strong contrast in dark mode */
  --header-bg: var(--orange);
  --header-text: #ffffff;
  --hover-bg: rgba(0, 0, 0, 0.26); /* slightly stronger for readability */
  --theme-icon-color: #ffffff; /* icon color on dark mode (light glyph) */
  --breadcrumbs-bg: var(--green-dark);
  --breadcrumbs-fg: #ffffff;
}

/* Duplicate root block retained by upstream; reassert provided palette */
:root {
  --orange: #E26830;
  --orange-dark: #C75A2A;
  --orange-soft: #FFE4D6;
  --orange-soft-border: #F7BFA8;
  --hairline-color: #F3C7B4;
  --text-default: #333333;
  --orange-contrast: #B64C1E;
  --orange-contrast-text: #ffffff;
  --green: #16a34a;
  --green-dark: #15803d;
  --breadcrumbs-bg: var(--green);
  --breadcrumbs-fg: #ffffff;
}

/* Header bar */
#header {
  background: var(--header-bg);
}
/* Force header color to match theme even if upstream CSS overrides */
#header {
  background-color: var(--accent-orange) !important;
}

/* Breadcrumbs bar below header */
.breadcrumbs { position: relative; background: radial-gradient(900px 300px at 12% -40%, rgba(255,255,255,0.22) 0%, rgba(255,255,255,0.0) 45%), linear-gradient(90deg, var(--green) 0%, #1aa357 50%, var(--green-dark) 100%) !important; color: #ffffff !important; border-top: 1px solid var(--hairline-color) !important; border-bottom: 1px solid var(--hairline-color) !important; box-shadow: 0 14px 28px rgba(0,0,0,0.20); border-radius: 0 0 16px 16px; padding: 14px 40px !important; font-size: 15px; }
.breadcrumbs { -webkit-backdrop-filter: saturate(140%) blur(2px); backdrop-filter: saturate(140%) blur(2px); text-shadow: 0 1px 2px rgba(0,0,0,0.28); box-shadow: inset 0 1px 0 rgba(255,255,255,0.25), 0 14px 28px rgba(0,0,0,0.20); }
.main .breadcrumbs, #content .breadcrumbs { background: radial-gradient(900px 300px at 12% -40%, rgba(255,255,255,0.22) 0%, rgba(255,255,255,0.0) 45%), linear-gradient(90deg, var(--green) 0%, #1aa357 50%, var(--green-dark) 100%) !important; color: #ffffff !important; }
.breadcrumbs::after { content: ""; position: absolute; inset: 0; left: -20%; width: 40%; background: linear-gradient(90deg, rgba(255,255,255,0.0) 0%, rgba(255,255,255,0.22) 50%, rgba(255,255,255,0.0) 100%); transform: skewX(-18deg); pointer-events: none; animation: breadcrumbsShine 6s ease-in-out infinite; }
@keyframes breadcrumbsShine { 0% { transform: translateX(0) skewX(-18deg); opacity: 0.75; } 50% { transform: translateX(220%) skewX(-18deg); opacity: 0.4; } 100% { transform: translateX(0) skewX(-18deg); opacity: 0.75; } }
.breadcrumbs::before { content: ""; position: absolute; left: 0; right: 0; bottom: -2px; height: 4px; background: linear-gradient(90deg, var(--orange) 0%, #ff9b61 50%, var(--orange-dark) 100%); opacity: 0.92; border-radius: 0 0 12px 12px; }
.breadcrumbs::before { box-shadow: 0 6px 12px rgba(226,104,48,0.28); }
@keyframes breadcrumbsShine { 0% { transform: translateX(0) skewX(-18deg); opacity: 0.75; } 50% { transform: translateX(220%) skewX(-18deg); opacity: 0.4; } 100% { transform: translateX(0) skewX(-18deg); opacity: 0.75; } }
.breadcrumbs a { color: #ffffff !important; text-decoration: none; }
.breadcrumbs a:hover { text-decoration: none; background-color: rgba(255,255,255,0.16); }
.breadcrumbs a { display: inline-block; padding: 8px 12px; border-radius: 18px; transition: background-color var(--transition-fast) ease, opacity var(--transition-fast) ease; border: 1px solid rgba(255,255,255,0.25); }
.breadcrumbs a:first-of-type::before { content: "🏠"; display: inline-block; margin-right: 8px; }
.breadcrumbs strong { display: inline-block; padding: 6px 12px; border-radius: 18px; background-color: rgba(255,255,255,0.20); font-weight: 700; border: 1px solid rgba(255,255,255,0.28); text-shadow: 0 1px 2px rgba(0,0,0,0.22); }
[data-theme="dark"] .breadcrumbs strong { text-shadow: 0 1px 2px rgba(0,0,0,0.35); }
.breadcrumbs strong { text-shadow: 0 1px 2px rgba(0,0,0,0.22); }
[data-theme="dark"] .breadcrumbs a:hover { background-color: rgba(255,255,255,0.12); }
.breadcrumbs a + a::before, .breadcrumbs strong + a::before { content: "›"; display: inline-block; margin: 0 6px 0 10px; opacity: 0.9; }
[data-theme="dark"] .breadcrumbs a + a::before, [data-theme="dark"] .breadcrumbs strong + a::before { opacity: 0.8; }
[data-theme="dark"] .breadcrumbs strong { background-color: rgba(255,255,255,0.12); }
[data-theme="dark"] .breadcrumbs { background: radial-gradient(900px 300px at 12% -40%, rgba(255,255,255,0.12) 0%, rgba(255,255,255,0.0) 45%), linear-gradient(90deg, var(--green-dark) 0%, #116c33 50%, #0e5a2a 100%) !important; color: #ffffff !important; border-color: #1f2937 !important; box-shadow: 0 16px 32px rgba(0,0,0,0.38); }
@media (max-width: 768px) { .breadcrumbs { padding: 10px 16px !important; border-radius: 0 0 12px 12px; font-size: 14px; } .breadcrumbs a, .breadcrumbs strong { padding: 6px 10px; } }
[data-theme="dark"] .breadcrumbs { background-color: var(--green-dark) !important; color: #ffffff !important; border-color: #1f2937 !important; }

.breadcrumbs { background: linear-gradient(180deg, var(--green) 0%, var(--green-dark) 100%) !important; box-shadow: 0 6px 12px rgba(0,0,0,0.14); border-radius: 0 0 10px 10px; padding: 12px 28px !important; font-size: 15px; letter-spacing: 0.2px; }
.breadcrumbs::after, .breadcrumbs::before { display: none !important; }
.breadcrumbs a { border: none; padding: 6px 12px; border-radius: 12px; background-color: rgba(255,255,255,0.12); }
.breadcrumbs a:hover { background-color: rgba(255,255,255,0.20); }
.breadcrumbs strong { background-color: rgba(255,255,255,0.20); border: none; }

/* =====================
   Branding: Site title
   ===================== */
#site-name { margin: 0; }
#site-name a {
  display: inline-flex;
  align-items: center;
  gap: 60px;
  color: var(--brand-title-color) !important;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 0.2px;
  text-decoration: none !important;
  padding: 4px 10px;
  border-radius: 8px;
  transition: color var(--transition-med) ease,
              text-decoration-color var(--transition-med) ease,
              box-shadow var(--transition-med) ease,
              filter var(--transition-med) ease,
              opacity var(--transition-med) ease;
}
#site-name a .brand-icon { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; margin-right: 0; margin-left: 8px; position: relative; overflow: visible; }
#site-name a .brand-icon svg { width: 30px; height: 30px; transform: scale(2.6); transform-origin: center; }
#site-name a .brand-icon img { width: 30px; height: 30px; object-fit: contain; display: block; transform: scale(2.6); transform-origin: center; }
#site-name a:hover {
  color: var(--brand-title-color) !important;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  background-color: transparent;
  box-shadow: none;
}
#site-name a:focus {
  color: var(--brand-title-color) !important;
  outline: none;
  background-color: transparent;
  box-shadow: 0 0 0 3px var(--brand-title-focus-ring);
}
#site-name a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--brand-title-focus-ring);
}

[data-theme="dark"] #site-name a:hover {
  background-color: transparent;
}

/* Header user tools (e.g., Logout, dark-mode icon) */
/* Ensure readable header tools and fix white-on-white hover */
#user-tools a,
#user-tools button,
#user-tools .action-link {
  color: var(--header-text) !important;
  background: transparent !important;
  transition: color var(--transition-med) ease,
              background-color var(--transition-med) ease,
              box-shadow var(--transition-med) ease,
              filter var(--transition-med) ease,
              opacity var(--transition-med) ease;
  position: relative;
}
#user-tools a::after,
#user-tools button::after,
#user-tools .action-link::after {
  content: "";
  position: absolute;
  inset: 0;
  background-color: var(--hover-bg);
  opacity: 0;
  border-radius: 4px;
  transition: opacity var(--transition-med) ease;
  pointer-events: none;
}
/* Do not draw hover overlay on theme toggle button itself */
#user-tools .theme-toggle::after {
  display: none !important;
}
#user-tools a:hover,
#user-tools a:focus,
#user-tools button:hover,
#user-tools button:focus,
#user-tools .action-link:hover,
#user-tools .action-link:focus {
  /* Avoid pure white background; keep text white */
  background-color: transparent !important; /* overlay handles hover bg */
  color: var(--header-text) !important;
  border-radius: 4px !important;
  text-decoration: none !important;
}
#user-tools a:hover::after,
#user-tools a:focus::after,
#user-tools button:hover::after,
#user-tools button:focus::after,
#user-tools .action-link:hover::after,
#user-tools .action-link:focus::after {
  opacity: 1;
}

/* Theme toggle icon (moon) — ensure visible and on-brand */
#user-tools .theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 4px;
  background-color: transparent !important; /* no square */
  background: none !important;
  background-image: none !important;
  cursor: pointer;
  color: var(--theme-icon-color);
  transition: color var(--transition-med) ease,
              background-color var(--transition-med) ease,
              box-shadow var(--transition-med) ease,
              transform var(--transition-fast) ease;
  width: 24px;
  height: 24px;
  position: relative;
  border: 0 !important;
  outline: none !important;
  appearance: none;
  -webkit-appearance: none;
  line-height: 0;
  font-size: 0;
}
/* Nuclear reset inside the toggle: no backgrounds, borders, or shadows */
#user-tools .theme-toggle *,
#user-tools .theme-toggle svg,
#user-tools .theme-toggle img {
  background: transparent !important;
  background-color: transparent !important;
  background-image: none !important;
  box-shadow: none !important;
  border: 0 !important;
}
#user-tools .theme-toggle:hover,
#user-tools .theme-toggle:focus {
  background-color: transparent !important;
  box-shadow: var(--hover-ring);
}
#user-tools .theme-toggle:active {
  transform: translateY(1px);
  background-color: transparent !important;
}
/* Make icon white; works for inline SVG and most PNGs */
#user-tools .theme-toggle svg {
  width: 18px;
  height: 18px;
  fill: currentColor !important;
  stroke: currentColor !important;
  color: currentColor !important;
  shape-rendering: geometricPrecision;
  vector-effect: non-scaling-stroke;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  opacity: 1;
  transition: opacity var(--transition-med) ease, filter var(--transition-med) ease;
}
#user-tools .theme-toggle img {
  width: 18px;
  height: 18px;
  /* force light-on-dark and tint towards orange */
  filter: brightness(0) invert(1) sepia(1) saturate(450%) hue-rotate(-10deg) !important;
}

/* Fallback glyph if SVG fails to render */
#user-tools .theme-toggle::before {
  content: "\1F319"; /* moon glyph */
  display: inline-block;
  color: var(--theme-icon-color);
  font-size: 16px;
  line-height: 1;
}
[data-theme="dark"] #user-tools .theme-toggle::before {
  content: "\2600"; /* sun glyph */
}

/* When SVGs are present, completely disable pseudo-elements to avoid boxes */
#user-tools .theme-toggle.has-svg::before,
#user-tools .theme-toggle.has-svg::after {
  content: none !important;
  display: none !important;
  background: none !important;
  background-color: transparent !important;
  background-image: none !important;
  box-shadow: none !important;
  border: 0 !important;
}

/* Cross-fade icons on theme change */
#user-tools .theme-toggle .icon-sun { opacity: 1; }
#user-tools .theme-toggle .icon-moon { opacity: 0; }
[data-theme="dark"] #user-tools .theme-toggle .icon-sun { opacity: 0; }
[data-theme="dark"] #user-tools .theme-toggle .icon-moon { opacity: 1; }

/* Fallback: make any header tool icons white */
#user-tools a svg,
#user-tools button svg,
#user-tools .action-link svg {
  fill: var(--header-text) !important;
  color: var(--header-text) !important;
}
#user-tools a img,
#user-tools button img,
#user-tools .action-link img {
  filter: brightness(0) invert(1) sepia(1) saturate(450%) hue-rotate(-10deg) !important;
}

/* If any icon uses font-based classes, force white */
#user-tools .fa,
#user-tools [class*="icon"],
#user-tools [class*="-icon"],
#user-tools .material-icons {
  color: #ffffff !important;
}

/* Buttons */
.button, .button.default, input[type="submit"], .submit-row input.default {
  background-color: var(--orange);
  border-color: var(--orange);
  color: #fff;
}
.button:hover, .button.default:hover, input[type="submit"]:hover, .submit-row input.default:hover {
  background-color: var(--orange-dark);
  border-color: var(--orange-dark);
}

#nav-sidebar {
  background: #ffffff;
  border-right: 1px solid #e5e7eb;
  padding: 16px 12px;
}

.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.brand-avatar { width: 40px; height: 40px; border-radius: 50%; background: #f3f4f6; color: #111827; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; }
.brand-info { line-height: 1.1; }
.brand-name { font-weight: 800; letter-spacing: .3px; }
.brand-sub { font-size: 12px; color: #6b7280; }

.sidebar-search { padding: 10px 8px 6px; }
.search-field { position: relative; display: flex; align-items: center; gap: 8px; border: 1.5px solid #e5e7eb; border-radius: 999px; padding: 8px 12px; background: #ffffff; }
.search-field .icon { width: 18px; height: 18px; color: #6b7280; flex-shrink: 0; }
.search-field input { border: 0; outline: none; background: transparent; width: 100%; color: #111827; }
.search-field:focus-within { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(226, 104, 48, 0.22); background: #ffffff; }
#nav-filter { border: 0 !important; outline: none !important; box-shadow: none !important; background: transparent !important; }
#nav-filter::placeholder { color: #9ca3af; opacity: 1; }
.kbd-pill { display: none; }

.menu-title { margin: 10px 8px 8px; font-weight: 600; color: #6b7280; }
.menu-list { list-style: none !important; padding: 0 !important; margin: 0; }
.menu-list li { list-style: none !important; }
.menu-list li::marker { content: '' !important; }
.menu-list li::before { content: none !important; }
.menu-item { margin: 6px 0; }
.menu-link { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; color: #111827; text-decoration: none; border: 1px solid transparent; }
.menu-link:hover { background: #fff7f3; border-color: #fde1d3; }
.menu-icon { width: 22px; height: 22px; color: #6b7280; display: inline-flex; align-items: center; justify-content: center; }
.menu-icon svg { width: 20px; height: 20px; }
.menu-text { font-weight: 600; }
.menu-item.is-active .menu-link { background: var(--orange); border-color: var(--orange); color: #ffffff; }
.menu-item.is-active .menu-icon { color: #ffffff; }

.sidebar-footer { padding: 10px 8px; }
.collapse-btn { border: 0; background: transparent; color: #6b7280; cursor: pointer; }


/* Model links */
#nav-sidebar .model-list li a {
  color: var(--orange-dark);
}
#nav-sidebar .model-list li a:hover,
#nav-sidebar .model-list li a:focus {
  background-color: #fff2ee;
  color: var(--orange-dark);
}

/* Sidebar filter input */


/* Right-side filter header */
#changelist-filter h2,
#changelist-filter .filter-title {
  background-color: var(--orange-contrast) !important;
  color: var(--orange-contrast-text) !important;
}

/* Table header accents */
.results thead th {
  background-color: var(--orange-soft);
  border-bottom: 1px solid var(--hairline-color);
}

/* Reserve space so filters never overlap table */
#changelist {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  max-width: 100%;
}
/* The flex child holding the table is `.changelist-form-container`;
   `#content-main` is #changelist's PARENT, so the old `#changelist
   #content-main` selector matched nothing and its overflow never applied.
   `min-width: 0` is the essential bit - without it a flex item refuses to
   shrink below its content, so a wide table pushed the whole page sideways
   instead of scrolling inside its own box. */
#changelist .changelist-form-container {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  padding: 8px;
  box-sizing: border-box;
}
#changelist-filter {
  width: 260px;
  flex-shrink: 0;
}

/* Changelist table: compact layout with horizontal scroll.
   `.results` is Django's wrapper DIV around #result_list. It used to be forced
   to `display: table`, which destroyed its ability to scroll - so the table
   overflowed and the PAGE grew a horizontal scrollbar. Keeping it a block with
   overflow-x confines the scrolling to the table. */
#changelist .results {
  display: block;
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}
#changelist #result_list {
  table-layout: auto;
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
#changelist .results th, #changelist .results td {
  white-space: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 6px 10px !important;
  max-width: 260px;
  overflow-wrap: anywhere;
  word-wrap: break-word;
  vertical-align: top;
}

/* Force all content inside cells to respect boundaries */
#changelist .results td * {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  vertical-align: middle;
}
/* Slim column widths for common fields.
   NOTE: scoped to the action-checkbox column on purpose. A bare :first-child
   rule also crushed the first real column to 35px on read-only changelists
   (no checkbox column), e.g. Activity Logs' TIMESTAMP. */
#changelist .results th.action-checkbox-column:first-child,
#changelist .results td.action-checkbox-column:first-child {
  width: 35px;
  max-width: 35px;
  min-width: 35px;
  padding: 4px !important;
}
#changelist .results th.action-checkbox-column, #changelist .results td.action-checkbox-column { 
  width: 35px;
  max-width: 35px;
  min-width: 35px;
  padding: 4px !important; 
}
/* date column width */
#changelist .results th:nth-child(7), #changelist .results td:nth-child(7) { 
  width: 140px; 
  max-width: 140px;
  min-width: 100px;
}
/* ID columns - make very slim */
#changelist .results th.field-id, #changelist .results td.field-id {
  width: 80px;
  max-width: 80px;
  min-width: 60px;
}
/* Short code columns. A dealer card code is 9 characters and an employee code
   is shorter still, so these do not need the generic 260px cell width. The
   `column-` classes match the sortable <th>, `field-` the <td>. */
#changelist .results th.column-employee_code,
#changelist .results td.field-employee_code {
  width: 90px;
  max-width: 90px;
  min-width: 70px;
}
#changelist .results th.column-dealer_card_code,
#changelist .results td.field-dealer_card_code {
  width: 110px;
  max-width: 110px;
  min-width: 90px;
}
/* Name/title columns - moderate width */
#changelist .results th.field-name, #changelist .results td.field-name,
#changelist .results th.field-title, #changelist .results td.field-title,
#changelist .results th.field-name_of_fsm, #changelist .results td.field-name_of_fsm { 
  max-width: 150px;
  min-width: 100px;
}
/* Company/Region/Territory columns */
#changelist .results th.field-company_fk, #changelist .results td.field-company_fk,
#changelist .results th.field-territory_fk, #changelist .results td.field-territory_fk,
#changelist .results th.field-region_fk, #changelist .results td.field-region_fk { 
  max-width: 180px;
  min-width: 120px;
}
/* Email/long text columns */
#changelist .results th.field-email, #changelist .results td.field-email { 
  max-width: 160px;
  min-width: 120px;
}
/* Actions column */
#changelist .results th.action-column, #changelist .results td.action-column { 
  width: 80px;
  max-width: 80px;
  min-width: 80px;
  text-align: center; 
}
/* Date columns */
#changelist .results th.field-date_created, #changelist .results td.field-date_created,
#changelist .results th.field-date_modified, #changelist .results td.field-date_modified,
#changelist .results th.field-created_at, #changelist .results td.field-created_at,
#changelist .results th.field-updated_at, #changelist .results td.field-updated_at { 
  width: 140px;
  max-width: 140px;
  min-width: 120px;
}

/* Ensure filter sits above table and has opaque background */
#changelist-filter {
  position: sticky;
  top: 70px;
  z-index: 6000;
  background: #fff;
  box-shadow: 0 8px 20px rgba(0,0,0,0.08);
  float: right;
  margin-left: 20px;
  /* Being sticky, the panel never scrolls with the page - without its own
     height cap any filter past the fold (e.g. "By leave type" on Leave
     requests) was permanently unreachable. Scroll inside the panel instead. */
  max-height: calc(100vh - 90px);
  overflow-y: auto;
}
#changelist-filter .filter, #changelist-filter .filter ul, #changelist-filter .filter li { background: #fff; }

/* Ensure main content doesn't overlap with filter */
#changelist .changelist-form-container {
  box-sizing: border-box;
  padding-right: 0;
}

/* Horizontal scroll wrapper for table */
#changelist .results-wrapper {
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  margin: 10px 0;
  border: 1px solid var(--hairline-color);
  border-radius: 8px;
  background: #fff;
  position: relative;
}

/* Pagination styling - make more prominent */
.paginator {
  padding: 12px 16px;
  background: #f9fafb;
  border: 1px solid var(--hairline-color);
  border-radius: 8px;
  margin: 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 13px;
}
.paginator a, .paginator span {
  padding: 6px 12px;
  border-radius: 6px;
  display: inline-block;
  min-width: 32px;
  text-align: center;
}
.paginator a {
  background: #fff;
  border: 1px solid var(--hairline-color);
  color: var(--orange-dark);
  text-decoration: none;
  transition: all 0.2s ease;
}
.paginator a:hover {
  background: var(--orange);
  color: #fff;
  border-color: var(--orange);
}
.paginator .this-page {
  background: var(--orange);
  color: #fff;
  font-weight: 600;
  border: 1px solid var(--orange);
}
.paginator .end {
  padding: 6px 10px;
}

/* Constrain each filter's option list so several sections stay visible at
   once; the panel itself scrolls for the rest. */
#changelist-filter .filter ul {
  max-height: 32vh;
  overflow-y: auto;
}

/* Actions bar - make compact */
.actions {
  padding: 8px 12px;
  background: #f9fafb;
  border: 1px solid var(--hairline-color);
  border-radius: 8px;
  margin: 10px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.actions label {
  font-size: 13px;
  margin: 0;
}
.actions select {
  padding: 4px 8px;
  font-size: 13px;
  border-radius: 6px;
  height: auto;
  min-height: 32px;
}
.actions button {
  padding: 4px 12px;
  font-size: 13px;
  border-radius: 6px;
  min-height: 32px;
}
.actions span.action-counter {
  font-size: 12px;
  color: #6b7280;
  margin-left: auto;
}
.actions .question {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--orange);
  color: #fff;
  font-size: 12px;
  cursor: help;
  margin-left: 4px;
}

/* Results count info */
#changelist .paginator + p,
#changelist p.paginator {
  font-size: 13px;
  color: #6b7280;
  margin: 8px 0;
}

/* List display and show all link */
#changelist .paginator .showall {
  margin-left: 10px;
  padding: 6px 12px;
  background: #fff;
  border: 1px solid var(--hairline-color);
  border-radius: 6px;
  color: var(--orange-dark);
  text-decoration: none;
  font-size: 12px;
  transition: all 0.2s ease;
}
#changelist .paginator .showall:hover {
  background: var(--orange-soft);
  border-color: var(--orange);
}

/* Compact changelist header */
#changelist .changelist-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 10px;
}

/* Make change list form more compact */
#changelist-form {
  margin: 0;
}

/* Column display toggle hint */
#changelist .results th[title] {
  cursor: help;
}
#changelist .results th[title]:hover {
  background-color: var(--orange-dark);
  color: #fff;
}

/* Improve table borders */
#changelist .results {
  border: 1px solid var(--hairline-color);
  border-radius: 8px;
}
#changelist .results th,
#changelist .results td {
  border-right: 1px solid #e5e7eb;
  border-bottom: 1px solid #f3f4f6;
}
#changelist .results th:last-child,
#changelist .results td:last-child {
  border-right: none;
}
#changelist .results tbody tr:last-child td {
  border-bottom: none;
}

/* Ensure the entire changelist form respects boundaries */
#changelist-form {
  overflow-x: auto;
  overflow-y: visible;
  max-width: 100%;
}

/* Table container wrapper */
.results-container {
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  max-width: 100%;
}

/* Compact row styling */
#changelist .results tbody tr {
  height: 38px;
}
#changelist .results tbody tr:hover {
  background-color: rgba(226, 104, 48, 0.08);
}

/* Additional overflow protection for all changelist elements */
#changelist .form-row,
#changelist .field-box,
#changelist .related-widget-wrapper,
#changelist .readonly {
  overflow: hidden;
  text-overflow: ellipsis;
  word-wrap: break-word;
}

/* Ensure long URLs and text in cells wrap properly */
#changelist .results td a,
#changelist .results td span,
#changelist .results td div,
#changelist .results td strong,
#changelist .results td em {
  display: inline;
  max-width: 100%;
  vertical-align: middle;
  line-height: 1.4;
  white-space: normal;
  overflow-wrap: anywhere;
  word-wrap: break-word;
}

#changelist .results td {
  position: relative;
}

/* Make links more compact */
#changelist .results td a {
  padding: 2px 4px;
  border-radius: 4px;
}

/* Action column should be fixed width */
#changelist .results th.action-checkbox-column,
#changelist .results td.action-checkbox-column {
  width: 35px;
  max-width: 35px;
  min-width: 35px;
  text-align: center;
}

/* Position page heading and action buttons in a single row */
#content {
  position: relative;
}

/* Make the heading area a flex container to hold h1 and object-tools side by side */
#content > h1 {
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--hairline-color);
}

/* Object tools (action buttons) - position right after heading.
   `right` is the nudge knob. Keep it >= 0: a negative value puts the button
   outside #content's box, which widens the page's scrollable area and was
   part of why the whole page scrolled sideways. */
.object-tools {
  position: absolute;
  top: 12px;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  z-index: 100;
}

.object-tools li {
  margin: 0;
  display: inline-block;
}

.object-tools a {
  padding: 10px 20px;
  font-size: 14px;
  border-radius: 8px;
  background: var(--orange);
  color: #fff !important;
  text-decoration: none;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  border: none;
  box-shadow: 0 2px 4px rgba(226, 104, 48, 0.2);
}

.object-tools a:hover {
  background: var(--orange-dark);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(226, 104, 48, 0.3);
}

.object-tools a::before {
  content: "+";
  font-size: 18px;
  font-weight: bold;
  line-height: 1;
}

/* For changelist pages specifically */
#changelist {
  padding-top: 0;
}

/* Make sure content has enough top padding for the absolute positioned button */
#content {
  padding-top: 20px;
  /* Django's base.css ships `padding: 20px 40px`, which left a wide empty gutter
     between the nav sidebar and the page content. Tightening it also gives the
     changelist table ~48px more room before it needs to scroll. */
  padding-left: 16px;
  padding-right: 16px;
}

/* Search bar - make more compact */
#changelist-search {
  padding: 10px;
  background: #f9fafb;
  border: 1px solid var(--hairline-color);
  border-radius: 8px;
  margin-bottom: 12px;
}
#changelist-search input[type="text"] {
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 6px;
}
#changelist-search input[type="submit"] {
  padding: 6px 16px;
  font-size: 13px;
  border-radius: 6px;
}

/* Narrow screens: stack filter above table */
@media (max-width: 1024px) {
  #changelist {
    flex-direction: column;
  }
  #changelist .changelist-form-container {
    margin-right: 0;
    max-width: 100%;
    padding: 4px;
    width: 100%;
  }
  #changelist-filter { 
    position: static; 
    width: 100%;
    box-shadow: none;
    margin-bottom: 16px;
  }
  #changelist .results {
    font-size: 12px;
  }
  #changelist .results th, #changelist .results td {
    padding: 4px 6px !important;
    max-width: 150px;
  }
  .paginator {
    font-size: 12px;
    padding: 8px;
  }
}

/* ==========================
   Dark mode hover adjustments
   ========================== */
@media (prefers-color-scheme: dark) {
  /* Keep header tools readable on dark or orange backgrounds */
  #user-tools a:hover,
  #user-tools button:hover,
  #user-tools .action-link:hover {
    background-color: transparent !important; /* overlay handles hover bg */
    color: var(--header-text) !important;
  }

  /* Sidebar links: avoid white hover on dark */
  #nav-sidebar .model-list li a:hover,
  #nav-sidebar .model-list li a:focus {
    background-color: rgba(255, 255, 255, 0.10) !important;
    color: #ffffff !important;
  }

  /* List/table row hover: use subtle light overlay */
  #content-main .module tbody tr:hover,
  .results tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.08) !important;
  }
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  #user-tools a,
  #user-tools button,
  #user-tools .action-link,
  #user-tools .theme-toggle {
    transition: none !important;
  }
}

/* ==========================
   Site administration (index)
   ========================== */
/* App/module captions at admin index */
#content-main .module caption,
#content-main .app-list .module caption {
  display: block;
  background-color: var(--orange-contrast);
  color: var(--orange-contrast-text);
  padding: 8px 12px;
  border: 1px solid var(--orange-contrast);
}

/* Caption link (app title) */
#content-main .module caption a {
  color: var(--orange-contrast-text);
  text-decoration: none;
}

/* App tables */
#content-main .module table {
  border: 1px solid var(--hairline-color);
  border-top: none; /* caption already draws top border */
}

#content-main .module tbody tr th a {
  color: var(--orange-dark);
}

#content-main .module tbody tr td a {
  color: var(--orange);
}

#content-main .module tbody tr:hover {
  background-color: #fff6f3;
}

/* =============================
   Changelist table enhancements
   ============================= */
/* Header cells - more compact and sticky */
#changelist .results thead th {
  background-color: var(--orange-soft);
  color: #2b2b2b;
  border-bottom: 2px solid var(--orange-soft-border);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 8px 10px !important;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
[data-theme="dark"] #changelist .results thead th {
  background-color: #1f1f1f;
  color: #f0f0f0;
  border-bottom: 2px solid #333;
}

/* Sortable column headers */
#changelist .results thead th.sortable a {
  padding: 0;
  display: block;
  color: inherit;
}
#changelist .results thead th.sorted {
  background-color: var(--orange);
  color: #fff;
}
#changelist .results thead th.sorted a {
  color: #fff;
}

/* ------------------------------------------------------------------
   Row striping + hover.
   ORDER MATTERS: striping is declared FIRST so hover/selection can win.
   Previously :nth-child(odd) came after :hover at identical specificity,
   which cancelled the hover state on every odd row. The cells are painted
   too (> td/th), because a cell background would otherwise sit on top of
   the row background and defeat the hover.
   ------------------------------------------------------------------ */
#changelist .results tbody tr,
#changelist .results tbody tr > td,
#changelist .results tbody tr > th { transition: background-color 120ms ease; }

/* No zebra striping - every row uses the same background. The :nth-child
   selectors are listed explicitly to cancel Django's own odd/even striping,
   which would otherwise tint alternate rows. */
/* !important because the previous rule used rgba(255,255,255,0.03) - i.e.
   effectively transparent - so rows inherited whatever tint sat behind them.
   Painting td/th opaquely (and winning outright) is what makes rows uniform. */
#changelist .results tbody tr,
#changelist .results tbody tr > td,
#changelist .results tbody tr > th,
#changelist .results tbody tr:nth-child(odd),
#changelist .results tbody tr:nth-child(odd) > td,
#changelist .results tbody tr:nth-child(odd) > th,
#changelist .results tbody tr:nth-child(even),
#changelist .results tbody tr:nth-child(even) > td,
#changelist .results tbody tr:nth-child(even) > th { background-color: #ffffff !important; }

/* Hover - declared after striping so it always applies. */
#changelist .results tbody tr:hover,
#changelist .results tbody tr:hover > td,
#changelist .results tbody tr:hover > th { background-color: #fff2ee !important; }

/* Selection beats hover. */
#changelist .results tbody tr.selected,
#changelist .results tbody tr.selected > td,
#changelist .results tbody tr.selected > th,
#changelist .results tbody tr:has(.action-select:checked),
#changelist .results tbody tr:has(.action-select:checked) > td,
#changelist .results tbody tr:has(.action-select:checked) > th {
  background-color: #ffe7db !important;
}
#changelist .results tbody tr.selected { outline: 1px solid var(--orange-soft-border); }

[data-theme="dark"] #changelist .results tbody tr,
[data-theme="dark"] #changelist .results tbody tr > td,
[data-theme="dark"] #changelist .results tbody tr > th,
[data-theme="dark"] #changelist .results tbody tr:nth-child(odd),
[data-theme="dark"] #changelist .results tbody tr:nth-child(odd) > td,
[data-theme="dark"] #changelist .results tbody tr:nth-child(odd) > th,
[data-theme="dark"] #changelist .results tbody tr:nth-child(even),
[data-theme="dark"] #changelist .results tbody tr:nth-child(even) > td,
[data-theme="dark"] #changelist .results tbody tr:nth-child(even) > th { background-color: #0f172a; }
[data-theme="dark"] #changelist .results tbody tr:hover,
[data-theme="dark"] #changelist .results tbody tr:hover > td,
[data-theme="dark"] #changelist .results tbody tr:hover > th { background-color: rgba(255, 255, 255, 0.07); }

/* Role badge / tags */
#changelist .results td .badge,
#changelist .results td .tag {
  background-color: var(--orange);
  color: #fff;
  border-radius: 12px;
  padding: 2px 8px;
  display: inline-block;
  font-weight: 600;
}

/* Action icons saturation (toned) */
#changelist .results td a img,
#changelist .results td a svg {
  filter: saturate(85%) contrast(105%);
}

/* ---------------------------
   Login: Show Password Toggle
   --------------------------- */
.password-field-wrapper {
  position: relative;
  display: block;
}
.password-field-wrapper input[type="password"],
.password-field-wrapper input[type="text"] {
  padding-right: 40px; /* room for eye icon */
}
.password-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--orange-dark);
  cursor: pointer;
}
.password-toggle:hover {
  color: var(--orange);
}
.password-toggle:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(231, 111, 81, 0.3);
  border-radius: 4px;
}
.password-toggle svg {
  width: 18px;
  height: 18px;
}
.password-toggle .icon-eye-off { display: none; }
.password-toggle[data-state="visible"] .icon-eye { display: none; }
.password-toggle[data-state="visible"] .icon-eye-off { display: inline; }

/* =============================
   Admin layout space for charts
   ============================= */
/* Preferred approach: app-specific overrides (no venv edits) */
.app-crop_manage #content {
  width: auto;
  max-width: none;
}

.app-crop_manage #content-related {
  width: 220px; /* slimmer sidebar */
  margin-right: -260px; /* 220 + 40 padding on #content */
}

.app-crop_manage .colMS { /* main content with right sidebar */
  margin-right: 260px;
}
.app-crop_manage .colSM { /* main content with left sidebar */
  margin-left: 260px;
}
.app-crop_manage .colSM #content-related { margin-left: -260px; }

/* Optional: a generic chart container helper for admin pages */
.chart-container {
  background: #fff;
  border: 1px solid var(--hairline-color);
  border-radius: 8px;
  padding: 16px;
}

/* Responsive fallback: let content shrink gracefully on narrower screens */
@media (max-width: 1280px) {
  .app-crop_manage #content { width: auto; }
}

/* Main admin dashboard: widen content and slim sidebar */
.dashboard #content {
  width: auto;
}
.dashboard #nav-sidebar { left: 0; right: auto; }
.dashboard #nav-sidebar { flex: 0 0 240px; }
.dashboard #content-related {
  width: 220px; /* slimmer sidebar */
  margin-left: -260px; /* 220 + 40px content padding */
  float: left;
}
.dashboard .colMS { margin-left: 260px; }
.dashboard .colSM { margin-right: 0; }
.dashboard .colSM #content-related { margin-right: -260px; }

/* Dashboard main content wrapper */
.dashboard-main-content { margin-left: 0; padding-right: 0; }

/* Ensure proper sidebar positioning */
.dashboard #content-related {
  position: relative;
  float: left;
  width: 220px;
  margin-left: -260px;
}

/* Content area adjustments */
.dashboard #content { width: 100% !important; max-width: none !important; }

/* Chart section positioning */
.dashboard .charts-section {
  width: 100%;
  margin-top: 20px;
}

/* Ensure content sits to the right of the opened left nav */
.dashboard .main > #nav-sidebar + .content { width: calc(100% - 263px) !important; max-width: none !important; }

@media (max-width: 1280px) {
  .dashboard #content { width: auto; }
  .dashboard-main-content { margin-left: 0; padding-right: 0; }
  .dashboard #content-related { 
    position: static; 
    float: none; 
    width: 100%; 
    margin-left: 0; 
    margin-bottom: 20px;
  }
}

@media (max-width: 1200px) { .dashboard .chart-grid { grid-template-columns: repeat(2, minmax(280px, 1fr)); } }
@media (max-width: 768px) { .dashboard .chart-grid { grid-template-columns: 1fr; } }

/* ---------------------------
   Dashboard charts aesthetics
   --------------------------- */
.dashboard .charts-section {
  margin-top: 24px; /* space beneath default content */
}
.dashboard .charts-section h2 {
  margin: 0 0 12px 0;
  font-weight: 700;
  color: #ffffff !important;
}
.dashboard .page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0 16px; border-bottom: 1px solid var(--hairline-color); margin-bottom: 12px; }
.dashboard .page-head-left { display: flex; flex-direction: column; }
.dashboard .page-title { font-size: 20px; font-weight: 700; color: var(--text-default); }
.dashboard .page-meta { font-size: 12px; color: var(--body-quiet-color); }
.dashboard .page-head-right { display: flex; align-items: center; gap: 10px; }
.dashboard .icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--hairline-color); background: #fff; color: var(--text-default); }
.dashboard .icon-btn:hover { background: #f8f8f8; }
.dashboard .user-pill { display: inline-flex; align-items: center; gap: 10px; padding: 6px 10px; border: 1px solid var(--hairline-color); border-radius: 18px; background: #fff; }
.dashboard .user-pill .avatar { width: 28px; height: 28px; border-radius: 50%; background: #f3f4f6; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; color: var(--body-quiet-color); }
.dashboard .user-pill .user-info { line-height: 1.1; }
.dashboard .user-pill .user-name { font-weight: 600; font-size: 12px; }
.dashboard .user-pill .user-email { font-size: 12px; color: var(--body-quiet-color); }
.dashboard .dashboard-toolbar { display: flex; gap: 12px; align-items: center; justify-content: flex-end; margin: 8px 0 16px; }
.dashboard .chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--hairline-color); border-radius: 16px; background: #ffffff; color: var(--text-default); font-size: 12px; }
.dashboard .button-export { display: inline-flex; align-items: center; padding: 8px 12px; border-radius: 16px; background: var(--orange); color: #ffffff; border: 1px solid var(--orange); font-weight: 600; }
.dashboard .chart-grid { display: grid; grid-template-columns: repeat(3, minmax(280px, 1fr)); gap: 16px; width: 100%; }
.dashboard .chart-card { background: #ffffff; border: 1px solid var(--hairline-color); border-radius: 14px; padding: 16px; box-shadow: 0 2px 6px rgba(0,0,0,0.06); min-height: 220px; }
.dashboard .kpi-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dashboard .kpi-title { font-weight: 600; color: var(--text-default); }
.dashboard .kpi-info { border: 0; background: transparent; color: var(--body-quiet-color); cursor: pointer; }
.dashboard .kpi-body { display: flex; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.dashboard .kpi-value { font-size: 20px; font-weight: 700; color: var(--text-default); }
.dashboard .kpi-sub { font-size: 12px; color: var(--body-quiet-color); }
.dashboard .badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 12px; font-weight: 600; font-size: 12px; }
.dashboard .badge.up { background: #eafff2; color: #16a34a; }
.dashboard .badge.down { background: #fff0f0; color: #dc2626; }
/* Chart.js with maintainAspectRatio:false needs a fixed-height POSITIONED
   parent. Without it the canvas height and the container height feed each
   other and the card (and the whole page) keeps growing on every resize -
   the cause of the runaway white space below the dashboard. Pin the wrapper;
   the canvas fills it absolutely. */
.dashboard .kpi-chart { position: relative; height: 170px; margin-top: 4px; }

.dashboard #header {}
.dashboard #header a, .dashboard #user-tools a, .dashboard #logout-form button {}
.dashboard #user-tools a, .dashboard #user-tools button {}
.dashboard #user-tools a:hover, .dashboard #user-tools button:hover {}
.dashboard #nav-sidebar .module td a { display: block; padding: 10px 12px; border-radius: 12px; }
.dashboard #nav-sidebar .module td a:hover { background-color: #fff2ee; }
.dashboard #nav-sidebar .current-model { background: #ffe7db; border-radius: 12px; }
.dashboard .chart-card:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(0,0,0,0.08); }
.dashboard .kpi-info { width: 28px; height: 28px; border: 1px solid var(--hairline-color); border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.dashboard .chip { border-radius: 18px; }
.dashboard .button-export { gap: 6px; border-radius: 18px; }
.dashboard .button-export::before { content: "⤓"; }
.dashboard .chart-grid { gap: 20px; }
.dashboard .kpi-chart canvas,
.dashboard .chart-card canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  display: block;
}

#content-main .table-responsive { width: 100%; overflow-x: visible; -webkit-overflow-scrolling: touch; }
#content-main .result-table { min-width: 640px; }
@media (max-width: 768px) {
  #content-main .result-table thead th, #content-main .result-table tbody td { padding: 8px 10px; }
}
/* contain:layout is load-bearing: the recent-actions list has 100 rows in a
   420px overflow-y:auto box. Inside the dashboard's floated content column that
   scroll box fails to contain its own height and the full 5300px UL leaks into
   the page's scrollHeight - producing ~4600px of empty white space below the
   dashboard. Layout containment stops the leak; the inner scroll still works. */
#recent-actions-module { background-color: #ffffff; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); padding: 16px; border: 1px solid var(--hairline-color); contain: layout; }
[data-theme="dark"] #recent-actions-module { background-color: #0f172a; border-color: #1f2937; box-shadow: 0 2px 8px rgba(0,0,0,0.35); }
#recent-actions-module h2 { font-size: 18px; font-weight: 700; color: var(--text-default); margin: 0 0 12px 0; }
#recent-actions-module h3 { font-size: 14px; font-weight: 700; color: var(--text-default); margin: 0 0 8px 0; opacity: 0.8; }
/* Scrollable container so the full recent-action history is reachable
   without stretching the dashboard. */
#recent-actions-module .actionlist-scroll { max-height: 420px; overflow-y: auto; overscroll-behavior: contain; padding-right: 6px; }
#recent-actions-module .actionlist-scroll::-webkit-scrollbar { width: 8px; }
#recent-actions-module .actionlist-scroll::-webkit-scrollbar-track { background: transparent; }
#recent-actions-module .actionlist-scroll::-webkit-scrollbar-thumb { background: var(--hairline-color); border-radius: 4px; }
#recent-actions-module .actionlist-scroll::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
[data-theme="dark"] #recent-actions-module .actionlist-scroll::-webkit-scrollbar-thumb { background: #334155; }
#recent-actions-module .actionlist { list-style: none; padding: 0; margin: 0; }
#recent-actions-module .actionlist li { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 8px; transition: background-color var(--transition-fast) ease; }
#recent-actions-module .actionlist li:hover { background-color: var(--orange-soft); }
[data-theme="dark"] #recent-actions-module .actionlist li:hover { background-color: rgba(255,255,255,0.06); }
#recent-actions-module .actionlist li::before { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--hairline-color); background: #fff; color: var(--text-default); font-size: 16px; content: ""; }
[data-theme="dark"] #recent-actions-module .actionlist li::before { background: #0b1224; border-color: #1f2937; color: #e2e8f0; }
/* ==========================
   Form dropdown sizing
   ========================== */
.form-row select:not([multiple]),
#content-main select:not([multiple]),
.inline-group .tabular select:not([multiple]),
.related-widget-wrapper select:not([multiple]),
select.sap-customer-lov,
select.sap-item-lov,
select.sap-warehouse-lov,
select.sap-tax-lov,
select.sap-project-lov,
select.sap-crop-lov {
  height: 42px;
  font-size: 14px;
  background-color: #fff;
  cursor: pointer;
  padding: 6px 30px 6px 10px; /* Adjust padding to avoid click conflicts */
  appearance: auto; /* Force native appearance */
  -webkit-appearance: auto;
  -moz-appearance: auto;
}

/* Fix for dropdowns in generic result tables (not changelist).
   Scoped to cells that actually contain a <select> so long text in
   plain cells no longer bleeds into neighbouring columns. */
.results:has(td select) {
  overflow: visible !important;
  overflow-x: visible !important;
  overflow-y: visible !important;
}

/* ...but the rule above is not actually scoped away from the changelist, and
   any changelist using `list_editable` renders <select> cells - which turned
   the table's scroll container back into an overflowing block and pushed the
   whole page sideways (e.g. Users). Native <select> popups are painted by the
   browser outside the document flow, so they are not clipped by an ancestor's
   overflow; the container can safely scroll. Higher specificity wins here. */
#changelist .results:has(td select) {
  overflow-x: auto !important;
  overflow-y: auto !important;
}

#changelist .results td:has(select),
#changelist .results td:has(.related-widget-wrapper),
#changelist .results td:has(.select2-container) {
  overflow: visible !important;
}

#changelist .results td {
  position: relative; /* Keep z-index context for the select rule above */
}

#changelist .results select {
  position: relative;
  z-index: 500; /* Higher z-index */
  width: 100%;
  max-width: 100%;
}

/* Ensure Select2 dropdowns are above everything (branding, sidebar) */
.select2-container {
  z-index: 9999 !important;
}
.select2-dropdown {
  z-index: 9999 !important;
}
#recent-actions-module .actionlist li.addlink::before { content: "➕"; color: #16a34a; border-color: #22c55e; background: #eafff2; }
#recent-actions-module .actionlist li.changelink::before { content: "✏️"; color: #ca8a04; border-color: #eab308; background: #fefce8; }
#recent-actions-module .actionlist li.deletelink::before { content: "✖️"; color: #dc2626; border-color: #ef4444; background: #fef2f2; }
[data-theme="dark"] #recent-actions-module .actionlist li.addlink::before { background: rgba(22,163,74,0.15); }
[data-theme="dark"] #recent-actions-module .actionlist li.changelink::before { background: rgba(234,179,8,0.15); }
[data-theme="dark"] #recent-actions-module .actionlist li.deletelink::before { background: rgba(220,38,38,0.15); }
#recent-actions-module .actionlist li a { color: var(--orange); font-weight: 600; text-decoration: none; }
#recent-actions-module .actionlist li a:hover { color: var(--orange-dark); text-decoration: underline; text-underline-offset: 2px; }
#recent-actions-module .mini.quiet { color: var(--body-quiet-color); font-size: 12px; }
[data-theme="dark"] #recent-actions-module .mini.quiet { color: #94a3b8; }

@media (prefers-color-scheme: dark) {
  .dashboard .chart-card {
    background: #1a1a1a;
    border-color: #2a2a2a;
    box-shadow: none;
  }
  .dashboard .charts-section h2 { color: #f0f0f0; }
}

/* Recent actions moved below charts */
.dashboard .recent-actions-below .module {
  margin-top: 12px;
}
.dashboard .recent-actions-below h2 {
  font-weight: 600;
}
.dashboard .recent-actions-below .actionlist li {
  padding: 6px 0;
  border-bottom: 1px solid var(--hairline-color, #e9ecef);
}

/* =====================
   Fix Inline Form Overlapping Text
   ===================== */

/* Hide the .original paragraph that shows "Line 0: FG00001 - 20.00" text */
/* This paragraph contains initial values and overlaps with form fields */
.inline-group .tabular tbody tr td .original,
.inline-group .tabular .original,
.inline-related tbody tr td p.original,
tbody tr td p.original {
    display: none !important;
}

/* Ensure proper spacing for inline table cells */
.inline-group .tabular tbody tr td {
    padding: 8px 10px !important;
    vertical-align: middle !important;
}

/* Fix table row display */
.inline-group .tabular tbody tr {
    display: table-row !important;
}

/* Ensure form fields are visible and properly styled */
.inline-group .tabular tbody tr td input,
.inline-group .tabular tbody tr td select,
.inline-group .tabular tbody tr td textarea {
    width: 100% !important;
    box-sizing: border-box !important;
    margin: 0 !important;
}

/* Style the inline table headers */
.inline-group .tabular thead th {
    background-color: var(--orange, #E26830) !important;
    color: white !important;
    font-weight: 600 !important;
    padding: 12px 10px !important;
    text-align: left !important;
    border: none !important;
}

/* Add alternating row colors for better readability */
.inline-group .tabular tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

.inline-group .tabular tbody tr:nth-child(odd) {
    background-color: white;
}

/* Dark mode support */
[data-theme="dark"] .inline-group .tabular tbody tr:nth-child(even) {
    background-color: #2a2a2a;
}

[data-theme="dark"] .inline-group .tabular tbody tr:nth-child(odd) {
    background-color: #1a1a1a;
}

/* ------------------------------------------------------------------
   Changelist column sizing (log/monitoring tables)
   Fixes headers rendering one letter per line and squeezed cells.
   ------------------------------------------------------------------ */

/* Column headers must never break mid-word. The global `overflow-wrap:anywhere`
   used for cell content was stacking "TIMESTAMP" vertically. */
#changelist .results th {
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
  max-width: none;
}
#changelist .results th .text,
#changelist .results th .text a,
#changelist .results th a { white-space: nowrap; }

/* Very wide tables scroll horizontally instead of crushing every column.
   The scroll must stay inside .results; these containment rules stop a wide
   table (or any stray wide child) from widening the page itself, which is what
   forced the browser's global horizontal scrollbar. */
#changelist .results { overflow-x: auto; }
#content,
#content-main,
#changelist,
#changelist-form {
  max-width: 100%;
  box-sizing: border-box;
}
#changelist-form { min-width: 0; }

/* Per-column sizing for ActivityLog / LogEntry changelists. */
#changelist .results th.column-timestamp,   #changelist .results td.field-timestamp,
#changelist .results th.column-action_time, #changelist .results td.field-action_time {
  min-width: 170px; white-space: nowrap;
}
#changelist .results td.field-username,
#changelist .results td.field-user           { min-width: 170px; }
#changelist .results th.column-method,
#changelist .results td.field-method         { width: 80px;  white-space: nowrap; }
#changelist .results th.column-status_badge, #changelist .results td.field-status_badge,
#changelist .results th.column-action_badge, #changelist .results td.field-action_badge {
  width: 96px; white-space: nowrap; text-align: center;
}
#changelist .results td.field-duration_ms    { width: 96px;  white-space: nowrap; text-align: right; }
#changelist .results td.field-path           { min-width: 280px; max-width: 460px; }
#changelist .results td.field-view_module    { min-width: 160px; }
#changelist .results td.field-ip_address     { min-width: 120px; white-space: nowrap; }
#changelist .results td.field-object_repr    { min-width: 200px; }
#changelist .results td.field-content_type   { min-width: 140px; white-space: nowrap; }
#changelist .results td.field-change_message { min-width: 220px; max-width: 400px; }

/* Status/action badges must not be clipped by the generic cell-child rule. */
#changelist .results td.field-status_badge *,
#changelist .results td.field-action_badge * { overflow: visible; max-width: none; }

/* Module column on the monitoring log */
#changelist .results th.column-module_label,
#changelist .results td.field-module_label { min-width: 165px; white-space: nowrap; }

/* ------------------------------------------------------------------
   Search-box type-ahead suggestions (admin_search_suggest.js)
   ------------------------------------------------------------------ */
.admin-suggest-box {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 1200;
  margin-top: 4px;
  max-height: 320px;
  overflow-y: auto;
  min-width: 240px;
  background: #fff;
  border: 1px solid var(--hairline-color, #d1d5db);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.14);
}
.admin-suggest-item {
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.35;
  cursor: pointer;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  white-space: normal;
  overflow-wrap: anywhere;
}
.admin-suggest-item:last-child { border-bottom: none; }
.admin-suggest-item.is-active,
.admin-suggest-item:hover { background: var(--orange-soft, #FFE4D6); }
.admin-suggest-item strong { color: var(--orange, #E26830); font-weight: 700; }

[data-theme="dark"] .admin-suggest-box { background: #0f172a; border-color: #1f2937; box-shadow: 0 8px 20px rgba(0,0,0,0.45); }
[data-theme="dark"] .admin-suggest-item { border-bottom-color: rgba(255,255,255,0.06); color: #e2e8f0; }
[data-theme="dark"] .admin-suggest-item.is-active,
[data-theme="dark"] .admin-suggest-item:hover { background: rgba(255,255,255,0.08); }

/* ------------------------------------------------------------------
   Image / attachment download button (web_portal/admin_thumbnails.py)
   ------------------------------------------------------------------ */
.adm-dl {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 5px;
  padding: 3px 9px;
  border: 1px solid var(--hairline-color, #d1d5db);
  border-radius: 6px;
  background: #f8fafc;
  color: #334155 !important;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  text-decoration: none;
}
.adm-dl:hover { background: var(--orange, #E26830); border-color: var(--orange, #E26830); color: #fff !important; }
/* Icon-only under a 40px changelist thumbnail, where a labelled button would
   widen the column and push the rows apart. */
.adm-dl-compact { margin-top: 3px; padding: 1px 6px; font-size: 10px; }

.adm-file-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 0; }
.adm-file-chip {
  display: inline-block;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  vertical-align: middle;
}

[data-theme="dark"] .adm-dl { background: rgba(255, 255, 255, 0.06); border-color: #1f2937; color: #e2e8f0 !important; }
[data-theme="dark"] .adm-dl:hover { background: var(--orange, #E26830); border-color: var(--orange, #E26830); color: #fff !important; }
