/*
  Insight Nexus UI modernization layer
  - Works on top of Bootstrap 4.6
  - Light/Dark via html.theme-dark + body.theme-dark
  - Avoids rewriting Bootstrap core; focuses on surfaces, spacing, typography, and ergonomics.
*/

:root {
  /* Core palette (light) — ported from v2 React theme */
  --nx-bg: #f8f9fc;
  --nx-surface: #ffffff;
  --nx-surface-2: #f0f4ff;
  --nx-text: #111827;
  --nx-muted: #6b7280;
  --nx-border: #e2e5ee;
  --nx-border-strong: rgba(17, 24, 39, 0.22);

  /* Accent — indigo-blue from v2 */
  --nx-accent: #4c6ef5;
  --nx-accent-hover: #4263eb;
  --nx-accent-light: #dbe4ff;
  --nx-link: #4c6ef5;
  --nx-link-hover: #4263eb;

  /* Shadows */
  --nx-shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
  --nx-shadow-md: 0 8px 32px rgba(0,0,0,0.08);

  /* Layout */
  --nx-radius-lg: 1rem;
  --nx-radius-md: .75rem;
  --nx-radius-sm: .6rem;

  /* Navbar — dark navy from v2 */
  --nx-nav-bg: #0f1117;
  --nx-nav-border: #2a2d37;
  --nx-nav-link: rgba(255,255,255,0.78);
  --nx-nav-link-active: #ffffff;
  --nx-nav-pill: rgba(76, 110, 245, 0.20);
}

/* Let browsers render native controls (date pickers, scrollbars) appropriately */
html { color-scheme: light; }
html.theme-dark { color-scheme: dark; }

html.theme-dark {
  /* Core palette (dark) — from v2 React dark mode */
  --nx-bg: #0f1117;
  --nx-surface: #181a20;
  --nx-surface-2: #1e2028;
  --nx-text: #e5e7eb;
  --nx-muted: #9aa4b2;
  --nx-border: #2a2d37;
  --nx-border-strong: rgba(148, 163, 184, 0.26);

  --nx-accent: #5c7cfa;
  --nx-accent-hover: #748ffc;
  --nx-accent-light: rgba(76, 110, 245, 0.15);
  --nx-link: #91a7ff;
  --nx-link-hover: #bac8ff;

  --nx-shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --nx-shadow-md: 0 8px 32px rgba(0,0,0,0.4);

  --nx-nav-bg: #0a0c12;
  --nx-nav-border: #2a2d37;
  --nx-nav-link: rgba(255,255,255,0.78);
  --nx-nav-link-active: #ffffff;
  --nx-nav-pill: rgba(76, 110, 245, 0.25);
}

/* Base */
html, body {
  height: 100%;
}

body {
  background: var(--nx-bg);
  color: var(--nx-text);
  padding-top: 48px; /* fixed navbar — compact */
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Headings use slightly heavier weight */
h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Monospace: code, pre, inputs that show code */
code, pre, .font-mono, kbd {
  font-family: 'JetBrains Mono', 'Consolas', monospace;
  font-size: 0.875em;
}

/* Smooth transitions everywhere */
*, *::before, *::after {
  transition-property: background-color, border-color, box-shadow, color, opacity;
  transition-duration: 0.15s;
  transition-timing-function: ease;
}

/* Improve placeholder visibility, especially in dark mode */
.form-control::placeholder { color: rgba(107,114,128,0.9); }
html.theme-dark .form-control::placeholder,
body.theme-dark .form-control::placeholder { color: rgba(154,164,178,0.9); }

a {
  color: var(--nx-link);
}

a:hover {
  color: var(--nx-link-hover);
}

.text-muted {
  color: var(--nx-muted) !important;
}

/* Container */
.app-container {
  max-width: 1520px;
  margin-left: auto;
  margin-right: auto;
}

/* Navbar */
.navbar.app-navbar {
  background: var(--nx-nav-bg) !important;
  border-bottom: 1px solid var(--nx-nav-border);
  --bs-navbar-padding-y: 0;
  --bs-navbar-padding-x: 1.25rem;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
  min-height: 0;
}

.navbar.app-navbar .navbar-brand {
  padding-top: 0.45rem;
  padding-bottom: 0.45rem;
  margin-right: 0;
}

.navbar.app-navbar .navbar-toggler {
  padding: 0.2rem 0.4rem;
  font-size: 0.85rem;
}

/* True-center nav links on desktop */
@media (min-width: 992px) {
  .nx-nav-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin: 0 !important;
    display: flex;
    align-items: center;
    top: 0;
    bottom: 0;
  }
}

