/* ============================================================
   LBOS Design System — v1.0
   Brand: Navy #0B1F3A · Gold #C9A84C
   Style: Enterprise SaaS — clean, white, minimal shadows
   ============================================================ */

/* ============================================================
   1. CUSTOM PROPERTIES (DESIGN TOKENS)
   ============================================================ */
:root {
  /* Brand */
  --navy:           #0B1F3A;
  --navy-light:     #162f57;
  --navy-dark:      #071527;
  --gold:           #C9A84C;
  --gold-light:     #d9bb72;
  --gold-dark:      #a8872e;
  --gold-muted:     rgba(201, 168, 76, 0.12);

  /* Grays */
  --gray-50:        #f9fafb;
  --gray-100:       #f3f4f6;
  --gray-200:       #e5e7eb;
  --gray-300:       #d1d5db;
  --gray-400:       #9ca3af;
  --gray-500:       #6b7280;
  --gray-600:       #4b5563;
  --gray-700:       #374151;
  --gray-800:       #1f2937;
  --gray-900:       #111827;

  /* Semantic */
  --color-success:       #047857;
  --color-success-bg:    #d1fae5;
  --color-success-border:#a7f3d0;
  --color-danger:        #dc2626;
  --color-danger-bg:     #fee2e2;
  --color-danger-border: #fca5a5;
  --color-warning:       #d97706;
  --color-warning-bg:    #fef3c7;
  --color-warning-border:#fde68a;
  --color-info:          #2563eb;
  --color-info-bg:       #dbeafe;
  --color-info-border:   #bfdbfe;
  --color-orange:        #ea580c;
  --color-orange-bg:     #fff7ed;
  --color-orange-border: #fed7aa;

  /* Shadows */
  --shadow-xs:  0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:  0 4px 6px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg:  0 10px 20px rgba(0,0,0,0.08), 0 4px 8px rgba(0,0,0,0.04);
  --shadow-xl:  0 25px 50px rgba(0,0,0,0.12);

  /* Border radius */
  --radius-sm:  4px;
  --radius-md:  6px;
  --radius-lg:  8px;
  --radius-xl:  12px;
  --radius-2xl: 16px;
  --radius-full: 9999px;

  /* Spacing scale */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Typography */
  --font-ui:    'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-prose: Georgia, 'Times New Roman', serif;
  --font-mono:  'JetBrains Mono', 'Fira Code', Consolas, monospace;

  --text-xs:   0.6875rem;
  --text-sm:   0.8125rem;
  --text-base: 0.875rem;
  --text-md:   0.9375rem;
  --text-lg:   1.0625rem;
  --text-xl:   1.125rem;
  --text-2xl:  1.375rem;
  --text-3xl:  1.75rem;

  --leading-tight:  1.25;
  --leading-normal: 1.5;
  --leading-relaxed:1.75;

  /* Layout */
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --content-max-w: none;

  /* Transitions */
  --transition-fast:   0.1s ease;
  --transition-normal: 0.15s ease;
  --transition-slow:   0.25s ease;
}


/* ============================================================
   2. RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--gray-900);
  background: var(--gray-50);
}

a {
  color: var(--gold);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--gold-dark); text-decoration: underline; }

img, svg { display: block; max-width: 100%; }

h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: var(--leading-tight);
  color: var(--navy);
}
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-md); }
h6 { font-size: var(--text-base); }

p { margin-bottom: var(--space-4); }
p:last-child { margin-bottom: 0; }

ul, ol { padding-left: var(--space-6); }

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--gray-100);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
  color: var(--navy);
}


/* ============================================================
   3. IMPERSONATION BANNER
   ============================================================ */
.impersonation-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: var(--color-orange);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: 0.5rem var(--space-6);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: 0 2px 8px rgba(234, 88, 12, 0.35);
}

.impersonation-banner__icon {
  font-size: 1rem;
  flex-shrink: 0;
}

.impersonation-banner__text {
  flex: 1;
  text-align: center;
}

.impersonation-banner__exit {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: var(--radius-md);
  padding: 0.25rem 0.875rem;
  font-size: var(--text-xs);
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition-fast);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-family: var(--font-ui);
}
.impersonation-banner__exit:hover { background: rgba(255,255,255,0.3); }

/* Shift layout when impersonation banner is active.
   The is-impersonating class is on .layout (not body),
   so selectors must match that. Sidebar and topbar are fixed/sticky
   so they need explicit top offsets. */
.layout.is-impersonating .sidebar {
  top: 36px;
}
.layout.is-impersonating .topbar {
  top: 36px;
}
.layout.is-impersonating .main {
  padding-top: 36px;
}


/* ============================================================
   4. LAYOUT SHELL
   ============================================================ */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform var(--transition-slow);
}

.sidebar-logo {
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.sidebar-logo .wordmark {
  font-size: 1.375rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.03em;
  line-height: 1;
}
.sidebar-logo .wordmark span { color: var(--gold); }

.sidebar-logo .tagline {
  font-size: var(--text-xs);
  color: rgba(255, 255, 255, 0.6);
  margin-top: 0.3rem;
  letter-spacing: 0.01em;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: var(--radius-full); }

.nav-section-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.5);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.875rem 1.25rem 0.25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5625rem 1.25rem;
  font-size: var(--text-base);
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
  position: relative;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--gold);
  text-decoration: none;
}

.nav-item.active {
  color: var(--gold);
  border-left-color: var(--gold);
  background: var(--gold-muted);
}
.nav-item.active:hover { background: rgba(201, 168, 76, 0.16); }

.nav-icon {
  width: 18px;
  text-align: center;
  font-size: 1rem;
  flex-shrink: 0;
  opacity: 1;
  color: #fff;
  transition: color var(--transition-fast);
}
.nav-item:hover .nav-icon { color: var(--gold); }
.nav-item.active .nav-icon { color: var(--gold); opacity: 1; }

.nav-badge {
  margin-left: auto;
  background: var(--gold);
  color: var(--navy);
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-full);
  line-height: 1.4;
}

.sidebar-footer {
  flex-shrink: 0;
  padding: var(--space-4) 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.user-info {
  margin-bottom: var(--space-3);
}

.user-name {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: #fff;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-role {
  font-size: var(--text-xs);
  color: var(--gold);
  letter-spacing: 0.01em;
}

/* ---- MAIN AREA ---- */
.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- TOPBAR ---- */
.topbar {
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.75rem;
  position: sticky;
  top: 0;
  z-index: 50;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.topbar-title {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.01em;
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--gray-400);
}
.topbar-breadcrumb a { color: var(--gray-500); }
.topbar-breadcrumb a:hover { color: var(--navy); }
.topbar-breadcrumb .sep { color: var(--gray-300); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Hamburger for mobile */
.sidebar-toggle {
  display: none;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: var(--space-2);
  color: var(--gray-600);
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}
.sidebar-toggle:hover { background: var(--gray-100); }

/* ---- CONTENT ---- */
.content {
  padding: 1.75rem;
  flex: 1;
  max-width: var(--content-max-w);
  width: 100%;
}

.content-full {
  padding: 1.75rem;
  flex: 1;
}


/* ============================================================
   5. PAGE HEADER
   ============================================================ */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-6);
  gap: var(--space-4);
}

.page-header-left { flex: 1; min-width: 0; }

.page-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.page-subtitle {
  font-size: var(--text-base);
  color: var(--gray-500);
  margin-top: 0.25rem;
  font-weight: 400;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}


/* ============================================================
   6. BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.5rem 1.125rem;
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--transition-fast), color var(--transition-fast),
              border-color var(--transition-fast), box-shadow var(--transition-fast),
              opacity var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
  -webkit-user-select: none;
  user-select: none;
}
.btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.btn:disabled, .btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Sizes */
.btn-xs { padding: 0.25rem 0.625rem; font-size: var(--text-xs); border-radius: var(--radius-sm); }
.btn-sm { padding: 0.375rem 0.875rem; font-size: var(--text-sm); }
.btn-lg { padding: 0.6875rem 1.5rem; font-size: var(--text-md); }
.btn-xl { padding: 0.875rem 2rem;    font-size: var(--text-lg); border-radius: var(--radius-lg); }

/* Variants */
.btn-primary {
  background: var(--gold);
  color: var(--navy);
  border-color: var(--gold);
}
.btn-primary:hover {
  background: var(--gold-dark);
  border-color: var(--gold-dark);
  color: var(--navy);
  text-decoration: none;
  box-shadow: var(--shadow-sm);
}

.btn-secondary {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}
.btn-secondary:hover {
  background: var(--navy-light);
  border-color: var(--navy-light);
  color: #fff;
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  color: var(--gray-600);
  border-color: var(--gray-300);
}
.btn-ghost:hover {
  background: var(--gray-50);
  color: var(--gray-900);
  border-color: var(--gray-400);
  text-decoration: none;
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}
.btn-danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
  text-decoration: none;
}

.btn-danger-ghost {
  background: transparent;
  color: var(--color-danger);
  border-color: var(--color-danger-border);
}
.btn-danger-ghost:hover {
  background: var(--color-danger-bg);
  border-color: var(--color-danger);
  text-decoration: none;
}

.btn-success {
  background: var(--color-success);
  color: #fff;
  border-color: var(--color-success);
}
.btn-success:hover { background: #035f44; color: #fff; text-decoration: none; }

.btn-outline-navy {
  background: transparent;
  color: var(--navy);
  border-color: var(--navy);
}
.btn-outline-navy:hover { background: var(--navy); color: #fff; text-decoration: none; }

/* Icon-only button */
.btn-icon {
  padding: 0.5rem;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-md);
}
.btn-icon.btn-sm { width: 1.75rem; height: 1.75rem; padding: 0.3125rem; }

/* Full-width */
.btn-block { width: 100%; }

/* Loading state */
.btn-loading { position: relative; color: transparent; pointer-events: none; }
.btn-loading::after {
  content: '';
  position: absolute;
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}


/* ============================================================
   7. CARDS
   ============================================================ */
.card {
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  padding: var(--space-6);
  box-shadow: var(--shadow-xs);
}

.card-sm { padding: var(--space-4); }
.card-lg { padding: var(--space-8); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--gray-100);
}

.card-title {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.01em;
}
.card-subtitle {
  font-size: var(--text-sm);
  color: var(--gray-500);
  margin-top: 0.125rem;
}

.card-body { flex: 1; }

.card-footer {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Hover card */
.card-hover {
  transition: box-shadow var(--transition-normal), transform var(--transition-normal);
  cursor: pointer;
}
.card-hover:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}


/* ============================================================
   8. STAT CARDS
   ============================================================ */
.stat-card {
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  padding: 1.25rem 1.5rem 1.375rem;
  box-shadow: var(--shadow-xs);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--gray-200);
}

.stat-gold::before   { background: var(--gold); }
.stat-navy::before   { background: var(--navy); }
.stat-green::before  { background: var(--color-success); }
.stat-red::before    { background: var(--color-danger); }
.stat-blue::before   { background: var(--color-info); }
.stat-orange::before { background: var(--color-orange); }

.stat-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--navy);
  margin-top: 0.3rem;
  line-height: 1;
  letter-spacing: -0.02em;
}

.stat-meta {
  font-size: var(--text-xs);
  color: var(--gray-400);
  margin-top: var(--space-2);
}

.stat-change {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: var(--text-xs);
  font-weight: 600;
  margin-top: var(--space-1);
}
.stat-change.up   { color: var(--color-success); }
.stat-change.down { color: var(--color-danger); }

/* Stat grid helper */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.stats-grid-4 { grid-template-columns: repeat(4, 1fr); }
.stats-grid-3 { grid-template-columns: repeat(3, 1fr); }
.stats-grid-2 { grid-template-columns: repeat(2, 1fr); }


