:root {
  --sidebar-bg: #111827;
  --sidebar-text: #9ca3af;
  --sidebar-text-hover: #f3f4f6;

  --bg-body: #f3f4f6;
  --card-bg: #ffffff;

  --text-primary: #1f2937;
  --text-secondary: #6b7280;

  --border-color: #e5e7eb;

  --primary-color: #3d686b;
  --primary-hover: #31575a;

  --success-color: #10b981;
  --success-dark: #047857;

  --danger-color: #ef4444;
  --danger-dark: #b91c1c;

  --warning-color: #f59e0b;

  --sidebar-width: 260px;
  --sidebar-collapsed-width: 64px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -1px rgba(0, 0, 0, 0.06);

  --radius: 8px;

  --font: "Inter", sans-serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;

  /*
    The virtual holdings table columns are generated dynamically in
    portfolio-drilldown.html via applyTableColumnTemplate().
    These are only safe fallbacks for the empty/loading state.
  */
  --table-min-width: 980px;
  --table-columns: 135px 95px 340px 170px 72px 130px 120px 130px 110px 110px 90px 90px 120px 95px 95px 95px 120px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  background: var(--bg-body);
}

body {
  font-family: var(--font);
  background-color: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
}

/* --- SIDEBAR --- */

aside {
  width: var(--sidebar-width);
  background-color: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid #374151;
  transition: width 0.25s ease, transform 0.25s ease;
  overflow: hidden;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 100;
}

aside.collapsed {
  width: var(--sidebar-collapsed-width);
}

.brand {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 0 24px;
  color: white;
  font-weight: 700;
  font-size: 1.25rem;
  border-bottom: 1px solid #1f2937;
  flex-shrink: 0;
}

.brand-text {
  min-width: 0;
  overflow: hidden;
}

.brand-text a {
  all: unset;
  cursor: pointer;
  white-space: nowrap;
}

.brand-text span {
  color: var(--primary-color);
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: white;
}

.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  flex: 0 0 28px;
}

aside.collapsed .brand-link {
  justify-content: center;
}

aside.collapsed .brand-text {
  display: none;
}

.toggle-btn,
.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background 0.2s, transform 0.25s ease;
  flex-shrink: 0;
  margin: 0;
  width: auto;
}

.toggle-btn {
  color: var(--sidebar-text);
}

.toggle-btn:hover {
  color: white;
  background: #1f2937;
}

.toggle-btn svg,
.hamburger svg {
  width: 20px;
  height: 20px;
}

nav {
  padding: 16px;
  flex: 1;
}

nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 6px;
  margin-bottom: 4px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: color 0.2s, background-color 0.2s;
  white-space: nowrap;
}

nav a:hover,
nav a.active {
  background-color: #1f2937;
  color: var(--sidebar-text-hover);
  /*border-bottom: 2px solid var(--primary-color);*/
}

nav a.active {
  border-bottom: 2px solid var(--primary-color);
}

nav a.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  /*width: 3px;*/
  border-radius: 999px;
  background: var(--primary-color);
}

nav a svg {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  display: block;
}

/* --- COLLAPSED SIDEBAR FIXES --- */

aside.collapsed .brand {
  justify-content: center;
  padding: 0;
}

aside.collapsed .brand-text,
aside.collapsed nav a span {
  opacity: 0;
  width: 0;
  max-width: 0;
  overflow: hidden;
  white-space: nowrap;
  pointer-events: none;
}

aside.collapsed .toggle-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  margin: 0 auto;
  transform: rotate(180deg);
}

aside.collapsed nav {
  padding: 16px 12px;
}

aside.collapsed nav a {
  width: 40px;
  height: 40px;
  justify-content: center;
  align-items: center;
  padding: 0;
  margin: 0 auto 6px;
  gap: 0;
}

aside.collapsed nav a svg {
  margin: 0;
}

aside.collapsed nav a.active::before {
  left: -12px;
  top: 8px;
  bottom: 8px;
}

/* --- MOBILE SIDEBAR --- */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

.sidebar-overlay.active {
  display: block;
}

.hamburger {
  display: none;
  color: var(--text-primary);
}

.hamburger:hover {
  background: #f3f4f6;
}

/* --- MAIN CONTENT --- */