/* On mobile, center nav stacks normally */
@media (max-width: 991.98px) {
  .nx-nav-center {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
}

/* Brand text — v2 style */
.nx-brand-text {
  font-family: 'DM Sans', sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.nx-brand-accent {
  color: var(--nx-accent);
}

/* Brand link */
.navbar.app-navbar .navbar-brand {
  color: #ffffff !important;
  padding-top: 0.4rem;
  padding-bottom: 0.4rem;
  margin-right: 0;
}

/* Compact icon buttons inside navbar */
.navbar.app-navbar .btn-icon {
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 0.8rem;
}

/* Nav links only */
.navbar.app-navbar .nav-link {
  color: var(--nx-nav-link) !important;
  font-weight: 500;
  font-size: 0.875rem;
  letter-spacing: 0.01em;
  padding: 0.4rem 0.75rem !important;
  line-height: 1.4;
}

.navbar.app-navbar .nav-link:hover {
  color: var(--nx-nav-link-active) !important;
}

/* Active nav item (added by JS) */
.navbar.app-navbar .nav-link.active,
.navbar.app-navbar .dropdown-toggle.active {
  color: var(--nx-nav-link-active) !important;
  background: var(--nx-nav-pill);
  border-radius: .6rem;
}

/* Dropdown menus — readability in both themes */
.navbar.app-navbar .dropdown-menu,
.dropdown-menu {
  border-radius: var(--nx-radius-md);
  box-shadow: var(--nx-shadow-md);
  border: 1px solid var(--nx-border);
  background: var(--nx-surface);
  padding: 0.35rem;
}

.dropdown-item {
  color: var(--nx-text);
  font-size: 0.875rem;
  font-weight: 450;
  border-radius: 0.4rem;
  padding: 0.45rem 0.75rem;
}

.dropdown-item:hover,
.dropdown-item:focus {
  background: var(--nx-surface-2);
  color: var(--nx-text);
}

/* Surfaces */
.app-surface,
.card {
  background: var(--nx-surface);
  border: 1px solid var(--nx-border);
  border-radius: var(--nx-radius-lg);
  box-shadow: var(--nx-shadow-sm);
  transition: box-shadow 0.2s ease, transform 0.15s ease;
}

.card {
  overflow: hidden;
}

/* Subtle hover lift for clickable cards */
a.card:hover,
.card-hover:hover {
  box-shadow: var(--nx-shadow-md);
  transform: translateY(-1px);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--nx-border);
}

/* Buttons */
.btn {
  border-radius: var(--nx-radius-sm);
  font-weight: 500;
  font-size: 0.875rem;
}

/* Override Bootstrap primary to v2 indigo accent */
.btn-primary {
  background-color: var(--nx-accent);
  border-color: var(--nx-accent);
}

.btn-primary:hover, .btn-primary:focus {
  background-color: var(--nx-accent-hover);
  border-color: var(--nx-accent-hover);
}

.btn-primary:focus {
  box-shadow: 0 0 0 0.2rem rgba(76, 110, 245, 0.35);
}

.btn-outline-primary {
  color: var(--nx-accent);
  border-color: var(--nx-accent);
}

.btn-outline-primary:hover, .btn-outline-primary:focus {
  background-color: var(--nx-accent);
  border-color: var(--nx-accent);
  color: #fff;
}

html.theme-dark .btn-outline-primary,
body.theme-dark .btn-outline-primary {
  color: #91a7ff;
  border-color: rgba(92, 124, 250, 0.5);
}

html.theme-dark .btn-outline-primary:hover,
body.theme-dark .btn-outline-primary:hover {
  background-color: var(--nx-accent);
  border-color: var(--nx-accent);
  color: #fff;
}

/*
  Improve contrast for "warning" buttons in LIGHT mode.
  Bootstrap 4's default warning palette is low-contrast on white surfaces.
  Keep dark mode unchanged (user confirmed dark mode colors are acceptable).
*/
html:not(.theme-dark) .btn-warning,
body:not(.theme-dark) .btn-warning {
  background-color: #d39e00;
  border-color: #c69500;
  color: #111827;
}

html:not(.theme-dark) .btn-warning:hover,
body:not(.theme-dark) .btn-warning:hover {
  background-color: #c69500;
  border-color: #b98e00;
  color: #111827;
}

html:not(.theme-dark) .btn-outline-warning,
body:not(.theme-dark) .btn-outline-warning {
  color: #7a4f00;
  border-color: #d39e00;
}

html:not(.theme-dark) .btn-outline-warning:hover,
body:not(.theme-dark) .btn-outline-warning:hover {
  background-color: #d39e00;
  border-color: #c69500;
  color: #111827;
}

html:not(.theme-dark) .btn-outline-warning:focus,
body:not(.theme-dark) .btn-outline-warning:focus,
html:not(.theme-dark) .btn-warning:focus,
body:not(.theme-dark) .btn-warning:focus {
  box-shadow: 0 0 0 0.2rem rgba(211, 158, 0, 0.25);
}

.btn.btn-link {
  border-radius: .5rem;
}

.btn-icon {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* Inputs */
.form-control,
.form-select,
.custom-file-label {
  border-radius: var(--nx-radius-sm);
  border-color: var(--nx-border-strong);
}

/* Input groups (search icons, prefixes) */
.input-group-text {
  background: var(--nx-surface-2);
  border-color: var(--nx-border-strong);
  color: var(--nx-muted);
}

html.theme-dark .input-group-text,
body.theme-dark .input-group-text {
  background: #0f1117;
  border-color: var(--nx-border-strong);
  color: var(--nx-muted);
}

.form-control:focus {
  border-color: rgba(76, 110, 245, 0.55);
  box-shadow: 0 0 0 0.2rem rgba(76, 110, 245, 0.15);
}

.form-select:focus {
  border-color: rgba(76, 110, 245, 0.55);
  box-shadow: 0 0 0 0.2rem rgba(76, 110, 245, 0.15);
}

html.theme-dark .form-control,
body.theme-dark .form-select,
html.theme-dark .form-select,
body.theme-dark .form-control,
html.theme-dark .custom-file-label,
body.theme-dark .custom-file-label {
  background: #0f1117;
  border-color: var(--nx-border-strong);
  color: var(--nx-text);
}

/* Ensure BS5 close buttons are visible in dark mode */
html.theme-dark .btn-close,
body.theme-dark .btn-close {
  filter: invert(1) grayscale(100%);
  opacity: 0.85;
}

html.theme-dark .form-control:focus,
body.theme-dark .form-control:focus {
  border-color: rgba(92, 124, 250, 0.60);
  box-shadow: 0 0 0 0.2rem rgba(92, 124, 250, 0.16);
}

html.theme-dark .form-select:focus,
body.theme-dark .form-select:focus {
  border-color: rgba(92, 124, 250, 0.60);
  box-shadow: 0 0 0 0.2rem rgba(92, 124, 250, 0.16);
}

/* Toolbars / headers */
.app-page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: 1rem;
}

.app-page-title {
  margin: 0;
}

.app-meta {
  color: var(--nx-muted);
  font-size: .875rem;
}

.app-toolbar {
  padding: .85rem;
  border-radius: var(--nx-radius-lg);
  background: var(--nx-surface);
  border: 1px solid var(--nx-border);
  box-shadow: var(--nx-shadow-sm);
  margin-bottom: 1rem;
}

.app-toolbar .row,
.app-toolbar .form-inline {
  margin-bottom: 0;
}

/* Tables */
.table-wrap {
  border-radius: var(--nx-radius-lg);
  /*
    IMPORTANT (BS5): Do not hide overflow here.
    Many list views apply `table-wrap` on the same element as `.table-responsive`.
    `overflow: hidden` prevents horizontal scrolling, making the Actions column
    unreachable on smaller screens.
  */
  overflow-x: auto;
  overflow-y: visible;
}

.table-responsive {
  -webkit-overflow-scrolling: touch;
}

/* Table theming (BS5 uses CSS variables for table backgrounds/colors). */
.table {
  color: var(--nx-text);
  margin-bottom: 0;

  /* Keep table cell background aligned with Insight Nexus surfaces. */
  --bs-table-color: var(--nx-text);
  --bs-table-bg: var(--nx-surface);
  --bs-table-border-color: var(--nx-border);

  /* Subtle stripes/hover that match the v2 palette. */
  --bs-table-striped-bg: rgba(76, 110, 245, 0.02);
  --bs-table-hover-bg: rgba(76, 110, 245, 0.06);
}

html.theme-dark .table,
body.theme-dark .table {
  --bs-table-color: var(--nx-text);
  --bs-table-bg: var(--nx-surface);
  --bs-table-border-color: var(--nx-border);
  --bs-table-striped-bg: rgba(255, 255, 255, 0.03);
  --bs-table-hover-bg: rgba(92, 124, 250, 0.08);
}

/* If Bootstrap's native theming hook is active, mirror the same table palette. */
html[data-bs-theme="dark"] .table {
  --bs-table-color: var(--nx-text);
  --bs-table-bg: var(--nx-surface);
  --bs-table-border-color: var(--nx-border);
  --bs-table-striped-bg: rgba(255, 255, 255, 0.03);
  --bs-table-hover-bg: rgba(92, 124, 250, 0.08);
}
html.theme-dark .table,
body.theme-dark .table { color: var(--nx-text); }

.table td,
.table th { color: inherit; }

.table thead th {
  border-bottom: 1px solid var(--nx-border-strong);
}

.table td,
.table th {
  border-top: 1px solid var(--nx-border);
}

.table-sticky thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--nx-surface-2);
}