/* ============================================================
   9. BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.4;
  white-space: nowrap;
}

.badge-gold    { background: var(--color-warning-bg);  color: #92400e; }
.badge-green   { background: var(--color-success-bg);  color: var(--color-success); }
.badge-red     { background: var(--color-danger-bg);   color: var(--color-danger); }
.badge-gray    { background: var(--gray-100);          color: var(--gray-600); }
.badge-navy    { background: var(--navy);              color: #fff; }
.badge-blue    { background: var(--color-info-bg);     color: var(--color-info); }
.badge-orange  { background: var(--color-orange-bg);   color: var(--color-orange); }
.badge-purple  { background: #f3e8ff;                  color: #7c3aed; }
.badge-teal    { background: #ccfbf1;                  color: #0f766e; }

/* Role-specific badges */
.badge-role-client    { background: var(--color-info-bg);    color: var(--color-info); }
.badge-role-advisor   { background: var(--color-success-bg); color: var(--color-success); }
.badge-role-lwcg      { background: var(--navy);             color: var(--gold); }

/* Outline badges */
.badge-outline {
  background: transparent;
  border: 1px solid currentColor;
}

/* Dot indicator */
.badge-dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
  flex-shrink: 0;
}


/* ============================================================
   10. TABLES
   ============================================================ */
.table-wrap {
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-base);
}

.table th {
  text-align: left;
  padding: 0.6875rem 1rem;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  font-weight: 600;
  font-size: var(--text-xs);
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
}

/* Sortable column header */
.th-sortable {
  cursor: pointer;
  transition: color var(--transition-fast);
}
.th-sortable:hover { color: var(--navy); }
.th-sortable::after {
  content: ' ↕';
  opacity: 0.4;
  font-size: 0.7em;
}
.th-sort-asc::after  { content: ' ↑'; opacity: 1; color: var(--gold); }
.th-sort-desc::after { content: ' ↓'; opacity: 1; color: var(--gold); }

.table td {
  padding: 0.8125rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  vertical-align: middle;
}

.table tr:last-child td { border-bottom: none; }

.table tbody tr {
  transition: background var(--transition-fast);
}
.table tbody tr:hover td {
  background: var(--gray-50);
}

/* Table footer for pagination / summary */
.table-footer {
  padding: 0.75rem 1rem;
  background: var(--gray-50);
  border-top: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-sm);
  color: var(--gray-500);
}

/* Cell helpers */
.td-mono  { font-family: var(--font-mono); font-size: 0.8125rem; }
.td-right { text-align: right; }
.td-center { text-align: center; }
.td-truncate { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Empty state inside table */
.table-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--gray-400);
}
.table-empty-icon { font-size: 2.5rem; margin-bottom: var(--space-3); opacity: 0.5; }
.table-empty-msg  { font-size: var(--text-md); font-weight: 600; color: var(--gray-500); }
.table-empty-sub  { font-size: var(--text-sm); margin-top: var(--space-2); }


/* ============================================================
   11. FORMS
   ============================================================ */
.form-group {
  margin-bottom: 1.125rem;
}

.form-group:last-child { margin-bottom: 0; }

label, .label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 0.375rem;
  line-height: 1.4;
}

.label-optional {
  font-size: var(--text-xs);
  font-weight: 400;
  color: var(--gray-400);
  margin-left: 0.25rem;
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--gray-500);
  margin-top: 0.3rem;
}
.form-error {
  font-size: var(--text-xs);
  color: var(--color-danger);
  margin-top: 0.3rem;
  font-weight: 500;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="search"],
input[type="date"],
textarea,
select {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  color: var(--gray-900);
  background: #fff;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  line-height: 1.5;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.15);
}

input::placeholder,
textarea::placeholder {
  color: var(--gray-400);
}

input:disabled,
textarea:disabled,
select:disabled {
  background: var(--gray-50);
  color: var(--gray-400);
  cursor: not-allowed;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
}

textarea { resize: vertical; min-height: 100px; }

/* Input with prefix/suffix icon */
.input-group {
  position: relative;
}
.input-prefix,
.input-suffix {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  font-size: var(--text-base);
  pointer-events: none;
}
.input-prefix { left: 0.75rem; }
.input-suffix { right: 0.75rem; }
.input-group input[type="text"],
.input-group input[type="email"],
.input-group input[type="search"] {
  padding-left: 2.25rem;
}
.input-group.has-suffix input { padding-right: 2.25rem; }

/* Error state */
.input-error {
  border-color: var(--color-danger) !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1) !important;
}

/* Checkbox and radio */
input[type="checkbox"],
input[type="radio"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--gold);
  cursor: pointer;
}

.form-check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
}
.form-check input { flex-shrink: 0; }
.form-check label { margin-bottom: 0; cursor: pointer; }

/* Inline form */
.form-inline {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.form-inline .form-group { margin-bottom: 0; flex: 1; }

/* Search bar */
.search-bar {
  position: relative;
  max-width: 320px;
}
.search-bar input {
  padding-left: 2.25rem;
  padding-right: var(--space-4);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  height: 36px;
}
.search-bar__icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  font-size: 0.875rem;
  pointer-events: none;
}


/* ============================================================
   12. ALERTS / NOTIFICATIONS
   ============================================================ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: 0.875rem 1rem;
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  border: 1px solid transparent;
  margin-bottom: var(--space-4);
}

.alert-icon { flex-shrink: 0; font-size: 1rem; margin-top: 0.1rem; }
.alert-body { flex: 1; }
.alert-title { font-weight: 700; margin-bottom: 0.2rem; font-size: var(--text-base); }
.alert-close {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  opacity: 0.6;
  font-size: 1rem;
  padding: 0;
  flex-shrink: 0;
}
.alert-close:hover { opacity: 1; }

.alert-error   { background: var(--color-danger-bg);  color: var(--color-danger);  border-color: var(--color-danger-border); }
.alert-success { background: var(--color-success-bg); color: var(--color-success); border-color: var(--color-success-border); }
.alert-warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: var(--color-warning-border); }
.alert-info    { background: var(--color-info-bg);    color: var(--color-info);    border-color: var(--color-info-border); }


/* ============================================================
   13. MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 31, 58, 0.5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: var(--space-4);
}

.modal-box {
  background: #fff;
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  padding: 2rem;
  box-shadow: var(--shadow-xl);
  position: relative;
  animation: modal-in 0.18s ease;
}

.modal-box-lg { max-width: 720px; }
.modal-box-sm { max-width: 360px; }

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.modal-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.02em;
}
.modal-subtitle { font-size: var(--text-sm); color: var(--gray-500); margin-top: 0.2rem; }

.modal-close {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--gray-400);
  font-size: 1.25rem;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background var(--transition-fast);
  flex-shrink: 0;
  margin-left: var(--space-3);
}
.modal-close:hover { color: var(--gray-700); background: var(--gray-100); }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--gray-100);
}


/* ============================================================
   14. TABS
   ============================================================ */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--gray-200);
  margin-bottom: var(--space-6);
  gap: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.625rem 1.125rem;
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--gray-500);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--transition-fast), border-color var(--transition-fast);
  text-decoration: none;
}
.tab-item:hover { color: var(--navy); text-decoration: none; }
.tab-item.active {
  color: var(--navy);
  border-bottom-color: var(--gold);
  font-weight: 700;
}

.tab-count {
  background: var(--gray-100);
  color: var(--gray-500);
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-full);
}
.tab-item.active .tab-count {
  background: var(--gold-muted);
  color: var(--gold-dark);
}


/* ============================================================
   15. AVATAR
   ============================================================ */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 700;
  letter-spacing: -0.02em;
  flex-shrink: 0;
  text-transform: uppercase;
}

.avatar-xs { width: 1.5rem;  height: 1.5rem;  font-size: 0.5rem; }
.avatar-sm { width: 2rem;    height: 2rem;    font-size: 0.6875rem; }
.avatar-md { width: 2.5rem;  height: 2.5rem;  font-size: 0.875rem; }
.avatar-lg { width: 3rem;    height: 3rem;    font-size: 1.125rem; }
.avatar-xl { width: 4rem;    height: 4rem;    font-size: 1.5rem; }