main {
  flex: 1;
  min-width: 0;
  display: block;
  overflow: visible;
}

header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 101;
}

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

.controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: nowrap;
    flex-shrink: 0;
}

/*.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}*/

.header-title h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.header-title p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.content-container {
  padding: 24px;
  max-width: none;
  margin: 0;
  width: 100%;
}

/* --- CARDS / LAYOUT --- */

.panel-row {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
  grid-template-columns: 1fr 1fr;
}

.analytics-row {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.55fr);
  align-items: stretch;
  width: 100%;
}

.panel-full {
  margin-bottom: 16px;
  width: 100%;
}

.card {
  background: var(--card-bg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.card-header {
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-top: 4px;
  line-height: 1.45;
}

/* --- ONE-PAGE LANDING / MONETIZATION SECTIONS --- */

.hero-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.55fr);
  gap: 24px;
  align-items: stretch;
  background: radial-gradient(
      circle at top left,
      rgba(61, 104, 107, 0.16),
      transparent 34%
    ),
    var(--card-bg);
}

.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 5px 10px;
  border-radius: 999px;
  background: #edf4f3;
  color: var(--primary-color);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

.hero-title {
  font-size: clamp(1.9rem, 3.2vw, 3.1rem);
  line-height: 1.05;
  letter-spacing: -0.045em;
  color: var(--text-primary);
  margin-bottom: 14px;
}

.hero-copy {
  max-width: 760px;
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1.7;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.hero-actions .btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.feature-list {
  display: grid;
  gap: 10px;
  align-content: start;
}

.feature-pill {
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.72);
}

.feature-pill strong {
  display: block;
  color: var(--text-primary);
  font-size: 0.88rem;
  margin-bottom: 3px;
}

.feature-pill span {
  display: block;
  color: var(--text-secondary);
  font-size: 0.78rem;
  line-height: 1.45;
}

.ad-slot {
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  background: repeating-linear-gradient(
    135deg,
    #f8fafc,
    #f8fafc 10px,
    #f1f5f9 10px,
    #f1f5f9 20px
  );
  color: #64748b;
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.ad-slot span {
  display: block;
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  margin-top: 4px;
  color: #94a3b8;
}

.ad-slot.ad-leaderboard {
  min-height: 112px;
  margin-bottom: 16px;
}

.ad-slot.ad-sidebar {
  min-height: 300px;
  position: sticky;
  top: 88px;
}

.ad-slot.ad-inline {
  min-height: 140px;
  margin-bottom: 16px;
}

.tool-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

.tool-main,
.ad-rail {
  min-width: 0;
}

.explainer-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.explainer-card {
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 16px;
  background: #ffffff;
}

.explainer-card h4 {
  font-size: 0.95rem;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.explainer-card p,
.disclosure-text {
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.65;
}

.disclosure-text strong {
  color: var(--text-primary);
}

.sample-portfolio-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin: 12px 0 16px;
}

.sample-portfolio-card {
  text-align: left;
  background: #f8fafc;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
}

.sample-portfolio-card:hover {
  background: #edf4f3;
  border-color: var(--primary-color);
}

.sample-portfolio-card strong {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 4px;
}

.sample-portfolio-card span {
  display: block;
  /*color: var(--text-secondary);*/
  color: #dfdfdf;
  font-size: 0.76rem;
  line-height: 1.4;
}

.mobile-summary-grid {
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.mobile-summary-card {
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: #ffffff;
  padding: 12px;
}

.mobile-summary-label {
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.mobile-summary-value {
  color: var(--text-primary);
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 700;
  margin-top: 6px;
}

.loading-steps {
  display: none;
  margin-top: 10px;
  padding: 12px;
  border: 1px solid #b2ceca;
  border-radius: 10px;
  background: #edf4f3;
  color: #254447;
  font-size: 0.82rem;
  line-height: 1.5;
}

.loading-steps.is-visible {
  display: block;
}

.site-footer {
  color: var(--text-secondary);
  font-size: 0.78rem;
  line-height: 1.6;
  text-align: center;
  padding: 8px 0 18px;
}

/* --- FORM CONTROLS --- */

.input-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

label,
.input-group label,
.section-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-control,
input[type="text"] {
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--text-primary);
  background: white;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: var(--font);
  min-width: 0;
  width: 100%;
}

.form-control:focus,
input[type="text"]:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(61, 104, 107, 0.20);
}

/* --- BUTTONS --- */

.btn,
button {
  border: 1px solid transparent;
  padding: 9px 16px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.15s;
  font-family: var(--font);
  margin: 0;
}


.btn-with-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;     /* Prevent icon/text wrapping */
    flex-wrap: nowrap;
    flex-shrink: 0;          /* Don't let this button get squeezed */
}