html.theme-dark .table-sticky thead th,
body.theme-dark .table-sticky thead th {
  background: #181a20;
}

.table-hover tbody tr:hover {
  background: rgba(76, 110, 245, 0.06);
}

html.theme-dark .table-hover tbody tr:hover,
body.theme-dark .table-hover tbody tr:hover {
  background: rgba(92, 124, 250, 0.08);
}

/* Badges (soft) */
.badge-soft {
  border: 1px solid var(--nx-border);
  background: var(--nx-surface-2);
  color: var(--nx-text);
}

/* Form sections */
.app-section {
  border-radius: var(--nx-radius-lg);
  border: 1px solid var(--nx-border);
  background: var(--nx-surface);
  box-shadow: var(--nx-shadow-sm);
  margin-bottom: 1rem;
}

.app-section .app-section-header {
  padding: .9rem 1rem;
  border-bottom: 1px solid var(--nx-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}

.app-section .app-section-body {
  padding: 1rem;
}

.app-section-title {
  margin: 0;
  font-weight: 700;
  font-size: 1rem;
}

/* Sticky form actions */
.app-form-actions {
  position: sticky;
  bottom: 0;
  z-index: 15;
  margin-top: 1rem;
  background: var(--nx-surface);
  border: 1px solid var(--nx-border);
  border-radius: var(--nx-radius-lg);
  box-shadow: var(--nx-shadow-md);
  padding: .75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  justify-content: flex-end;
}

/* Quill tweaks (keep compatibility with existing dark mode rules) */
.ql-toolbar.ql-snow,
.ql-container.ql-snow {
  border-radius: var(--nx-radius-md);
}

/* ── Landing page hero ─────────────────────────────────────────── */
.nx-landing-hero {
  margin-bottom: 1.5rem;
  padding: 1.75rem 2rem;
  border-radius: var(--nx-radius-lg);
  background: linear-gradient(135deg, var(--nx-accent) 0%, #7048e8 100%);
  color: #ffffff;
  box-shadow: 0 4px 24px rgba(76, 110, 245, 0.25);
}

html.theme-dark .nx-landing-hero {
  background: linear-gradient(135deg, rgba(76,110,245,0.25) 0%, rgba(112,72,232,0.20) 100%);
  box-shadow: 0 4px 24px rgba(0,0,0,0.3);
}

.nx-hero-content {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nx-hero-logo {
  height: 48px;
  width: auto;
  filter: brightness(0) invert(1);
  opacity: 0.9;
}

html.theme-dark .nx-hero-logo {
  filter: none;
  opacity: 0.85;
}

.nx-hero-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
}

.nx-hero-sub {
  margin: 0.15rem 0 0;
  font-size: 0.875rem;
  opacity: 0.85;
}

/* ── Landing tiles ────────────────────────────────────────────── */
.nx-tiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
}

.nx-tile-link {
  text-decoration: none !important;
  color: inherit !important;
  display: block;
  height: 100%;
}

.nx-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 1rem 0.75rem;
  height: 100%;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.nx-tile:hover {
  transform: translateY(-3px);
  box-shadow: var(--nx-shadow-md);
}

.nx-tile-icon-wrap {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.6rem;
  font-size: 1.2rem;
  transition: transform 0.2s ease;
}

.nx-tile:hover .nx-tile-icon-wrap {
  transform: scale(1.1);
}

.nx-tile-body { flex: 1; }

.nx-tile-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--nx-text);
  margin-bottom: 0.2rem;
}