/* Color variants for initials */
.avatar-navy   { background: var(--navy);  color: var(--gold); }
.avatar-gold   { background: var(--gold);  color: var(--navy); }
.avatar-blue   { background: #dbeafe;      color: #1e40af; }
.avatar-green  { background: #d1fae5;      color: #065f46; }
.avatar-purple { background: #ede9fe;      color: #6d28d9; }
.avatar-red    { background: #fee2e2;      color: #991b1b; }
.avatar-teal   { background: #ccfbf1;      color: #115e59; }
.avatar-orange { background: #ffedd5;      color: #9a3412; }


/* ============================================================
   16. DROPDOWN / ACTION MENU
   ============================================================ */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 160px;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  overflow: hidden;
  animation: dropdown-in 0.12s ease;
}

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.5625rem 1rem;
  font-size: var(--text-base);
  color: var(--gray-700);
  cursor: pointer;
  transition: background var(--transition-fast);
  text-decoration: none;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-ui);
}

.dropdown-item:hover { background: var(--gray-50); color: var(--navy); text-decoration: none; }
.dropdown-item.danger { color: var(--color-danger); }
.dropdown-item.danger:hover { background: var(--color-danger-bg); }

.dropdown-divider {
  height: 1px;
  background: var(--gray-100);
  margin: var(--space-1) 0;
}

.dropdown-header {
  padding: 0.375rem 1rem;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}


/* ============================================================
   17. EMPTY STATE
   ============================================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4rem 2rem;
  color: var(--gray-400);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: var(--space-4);
  opacity: 0.4;
}

.empty-state-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--gray-600);
  margin-bottom: var(--space-2);
}

.empty-state-description {
  font-size: var(--text-base);
  max-width: 380px;
  margin-bottom: var(--space-6);
  line-height: var(--leading-relaxed);
}


/* ============================================================
   18. PAGINATION
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.5rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition-fast), border-color var(--transition-fast);
  background: #fff;
}
.page-link:hover { background: var(--gray-50); border-color: var(--gray-300); text-decoration: none; }
.page-link.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.page-link:disabled { opacity: 0.4; cursor: not-allowed; }


/* ============================================================
   19. UTILITY CLASSES
   ============================================================ */

/* Flex helpers */
.flex      { display: flex; }
.flex-col  { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.items-start  { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.justify-end     { justify-content: flex-end; }
.flex-1    { flex: 1; }
.gap-1     { gap: var(--space-1); }
.gap-2     { gap: var(--space-2); }
.gap-3     { gap: var(--space-3); }
.gap-4     { gap: var(--space-4); }
.gap-6     { gap: var(--space-6); }
.flex-wrap { flex-wrap: wrap; }

/* Grid helpers */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }

/* Spacing */
.mt-1  { margin-top: var(--space-1); }
.mt-2  { margin-top: var(--space-2); }
.mt-3  { margin-top: var(--space-3); }
.mt-4  { margin-top: var(--space-4); }
.mt-6  { margin-top: var(--space-6); }
.mt-8  { margin-top: var(--space-8); }
.mb-1  { margin-bottom: var(--space-1); }
.mb-2  { margin-bottom: var(--space-2); }
.mb-3  { margin-bottom: var(--space-3); }
.mb-4  { margin-bottom: var(--space-4); }
.mb-6  { margin-bottom: var(--space-6); }
.mb-8  { margin-bottom: var(--space-8); }
.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }

/* Text */
.text-xs  { font-size: var(--text-xs); }
.text-sm  { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg  { font-size: var(--text-lg); }
.text-xl  { font-size: var(--text-xl); }
.text-navy   { color: var(--navy); }
.text-gold   { color: var(--gold); }
.text-muted  { color: var(--gray-400); }
.text-light  { color: var(--gray-500); }
.text-dark   { color: var(--gray-700); }
.text-danger { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.font-mono   { font-family: var(--font-mono); }
.font-bold   { font-weight: 700; }
.font-semibold { font-weight: 600; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Misc */
.divider {
  height: 1px;
  background: var(--gray-200);
  margin: var(--space-4) 0;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border-width: 0; }

/* Dot separator */
.dot-sep::before {
  content: '·';
  margin: 0 var(--space-2);
  color: var(--gray-300);
}


/* ============================================================
   20. HTMX HELPERS
   ============================================================ */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-request.htmx-indicator { display: inline-block; }

@keyframes spin {
  to { transform: rotate(360deg); }
}
.spinner {
  display: inline-block;
  width: 1rem; height: 1rem;
  border: 2px solid var(--gray-200);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.spinner-sm { width: 0.75rem; height: 0.75rem; }
.spinner-lg { width: 1.5rem; height: 1.5rem; }


/* ============================================================
   21. DRAG AND DROP KANBAN
   ============================================================ */
.kanban-board {
  display: flex;
  gap: var(--space-4);
  overflow-x: auto;
  align-items: flex-start;
  padding-bottom: var(--space-4);
}

.kanban-column {
  flex-shrink: 0;
  width: 280px;
  background: var(--gray-100);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
}

.kanban-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
  padding: var(--space-1) var(--space-1);
}

.kanban-column-title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.kanban-count {
  background: var(--gray-300);
  color: var(--gray-600);
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
}

.kanban-card {
  background: #fff;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
  cursor: grab;
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--transition-fast);
}
.kanban-card:hover { box-shadow: var(--shadow-sm); }
.kanban-card.dragging { opacity: 0.5; cursor: grabbing; }


/* ============================================================
   22. RESPONSIVE — SIDEBAR MOBILE COLLAPSE
   ============================================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 31, 58, 0.5);
  z-index: 99;
  backdrop-filter: blur(1px);
}

@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-overlay.is-open {
    display: block;
  }

  .main {
    margin-left: 0;
  }

  .sidebar-toggle {
    display: flex;
  }

  .stats-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  /* Sidebar is hidden off-canvas — hamburger (sidebar-toggle) reveals it */
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.is-open {
    transform: translateX(0);
  }

  .main {
    margin-left: 0 !important;
    padding: 0 !important;
  }

  .sidebar-toggle {
    display: flex;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr !important;
  }
  .stats-grid-4 {
    grid-template-columns: 1fr 1fr !important;
  }

  /* Kanban/engagement board columns stack vertically */
  .board {
    flex-direction: column !important;
  }
  .board-col {
    flex: none !important;
    width: 100% !important;
  }

  table {
    font-size: 0.8125rem;
  }

  .topbar {
    padding: 0.75rem 1rem !important;
  }
}

@media (max-width: 640px) {
  .content, .content-full { padding: var(--space-4); }
  .topbar { padding: 0 var(--space-4); }

  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header-actions { width: 100%; }

  .stats-grid-4 { grid-template-columns: 1fr; }
  .stats-grid-3 { grid-template-columns: 1fr; }
  .stats-grid-2 { grid-template-columns: 1fr; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

  .modal-box { padding: 1.25rem; }
  .kanban-board { flex-direction: column; }
  .kanban-column { width: 100%; }

  .table th, .table td { padding: 0.625rem 0.625rem; }
}

/* ============================================================
   DARK MODE
   Toggle via html[data-theme="dark"]. Stored in localStorage.
   ============================================================ */
html[data-theme="dark"] {
  /* Neutrals - invert the gray scale */
  --gray-50:  #0d1117;
  --gray-100: #161b22;
  --gray-200: #21262d;
  --gray-300: #30363d;
  --gray-400: #a0aab4;
  --gray-500: #b8c4ce;
  --gray-600: #d0d8e0;
  --gray-700: #dde2e8;
  --gray-800: #eaecef;
  --gray-900: #f0f6fc;

  /* Success/danger/warning - muted for dark */
  --color-success:        #3fb950;
  --color-success-bg:     #0d2817;
  --color-success-border: #1a4a2b;
  --color-danger:         #f85149;
  --color-danger-bg:      #2d0f0e;
  --color-danger-border:  #6e1a18;
  --color-warning:        #e3b341;
  --color-warning-bg:     #2d1f02;
  --color-warning-border: #5e4202;
  --color-info:           #58a6ff;
  --color-info-bg:        #051d4d;
  --color-info-border:    #0d419d;
  --color-orange:         #f0883e;
  --color-orange-bg:      #2d1500;
}

html[data-theme="dark"] body {
  background: var(--gray-50);
  color: var(--gray-900);
}

/* Cards */
html[data-theme="dark"] .card,
html[data-theme="dark"] .stat-card {
  background: var(--gray-100);
  border-color: var(--gray-200);
}

/* Topbar */
html[data-theme="dark"] .rf-topbar {
  background: var(--gray-100);
  border-bottom-color: var(--gray-200);
}

/* Main content area */
html[data-theme="dark"] .rf-main {
  background: var(--gray-50);
}

html[data-theme="dark"] .rf-shell {
  background: var(--gray-50);
}

/* Form inputs */
html[data-theme="dark"] input[type="text"],
html[data-theme="dark"] input[type="email"],
html[data-theme="dark"] input[type="number"],
html[data-theme="dark"] input[type="password"],
html[data-theme="dark"] input[type="search"],
html[data-theme="dark"] textarea,
html[data-theme="dark"] select {
  background: var(--gray-200);
  border-color: var(--gray-300);
  color: var(--gray-900);
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: var(--gray-400);
}

/* Tables */
html[data-theme="dark"] table {
  color: var(--gray-900);
}

html[data-theme="dark"] th {
  background: var(--gray-200);
  border-bottom-color: var(--gray-300);
  color: var(--gray-600);
}

html[data-theme="dark"] td {
  border-bottom-color: var(--gray-200);
}

html[data-theme="dark"] tr:hover td {
  background: var(--gray-200);
}

/* Headings */
html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] h4,
html[data-theme="dark"] h5,
html[data-theme="dark"] h6 {
  color: var(--gray-900);
}

/* Page header */
html[data-theme="dark"] .page-title {
  color: var(--gray-900);
}

html[data-theme="dark"] .page-subtitle {
  color: var(--gray-500);
}

/* Badges */
html[data-theme="dark"] .badge {
  filter: brightness(0.85);
}

/* Topbar search */
html[data-theme="dark"] .rf-search {
  background: var(--gray-200);
  border-color: var(--gray-300);
  color: var(--gray-500);
}

/* Dropdowns / menus */
html[data-theme="dark"] .dropdown-menu,
html[data-theme="dark"] [style*="background:#fff"],
html[data-theme="dark"] [style*="background: #fff"] {
  background: var(--gray-100) !important;
  border-color: var(--gray-200) !important;
}

/* Help bubble panel */
html[data-theme="dark"] #help-panel {
  background: var(--gray-100) !important;
}

html[data-theme="dark"] .help-msg--ai .help-msg__body {
  background: var(--gray-200) !important;
  color: var(--gray-900) !important;
}

html[data-theme="dark"] #help-input {
  background: var(--gray-200) !important;
  border-color: var(--gray-300) !important;
  color: var(--gray-900) !important;
}

/* Stat cards */
html[data-theme="dark"] .stat-label {
  color: var(--gray-500);
}

html[data-theme="dark"] .stat-value {
  color: var(--gray-900);
}

/* Dividers / borders */
html[data-theme="dark"] hr,
html[data-theme="dark"] .divider {
  border-color: var(--gray-200);
}

/* Buttons in dark mode — reset browser default white background */
html[data-theme="dark"] .btn {
  background: transparent;
  color: var(--gray-700);
}

html[data-theme="dark"] .btn-primary {
  background: var(--gold);
  color: #0B1F3A;
  border-color: var(--gold);
}

html[data-theme="dark"] .btn-secondary {
  background: #1e3a5c;
  color: var(--gray-900);
  border-color: #2a4f7a;
}

html[data-theme="dark"] .btn-ghost,
html[data-theme="dark"] .btn-outline {
  background: transparent;
  border-color: var(--gray-300);
  color: var(--gray-700);
}

html[data-theme="dark"] .btn-ghost:hover,
html[data-theme="dark"] .btn-outline:hover {
  background: var(--gray-200);
  color: var(--gray-900);
}

/* Chat messages */
html[data-theme="dark"] #messages {
  background: var(--gray-100) !important;
}

html[data-theme="dark"] .chat-msg .msg-bubble {
  background: var(--gray-200);
  color: var(--gray-900);
}

/* ---- Step 1: redefine --navy and --gold in dark mode ---- */
html[data-theme="dark"] {
  --navy:      #ffffff;
  --navy-dark: #b8d4ea;
  --gold:      #f0b429;
  --gold-dark: #d4981f;
}

/* ---- Step 2: inline style="color:var(--navy)" ---- */
html[data-theme="dark"] [style*="color:var(--navy)"],
html[data-theme="dark"] [style*="color: var(--navy)"] {
  color: var(--navy) !important;
}

/* ---- Step 4: inline background:var(--navy) inside content cards ---- */
html[data-theme="dark"] [style*="background:var(--navy)"],
html[data-theme="dark"] [style*="background: var(--navy)"] {
  background: #1a3a5c !important;
  color: #e8f0f8 !important;
}

/* ---- Step 6: hardcoded near-black text colors ---- */
html[data-theme="dark"] [style*="color:#374151"],
html[data-theme="dark"] [style*="color: #374151"],
html[data-theme="dark"] [style*="color:#1f2937"],
html[data-theme="dark"] [style*="color: #1f2937"],
html[data-theme="dark"] [style*="color:#111827"],
html[data-theme="dark"] [style*="color: #111827"],
html[data-theme="dark"] [style*="color:#0f172a"],
html[data-theme="dark"] [style*="color: #0f172a"] {
  color: var(--gray-800) !important;
}

/* ---- Step 7: hardcoded mid-gray text colors ---- */
html[data-theme="dark"] [style*="color:#6b7280"],
html[data-theme="dark"] [style*="color: #6b7280"],
html[data-theme="dark"] [style*="color:#9ca3af"],
html[data-theme="dark"] [style*="color: #9ca3af"] {
  color: var(--gray-500) !important;
}

/* ---- Step 8: hardcoded white / light-gray backgrounds ---- */
html[data-theme="dark"] [style*="background:#ffffff"],
html[data-theme="dark"] [style*="background: #ffffff"],
html[data-theme="dark"] [style*="background:white"],
html[data-theme="dark"] [style*="background: white"],
html[data-theme="dark"] [style*="background:#f9fafb"],
html[data-theme="dark"] [style*="background: #f9fafb"],
html[data-theme="dark"] [style*="background:#f3f4f6"],
html[data-theme="dark"] [style*="background: #f3f4f6"] {
  background: var(--gray-100) !important;
}

/* ---- Step 9: hardcoded light border colors ---- */
html[data-theme="dark"] [style*="border:1px solid #e5e7eb"],
html[data-theme="dark"] [style*="border: 1px solid #e5e7eb"],
html[data-theme="dark"] [style*="border-color:#e5e7eb"],
html[data-theme="dark"] [style*="border-bottom:1px solid var(--gray-100)"],
html[data-theme="dark"] [style*="border-bottom: 1px solid var(--gray-100)"] {
  border-color: var(--gray-300) !important;
}

/* ---- Step 12: date and time inputs ---- */
html[data-theme="dark"] input[type="date"],
html[data-theme="dark"] input[type="time"] {
  background: var(--gray-200);
  border-color: var(--gray-300);
  color: var(--gray-900);
}

/* ---- Step 13: label text color ---- */
html[data-theme="dark"] label,
html[data-theme="dark"] .form-group label {
  color: var(--gray-700);
}

/* ---- Step 14: card base text ---- */
html[data-theme="dark"] .card {
  color: var(--gray-800);
}

/* ---- Inline signal badge backgrounds — flip to dark equivalents ---- */
html[data-theme="dark"] [style*="background:#fee2e2"][style*="color:#dc2626"] {
  background: #3d1414 !important;
  color: #f87171 !important;
}
html[data-theme="dark"] [style*="background:#fef3c7"][style*="color:#d97706"] {
  background: #3d2c00 !important;
  color: #fbbf24 !important;
}
html[data-theme="dark"] [style*="background:#eff6ff"][style*="color:#1d4ed8"] {
  background: #0c1f4a !important;
  color: #60a5fa !important;
}
html[data-theme="dark"] [style*="background:#d1fae5"][style*="color:#065f46"] {
  background: #0d2e1f !important;
  color: #34d399 !important;
}
/* Alert boxes */
html[data-theme="dark"] [style*="background:#fee2e2"] {
  background: #3d1414 !important;
  color: #f87171 !important;
  border-color: #6e2424 !important;
}
html[data-theme="dark"] [style*="background:#fef3c7"] {
  background: #3d2c00 !important;
  color: #fbbf24 !important;
  border-color: #5e4202 !important;
}
html[data-theme="dark"] [style*="background:#d1fae5"] {
  background: #0d2e1f !important;
  color: #34d399 !important;
  border-color: #1a4a2b !important;
}
html[data-theme="dark"] [style*="background:#dbeafe"] {
  background: #0c1f4a !important;
  color: #60a5fa !important;
  border-color: #1e3a7a !important;
}

/* Sidebar stays dark (already dark navy) but tweak for dark mode */
html[data-theme="dark"] .rf-sidebar {
  background: linear-gradient(180deg, #07152a 0%, #0B1F3A 100%);
}

/* Modals */
html[data-theme="dark"] [style*="background:#fff"] {
  background: var(--gray-100) !important;
}

/* Empty states */
html[data-theme="dark"] .empty-state-title {
  color: var(--gray-900);
}

html[data-theme="dark"] .empty-state-description,
html[data-theme="dark"] .empty-state-body {
  color: var(--gray-500);
}

/* Dashboard home stat cards  */
html[data-theme="dark"] [style*="background:var(--gray-50)"],
html[data-theme="dark"] [style*="background: var(--gray-50)"] {
  background: var(--gray-200) !important;
}

/* Scrollbars */
html[data-theme="dark"] ::-webkit-scrollbar-track {
  background: var(--gray-100);
}
html[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: var(--gray-300);
}

/* ============================================================
   HARDCODED DARK MODE TEXT OVERRIDES
   Bypass CSS variable resolution entirely — these use #hex
   values so they work regardless of variable cascade issues.
   ============================================================ */

/* CSS classes that set color: var(--navy) */
html[data-theme="dark"] .card-title,
html[data-theme="dark"] .page-title,
html[data-theme="dark"] .stat-value,
html[data-theme="dark"] .rf-topbar-title {
  color: #ffffff !important;
}

/* Inline style="...color:var(--navy)..." on any element */
html[data-theme="dark"] [style*="color:var(--navy)"],
html[data-theme="dark"] [style*="color: var(--navy)"] {
  color: #ffffff !important;
}

/* Navy backgrounds used for badge circles, pills, filled buttons */
html[data-theme="dark"] [style*="background:var(--navy)"],
html[data-theme="dark"] [style*="background: var(--navy)"],
html[data-theme="dark"] .badge-navy,
html[data-theme="dark"] .btn-secondary {
  background: #1e3a5c !important;
  color: #ffffff !important;
}

/* .card-header border uses var(--gray-100) which is fine, but reinforce title */
html[data-theme="dark"] .card-header {
  border-bottom-color: #21262d;
}

/* th and td text that use var(--navy) via inline */
html[data-theme="dark"] th[style*="color:var(--navy)"],
html[data-theme="dark"] td[style*="color:var(--navy)"],
html[data-theme="dark"] th[style*="color: var(--navy)"],
html[data-theme="dark"] td[style*="color: var(--navy)"] {
  color: #ffffff !important;
}

/* Link text using var(--navy) */
html[data-theme="dark"] a[style*="color:var(--navy)"],
html[data-theme="dark"] a[style*="color: var(--navy)"] {
  color: #5ba8f5 !important;
}

/* .help-msg uses var(--navy) for AI body and user label */
html[data-theme="dark"] .help-msg--ai .help-msg__body {
  background: #21262d !important;
  color: #ffffff !important;
}
html[data-theme="dark"] .help-msg--user .help-msg__label {
  color: #5ba8f5 !important;
}
html[data-theme="dark"] .help-msg--user .help-msg__body {
  background: #1e3a5c !important;
  color: #ffffff !important;
}

/* PII tokenization notice ("Sensitive identifiers were protected before sending"):
   small muted line under an AI answer (Help fragment, assistant panel, coach). */
.help-msg__notice,
.pii-notice {
  display: block;
  margin-top: .375rem;
  font-size: .75rem;
  line-height: 1.4;
  color: var(--gray-500);
}
html[data-theme="dark"] .help-msg__notice,
html[data-theme="dark"] .pii-notice {
  color: var(--gray-400) !important;
}

/* btn-outline-navy */
html[data-theme="dark"] .btn-outline-navy {
  color: #ffffff !important;
  border-color: #4a7aac !important;
  background: transparent !important;
}

/* ============================================================
   TOPBAR v2  (.tb-*)
   Three-zone header: left (burger + breadcrumb),
   center (search), right (actions + dropdowns).
   Namespaced to avoid collision with legacy .rf-topbar rules.
   Uses existing brand CSS custom properties from :root above.
   ============================================================ */

/* Shell */
.tb {
  display: flex;
  align-items: center;
  height: var(--topbar-height, 56px);
  padding: 0 1rem;
  gap: 0.75rem;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 200;
  flex-shrink: 0;
}

/* Zones */
.tb-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  min-width: 0;
}

.tb-center {
  flex: 1 1 0;
  min-width: 0;
  max-width: 560px;
  margin: 0 auto;
}

.tb-right {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 0;
  margin-left: auto;
}

/* Burger button */
.tb-burger {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  color: var(--gray-400);
  display: flex;
  align-items: center;
  border-radius: 6px;
  transition: color var(--transition-fast);
  flex-shrink: 0;
}
.tb-burger:hover { color: var(--navy); }

/* Breadcrumb */
.tb-crumb {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  color: var(--gray-500);
  white-space: nowrap;
  overflow: hidden;
}
.tb-crumb a {
  color: var(--gray-500);
  text-decoration: none;
  font-weight: 500;
}
.tb-crumb a:hover { color: var(--navy); }
.tb-crumb .sep {
  color: var(--gray-300);
  font-size: 0.75rem;
}
.tb-crumb b {
  color: var(--navy);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Role switcher - dual-role (client + advisor) topbar control, .tb-left zone */
.role-switcher {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  margin-left: 0.5rem;
  padding-left: 0.5rem;
  border-left: 1px solid var(--gray-200);
  gap: 0.125rem;
}
.role-switcher-opt {
  font-size: 0.6875rem;
  font-weight: 600;
  font-family: var(--font-ui);
  line-height: 1;
  white-space: nowrap;
  padding: 0.3125rem 0.5rem;
  border-radius: 999px;
  color: var(--gray-500);
  text-decoration: none;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}
.role-switcher-opt:hover:not(.is-active) { color: var(--navy); background: var(--gray-100); }
.role-switcher-opt.is-active {
  background: var(--navy);
  color: #fff;
  cursor: default;
}

/* Search */
.tb-search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--gray-50);
  border: 1.5px solid var(--gray-200);
  border-radius: 10px;
  padding: 0.3rem 0.3rem 0.3rem 0.75rem;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.tb-search:focus-within {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201,168,76,0.15);
}
.tb-search svg { flex-shrink: 0; color: var(--gray-400); }
.tb-search input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 0.875rem;
  font-family: var(--font-ui);
  color: var(--navy);
  min-width: 0;
}
.tb-search input::placeholder { color: var(--gray-400); }