.btn-with-icon .btn-icon {
    width: 16px;
    height: 16px;
    display: block;
    flex: 0 0 16px;
}

.btn-with-icon span {
    white-space: nowrap;
    line-height: 1;
}

.btn:active,
button:active {
  transform: translateY(1px);
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-secondary,
button.green {
  background: #ffffff;
  color: #374151;
  border-color: #d1d5db;
}

.btn-secondary:hover,
button.green:hover {
  background: #f9fafb;
  border-color: #9ca3af;
}

.btn-success {
  background: #ecfdf5;
  color: var(--success-dark);
  border-color: #a7f3d0;
}

.btn-success:hover {
  background: #d1fae5;
  border-color: #6ee7b7;
}

.btn-danger-soft {
  background: #fef2f2;
  color: var(--danger-dark);
  border-color: #fecaca;
}

.btn-danger-soft:hover {
  background: #fee2e2;
  border-color: #fca5a5;
}

/* Fallback for plain buttons without a specific class */
/*button:not(.toggle-btn):not(.hamburger):not(.btn-secondary):not(
    .btn-success
  ):not(.btn-danger-soft):not(.green) {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

button:not(.toggle-btn):not(.hamburger):not(.btn-secondary):not(
    .btn-success
  ):not(.btn-danger-soft):not(.green):hover {
  background-color: var(--primary-hover);
  border-color: var(--primary-hover);
}*/

/* --- SOURCE INPUT AREA --- */

.source-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.8fr);
  gap: 16px;
  align-items: start;
}

.public-source-grid {
  grid-template-columns: 1fr;
}

.public-csv-card {
  max-width: none;
}

.account-picker-card,
.csv-upload-card {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 16px;
  background: #ffffff;
}

.account-picker-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.account-toolbar,
.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(125px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.account-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: #f9fafb;
  color: var(--text-primary);
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
}

.account-option:hover {
  border-color: var(--primary-color);
  background: #edf4f3;
}

.account-option input {
  accent-color: var(--primary-color);
}

.account-state,
.hint,
.csv-hint,
#txtHint {
  color: var(--text-secondary);
  font-size: 0.82rem;
  line-height: 1.45;
}

#txtHint {
  color: var(--success-color);
  font-weight: 600;
}

.csv-hint {
  margin-top: 8px;
}

.csv-hint code {
  color: var(--primary-color);
  font-family: var(--mono);
}

/* Account loading pulse */

#abc2c1ountState.is-loading {
  color: var(--primary-color);
  font-weight: 600;
  animation: accountStatePulse 1.15s ease-in-out infinite;
}

@keyframes accountStatePulse {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.45;
  }
}

.csv-upload-card input[type="file"] {
  width: 100%;
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 8px;
}

.csv-upload-card input[type="file"]::file-selector-button {
  background: white;
  border: 1px solid #d1d5db;
  color: var(--text-primary);
  padding: 7px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  margin-right: 10px;
}

.csv-upload-card input[type="file"]::file-selector-button:hover {
  background: #f9fafb;
}

/* --- POSITION INPUT TABLE --- */

.manual-positions-card {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 16px;
  background: #ffffff;
  margin-bottom: 16px;
}

.custom-benchmark-card {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 16px;
  background: #ffffff;
  margin-bottom: 16px;
}

.custom-benchmark-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.benchmark-summary {
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-family: var(--mono);
}

.benchmark-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}

.benchmark-actions-left {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.custom-benchmark-card .position-input-table .benchmark-ticker-input {
  text-transform: uppercase;
  color: var(--primary-color);
  font-weight: 700;
}

@media (max-width: 640px) {
  .custom-benchmark-header,
  .benchmark-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .benchmark-actions-left {
    display: grid;
    grid-template-columns: 1fr;
  }
}

.manual-positions-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.position-table-wrap {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
}

.position-input-table {
  width: 100%;
  border-collapse: collapse;
}

.position-input-table th,
.position-input-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  background: #ffffff;
}

