: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: #3B82F6;
  --primary-hover: #2563EB;

  --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;

  --table-min-width: 100%;
  --table-columns:
    minmax(78px, 0.7fr)
    minmax(80px, 0.65fr)
    minmax(170px, 1.7fr)
    minmax(130px, 1.1fr)
    52px
    minmax(92px, 0.8fr)
    minmax(92px, 0.8fr)
    minmax(86px, 0.75fr)
    minmax(76px, 0.7fr)
    minmax(92px, 0.8fr);
}

* {
  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 {
  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(59, 130, 246, 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: #EFF6FF;
  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;*/
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

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

.ad-rail {
  display: none;
}

.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: #EFF6FF;
  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 #BFDBFE;
  border-radius: 10px;
  background: #EFF6FF;
  color: #1D4ED8;
  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(59, 130, 246, 0.2);
}

/* --- 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: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: #EFF6FF;
}

.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 */

#accountState.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(59, 130, 246, 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 {
  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%;
}

.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 {
  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;
}

.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: #EFF6FF;
  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.loading-overlay {
  display: block;
}

/* The animated circle loader */
.loading-spinner {
  width: 40px; /* Made slightly smaller for a corner widget */
  height: 40px;
  border: 4px solid #f3f3f3; 
  border-top: 4px solid #3498db; 
  border-radius: 50%; 
  animation: spin 1s linear infinite; 
}

/* Rotation keyframe remains the same */
@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: #EFF6FF;
  color: #1D4ED8;
  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, #DBEAFE 0%, #DBEAFE 20%, #BFDBFE 20%, #BFDBFE 40%, #93C5FD 40%, #93C5FD 60%, #60A5FA 60%, #60A5FA 80%, #2563EB 80%, #2563EB 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: #EFF6FF;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 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;
    margin-top: 200px;
  }

  .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;*/
    position: fixed;
    top: auto;
    /*z-index: auto;*/
    z-index: 4000;
    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;
  }
}