/* Kbd chips */
.tb-kbd {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  flex-shrink: 0;
}
.tb-kbd kbd {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--gray-400);
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  padding: 0.1rem 0.3rem;
  font-family: var(--font-ui);
  line-height: 1.4;
}

/* Generic action button */
.tb-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  border-radius: 8px;
  border: 1.5px solid var(--gray-200);
  background: #fff;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--navy);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s;
  font-family: var(--font-ui);
}
.tb-btn:hover { border-color: var(--gold); }
.tb-btn.open { border-color: var(--gold); background: #fffbf0; }

/* Ask AI variant */
.tb-btn-ai {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--gold);
}
.tb-btn-ai:hover { background: var(--navy-light); border-color: var(--navy-light); }
.tb-btn-ai.open { background: var(--navy-light); border-color: var(--navy-light); }

/* Icon-only button */
.tb-iconbtn {
  background: none;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--gray-500);
  transition: border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}
.tb-iconbtn:hover { border-color: var(--gold); color: var(--gold); }

/* Vertical divider */
.tb-divider {
  width: 1px;
  height: 20px;
  background: var(--gray-200);
  flex-shrink: 0;
}

/* Start Session button */
.tb-start {
  background: transparent;
  border: 1.5px solid var(--navy);
  color: var(--navy);
  font-weight: 700;
  font-size: 0.8125rem;
}
.tb-start:hover { background: var(--navy); color: #fff; }

/* Invite Client button */
.tb-invite {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--navy);
  font-weight: 700;
}
.tb-invite:hover { background: var(--gold-dark); border-color: var(--gold-dark); }

/* Dropdown popover */
.tb-pop {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 9200;
  min-width: 300px;
  max-width: 380px;
  background: #fff;
  border: 1.5px solid var(--gray-200);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(11,31,58,0.14);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.tb-pop-head {
  padding: 0.875rem 1rem 0.625rem;
  border-bottom: 1px solid var(--gray-100);
  flex-shrink: 0;
}
.tb-pop-title {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--navy);
}
.tb-pop-sub {
  font-size: 0.75rem;
  color: var(--gray-400);
  margin-top: 0.125rem;
}
.tb-pop-body {
  overflow-y: auto;
  max-height: 480px;
  padding: 0.5rem 0;
}

/* Ask AI textarea */
.tb-ai-input {
  width: 100%;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-family: var(--font-ui);
  color: var(--navy);
  resize: none;
  outline: none;
  line-height: 1.5;
  background: var(--gray-50);
  transition: border-color 0.15s;
  box-sizing: border-box;
}
.tb-ai-input:focus { border-color: var(--gold); background: #fff; }

/* Ask AI send button */
.tb-ai-send {
  margin-top: 0.5rem;
  width: 100%;
  padding: 0.5rem;
  background: var(--navy);
  color: var(--gold);
  border: none;
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font-ui);
  transition: background 0.15s;
}
.tb-ai-send:hover { background: var(--navy-light); }
.tb-ai-send:disabled { opacity: 0.55; cursor: not-allowed; }

/* Suggested prompts label */
.tb-suglabel {
  font-size: 0.6375rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--gray-400);
  padding: 0.5rem 1rem 0.25rem;
}

/* Dropdown list item */
.tb-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 1rem;
  border: none;
  background: none;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--gray-700);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-ui);
  text-decoration: none;
  transition: background 0.1s;
}
.tb-item:hover { background: var(--gray-50); color: var(--navy); }
.tb-item.active { background: #f0f4ff; color: var(--navy); font-weight: 700; }

.tb-item-ico {
  flex-shrink: 0;
  color: var(--gray-400);
  display: flex;
  align-items: center;
}
.tb-item-t {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tb-item-s {
  flex-shrink: 0;
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--gold);
  min-width: 1.125rem;
  text-align: right;
}
.tb-item-go {
  flex-shrink: 0;
  color: var(--gray-300);
}

/* Playbook menu item (aliased) */
.tb-menu-item { /* same as .tb-item */ }

/* Alpine x-cloak */
[x-cloak] { display: none !important; }

/* Answer area inside the AI pop */
#tb-ai-answer {
  font-size: 0.875rem;
  line-height: 1.65;
  color: var(--navy);
  white-space: pre-line;
  font-family: Georgia, 'Times New Roman', serif;
  padding: 0.75rem 0 0;
  min-height: 2.5rem;
}