.position-input-table th {
  background: #f9fafb;
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: left;
}

.position-input-table th:nth-child(2),
.position-input-table td:nth-child(2) {
  width: 170px;
}

.position-input-table th:nth-child(3),
.position-input-table td:nth-child(3) {
  width: 92px;
  text-align: right;
}

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

.position-input-table input {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--text-primary);
  outline: none;
}

.position-input-table input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(61, 104, 107, 0.15);
}

.position-input-table .position-ticker-input {
  text-transform: uppercase;
  color: var(--primary-color);
  font-weight: 700;
}

.position-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}

.position-actions-left {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.position-remove-btn {
  padding: 7px 10px;
  font-size: 0.78rem;
}

.position-summary {
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-family: var(--mono);
}

.legacy-comma-inputs {
  display: none;
}

@media (max-width: 640px) {
  .manual-positions-header,
  .position-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .position-actions-left {
    display: grid;
    grid-template-columns: 1fr;
  }

  .position-table-wrap {
    overflow-x: auto;
  }

  .position-input-table {
    min-width: 480px;
  }
}

/* --- DEBUG PANEL --- */

.debug-panel {
  display: none;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #111827;
  color: #d1d5db;
  font-family: var(--mono);
  font-size: 0.72rem;
  white-space: pre-wrap;
  overflow: auto;
  max-height: 220px;
}

.debug-panel.is-visible {
  display: block;
}

.loader {
  font-size: 0.875rem;
  color: var(--text-secondary);
  padding: 20px;
  text-align: center;
}

/* --- CHARTS --- */

#sectorWeightChart,
#assetAllocationChart,
#bondMaturityChart,
#bondTypeChart {
  width: 100%;
  min-height: 380px;
}

#assetAllocationChart {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- VIRTUAL HOLDINGS TABLE --- */

.table-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.tbl-container {
  height: 620px;
  overflow: auto;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  position: relative;
  background: white;
  width: 100%;
  overflow: auto;
}

.tbl-container::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.tbl-container::-webkit-scrollbar-track {
  background: #f3f4f6;
  border-radius: 4px;
}

.tbl-container::-webkit-scrollbar-thumb {
  background: #9ca3af;
  border-radius: 4px;
}

.tbl-container::-webkit-scrollbar-thumb:hover {
  background: #6b7280;
}

.header-row,
.virtual-scroll-content,
.div-row {
  /* Keep every virtualized row on the exact same grid width.
     Individual rows must not use max-content, or long names can expand one
     row's grid tracks and push later columns out of alignment. */
  width: max(var(--table-min-width), 100%);
  min-width: var(--table-min-width);
}

.table-grid {
  display: grid;
  grid-template-columns: var(--table-columns);
  align-items: center;
}

.header-row {
  position: sticky;
  top: 0;
  background: #f9fafb;
  z-index: 20;
  font-weight: 700;
  height: 46px;
  border-bottom: 2px solid var(--border-color);
}

.virtual-scroll-content {
  position: relative;
}

.div-row {
  min-height: 40px;
  height: 40px;
  border-left: none;
  background: white;
}

.holding-row {
  cursor: pointer;
  transition: background 0.12s ease;
}