.nx-tile-desc {
  font-size: 0.75rem;
  color: var(--nx-muted);
}

.nx-tile-arrow {
  margin-top: 0.75rem;
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  color: var(--nx-muted);
  font-size: 0.85rem;
}

.nx-tile:hover .nx-tile-arrow {
  opacity: 1;
  transform: translateX(0);
}

/* ── Tile color variants ──────────────────────────────────────── */
.nx-tile-blue .nx-tile-icon-wrap    { background: rgba(76,110,245,0.12); color: #4c6ef5; }
.nx-tile-violet .nx-tile-icon-wrap  { background: rgba(124,77,255,0.12); color: #7c4dff; }
.nx-tile-emerald .nx-tile-icon-wrap { background: rgba(16,185,129,0.12); color: #10b981; }
.nx-tile-amber .nx-tile-icon-wrap   { background: rgba(245,158,11,0.12); color: #f59e0b; }
.nx-tile-teal .nx-tile-icon-wrap    { background: rgba(20,184,166,0.12); color: #14b8a6; }
.nx-tile-pink .nx-tile-icon-wrap    { background: rgba(236,72,153,0.12); color: #ec4899; }
.nx-tile-orange .nx-tile-icon-wrap  { background: rgba(249,115,22,0.12); color: #f97316; }
.nx-tile-rose .nx-tile-icon-wrap    { background: rgba(244,63,94,0.12);  color: #f43f5e; }
.nx-tile-cyan .nx-tile-icon-wrap    { background: rgba(6,182,212,0.12);  color: #06b6d4; }
.nx-tile-indigo .nx-tile-icon-wrap  { background: rgba(99,102,241,0.12); color: #6366f1; }
.nx-tile-slate .nx-tile-icon-wrap   { background: rgba(100,116,139,0.12);color: #64748b; }
.nx-tile-gray .nx-tile-icon-wrap    { background: rgba(107,114,128,0.12);color: #6b7280; }

/* Dark mode: slightly brighter icon backgrounds */
html.theme-dark .nx-tile-blue .nx-tile-icon-wrap    { background: rgba(76,110,245,0.18); color: #748ffc; }
html.theme-dark .nx-tile-violet .nx-tile-icon-wrap  { background: rgba(124,77,255,0.18); color: #b388ff; }
html.theme-dark .nx-tile-emerald .nx-tile-icon-wrap { background: rgba(16,185,129,0.18); color: #34d399; }
html.theme-dark .nx-tile-amber .nx-tile-icon-wrap   { background: rgba(245,158,11,0.18); color: #fbbf24; }
html.theme-dark .nx-tile-teal .nx-tile-icon-wrap    { background: rgba(20,184,166,0.18); color: #2dd4bf; }
html.theme-dark .nx-tile-pink .nx-tile-icon-wrap    { background: rgba(236,72,153,0.18); color: #f472b6; }
html.theme-dark .nx-tile-orange .nx-tile-icon-wrap  { background: rgba(249,115,22,0.18); color: #fb923c; }
html.theme-dark .nx-tile-rose .nx-tile-icon-wrap    { background: rgba(244,63,94,0.18);  color: #fb7185; }
html.theme-dark .nx-tile-cyan .nx-tile-icon-wrap    { background: rgba(6,182,212,0.18);  color: #22d3ee; }
html.theme-dark .nx-tile-indigo .nx-tile-icon-wrap  { background: rgba(99,102,241,0.18); color: #818cf8; }
html.theme-dark .nx-tile-slate .nx-tile-icon-wrap   { background: rgba(100,116,139,0.18);color: #94a3b8; }
html.theme-dark .nx-tile-gray .nx-tile-icon-wrap    { background: rgba(107,114,128,0.18);color: #9ca3af; }

/* ── Tile customization UI ──────────────────────────────────── */
.nx-tile-wrapper {
  position: relative;
  min-width: 0;
}

.nx-tile-toggle {
  display: none;
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 5;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--nx-border);
  background: var(--nx-surface);
  color: var(--nx-accent);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  box-shadow: var(--nx-shadow-sm);
  transition: background 0.15s, color 0.15s;
}

.nx-tile-toggle:hover {
  background: var(--nx-accent);
  color: #fff;
}

/* Show toggles in edit mode */
.nx-editing .nx-tile-toggle {
  display: flex;
}

/* Dim hidden tiles in edit mode */
.nx-editing .nx-tile-hidden .nx-tile {
  opacity: 0.35;
}

.nx-editing .nx-tile-hidden .nx-tile-toggle {
  color: var(--nx-muted);
  border-color: var(--nx-border);
}

/* Pulsing border in edit mode */
.nx-editing .nx-tile-wrapper {
  border-radius: var(--nx-radius-lg);
  outline: 2px dashed var(--nx-border);
  outline-offset: 2px;
}

/* Disable pointer events on link in edit mode */
.nx-editing .nx-tile-link {
  pointer-events: none;
}

/* Small helpers */
.truncate {
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Dark-mode component corrections (Bootstrap defaults are too bright/dim) */
body.theme-dark .list-group-item {
  background: var(--nx-surface);
  border-color: var(--nx-border);
  color: var(--nx-text);
}

body.theme-dark .alert {
  background: var(--nx-surface-2);
  border-color: var(--nx-border-strong);
  color: var(--nx-text);
}

body.theme-dark .alert a {
  color: var(--nx-link);
}

body.theme-dark .btn-outline-secondary {
  color: var(--nx-text);
  border-color: var(--nx-border-strong);
}

body.theme-dark .btn-outline-secondary:hover {
  background: var(--nx-surface-2);
}

/* Scrollbars */
body { scrollbar-width: thin; scrollbar-color: rgba(76,110,245,0.35) transparent; }
html.theme-dark body,
body.theme-dark { scrollbar-color: rgba(92,124,250,0.30) #0f1117; }

html.theme-dark ::-webkit-scrollbar { width: 10px; height: 10px; }
html.theme-dark ::-webkit-scrollbar-track { background: #0f1117; }
html.theme-dark ::-webkit-scrollbar-thumb {
  background: rgba(92,124,250,0.30);
  border-radius: 10px;
  border: 2px solid #0f1117;
}
html.theme-dark ::-webkit-scrollbar-thumb:hover { background: rgba(92,124,250,0.50); }

/* ── Sticky Actions column ────────────────────────────────────
   Freezes the last column (Actions) in all horizontally-scrollable tables
   so it stays visible when the user scrolls right. */
.table-responsive td:last-child,
.table-responsive th:last-child,
.table-wrap td:last-child,
.table-wrap th:last-child {
  position: sticky;
  right: 0;
  z-index: 3;
  background: var(--nx-surface);
  /* Left-side shadow to visually separate from scrolled content */
  box-shadow: -4px 0 8px rgba(0, 0, 0, 0.04);
}

/* Header cells need higher z-index when both sticky-top and sticky-right */
.table-responsive thead th:last-child,
.table-wrap thead th:last-child {
  z-index: 5;
  background: var(--nx-surface-2);
}

/* Dark mode backgrounds */
html.theme-dark .table-responsive td:last-child,
html.theme-dark .table-responsive th:last-child,
html.theme-dark .table-wrap td:last-child,
html.theme-dark .table-wrap th:last-child,
body.theme-dark .table-responsive td:last-child,
body.theme-dark .table-responsive th:last-child,
body.theme-dark .table-wrap td:last-child,
body.theme-dark .table-wrap th:last-child {
  background: var(--nx-surface);
  box-shadow: -4px 0 8px rgba(0, 0, 0, 0.25);
}

html.theme-dark .table-responsive thead th:last-child,
html.theme-dark .table-wrap thead th:last-child,
body.theme-dark .table-responsive thead th:last-child,
body.theme-dark .table-wrap thead th:last-child {
  background: #1e2028;
}

/* Hover row: ensure sticky cell matches the hover bg */
.table-hover tbody tr:hover td:last-child {
  background: var(--nx-surface-2);
}

html.theme-dark .table-hover tbody tr:hover td:last-child,
body.theme-dark .table-hover tbody tr:hover td:last-child {
  background: #1e2028;
}

/* ── Sortable table headers ─────────────────────────────────── */
th[data-sortable] {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th[data-sortable]:hover {
  color: var(--nx-accent);
}

th[data-sortable]::after {
  content: ' ⇅';
  font-size: 0.7em;
  opacity: 0.35;
  margin-left: 2px;
}

th[data-sortable].sort-asc::after {
  content: ' ↑';
  opacity: 0.9;
  color: var(--nx-accent);
}

th[data-sortable].sort-desc::after {
  content: ' ↓';
  opacity: 0.9;
  color: var(--nx-accent);
}

/* Sort links in contacts/vendors (server-side) */
th a[href*="sort="] {
  color: inherit;
  text-decoration: none;
}

th a[href*="sort="]:hover {
  color: var(--nx-accent);
}