/* Responsive */
@media (max-width: 1024px) {
  .tb-center { max-width: 100%; }
  .tb-crumb b { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (max-width: 768px) {
  .tb-center { display: none; }
  .tb-right .tb-btn span:not(.tb-btn-icon) { display: none; }
  .tb-kbd { display: none !important; }
}

@media (max-width: 480px) {
  .tb { padding: 0 0.625rem; gap: 0.5rem; }
  .tb-right { gap: 0.25rem; }

  /* Narrow phones: the right zone keeps its natural size (every control stays), the left zone
     gives way. Without this .tb-left (flex-shrink:0, nowrap crumb) pushed .tb-right off the edge. */
  .tb-left { flex: 1 1 auto; gap: 0.25rem; }
  .tb-crumb { flex: 1 1 auto; min-width: 0; }
  .tb-crumb a { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .tb-crumb .sep { flex: 0 0 auto; }
  .tb-crumb b { flex: 1 1 0; min-width: 0; max-width: none; }
  /* Back keeps its arrow (aria-label="Back" carries the name); only the word is dropped */
  #tb-back-btn { flex: 0 0 auto; padding-left: 0.5rem; padding-right: 0.5rem; }
  #tb-back-btn .tb-back-label { display: none; }
  .tb-right .tb-btn { padding-left: 0.5rem; padding-right: 0.5rem; }
  /* The dual-role switcher is ~200px wide; advisors keep the "Dashboard" link in the sidebar footer */
  .tb-left .role-switcher { display: none; }
  /* Dropdowns span the viewport instead of hanging 340px off a button near the middle of the bar */
  .tb-pop {
    position: fixed;
    top: calc(var(--topbar-height, 56px) + 6px);
    left: 0.625rem;
    right: 0.625rem;
    width: auto !important;
    min-width: 0;
    max-width: none;
    max-height: calc(100vh - var(--topbar-height, 56px) - 1.5rem);
    overflow-y: auto;
  }
}

/* Dark mode overrides for .tb */
html[data-theme="dark"] .tb {
  /* Literal, not var(--navy-dark): dark mode redefines --navy-dark as a LIGHT blue (#98bedd in base.html), which left white crumb text on a pale bar. */
  background: #071527;
  border-bottom-color: rgba(255,255,255,0.08);
}
html[data-theme="dark"] .tb-crumb a,
html[data-theme="dark"] .tb-crumb { color: rgba(255,255,255,0.5); }
html[data-theme="dark"] .tb-crumb b { color: #fff; }
html[data-theme="dark"] .role-switcher { border-left-color: rgba(255,255,255,0.12); }
html[data-theme="dark"] .role-switcher-opt { color: rgba(255,255,255,0.5); }
html[data-theme="dark"] .role-switcher-opt:hover:not(.is-active) { color: #fff; background: rgba(255,255,255,0.08); }
html[data-theme="dark"] .role-switcher-opt.is-active { background: #fff; color: #0B1F3A; }
html[data-theme="dark"] .tb-search {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.12);
}
html[data-theme="dark"] .tb-search input { color: #fff; }
html[data-theme="dark"] .tb-btn {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.12);
  color: #fff;
}
html[data-theme="dark"] .tb-iconbtn {
  border-color: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.6);
}
html[data-theme="dark"] .tb-pop {
  background: #162f57;
  border-color: rgba(255,255,255,0.1);
}
html[data-theme="dark"] .tb-pop-title { color: #fff; }
html[data-theme="dark"] .tb-item { color: rgba(255,255,255,0.75); }
html[data-theme="dark"] .tb-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
html[data-theme="dark"] .tb-divider { background: rgba(255,255,255,0.1); }

/* ============================================================
   SIDEBAR TOGGLE CHEVRON
   Points left (<) when sidebar is open; rotates to point right
   (>) when .sidebar-collapsed is on .rf-shell (desktop collapse).
   On mobile the sidebar uses is-open class, so the chevron
   direction is inverted via the sibling combinator.
   ============================================================ */
.tb-sidebar-chevron {
  transition: transform 0.2s ease;
}
.sidebar-collapsed .tb-sidebar-chevron {
  transform: rotate(180deg);
}

/* ============================================================
   DARK MODE CONTRAST FIXES
   Items #11-#16 from QA pass.
   ============================================================ */

/* #11 - Generic .btn (transparent base) needs legible text in dark mode.
   The base rule sets color:var(--gray-700) which maps to #dde2e8 in dark -
   that is fine, but any un-typed .btn on a dark card surface can appear
   washed out. Reinforce to a fully readable light value. */
html[data-theme="dark"] .btn {
  color: var(--gray-800);
}

/* #12 - Chat option/suggestion buttons: tb-item inside tb-pop already has
   color:rgba(255,255,255,0.75) above, which is readable.  The standalone
   channel-list links use inline style="color:var(--navy)" which the Step-2
   rule above already lifts to #fff.  The empty-state and send-form area use
   hardcoded near-white - covered by Step 6/8 rules.  Additionally ensure
   the chat send-form input textarea is readable. */
html[data-theme="dark"] #chat-input {
  background: var(--gray-200) !important;
  border-color: var(--gray-300) !important;
  color: var(--gray-900) !important;
}

/* #13 - Agent panel description card: background is hardcoded #f8f6f0
   (a warm off-white) which reads as near-black in dark mode. Lift it. */
html[data-theme="dark"] [style*="background:#f8f6f0"] {
  background: var(--gray-200) !important;
}

/* Agent heading "Financial Agent" uses style color:var(--navy) - already
   covered by Step-2 rule above (lifted to #fff).  Reinforce via class
   match in case the inline var resolution is off. */
html[data-theme="dark"] .agent-panel [style*="color:var(--navy)"] {
  color: #ffffff !important;
}

/* #14 - Agent pill (inactive) label: uses color:var(--gray-600) which in
   dark maps to #d0d8e0 - already readable.  Active pill is navy bg + white
   text - fine.  Inactive pill has background:#fff which goes dark via
   Step-8 rule, leaving the gray-600 text (#d0d8e0) on gray-100 bg - ok.
   Ensure inactive pills have enough contrast by pinning to gray-800. */
html[data-theme="dark"] .agent-pill {
  background: var(--gray-200);
  border-color: var(--gray-300);
  color: var(--gray-800);
}
html[data-theme="dark"] .agent-pill:hover {
  border-color: var(--gold);
  color: var(--gray-900);
}
html[data-theme="dark"] .agent-pill--active {
  background: #1e3a5c;
  border-color: #3a6090;
  color: #ffffff;
}

/* #15 - Focus Commitments filter tabs: .tab-item uses color:var(--gray-500)
   which in dark mode maps to #b8c4ce - visible but the active state uses
   color:var(--navy) which Step-2 lifts to #fff. The inactive "All" tab
   therefore needs its own dark-mode colour to meet contrast. */
html[data-theme="dark"] .tab-item {
  color: var(--gray-600);
}
html[data-theme="dark"] .tab-item:hover {
  color: var(--gray-900);
}
html[data-theme="dark"] .tab-item.active {
  color: var(--gray-900);
  border-bottom-color: var(--gold);
}

/* #16 - Legacy Blueprint field helper/placeholder text:
   style="color:var(--gray-300)" is used for the italic placeholder text
   ("What principles guide every decision?", etc.). In dark mode --gray-300
   resolves to #30363d which is near-black on a dark card - invisible.
   Lift those dim placeholders to a mid-light value. */
html[data-theme="dark"] [style*="color:var(--gray-300)"],
html[data-theme="dark"] [style*="color: var(--gray-300)"] {
  color: var(--gray-500) !important;
}

/* ============================================================
   ADVISOR QA - DARK MODE FIXES (#4, #5, #6, #7, #8)
   ============================================================ */

/* #4 - Sidebar user-menu: Settings / Account / Sign out links
   The sidebar stays dark-navy in both themes; the 50% white opacity
   is too dim. Lift to 85% so text is clearly readable. */
html[data-theme="dark"] .rf-sidebar a[href*="settings"],
html[data-theme="dark"] .rf-sidebar a[href*="account"],
html[data-theme="dark"] .rf-sidebar button[type="submit"] {
  color: rgba(255, 255, 255, 0.85) !important;
  border-color: rgba(255, 255, 255, 0.28) !important;
}
html[data-theme="dark"] .rf-sidebar a[href*="settings"]:hover,
html[data-theme="dark"] .rf-sidebar a[href*="account"]:hover,
html[data-theme="dark"] .rf-sidebar button[type="submit"]:hover {
  color: #ffffff !important;
  background: rgba(255, 255, 255, 0.1) !important;
}

/* #5 - Members table: .table-wrap has background:#fff from CSS (not inline),
   so it is not caught by the [style*="background:#fff"] blanket rule.
   Give the wrap, rows, footer, and selected/hover states dark-mode colors. */
html[data-theme="dark"] .table-wrap {
  background: var(--gray-100);
  border-color: var(--gray-200);
}
html[data-theme="dark"] .table tbody tr td {
  background: var(--gray-100);
  color: var(--gray-800);
  border-bottom-color: var(--gray-200);
}
html[data-theme="dark"] .table tbody tr:hover td {
  background: var(--gray-200) !important;
  color: var(--gray-900);
}
html[data-theme="dark"] .table-footer {
  background: var(--gray-200);
  border-top-color: var(--gray-300);
  color: var(--gray-600);
}
html[data-theme="dark"] .table-empty {
  background: var(--gray-100);
  color: var(--gray-500);
}

/* #6 - Members filter tabs active text contrast.
   In dark mode --navy is redefined to #fff, so .tab-item.active uses
   color:var(--navy) = white - correct. But the inherited gray-900 text
   from the previous fix (#15) can conflict. Ensure active tab is gold-
   underlined AND white text, inactive tabs are mid-gray readable. */
html[data-theme="dark"] .tab-item {
  color: var(--gray-500);  /* #b8c4ce - readable mid-tone */
}
html[data-theme="dark"] .tab-item:hover {
  color: var(--gray-800);
  text-decoration: none;
}
html[data-theme="dark"] .tab-item.active {
  color: var(--gray-900);       /* #f0f6fc - near-white, high contrast */
  border-bottom-color: var(--gold);
  font-weight: 700;
}
html[data-theme="dark"] .tab-item.active .tab-count {
  background: rgba(240, 180, 41, 0.18);
  color: var(--gold);
}

/* #7 - Programs filter tabs: same classes, covered by the rules above. */

/* #8 - Engagement Board: .btn-ghost "View" text and "No engagements here"
   empty text inside board columns. The board columns use background:var(--gray-100)
   which maps to #161b22 in dark mode - already dark. The btn-ghost rule
   (defined earlier) gives color:var(--gray-700) = #dde2e8 - readable.
   Reinforce here in case specificity is overridden by the board inline style. */
html[data-theme="dark"] .board-col .btn-ghost {
  color: var(--gray-700);
  border-color: var(--gray-300);
}
html[data-theme="dark"] .board-col .btn-ghost:hover {
  background: var(--gray-200);
  color: var(--gray-900);
}
/* "No engagements here" uses color:var(--gray-300) inline - already lifted
   by rule #16 above. Reinforce for the board italic empty text specifically. */
html[data-theme="dark"] .board-col [style*="color:var(--gray-300)"] {
  color: var(--gray-500) !important;
}


/* ============================================================
   ROADMAP TRACKER (client_portal/roadmap.html + _roadmap_rail.html)
   Tokens only (--gray-*, --gold, --color-*). Never --navy for text.
   Accent stays on --gold so advisor-firm branding (.rf override) applies.
   Text is never colour-only: every state has a glyph and a text label in the markup.
   Base = vertical stack (600px and below); horizontal rail from 601px.
   ============================================================ */
.roadmap-page { display: flex; flex-direction: column; gap: var(--space-5); min-width: 0; }
.roadmap-lens { margin: 0.375rem 0 0; font-size: var(--text-sm); font-weight: 600; color: var(--gray-600); }
.roadmap-heading { margin: 0; font-size: var(--text-xl); font-weight: 700; color: var(--gray-900); letter-spacing: -0.01em; }

/* Rail */
.roadmap-rail { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); }
.roadmap-stage.card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-4);
  border-top-width: 4px;
}
.roadmap-stage__head { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.roadmap-stage__num {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 2px solid var(--gray-400);
  border-radius: var(--radius-full);
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--gray-900);
}
.roadmap-stage__name { min-width: 0; overflow-wrap: anywhere; font-size: var(--text-md); font-weight: 700; color: var(--gray-900); line-height: 1.3; }
.roadmap-stage__state { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); font-weight: 600; color: var(--gray-700); }
.roadmap-stage__glyph { display: inline-block; min-width: 1em; text-align: center; color: var(--gray-500); }
.roadmap-stage__art { display: flex; justify-content: center; margin: var(--space-1) 0; }
.roadmap-stage__art img { display: block; max-width: 100%; height: auto; border-radius: var(--radius-md); }
.roadmap-stage__summary { margin: 0; font-size: var(--text-sm); color: var(--gray-600); line-height: 1.5; }