.header-row > div,
.div-row > div {
  min-width: 0;
  color: var(--text-primary);
  text-align: right;
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 0 12px;
  border-bottom: 1px solid var(--border-color);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Header cells */

.header-row > div {
  height: 46px;
  line-height: 46px;
  background: #f9fafb;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Body cells: flex prevents empty cells from collapsing visually */

.div-row > div {
  min-height: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  line-height: 1.2;
}

/* Text columns */

.header-row > div:nth-child(-n + 5),
.div-row > div:nth-child(-n + 5) {
  text-align: left;
}

.div-row > div:nth-child(-n + 5) {
  justify-content: flex-start;
}

/* Numeric columns */

.div-row > div:nth-child(n + 6) {
  justify-content: flex-end;
  text-align: right;
}

/* Prevent empty cells like Direct from visually collapsing */

.div-row > div:empty::after {
  content: "";
  display: inline-block;
  min-height: 1px;
}

.holding-row:hover > div {
  background-color: #f3f5f7;
}

.holding-row > div:nth-child(1),
.holding-row > div:nth-child(2) {
  color: var(--primary-color);
  font-family: var(--mono);
  font-weight: 600;
}

.holding-row > div:nth-child(3) {
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
}

.holding-row > div:nth-child(4) {
  color: var(--text-secondary);
  font-family: var(--font);
}

.holding-row > div:nth-child(9) {
  color: var(--success-color);
  font-weight: 700;
}

/* Source rows */

.source-row > div {
  background-color: #f9fafb;
  color: var(--text-secondary);
  font-size: 0.78rem;
  min-height: 40px;
  height: 40px;
}

.source-row > div:nth-child(3) {
  justify-content: flex-start;
  padding-left: 30px;
  color: var(--text-secondary);
  font-family: var(--mono);
}

.source-row > div:nth-child(7),
.source-row > div:nth-child(8),
.source-row > div:nth-child(9) {
  color: var(--success-color);
  font-weight: 600;
}

.expand-toggle {
  display: inline-block;
  width: 18px;
  color: var(--text-secondary);
  font-size: 1.2rem;
  font-weight: 800;
}

.sort-indicator {
  margin-left: 4px;
  font-size: 11px;
  color: var(--primary-color);
}

.asset-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  font-family: var(--mono);
  background: #edf4f3;
  color: var(--primary-color);
}

/* Existing holdings-loading pulse */

.new-class {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.55;
  }
}

/* --- Loading Spinner --- */
/* Positioned backdrop overlay in the bottom right */
.loading-overlay {
  position: fixed;
  bottom: 20px; /* Space from the bottom edge */
  right: 20px; /* Space from the right edge */
  z-index: 9999; /* Ensures it sits on top of all other content */
  display: none;
}

.loading-overlay.is-visible {
  display: block;
}

/* The animated circle loader */
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #4f7c7e;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
    

/* --- ACTIVE WEIGHT SUMMARY CARD --- */

.active-weight-card {
  gap: 18px;
}

.active-weight-layout {
  display: grid;
  grid-template-columns: minmax(220px, 0.42fr) minmax(0, 0.58fr);
  gap: 20px;
  align-items: stretch;
}

.active-weight-score {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: linear-gradient(135deg, #f8fafc, #ffffff);
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 180px;
}

.active-weight-label {
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.active-weight-value {
  color: var(--text-primary);
  font-family: var(--mono);
  font-size: clamp(2.2rem, 5vw, 4rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.05em;
  margin: 12px 0;
}

.active-weight-badge {
  width: fit-content;
  border-radius: 999px;
  padding: 7px 11px;
  /*background: #edf4f3;
  color: #254447;*/
  background: ##efeff1;
  color: #4aab17;
  font-size: 0.78rem;
  font-weight: 800;
}

.active-weight-description {
  color: var(--text-secondary);
  font-size: 0.84rem;
  line-height: 1.55;
  margin-top: 10px;
}

.active-weight-details {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  min-width: 0;
}

/*.active-weight-bar {
  position: relative;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: linear-gradient(
    90deg,
    #dce9e6 0%,
    #dce9e6 20%,
    #b2ceca 20%,
    #b2ceca 40%,
    #9ab8b5 40%,
    #9ab8b5 60%,
    #6f9595 60%,
    #6f9595 80%,
    #31575a 80%,
    #31575a 100%
  );
}*/

.active-weight-bar {
  position: relative;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: linear-gradient(
    90deg,
    #e2ece9 0%,
    #e2ece9 20%,
    #b2ceca 20%,
    #b2ceca 40%,
    #7ca3a2 40%,
    #7ca3a2 60%,
    #3d686b 60%,
    #3d686b 80%,
    #254447 80%,
    #254447 100%
  );
}

.active-weight-marker {
  position: absolute;
  top: -4px;
  width: 4px;
  height: 22px;
  border-radius: 999px;
  background: #111827;
  transform: translateX(-50%);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.85);
}

.active-weight-ranges {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.active-weight-range {
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px;
  background: #ffffff;
}

.active-weight-range.is-current {
  border-color: var(--primary-color);
  background: #edf4f3;
  box-shadow: 0 0 0 2px rgba(61, 104, 107, 0.14);
}

.active-weight-range strong {
  display: block;
  color: var(--text-primary);
  font-size: 0.76rem;
  margin-bottom: 3px;
}

.active-weight-range span {
  display: block;
  color: var(--text-secondary);
  font-family: var(--mono);
  font-size: 0.72rem;
}

.active-weight-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.active-weight-meta-item {
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: #f9fafb;
  padding: 10px;
}

.active-weight-meta-item span {
  display: block;
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.active-weight-meta-item strong {
  display: block;
  color: var(--text-primary);
  font-family: var(--mono);
  font-size: 0.95rem;
  margin-top: 5px;
}

@media (max-width: 900px) {
  .active-weight-layout,
  .active-weight-meta {
    grid-template-columns: 1fr;
  }

  .active-weight-ranges {
    grid-template-columns: 1fr;
  }
}

/* --- RESPONSIVE --- */

@media (max-width: 1180px) {
  .tool-layout,
  .analytics-row {
    grid-template-columns: 1fr;
  }

  .ad-slot.ad-sidebar {
    position: static;
    min-height: 110px;
  }
}

@media (max-width: 1024px) {
  .panel-row,
  .source-grid,
  .hero-card,
  .explainer-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  :root {
    --table-min-width: 1180px;
  }

  aside {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: var(--sidebar-width) !important;
    transform: translateX(-100%);
    z-index: 100;
  }

  aside.mobile-open {
    transform: translateX(0);
  }

  .hamburger {
    display: flex;
  }

  .header-left {
    flex: 1;
  }

  .controls {
    width: 100%;
    order: 3;
    justify-content: flex-start;
  }

  .controls .btn,
  .controls button {
    flex: 1;
  }

  .content-container {
    padding: 16px;
  }

  .card {
    padding: 16px;
  }

  .input-grid {
    grid-template-columns: 1fr;
  }

  .account-picker-header {
    flex-direction: column;
  }

  .account-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .tbl-container {
    height: 560px;
  }

  .mobile-summary-grid {
    display: grid;
  }
}

@media (max-width: 480px) {
  header {
    padding: 10px 16px;
    z-index: 80;
  }

  .content-container {
    padding: 12px;
  }

  .form-control,
  input[type="text"] {
    font-size: 16px;
  }

  .controls .btn,
  .controls button {
    flex: 1 1 100%;
  }
}

/* --- FINAL LAYOUT POLISH: COLLAPSED SIDEBAR + MOBILE HEADER --- */

/* Desktop collapsed sidebar: stack logo and toggle so they do not collide */
@media (min-width: 769px) {
  aside.collapsed .brand {
    height: 112px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 12px 0;
  }

  aside.collapsed .brand-link {
    width: 40px;
    height: 40px;
    justify-content: center;
    align-items: center;
    gap: 0;
  }

  aside.collapsed .brand-logo {
    width: 30px;
    height: 30px;
    flex-basis: 30px;
  }

  aside.collapsed .brand-text {
    display: none;
  }

  aside.collapsed .toggle-btn {
    width: 38px;
    height: 38px;
    padding: 0;
    margin: 0;
    border: 1px solid rgba(156, 163, 175, 0.16);
    background: rgba(31, 41, 55, 0.72);
    transform: rotate(180deg);
  }

  aside.collapsed .toggle-btn:hover {
    background: #1f2937;
  }

  aside.collapsed nav {
    padding-top: 14px;
  }
}

/* Mobile: header should not stay pinned over the page content */
@media (max-width: 768px) {
  header {
    position: static;
    top: auto;
    z-index: auto;
    padding: 14px 16px;
    align-items: flex-start;
  }

  .header-left {
    width: 100%;
    align-items: flex-start;
  }

  .header-title h1 {
    font-size: 1.35rem;
    line-height: 1.15;
  }

  .header-title p {
    font-size: 0.82rem;
    line-height: 1.35;
  }

  .controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 8px;
    margin-top: 4px;
  }

  .controls .btn,
  .controls button {
    width: 100%;
    min-height: 42px;
    padding: 9px 10px;
    flex: initial;
    font-size: 0.84rem;
  }

  .content-container {
    padding-top: 14px;
  }
}

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

  .controls .btn,
  .controls button {
    flex: initial;
  }
}


/* --- DYNAMIC VIRTUAL TABLE COLUMN FIXES --- */
/* The table uses CSS variables set by JS, so these rules avoid positional
   nth-child assumptions when bond columns appear/disappear. */

.header-row,
.virtual-scroll-content,
.div-row {
  width: max(var(--table-min-width), 100%);
  min-width: var(--table-min-width);
}

.table-grid {
  grid-template-columns: var(--table-columns);
}

.header-row > div,
.div-row > div {
  text-align: left;
  justify-content: flex-start;
  /* Prevent text from overflowing cell boundaries */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* Add cursor to indicate truncated text is hoverable */
  cursor: default;
}

.div-row > div[title] {
  /* Keep the native title tooltip without showing the browser's help cursor. */
  cursor: default;
}

.header-row > div.is-numeric,
.div-row > div.is-numeric {
  text-align: right;
  justify-content: flex-end;
}

.header-row > div.is-text,
.div-row > div.is-text {
  text-align: left;
  justify-content: flex-start;
  /* Truncate long text with ellipsis */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.div-row > div[data-column-key="id"],
.div-row > div[data-column-key="ticker"] {
  color: var(--primary-color);
  font-family: var(--mono);
  font-weight: 600;
}

.div-row > div[data-column-key="name"] {
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
}

.div-row > div[data-column-key="sector"] {
  color: var(--text-secondary);
  font-family: var(--font);
}

.holding-row > div[data-column-key="total"] {
  color: var(--success-color);
  font-weight: 700;
}


.header-row > div,
.div-row > div {
  max-width: 100%;
}

.div-row > div > span:not(.asset-badge):not(.expand-toggle),
.header-row > div > span:not(.column-resize-handle):not(.sort-indicator) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-row > div[data-column-key="name"] {
  justify-content: flex-start;
  padding-left: 30px;
  color: var(--text-secondary);
  font-family: var(--mono);
}

.source-row > div[data-column-key="direct"],
.source-row > div[data-column-key="fund"],
.source-row > div[data-column-key="total"] {
  color: var(--success-color);
  font-weight: 600;
}

.header-row > div {
  position: relative;
}

.column-resize-handle {
  z-index: 3;
}

/* --- COLUMN VISIBILITY MENU --- */

.column-menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 500;
  animation: fadeIn 0.15s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.column-menu {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15);
  z-index: 600;
  max-height: 80vh;
  width: 90%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translate(-50%, -40%);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

.column-menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.column-menu-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.column-menu-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease;
}

.column-menu-close:hover {
  color: var(--text-primary);
}

.column-menu-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.column-menu-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.column-menu-search input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(61, 104, 107, 0.10);
}

.column-menu-search input::placeholder {
  color: var(--text-secondary);
}

.column-menu-content {
  overflow-y: auto;
  flex: 1;
  padding: 8px 0;
}

.column-menu-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  gap: 10px;
  cursor: pointer;
  transition: background-color 0.15s ease;
  user-select: none;
}