/* State colours (3-class selectors so they beat the dark-mode .card border-color rule) */
.roadmap-rail .roadmap-stage.roadmap-stage--done { border-top-color: var(--color-success); }
.roadmap-rail .roadmap-stage--done .roadmap-stage__num { border-color: var(--color-success); }
.roadmap-rail .roadmap-stage--done .roadmap-stage__glyph { color: var(--color-success); }
.roadmap-rail .roadmap-stage.roadmap-stage--current { border-top-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.roadmap-rail .roadmap-stage--current .roadmap-stage__num { border-color: var(--gold); background: var(--gold-muted); }
.roadmap-rail .roadmap-stage--current .roadmap-stage__glyph { color: var(--gold); }
.roadmap-rail .roadmap-stage.roadmap-stage--next { border-top-color: var(--color-info); }
.roadmap-rail .roadmap-stage--next .roadmap-stage__num { border-color: var(--color-info); }
.roadmap-rail .roadmap-stage--next .roadmap-stage__glyph { color: var(--color-info); }
.roadmap-rail .roadmap-stage.roadmap-stage--prospective { border-top-color: var(--gold); border-top-style: dashed; }
.roadmap-rail .roadmap-stage--prospective .roadmap-stage__num { border-color: var(--gold); border-style: dashed; }
.roadmap-rail .roadmap-stage--prospective .roadmap-stage__glyph { color: var(--gold); }
.roadmap-rail .roadmap-stage.roadmap-stage--later,
.roadmap-rail .roadmap-stage.roadmap-stage--unplaced { border-top-color: var(--gray-300); }

/* Placeholder art: inline SVG, themed by currentColor and variables */
.roadmap-art-ph { display: block; width: 100%; max-width: 160px; height: auto; color: var(--gray-400); }
.roadmap-art-ph__bg { fill: var(--gray-50); stroke: var(--gray-200); stroke-width: 1; }
.roadmap-art-ph__path,
.roadmap-art-ph__ring { stroke: currentColor; }
.roadmap-art-ph__num { fill: currentColor; }
.roadmap-stage--done .roadmap-art-ph { color: var(--color-success); }
.roadmap-stage--current .roadmap-art-ph,
.roadmap-stage--prospective .roadmap-art-ph { color: var(--gold); }
.roadmap-stage--next .roadmap-art-ph { color: var(--color-info); }

/* Focus bullets: native details, keyboard operable */
.roadmap-stage__focus { margin-top: auto; border-top: 1px solid var(--gray-100); }
.roadmap-stage__focus > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-height: 44px;
  cursor: pointer;
  list-style: none;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--gray-800);
}
.roadmap-stage__focus > summary::-webkit-details-marker { display: none; }
.roadmap-stage__focus > summary::after { content: "+"; font-size: var(--text-lg); font-weight: 700; color: var(--gray-500); }
.roadmap-stage__focus[open] > summary::after { content: "-"; }
/* Two-tone ring (dark outer, gold inner): gold alone is ~2:1 on white in light mode */
.roadmap-stage__focus > summary:focus-visible { outline: 2px solid var(--gray-900); outline-offset: 2px; box-shadow: 0 0 0 2px var(--gold); border-radius: var(--radius-sm); }
.roadmap-stage__focus ul { margin: 0 0 var(--space-3); padding-left: 1.1rem; font-size: var(--text-sm); color: var(--gray-700); line-height: 1.5; }
.roadmap-stage__focus li + li { margin-top: var(--space-1); }

/* Horizontal rail from 601px; scrolls sideways rather than cramming on narrow tablets */
@media (min-width: 601px) {
  .roadmap-rail {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: minmax(10.5rem, 1fr);
    align-items: stretch;
    overflow-x: auto;
    padding: 4px;
  }
}

/* Panel */
.roadmap-panel { padding: var(--space-5); }
.roadmap-panel__title { margin: 0 0 var(--space-2); font-size: var(--text-lg); font-weight: 700; color: var(--gray-900); }
.roadmap-next { margin: 0 0 var(--space-2); font-size: var(--text-md); font-weight: 600; color: var(--gray-800); }
.roadmap-message { margin: 0; font-size: var(--text-base); color: var(--gray-700); line-height: 1.5; }
.roadmap-caption { margin: var(--space-3) 0 0; font-size: var(--text-sm); color: var(--gray-500); }

/* Quiet status line: plain text plus a glyph. Deliberately NOT pill-shaped (no border, fill, radius or hover) so it never reads as a button. */
.roadmap-status {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--gray-800);
  cursor: default;
  overflow-wrap: anywhere;
}
.roadmap-status__glyph { flex: 0 0 auto; min-width: 1em; text-align: center; font-weight: 800; color: var(--gray-500); }
.roadmap-status--met .roadmap-status__glyph { color: var(--color-success); }
.roadmap-status--on_track .roadmap-status__glyph { color: var(--color-info); }
.roadmap-status--stalled .roadmap-status__glyph { color: var(--color-warning); }

.roadmap-reqs { list-style: none; margin: var(--space-4) 0 0; padding: 0; display: grid; gap: var(--space-4); }
.roadmap-req__top { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.roadmap-req__glyph { min-width: 1em; text-align: center; font-weight: 800; color: var(--gray-500); }
.roadmap-req--met .roadmap-req__glyph { color: var(--color-success); }
.roadmap-req__label { font-size: var(--text-base); font-weight: 600; color: var(--gray-900); }
.roadmap-req__state { margin-left: auto; font-size: var(--text-sm); font-weight: 600; color: var(--gray-600); }
.roadmap-req__detail { margin-top: var(--space-1); padding-left: 1.5rem; font-size: var(--text-sm); color: var(--gray-700); }
.roadmap-bar { height: 0.5rem; margin: var(--space-2) 0 0 1.5rem; border-radius: var(--radius-full); background: var(--gray-200); overflow: hidden; }
.roadmap-bar__fill { display: block; height: 100%; border-radius: var(--radius-full); background: var(--gold); }
@media (prefers-reduced-motion: no-preference) {
  .roadmap-bar__fill { transition: width 0.4s ease; }
}

/* Owner actions */
.roadmap-actions { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--space-3); margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--gray-100); }
.roadmap-touch { min-height: 44px; }
.roadmap-numbers > summary { list-style: none; }
.roadmap-numbers > summary::-webkit-details-marker { display: none; }
.roadmap-numbers[open] { flex: 1 1 100%; }
.roadmap-numbers__body { margin-top: var(--space-3); }
.roadmap-numbers__hint { margin: 0 0 var(--space-3); font-size: var(--text-sm); color: var(--gray-600); line-height: 1.5; }
.roadmap-numbers__grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); }
.roadmap-numbers__grid label { display: block; margin-bottom: 0.2rem; font-size: var(--text-sm); font-weight: 600; color: var(--gray-600); }
.roadmap-numbers__grid input { min-height: 44px; }
.roadmap-numbers__foot { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-top: var(--space-3); }
.roadmap-numbers__note { font-size: var(--text-sm); color: var(--gray-500); }
@media (min-width: 601px) {
  .roadmap-numbers__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* "See your full roadmap" link on My Board */
.roadmap-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--gray-800);
  text-decoration: underline;
  text-decoration-color: var(--gold);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}
.roadmap-link:hover { color: var(--gray-900); }
.roadmap-link:focus-visible { outline: 2px solid var(--gray-900); outline-offset: 2px; box-shadow: 0 0 0 2px var(--gold); border-radius: var(--radius-sm); }


/* ============================================================
   DATA ROOM (templates/dataroom/*, static/js/dataroom_ui.js, static/js/dataroom_upload.js)
   Tokens only (--gray-*, --gold, --color-*). Never --navy for text (it does not invert in dark mode).
   Works in light and dark. 44px touch targets. State is always a word, never colour only.
   Base = stacked cards (600px and below, built for 360px); table layout from 601px.
   ============================================================ */
.dr { display: flex; flex-direction: column; gap: var(--space-5); min-width: 0; }
.dr [hidden] { display: none !important; }
.dr .page-header { margin-bottom: 0; }
.dr .page-title { color: var(--gray-900); }
.dr .page-subtitle { color: var(--gray-600); }
.dr-note { margin: 0.375rem 0 0; font-size: var(--text-sm); font-weight: 600; color: var(--gray-700); }
.dr-note--block { margin: 0; }
.dr-hint { margin: 0; font-size: var(--text-sm); color: var(--gray-600); line-height: 1.5; }
.dr-touch { min-height: 44px; }
.dr-section-title { margin: 0 0 var(--space-3); font-size: var(--text-lg); font-weight: 700; color: var(--gray-900); letter-spacing: -0.01em; }
.dr-upload .dr-section-title, .dr-group__head .dr-section-title, .dr-empty .dr-section-title { margin: 0; }
.dr label.btn { margin-bottom: 0; }
.dr-sub-title { margin: var(--space-5) 0 var(--space-3); font-size: var(--text-md); font-weight: 700; color: var(--gray-900); }

/* Two-tone focus ring (dark outer, gold inner): gold alone is too faint on white */
.dr a:focus-visible,
.dr button:focus-visible,
.dr summary:focus-visible,
.dr select:focus-visible,
.dr input:focus-visible,
.dr .dr-file-input:focus-visible + .btn {
  outline: 2px solid var(--gray-900);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--gold);
}
.dr-link {
  color: var(--gray-800);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: var(--gold);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}
.dr-link:hover { color: var(--gray-900); }

/* Quota and progress meters (a native progress element plus visible text beside it) */
.dr-quota { display: grid; gap: var(--space-2); padding: var(--space-4) var(--space-5); }
.dr-quota__text { margin: 0; font-size: var(--text-base); color: var(--gray-800); }
.dr-quota__pct { color: var(--gray-600); }
.dr-quota__warn { margin: 0; font-size: var(--text-sm); font-weight: 700; color: var(--gray-900); }
.dr-quota--near .dr-quota__warn { color: var(--color-warning); }
.dr-quota--full .dr-quota__warn { color: var(--color-danger); }
.dr-meter {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 0.625rem;
  border: 0;
  border-radius: var(--radius-full);
  background: var(--gray-200);
  overflow: hidden;
}
.dr-meter::-webkit-progress-bar { background: var(--gray-200); border-radius: var(--radius-full); }
.dr-meter::-webkit-progress-value { background: var(--gold); border-radius: var(--radius-full); }
.dr-meter::-moz-progress-bar { background: var(--gold); border-radius: var(--radius-full); }
.dr-quota--near .dr-meter::-webkit-progress-value { background: var(--color-warning); }
.dr-quota--near .dr-meter::-moz-progress-bar { background: var(--color-warning); }
.dr-quota--full .dr-meter::-webkit-progress-value { background: var(--color-danger); }
.dr-quota--full .dr-meter::-moz-progress-bar { background: var(--color-danger); }