.column-menu-item:hover {
  background-color: #f9fafb;
}

.column-menu-item input[type="checkbox"] {
  cursor: pointer;
  width: 18px;
  height: 18px;
  accent-color: var(--primary-color);
}

.column-menu-item label {
  flex: 1;
  cursor: pointer;
  margin: 0;
  font-size: 14px;
  color: var(--text-primary);
}

.column-menu-item.hidden {
  opacity: 0.5;
  display: none;
}

.column-menu-footer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  justify-content: flex-end;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  height: auto;
}

/* --- HOLDINGS ROW INTERACTION --- */

/*
  Parent holding rows are expandable, so use the pointer cursor to make
  the interaction obvious. Source rows are informational only and retain
  the standard cursor.
*/
.holding-row,
.holding-row > div,
.holding-row > div[title] {
  cursor: pointer;
}

.holding-row:hover {
  background: #f3f7f6;
}

.holding-row.row-expanded {
  background: #eef5f3;
}

.source-row,
.source-row > div,
.source-row > div[title],
.div-row.source-row,
.div-row.source-row > div,
.div-row.source-row > div[title] {
  cursor: default;
}

/* Column resizing remains a distinct interaction. */
.column-resize-handle,
.column-resize-handle:hover,
.column-resize-handle:focus,
body.resizing-columns .column-resize-handle {
  cursor: col-resize !important;
}