/* Tabs */
.dr-tabs { display: flex; flex-wrap: wrap; gap: var(--space-1); border-bottom: 1px solid var(--gray-200); }
.dr-tab {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-bottom: -1px;
  padding: 0 var(--space-4);
  border-bottom: 3px solid transparent;
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--gray-700);
  text-decoration: none;
}
.dr-tab:hover { color: var(--gray-900); text-decoration: none; background: var(--gray-100); }
.dr-tab.is-active { color: var(--gray-900); font-weight: 700; border-bottom-color: var(--gold); }

/* Breadcrumbs */
.dr-crumbs ol { display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--space-2); margin: 0; padding: 0; list-style: none; font-size: var(--text-sm); }
.dr-crumbs li { display: inline-flex; align-items: center; min-height: 44px; min-width: 0; }
.dr-crumbs li + li::before { content: "/"; margin-right: var(--space-2); color: var(--gray-500); }
.dr-crumbs [aria-current] { font-weight: 700; color: var(--gray-900); overflow-wrap: anywhere; }

/* Toolbar and small pop-over forms (native details) */
.dr-toolbar { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--space-3); }
.dr-pop { position: relative; }
.dr-pop > summary { list-style: none; cursor: pointer; }
.dr-pop > summary::-webkit-details-marker { display: none; }
.dr-pop__body {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  display: grid;
  gap: var(--space-2);
  width: min(20rem, calc(100vw - 2.5rem));
  padding: var(--space-4);
  background: var(--gray-50);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.dr input[type="text"], .dr select { min-height: 44px; }

/* Upload panel */
.dr-upload { display: grid; gap: var(--space-3); padding: var(--space-4) var(--space-5); }
.dr-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-4);
  border: 2px dashed var(--gray-400);
  border-radius: var(--radius-lg);
  text-align: center;
}
.dr-dropzone.is-dragover { border-color: var(--gold); background: var(--gold-muted); }
.dr-dropzone__text { margin: 0; font-size: var(--text-base); color: var(--gray-700); }
.dr-uploads { display: grid; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
.dr-uploads:empty { display: none; }
.dr-up { display: grid; gap: var(--space-2); padding: var(--space-3); border: 1px solid var(--gray-200); border-radius: var(--radius-md); min-width: 0; }
.dr-up__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-1) var(--space-3); }
.dr-up__name { flex: 1 1 10rem; min-width: 0; font-weight: 600; color: var(--gray-900); overflow-wrap: anywhere; }
.dr-up__status { font-size: var(--text-sm); font-weight: 600; color: var(--gray-700); overflow-wrap: anywhere; }
.dr-up__bar { height: 0.5rem; border-radius: var(--radius-full); background: var(--gray-200); overflow: hidden; }
.dr-up__fill { display: block; width: 0; height: 100%; border-radius: var(--radius-full); background: var(--gold); }
.dr-up[data-state="done"] .dr-up__fill { background: var(--color-success); }
.dr-up[data-state="error"] .dr-up__fill { background: var(--color-danger); }
.dr-up[data-state="error"] .dr-up__status { color: var(--color-danger); }
.dr-up__row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); }
.dr-up__pct { font-size: var(--text-sm); font-weight: 600; color: var(--gray-700); }
.dr-up__actions { display: inline-flex; flex-wrap: wrap; gap: var(--space-2); }
.dr-upload__foot { display: flex; }
@media (prefers-reduced-motion: no-preference) {
  .dr-up__fill { transition: width 0.2s ease; }
}

/* Folder rows */
.dr-folders { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
.dr-folder.card { display: flex; align-items: center; gap: var(--space-2); min-width: 0; padding: var(--space-2) var(--space-3); }
.dr-folder__link { display: flex; flex: 1 1 auto; align-items: center; gap: var(--space-3); min-width: 0; min-height: 44px; color: var(--gray-900); text-decoration: none; }
.dr-folder__link:hover { text-decoration: none; }
.dr-folder__link:hover .dr-folder__name { text-decoration: underline; text-decoration-color: var(--gold); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.dr-folder__glyph { flex: 0 0 auto; color: var(--gray-600); }
.dr-folder__text { display: flex; flex-direction: column; min-width: 0; }
.dr-folder__name { font-weight: 700; color: var(--gray-900); overflow-wrap: anywhere; }
.dr-folder__meta { font-size: var(--text-sm); color: var(--gray-600); }

/* Row action menus (native details) */
.dr-menu { position: relative; display: inline-block; }
.dr-menu > summary { list-style: none; cursor: pointer; }
.dr-menu > summary::-webkit-details-marker { display: none; }
.dr-menu__panel {
  position: absolute;
  z-index: 40;
  top: calc(100% + 4px);
  right: 0;
  display: grid;
  gap: 2px;
  min-width: 14rem;
  max-width: calc(100vw - 2rem);
  padding: var(--space-2);
  background: var(--gray-50);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.dr-menu__panel form { margin: 0; }
.dr-menu__item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  font-family: var(--font-ui);
  font-size: var(--text-base);
  font-weight: 600;
  text-align: left;
  color: var(--gray-800);
  cursor: pointer;
  list-style: none;
}
.dr-menu__item::-webkit-details-marker { display: none; }
.dr-menu__item:hover { background: var(--gray-100); }
.dr-menu__item--danger { color: var(--color-danger); }
.dr-sub[open] > summary { background: var(--gray-100); }
.dr-inline-form { display: grid; gap: var(--space-2); padding: var(--space-2) var(--space-3) var(--space-3); }
.dr-inline-form label { font-size: var(--text-sm); }
.dr-confirm { margin: 0; font-size: var(--text-sm); color: var(--gray-800); line-height: 1.5; }
/* The global dark .btn rule blanks .btn-danger; restore it for the confirm button (dark text on the lighter dark-mode red) */
html[data-theme="dark"] .dr .btn-danger { background: var(--color-danger); border-color: var(--color-danger); color: var(--gray-50); }

/* Files table: stacked cards by default, a real table from 601px */
.dr-card.card { padding: 0; }
.dr-table { width: 100%; border-collapse: collapse; }
.dr-table thead { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.dr-table, .dr-table tbody, .dr-table tr, .dr-table td { display: block; }
.dr-table tr { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--gray-200); }
.dr-table tr:last-child { border-bottom: 0; }
.dr .dr-table tr:hover td { background: transparent; }
.dr-table td { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); padding: var(--space-1) 0; border: 0; min-width: 0; color: var(--gray-800); }
.dr-table td::before { content: attr(data-label); flex: 0 0 6.5rem; font-size: var(--text-sm); font-weight: 600; color: var(--gray-600); }
.dr-table td.dr-cell-name { display: block; padding-top: 0; }
.dr-table td.dr-cell-name::before { content: none; }
.dr-table td.dr-cell-actions { display: flex; justify-content: flex-end; padding-top: var(--space-2); }
.dr-table td.dr-cell-actions::before { content: none; }
.dr-table td[data-label] > * { text-align: right; min-width: 0; overflow-wrap: anywhere; }
.dr-name { font-weight: 600; color: var(--gray-900); overflow-wrap: anywhere; }
.dr-actions-row { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); }
.dr-actions-row form { margin: 0; }
.dr-ready { font-size: var(--text-sm); color: var(--gray-700); }

@media (min-width: 601px) {
  .dr-folders { grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); }
  .dr-table { display: table; }
  .dr-table thead { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; }
  .dr-table tbody { display: table-row-group; }
  .dr-table tr { display: table-row; padding: 0; border-bottom: 0; }
  .dr-table td, .dr-table td.dr-cell-name, .dr-table td.dr-cell-actions { display: table-cell; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
  .dr-table td::before { content: none; }
  .dr-table td[data-label] > * { text-align: left; }
  .dr .dr-table tr:hover td { background: var(--gray-100); }
  .dr-table td.dr-cell-actions { text-align: right; white-space: nowrap; }
  .dr-actions-row { justify-content: flex-end; flex-wrap: nowrap; }
}

/* Empty states and checklist cards */
.dr-empty.card { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); padding: var(--space-8) var(--space-4); text-align: center; }
.dr-empty__text { margin: 0; max-width: 34rem; font-size: var(--text-base); color: var(--gray-700); line-height: 1.6; }
.dr-empty__text--left { max-width: none; text-align: left; }
.dr-first-folder { display: grid; gap: var(--space-2); width: 100%; max-width: 28rem; text-align: left; }
.dr-first-folder__row { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.dr-first-folder__row input { flex: 1 1 12rem; min-width: 0; }
.dr-tcards { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); width: 100%; margin: 0; padding: 0; list-style: none; text-align: left; }
.dr-tcard.card { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; padding: var(--space-4); }
.dr-tcard__title { margin: 0; font-size: var(--text-md); font-weight: 700; color: var(--gray-900); overflow-wrap: anywhere; }
.dr-tcard__desc { margin: 0 0 auto; font-size: var(--text-sm); color: var(--gray-700); line-height: 1.5; }
.dr-tcard form { margin: 0; }
@media (min-width: 601px) {
  .dr-tcards { grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }
}

/* Checklist page */
.dr-group.card { display: grid; gap: var(--space-3); padding: var(--space-5); }
.dr-group__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-1) var(--space-3); }
.dr-group__count { margin: 0; font-size: var(--text-base); color: var(--gray-800); }
.dr-checklist-folder__name { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-3); margin: var(--space-2) 0 0; font-size: var(--text-md); font-weight: 700; color: var(--gray-900); }
.dr-checklist-folder__meta { font-weight: 400; }
.dr-items { margin: var(--space-1) 0 0; padding: 0; list-style: none; }
.dr-item { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); padding: var(--space-3) 0; border-top: 1px solid var(--gray-100); }
.dr-item__label { flex: 1 1 14rem; min-width: 0; font-size: var(--text-base); color: var(--gray-900); overflow-wrap: anywhere; }
.dr-item__state { flex: 0 0 auto; min-width: 7rem; font-size: var(--text-sm); font-weight: 600; color: var(--gray-700); }
.dr-item__glyph { display: inline-block; min-width: 1em; text-align: center; color: var(--gray-600); }
.dr-status-form { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: 0; }
.dr-status-form select { width: auto; max-width: 100%; }

/* Pager */
.dr-pager { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-top: var(--space-3); }
.dr-pager__count { font-size: var(--text-sm); font-weight: 600; color: var(--gray-700); }
.dr-pager__gap { min-width: 1px; }

/* Plain state cards (unavailable, action error) */
.dr-state-card.card { display: flex; flex-direction: column; align-items: center; gap: var(--space-4); max-width: 32rem; width: 100%; margin: var(--space-8) auto; padding: var(--space-8) var(--space-6); text-align: center; }
.dr-state-card__icon { display: flex; align-items: center; justify-content: center; width: 64px; height: 64px; border-radius: var(--radius-full); background: var(--gray-100); color: var(--gray-700); }
.dr-state-card__title { margin: 0; font-family: var(--font-prose); font-size: var(--text-2xl); font-weight: 700; color: var(--gray-900); overflow-wrap: anywhere; }
.dr-state-card__text { margin: 0; font-family: var(--font-prose); font-size: var(--text-md); line-height: 1.7; color: var(--gray-700); overflow-wrap: anywhere; }
.dr-state-card .alert { width: 100%; margin: 0; text-align: left; }

/* Narrow phones: never allow sideways scroll */
@media (max-width: 400px) {
  .dr-quota, .dr-upload { padding: var(--space-3); }
  .dr-group.card { padding: var(--space-3); }
  .dr-table td::before { flex-basis: 5.5rem; }
  .dr-state-card.card { padding: var(--space-6) var(--space-4); }
  .dr-menu__panel { min-width: 12.5rem; }
}


/* ============================================================
   DATA ROOM ADMIN (templates/dataroom/admin_list.html, LWCG admin cross-company list)
   Reuses the DATA ROOM block above. Tokens only, both themes, 44px targets, 360px safe.
   ============================================================ */
.dr .dr-admin-banner { color: var(--gray-900); font-weight: 600; border-left: 4px solid var(--color-warning); margin-bottom: 0; }
.dr .stats-grid { margin-bottom: 0; }
.dr-admin-search { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.dr-admin-search input[type="search"] {
  flex: 1 1 14rem;
  min-width: 0;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  background: var(--gray-50);
  color: var(--gray-900);
  font-family: var(--font-ui);
  font-size: var(--text-base);
}
.dr-admin-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--space-3); margin-top: var(--space-1); }
.dr-admin-open { display: inline-flex; align-items: center; min-height: 44px; }
.dr-storage { display: grid; gap: var(--space-1); min-width: 0; }
.dr-storage__text { font-size: var(--text-sm); color: var(--gray-800); overflow-wrap: anywhere; }
.dr-bar { height: 0.5rem; width: 100%; min-width: 6rem; border-radius: var(--radius-full); background: var(--gray-200); overflow: hidden; }
.dr-bar__fill { display: block; height: 100%; max-width: 100%; border-radius: var(--radius-full); background: var(--gold); }
.dr-bar--near .dr-bar__fill { background: var(--color-warning); }
.dr-bar--full .dr-bar__fill { background: var(--color-danger); }
@media (max-width: 600px) {
  .dr-table td .dr-storage { flex: 1 1 auto; max-width: 14rem; }
  .dr-table td.dr-cell-name .dr-admin-sub { justify-content: flex-start; }
}
@media (min-width: 601px) {
  .dr-storage { min-width: 11rem; }
}


/* ============================================================
   ADMIN OVERVIEW (templates/dashboard/overview.html, section links on client_detail.html)
   Reuses the DATA ROOM blocks above. Tokens only, both themes, 44px targets, 360px safe.
   ============================================================ */
.dr-ov-more { margin-top: var(--space-1); }
.dr-ov-more > summary { list-style: none; cursor: pointer; }
.dr-ov-more > summary::-webkit-details-marker { display: none; }
.dr-sections { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: var(--space-2); margin: var(--space-2) 0 0; padding: 0; list-style: none; }
.dr-sections a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 var(--space-3);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--gray-800);
  text-decoration: none;
  overflow-wrap: anywhere;
}
.dr-sections a:hover { background: var(--gray-100); color: var(--gray-900); text-decoration: none; }
.dr-sections a:focus-visible { outline: 2px solid var(--gray-900); outline-offset: 2px; box-shadow: 0 0 0 2px var(--gold); }
.dr-sections-bar { margin-bottom: var(--space-5); }
.dr-sections-bar__label { font-size: var(--text-sm); font-weight: 700; color: var(--gray-700); }
.dr-sections-bar .dr-sections { margin-top: var(--space-2); }


/* ============================================================
   KEYSTONE OVERVIEW (templates/advisor_dashboard/family_office/overview.html)
   Reuses the DATA ROOM blocks above (.dr, .dr-table, .dr-section-title, .dr-hint). Tokens only,
   both themes, 44px targets, 360px safe. Text first: every state is a word, never colour only.
   ============================================================ */
.ko-card.card { display: grid; gap: var(--space-3); min-width: 0; padding: var(--space-5); }
.ko-card .dr-section-title { margin: 0; }
.ko-lead { margin: 0; font-size: var(--text-md); color: var(--gray-800); line-height: 1.6; }
.ko-sub { margin: 0 0 var(--space-2); font-size: var(--text-base); font-weight: 700; color: var(--gray-900); }
.ko-list { margin: 0; padding-left: 1.1rem; font-size: var(--text-base); color: var(--gray-800); line-height: 1.6; }
.ko-split { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
.ko-split--cards { gap: var(--space-5); }
.ko-form { display: grid; gap: var(--space-3); max-width: 40rem; }
.ko-form textarea { min-height: 7rem; width: 100%; }
.ko-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.ko-banner.alert { color: var(--gray-900); border-left: 4px solid var(--color-success); margin-bottom: 0; }
.ko-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: var(--space-3) var(--space-5); margin: 0; }
.ko-meta dt { font-size: var(--text-sm); font-weight: 600; color: var(--gray-600); }
.ko-meta dd { margin: 2px 0 0; font-size: var(--text-base); font-weight: 600; color: var(--gray-900); overflow-wrap: anywhere; }
.ko-pairs { display: grid; margin: 0; padding: 0; list-style: none; }
.ko-pairs li { display: flex; justify-content: space-between; gap: var(--space-3); padding: var(--space-2) 0; border-top: 1px solid var(--gray-100); font-size: var(--text-base); color: var(--gray-800); overflow-wrap: anywhere; }
.ko-pairs li:first-child { border-top: 0; }
.ko-pairs strong { flex: 0 0 auto; color: var(--gray-900); }
.ko-last { margin: 0; font-size: var(--text-sm); font-weight: 600; color: var(--gray-700); }
.ko-tiers { display: grid; gap: var(--space-2); margin: 0; padding: 0; border: 0; min-width: 0; }
.ko-tiers legend { padding: 0; margin-bottom: 0.375rem; font-size: var(--text-sm); font-weight: 600; color: var(--gray-700); }
.ko-tier { display: flex; align-items: flex-start; gap: var(--space-3); min-height: 44px; margin: 0; padding: var(--space-3); border: 1px solid var(--gray-300); border-radius: var(--radius-md); font-weight: 400; cursor: pointer; }
.ko-tier input[type="radio"] { flex: 0 0 auto; width: auto; margin: 0.25rem 0 0; }
.ko-tier:has(input:checked) { border-color: var(--gold); background: var(--gray-100); }
.ko-tier__body { display: grid; gap: 2px; min-width: 0; }
.ko-tier__name { font-size: var(--text-base); font-weight: 700; color: var(--gray-900); }
.ko-tier__meta { font-size: var(--text-sm); color: var(--gray-600); line-height: 1.5; }
@media (min-width: 601px) {
  .ko-split { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ko-split--three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 400px) {
  .ko-card.card { padding: var(--space-3); }
}


/* ============================================================
   DATA ROOM SHARE LINKS (Increment 2)
   templates/dataroom/links.html, link_log.html, link_created.html, _link_created_*.html,
   _share_dialog.html, _share_fields.html, plus the completeness summary on checklist.html.
   Reuses the DATA ROOM block above. Tokens only, both themes, 44px targets, 360px safe.
   State is always a word. The PUBLIC pages use static/css/dataroom_share.css instead.
   ============================================================ */
.dr-share-card.card { display: grid; gap: var(--space-3); min-width: 0; padding: var(--space-5); }
.dr-share-card .dr-section-title { margin: 0; }
.dr-share-count { margin: 0; font-size: var(--text-base); color: var(--gray-800); }
.dr-share-notes { margin: 0; padding-left: 1.1rem; font-size: var(--text-base); color: var(--gray-800); line-height: 1.6; }
.dr-share-notes--plain { font-size: var(--text-sm); color: var(--gray-700); }
.dr-share-listhead { margin-bottom: var(--space-3); }
.dr-share-line { display: block; overflow-wrap: anywhere; }
.dr-share-status { display: grid; gap: var(--space-1); justify-items: start; min-width: 0; }
.dr-share-ua { overflow-wrap: anywhere; font-size: var(--text-sm); }
.dr-menu__link { text-decoration: none; }
.dr-menu__link:hover { background: var(--gray-100); color: var(--gray-900); text-decoration: none; }
.dr .dr-menu__link:focus-visible { outline: 2px solid var(--gray-900); outline-offset: 2px; box-shadow: 0 0 0 2px var(--gold); }
.dr-pop__body--end { left: auto; right: 0; }
.dr-share-passform { display: grid; gap: var(--space-2); }

/* Create form (dialog and folder form) */
.dr-share-create.card { display: grid; gap: var(--space-3); padding: var(--space-4) var(--space-5); }
.dr-share-create > summary { list-style: none; cursor: pointer; justify-self: start; }
.dr-share-create > summary::-webkit-details-marker { display: none; }
.dr-share-create[open] > summary { margin-bottom: var(--space-3); }
.dr-share-form { display: grid; gap: var(--space-4); min-width: 0; max-width: 34rem; }
.dr-share-field { display: grid; gap: var(--space-1); min-width: 0; }
.dr-share-field label { margin-bottom: 0; }
.dr-share-opt { font-weight: 400; color: var(--gray-600); }
.dr-share-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.dr-share-row input { flex: 1 1 11rem; min-width: 0; }
.dr .dr-share-field input[type="number"], .dr .dr-share-field input[type="date"] { min-height: 44px; }
.dr-share-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.dr-share-error:empty { display: none; }
.dr-share-error .alert { margin: 0; }

/* Dialog */
.dr-share-dialog {
  width: min(34rem, calc(100vw - 1.5rem));
  max-height: calc(100vh - 2rem);
  padding: 0;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-lg);
  background: var(--gray-50);
  color: var(--gray-900);
  box-shadow: var(--shadow-xl);
  overflow: auto;
}
.dr-share-dialog::backdrop { background: rgba(11, 31, 58, 0.6); }
.dr-share-dialog__inner { display: grid; gap: var(--space-4); padding: var(--space-5); min-width: 0; }
.dr-share-dialog__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.dr-share-dialog__title { margin: 0; font-size: var(--text-lg); font-weight: 700; color: var(--gray-900); }
.dr-share-target { margin: 0 0 var(--space-3); font-size: var(--text-base); color: var(--gray-800); overflow-wrap: anywhere; }
.dr-share-result { min-width: 0; }
.dr-share-result:empty { display: none; }
.dr-share-result:focus { outline: none; }

/* One-time link panel */
.dr-share-created { display: grid; gap: var(--space-4); min-width: 0; }
.dr-share-warn { margin: 0; padding: var(--space-3); border: 1px solid var(--color-warning-border); border-left-width: 4px; border-radius: var(--radius-md); background: var(--color-warning-bg); color: var(--gray-900); font-size: var(--text-base); }
.dr-share-facts { display: grid; gap: var(--space-2); margin: 0; }
.dr-share-facts > div { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.dr-share-facts dt { font-size: var(--text-sm); font-weight: 600; color: var(--gray-600); }
.dr-share-facts dd { margin: 0; font-size: var(--text-base); font-weight: 600; color: var(--gray-900); overflow-wrap: anywhere; }

/* Checklist completeness */
.dr-complete.card { display: grid; gap: var(--space-3); padding: var(--space-5); }
.dr-complete .dr-section-title { margin: 0; }
.dr-complete__rows { display: grid; gap: var(--space-4); margin: var(--space-1) 0 0; padding: 0; list-style: none; }
.dr-complete__row { display: grid; gap: var(--space-2); padding-top: var(--space-3); border-top: 1px solid var(--gray-100); min-width: 0; }
.dr-complete__line { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-1) var(--space-3); }
.dr-complete__name { font-size: var(--text-base); font-weight: 700; color: var(--gray-900); overflow-wrap: anywhere; }
.dr-complete__num { font-size: var(--text-sm); font-weight: 600; color: var(--gray-700); }
.dr-complete__empty { overflow-wrap: anywhere; }

@media (min-width: 601px) {
  .dr-share-facts > div { grid-template-columns: 11rem minmax(0, 1fr); gap: var(--space-3); }
}
@media (max-width: 400px) {
  .dr-share-card.card, .dr-complete.card, .dr-share-create.card { padding: var(--space-3); }
  .dr-share-dialog__inner { padding: var(--space-3); }
}

/* Dark theme: the base sheet leaves date inputs unstyled */
html[data-theme="dark"] .dr input[type="date"] {
  background: var(--gray-200);
  border-color: var(--gray-300);
  color: var(--gray-900);
  color-scheme: dark;
}
html[data-theme="dark"] .dr-share-dialog { background: var(--gray-100); border-color: var(--gray-300); }
html[data-theme="dark"] .dr-share-dialog::backdrop { background: rgba(0, 0, 0, 0.7); }
