/* Import Google Font */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap');

/* Dark Navy Theme Variables */
:root {
  /* Background colors */
  --theme-bg-darkest: #081229;    /* Main background, primary buttons */
  --theme-bg-dark-mid: #1a3149;   /* Between darkest and dark — card rows */
  --theme-bg-dark: #0f3459;       /* Section backgrounds */
  --theme-bg-medium: #1b4a79;     /* Stats banner, card headers */
  --theme-bg-light: #416385;      /* Borders, subtle accents */
  --theme-bg-white: #ffffff;      /* White backgrounds (cards, tables) */
  --theme-sub-table-background: #d0d3d6; /* Sub-table/summary section backgrounds */
  --theme-bg-edit-mode: #2d0f1b;  /* Edit mode background #2d0f1b #460520*/

  /* Text colors */
  --theme-text-light: #ffffff;    /* Light text on dark backgrounds */
  --theme-text-muted: #a0aec0;    /* Muted text on dark backgrounds */
  --theme-text-dark: #1f2937;     /* Dark text on light backgrounds */
  --theme-text-secondary: #6b7280; /* Secondary/muted text on light backgrounds */
  --theme-border-grey: #979a9e;   /* Grey borders */
  --theme-accent: #ffffff;        /* Accent color for highlights */

  /* Semantic colors - positive/negative values */
  --theme-positive: #10b981;      /* Gains, positive returns */
  --theme-positive-dark: #059669; /* Darker positive for hover states */
  --theme-negative: #ef4444;      /* Losses, negative returns */
  --theme-negative-dark: #dc2626; /* Darker negative for hover states */

  /* Semantic colors - actions */
  --theme-success: #16a34a;       /* Success buttons, confirmations */
  --theme-success-hover: #22c55e; /* Success hover state */
  --theme-warning: #d97706;       /* Warnings, pending states */
  --theme-warning-hover: #b45309; /* Warning hover state */
  --theme-danger: #dc2626;        /* Delete buttons, errors */
  --theme-danger-hover: #b91c1c;  /* Danger hover state */
  --theme-danger-bg: #fee2e2;     /* Danger background (light red) */
  --theme-primary: #3b82f6;        /* Primary blue for interactive elements */
  --theme-link: #60a5fa;          /* Hyperlink / eyebrow / callout accent (lighter blue than --theme-primary) */
  --theme-info: #0284c7;          /* Info text color */
  --theme-info-bg: #e0f2fe;       /* Info background (light blue) */

  /* Light theme colors (for tables, cards on light backgrounds) */
  --theme-table-header: #f3f4f6;  /* Table header background */
  --theme-table-hover: #416385;   /* Table row hover */
  --theme-table-border: #e5e7eb;  /* Table cell borders */
  --theme-table-border-dark: #dee2e6; /* Darker table borders */
  --theme-input-border: #d1d5db;  /* Input field borders on light bg */
  --theme-input-disabled: #9ca3af; /* Disabled input border */

  /* Interactive states */
  --theme-hover-light: #2563a8;   /* Light hover on medium backgrounds */
  --theme-hover-dark: #0a1a3a;    /* Dark hover on primary buttons */

  /* Chart theme colors */
  --chart-axis-color: #ffffff;    /* Axis labels and ticks */
  --chart-legend-color: #ffffff;  /* Legend text */
  --chart-grid-color: rgba(255, 255, 255, 0.1); /* Grid lines */
}

input[type="text"], select {
  padding: 0.5rem;
  font-size: 1.05rem;
}


body {
  font-family: 'Inter', sans-serif;
  margin: 0;
  padding: 0;
  background-color: var(--theme-bg-dark);
  color: var(--theme-text-light);
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-content {
  flex: 1 1 auto;
  padding: 1.5rem;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--theme-bg-darkest);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar-left {
  position: relative;
}

.topbar-center {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  margin-left: -150px; /* Shift left to visually center with title on left */
}

.topbar-title {
  font-size: 1.7rem;
  font-weight: 600;
  color: var(--theme-text-light);
  margin: 0;
  display: flex;
  align-items: center;
}

.topbar-search {
  position: relative;
  width: clamp(200px, 100%, 400px);
}

.topbar-search-inner {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.topbar-search-input-wrapper {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
/*  border: 1px solid var(--theme-border-grey); */
  border: none;
  border-radius: 12px;
  background: var(--theme-bg-dark);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.08);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  padding-left: 0.5rem;
}

.topbar-search-input-wrapper:focus-within {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15), inset 0 1px 2px rgba(15, 23, 42, 0.08);
}

.search-filter-pill {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.5rem;
  background: #dbeafe;
  border: 1px solid #93c5fd;
  border-radius: 999px;
  font-size: 0.8rem;
  color: #1e40af;
  font-weight: 500;
  margin-right: 0.5rem;
  flex-shrink: 0;
}

.search-filter-pill[hidden] {
  display: none !important;
}

.filter-pill-text {
  text-transform: uppercase;
}

.filter-pill-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  padding: 0;
  border: none;
  background: #3b82f6;
  color: white;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  transition: background 0.15s ease;
}

.filter-pill-clear:hover {
  background: #2563eb;
}

.topbar-search-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.6rem 0.5rem;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  color: var(--theme-text-light);
  background: transparent;
}

.topbar-search-input::placeholder {
  color: var(--theme-text-muted);
}

.topbar-search-input:focus {
  outline: none;
}

.topbar-advanced-btn {
  height: 38px;
  padding: 0 1rem;
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--theme-text-light);
  background: var(--theme-bg-darkest);
/*  border: 1px solid var(--theme-border-grey); */
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.topbar-advanced-btn:hover {
  background: var(--theme-bg-medium);
  border-color: var(--theme-text-muted);
  color: var(--theme-text-light);
}

.topbar-advanced-btn:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.topbar-icon-button {
/*  border: 1px solid var(--theme-border-grey); */
  border: none;
  background: var(--theme-bg-dark);
  color: var(--theme-text-light);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.topbar-icon-button:hover {
  background: var(--theme-bg-medium);
}

.topbar-icon-button:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.topbar-icon-button svg {
  width: 22px;
  height: 22px;
}

.topbar-user {
  background: var(--theme-bg-dark);
/*  border: 1px solid var(--theme-border-grey); */
  border: none;
}

.topbar-user svg path {
  fill: var(--theme-text-light);
}

.topbar-menu {
  position: absolute;
  top: calc(100% + 0.6rem);
  left: 0;
  min-width: 220px;
  padding: 0.5rem 0;
  border-radius: 12px;
  border: 1px solid var(--theme-border-grey);
  background: var(--theme-bg-dark);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  z-index: 1100;
  overflow: hidden;
}

/* Right-aligned menu (for user menu) */
.topbar-right .topbar-menu {
  left: auto;
  right: 0;
}

.topbar-menu[hidden] {
  display: none !important;
}

.topbar-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  color: var(--theme-text-light);
  text-decoration: none;
  background: none;
  border: 0;
  cursor: pointer;
  transition: background-color 0.15s ease;
  white-space: nowrap;
}

.topbar-menu-item:hover:not(.is-disabled) {
  background: var(--theme-bg-medium);
}

.topbar-menu-item.is-disabled {
  color: var(--theme-text-muted);
  cursor: not-allowed;
}

.topbar-menu-item.is-disabled .menu-tag {
  background: var(--theme-bg-medium);
  color: var(--theme-text-muted);
}

.menu-tag {
  font-size: 0.7rem;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  background: var(--theme-bg-medium);
  color: var(--theme-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* User menu header (logged-in user info) */
.topbar-menu-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--theme-border-grey);
  background: var(--theme-bg-dark);
}

.user-menu-name {
  font-weight: 600;
  color: var(--theme-text-light);
  margin-bottom: 0.25rem;
}

.user-menu-email {
  font-size: 0.85rem;
  color: var(--theme-text-muted);
}

.topbar-menu-divider {
  height: 1px;
  background: var(--theme-border-grey);
  margin: 0.5rem 0;
}

.topbar-suggest {
  position: absolute;
  top: calc(100% + 0.6rem);
  left: 50%;
  transform: translateX(-50%);
  width: max(100%, 600px);
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--theme-bg-dark);
  border: 1px solid var(--theme-border-grey);
  border-radius: 12px;
  box-shadow: 0 20px 38px rgba(0, 0, 0, 0.3);
  max-height: 320px;
  overflow-y: auto;
  z-index: 1200;
}

.topbar-suggest-item,
.topbar-suggest-status {
  display: grid;
  grid-template-columns: minmax(60px, 0.9fr) 3fr minmax(30px, 0.5fr) minmax(70px, 0.9fr) auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.65rem 1rem;
  font-size: 0.95rem;
}

.topbar-suggest-item {
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.topbar-suggest-item:hover,
.topbar-suggest-item.is-active {
  background: var(--theme-bg-medium);
}

.topbar-suggest-status {
  cursor: default;
  grid-template-columns: 1fr;
  color: var(--theme-text-secondary);
}

.suggest-col {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.suggest-ticker {
  font-weight: 600;
  color: #60a5fa;
}

.suggest-name {
  font-weight: 500;
  color: var(--theme-text-light);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.suggest-currency {
  justify-content: flex-end;
  font-size: 0.85rem;
  color: var(--theme-text-secondary);
}

.suggest-type {
  justify-content: flex-end;
  font-size: 0.85rem;
  color: var(--theme-text-muted);
  text-transform: capitalize;
}

.suggest-actions {
  display: flex;
  gap: 0.375rem;
  justify-content: flex-end;
}

.suggest-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  border: 1px solid var(--theme-border-grey);
  background: var(--theme-bg-medium);
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--theme-text-light);
}

.suggest-action-btn:hover {
  background: var(--theme-bg-light);
  border-color: var(--theme-text-muted);
  color: var(--theme-text-light);
}

.suggest-action-btn:active {
  background: var(--theme-bg-light);
}

.filter-suggestion-item {
  background: var(--theme-bg-medium);
  border-left: 3px solid #3b82f6;
}

.filter-suggestion-item:hover,
.filter-suggestion-item.is-active {
  background: var(--theme-bg-light);
}

.filter-suggestion-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  background: #dbeafe;
  border: 1px solid #93c5fd;
  border-radius: 999px;
  font-weight: 500;
  color: #1e40af;
  font-size: 0.85rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.filter-pill-icon {
  font-size: 1rem;
}

.filter-pill-keyword {
  text-transform: capitalize;
}

.filter-suggestion-hint {
  font-size: 0.8rem;
  color: var(--theme-text-muted);
  font-style: italic;
  padding-right: 1rem;
}

.topbar-suggest::-webkit-scrollbar {
  width: 8px;
}

.topbar-suggest::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.6);
  border-radius: 999px;
}

.topbar-suggest::-webkit-scrollbar-thumb:hover {
  background: rgba(71, 85, 105, 0.6);
}

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .topbar-center {
    order: 3;
    width: 100%;
  }

  .topbar-search {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .topbar-suggest-item,
  .topbar-suggest-status {
    grid-template-columns: minmax(68px, 0.8fr) 2fr minmax(90px, 1fr);
  }

  .suggest-currency {
    display: none;
  }

  .suggest-type {
    justify-content: flex-start;
  }
}

h1, h2 {
  font-weight: 600;
  color: #222;
}

.dashboard {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 2rem;
  display: flex;
  flex-direction: column;
}

/* Portfolio Tab Navigation - Dark Navy Theme */
.portfolio-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--theme-bg-medium);
  margin-bottom: 2rem;
  position: sticky;
  top: 60px; /* Below the topbar */
  background: var(--theme-bg-darkest);
  z-index: 99;
  padding-top: 0.5rem;
}

.portfolio-tab {
  padding: 0.75rem 1.5rem;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  color: var(--theme-text-muted);
  transition: all 0.2s;
  position: relative;
  top: 2px;
}

.portfolio-tab:hover {
  color: var(--theme-text-light);
  background: var(--theme-bg-dark);
}

.portfolio-tab.active {
  color: var(--theme-accent);
  border-bottom-color: var(--theme-accent);
  font-weight: 600;
}

/* Portfolio Section styles */
.portfolio-section {
  margin-bottom: 0; /* Spacing handled by dashboard gap */
  scroll-margin-top: 120px; /* Account for topbar (60px) + tabs (60px) */
}

.section-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  color: var(--theme-text-light);
}

.section-flex {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

@media (min-width: 900px) {
  .section-flex {
    flex-direction: row;
    align-items: flex-start;
  }
}

.pie-chart {
  flex: 1;
  max-width: 400px;
}

.positions-table {
  flex: 2;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  background-color: white;
  box-shadow: 0 0 10px rgba(0,0,0,0.05);
}

thead {
  background-color: #e9ecef;
}

th, td {
  border: 1px solid #c9cdd1;
  text-align: left;
  padding: 0.6rem 0.8rem;
}

tr:hover {
  background-color: #f1f3f5;
}

th {
  font-weight: 600;
}

.currency {
  text-align: right;
  white-space: nowrap;
}

/* Pie chart responsiveness and constraint */
.pie-chart {
    flex: 1;
    max-width: 400px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  
  .pie-chart canvas {
    width: 100% !important;
    height: auto !important;
    max-width: 300px;
    max-height: 300px;
    display: block;
    margin: auto;
  }
  
  /* Make table visually clearer */
  table {
    width: 100%;
    border-collapse: collapse;
/*    background-color: var(--theme-bg-white); */
/*    box-shadow: 0 0 10px rgba(0,0,0,0.05); */
    font-size: 0.95rem;
  }

  thead {
    background-color: var(--theme-sub-table-background);
  }

  th, td {
    border: 1px solid var(--theme-border-grey);
    padding: 0.6rem 0.8rem;
    text-align: left;
    color: var(--theme-text-dark);
  }

  .positions-table th:first-child,
  .positions-table td:first-child {
    text-align: left;
  }

  tr:hover {
    background-color: var(--theme-sub-table-background);
  }
  
  /* Responsive layout */
  .dashboard {
    display: flex;
    flex-direction: column;
  }
  
  .section-flex {
    display: flex;
    flex-direction: column;
    gap: 2rem;
  }
  
  @media (min-width: 900px) {
    .section-flex {
      flex-direction: row;
      align-items: flex-start;
    }
  
    .positions-table {
      flex: 2;
    }
  
    .pie-chart {
      flex: 1;
      max-width: 400px;
      display: flex;
      flex-direction: column; /* 👈 force vertical stacking inside */
      justify-content: flex-start;
      align-items: stretch;
      height: 500px; /* 👈 Increase overall height */
    }
    
    #allocationChart {
      flex: 1;
      height: auto;
    }

    .chart-header {
      display: block;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 1rem;
      gap: 1rem;
    }
    
    .chart-header h2 {
      margin: 0;
      font-size: 1.2rem;
    }
    
    .chart-header label {
      font-weight: 500;
      font-size: 0.95rem;
    }
    
    .chart-header select {
      padding: 4px 6px;
      font-size: 0.95rem;
      margin-left: 0.5rem;
    }

    .chart-wrapper {
      position: relative;
      width: 100%;
      max-height: 500px;
    }
    
    .chart-loading-overlay {
      position: absolute;
      top: 0;
      left: 0;
      z-index: 10;
      width: 100%;
      height: 100%;
      background-color: rgba(255, 255, 255, 0.7); /* translucent white */
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      pointer-events: none;
    }
    

    .line-chart {
      background-color: var(--theme-bg-white);
      padding: 1.5rem;
      border: 1px solid var(--theme-border-grey);
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
      border-radius: 8px;
      margin-bottom: 2rem;
      width: 100%;
      max-width: 1000px; /* ✅ Limit max width */
      margin-left: auto;
      margin-right: auto;
    }
    
    
    .line-chart h2 {
      margin-top: 0;
      font-size: 1.2rem;
      font-weight: 600;
      margin-bottom: 1rem;
    }
    
    #line-chart,
    #performanceChart,
    #dividendChart,
    #returnChart,
    #portfolioChart {
/*      width: 100% !important; */
/*      height: 100% !important; */
      max-height: 800px;
    }

    #dividendChart,
    #returnChart {
      display: none;
    }
    
    .line-chart-container {
      width: 100%;
      max-width: 1000px;
      height: 600px; /* ✅ LOCK THIS HEIGHT */
      margin: 0 auto;
    }

    .chart-toggle-controls {
      display: flex;
      justify-content: space-between;
      align-items: center;
      flex-wrap: wrap;
      margin-bottom: 1rem;
    }
    
    .chart-toggle-controls .chart-left-controls,
    .chart-toggle-controls .chart-right-controls {
      display: flex;
      gap: 0.5rem;
    }
    
    .chart-toggle-controls button {
      font-size: 0.9rem;
      padding: 6px 10px;
      border: 1px solid var(--theme-border-grey);
      background-color: var(--theme-sub-table-background);
      cursor: pointer;
      border-radius: 4px;
      line-height: 1.2;
      min-height: 32px;
      vertical-align: middle;
      transition: background-color 0.2s;
    }

    .chart-button {
      font-size: 0.9rem;
      padding: 6px 10px;
      border: 1px solid var(--theme-border-grey);
      background-color: var(--theme-sub-table-background);
      cursor: pointer;
      border-radius: 4px;
      line-height: 1.2;
      min-height: 32px;
      vertical-align: middle;
      transition: background-color 0.2s;
      color: var(--theme-text-dark);
    }

    .chart-button:hover {
      background-color: var(--theme-border-grey);
    }

    .chart-button.is-active {
      background-color: var(--theme-bg-darkest);
      border-color: var(--theme-bg-darkest);
      color: var(--theme-text-light);
      box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
    }

    /* Subtle zoom preset buttons (matching datasheet style) */
    .zoom-preset-btn {
      padding: 0.25rem 0.75rem;
      border: 1px solid var(--theme-border-grey);
      background: var(--theme-bg-white);
      border-radius: 4px;
      cursor: pointer;
      font-size: 0.75rem;
      font-weight: 500;
      color: var(--theme-text-secondary);
      transition: all 0.2s;
      line-height: 1.2;
      min-height: 28px;
    }

    .zoom-preset-btn:hover {
      background: var(--theme-sub-table-background);
      border-color: var(--theme-border-grey);
      color: var(--theme-text-dark);
    }

    .zoom-preset-btn.active,
    .zoom-preset-btn.is-active,
    .zoom-preset-btn[aria-pressed="true"] {
      background: var(--theme-bg-darkest);
      border-color: var(--theme-bg-darkest);
      color: var(--theme-text-light);
    }

    /* Date inputs matching zoom button style */
    .zoom-date-input {
      padding: 0.25rem 0.5rem;
      border: 1px solid var(--theme-border-grey);
      background: var(--theme-bg-white);
      border-radius: 4px;
      font-size: 0.75rem;
      color: var(--theme-text-secondary);
      transition: all 0.2s;
      line-height: 1.2;
      height: 28px;
      box-sizing: border-box;
      vertical-align: middle;
    }

    .zoom-date-input:hover {
      border-color: var(--theme-border-grey);
    }

    .zoom-date-input:focus {
      outline: none;
      border-color: var(--theme-accent);
      box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
    }

    /* Chart Type dropdown */
    .chart-type-control { display: inline-flex; align-items: center; gap: .5rem; }
    .chart-type-label { font-size: .9rem; opacity: .85; }
    .chart-type-select-wrap { position: relative; }
    .chart-type-select {
      height: var(--pf-h, 38px);
      padding: 2px .6rem;
      border: 1px solid var(--theme-border-grey);
      background: var(--theme-sub-table-background);
      color: var(--theme-text-dark);
      border-radius: .5rem;
    }
    .chart-type-select:focus { outline: 2px solid var(--theme-accent); outline-offset: 1px; }

    /* Default hover for inactive buttons */
    .chart-toggle-controls button:hover {
      background-color: var(--theme-border-grey);
    }

    /* Active button style */
    .chart-toggle-controls button.active {
      background-color: var(--theme-bg-darkest);
      color: var(--theme-text-light);
      border-color: var(--theme-bg-darkest);
    }
    
    /* Hover on active button → light blue */
    .chart-toggle-controls button.active:hover {
      background-color: rgb(85, 86, 87);
    }

    /* Chart panel tweaks (reuses filters-panel look) */
    .chart-panel .filters-body {
      padding-top: 0.5rem;
    }

    /* Give Chart.js a sized, responsive container */
    .chart-canvas-wrap {
      width: min(100%, 1000px);
      margin: 0 auto;          /* center */
    }

    /* Let Chart.js control height from aspectRatio; don't stretch */
    .chart-canvas-wrap > canvas {
      width: 100% !important;
      height: auto !important;
    }

    .spinner {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      color: var(--theme-text-secondary);
      font-size: 0.95rem;
      margin-bottom: 1rem;
    }

    .spinner-dot {
      width: 10px;
      height: 10px;
      border: 2px solid var(--theme-border-grey);
      border-top: 2px solid var(--theme-accent);
      border-radius: 50%;
      animation: spin 0.6s linear infinite;
    }

    .chart-loading-overlay {
      position: absolute;
      top: 60px;
      left: 0;
      width: 100%;
      height: 500px;
      background: rgba(255, 255, 255, 0.85);
      z-index: 10;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      font-size: 1rem;
      color: var(--theme-text-dark);
      pointer-events: none;
    }

    .spinner-dot {
      width: 16px;
      height: 16px;
      border: 3px solid var(--theme-border-grey);
      border-top: 3px solid var(--theme-accent);
      border-radius: 50%;
      margin-bottom: 0.5rem;
      animation: spin 0.8s linear infinite;
    }
    
    @keyframes spin {
      to {
        transform: rotate(360deg);
      }
    }
    
    
    @keyframes spin {
      to {
        transform: rotate(360deg);
      }
    }

    #instrumentTable tbody tr {
      cursor: pointer;
    }

    /* Disable the generic tr:hover for instrument table */
    #instrumentTable tbody tr:hover {
      background-color: transparent;
    }

    /* When hovering over non-select cell, highlight all sibling non-select cells in that row */
    #instrumentTable tbody tr:has(td:not(.instrument-select-cell):hover) td:not(.instrument-select-cell) {
      background-color: var(--theme-sub-table-background);
    }

    /* Highlight select cell only when hovering directly over it */
    #instrumentTable tbody tr td.instrument-select-cell:hover {
      background-color: var(--theme-sub-table-background);
    }

    .filter-section {
      border: none;
      padding: 0.5rem;
      margin-bottom: 1rem;
      border-radius: 6px;
      background-color: var(--theme-bg-medium);
    }
    
    .filter-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      cursor: pointer;
      font-weight: bold;
      margin-bottom: 0.5rem;
    }
    
    .filter-content {
      display: none;
      padding-top: 0.5rem;
    }

    .filter-row {
      display: flex;
      gap: 1rem;
      flex-wrap: wrap;
      align-items: flex-end;
      margin-bottom: 1rem;
    }
    
    .filter-group {
      display: flex;
      flex-direction: column;
      flex: 1;
      min-width: 200px;
    }

    .filter-numbers {
      display: flex;
      flex-direction: column;
      gap: 0.5rem;
      margin-bottom: 1rem;
    }
    
    .filter-numbers-header {
      display: grid;
      grid-template-columns: 1fr 1fr 1fr;
      font-weight: bold;
      padding-left: 0.2rem;
    }
    
    .filter-number-row {
      display: grid;
      grid-template-columns: 1fr 1fr 1fr;
      gap: 0.5rem;
      align-items: center;
    }
    .filter-number-row label {
      white-space: nowrap;
    } 
    
    
    .numeric-filter {
      display: flex;
      flex-direction: column;
      gap: 0.4rem;
      margin: 0.6rem 0 1.0rem 0;
    }
    
    .numeric-filter > label {
      font-weight: 600;
      color: var(--theme-text-dark);
    }
    
    .numeric-filter .noUi-target {
      margin: 0.25rem 1rem 0.5rem 1rem; /* top right bottom left */
      max-width: none; /* ensures space on both sides */
    }
    
    .numeric-readout input {
      width: 7rem;
      padding: 0.3rem 0.4rem;
      font-size: 0.95rem;
      margin-right: 0.25rem;
    }
    
    
}



/* Pale look when a numeric slider is effectively "not active" */
.numeric-filter.inactive > label {
  color: var(--theme-text-secondary);
  font-weight: 500;
}

.numeric-filter.inactive .noUi-target {
  background: var(--theme-sub-table-background);
  border-color: var(--theme-border-grey);
}

.numeric-filter.inactive .noUi-connect {
  background: var(--theme-border-grey);
}

.numeric-filter.inactive .noUi-handle {
  background: var(--theme-sub-table-background);
  border: 1px solid var(--theme-border-grey);
  box-shadow: none;
}

/* Tunables for alignment */
:root{
  --filter-label-w: 220px;   /* width of the text label column */
  --filter-select-w: 280px;    /* width of the dropdowns */
  --filter-number-w: 7.5rem; /* width of the min/max inputs */
  --slider-gutter: 17px;     /* half handle width, keeps gaps symmetric */
}

/* Inline row: fixed label | fixed min | fluid slider | fixed max | Reset */
.numeric-filter .numeric-row{
  display: grid;
  grid-template-columns: var(--filter-label-w) var(--filter-number-w) 1fr var(--filter-number-w) auto;
  column-gap: 0.8rem;
  align-items: center;
}

/* Label: right-align so all min boxes start at the same x-position */
.numeric-filter .numeric-row label{
  justify-self: start;
  text-align: left;      /* ensure left alignment */
  white-space: nowrap;
  overflow: hidden;          /* optional, in case a label is too long */
  text-overflow: ellipsis;   /* optional */
}

/* Slider cell: equal gutters so track sits centered between inputs */
.numeric-filter .numeric-row .slider-cell{
  padding: 0 var(--slider-gutter);
}

.numeric-filter .numeric-row .slider-inline {
  width: 100%;   /* no margins needed */
 }

/* Keep the slider full-width within the padded cell */
.numeric-filter .numeric-row .slider-inline.noUi-target {
  margin: 0;
  width: 100%;
}

/* Inputs: identical widths */
.numeric-filter .numeric-row input[type="number"]{
  width: var(--filter-number-w);
  box-sizing: border-box;
  text-align: right;
  padding-right: 0.5rem;
}

/* Make the embedded noUi slider behave nicely in-row */
.numeric-filter .numeric-row .noUi-target {
  margin: 0;           /* override previous margin */
  width: 100%;
  max-width: none;    /* override previous max-width */
}

/* Inputs align neatly; max box naturally sits near the right */
.numeric-filter .numeric-row input[type="number"] {
  width: 7.5rem;
  text-align: center;
  padding: 6px 10px;
  border: 1px solid var(--theme-border-grey);
  background-color: var(--theme-bg-dark);
  border-radius: 4px;
  font-size: 0.9rem;
  min-height: 32px;
  box-sizing: border-box;
  color: var(--theme-text-light);
}

/* Remove increment arrows from number inputs in filters */
.numeric-filter .numeric-row input[type="number"]::-webkit-inner-spin-button,
.numeric-filter .numeric-row input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.numeric-filter .numeric-row input[type="number"] {
  -moz-appearance: textfield;
}

/* Focus state for filter inputs */
.numeric-filter .numeric-row input[type="number"]:focus {
  outline: none;
  border-color: var(--theme-accent);
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

/* (Optional) on narrow screens, fall back to stacked if you like */
@media (max-width: 899px){
  .numeric-filter .numeric-row{
    grid-template-columns: 1fr;  /* stack */
    row-gap: 0.4rem;
  }

  .numeric-filter .numeric-row label{
    justify-self: start;
  }

  .filters-header {
    flex-wrap: wrap;
  }
  .filters-header-right {
    width: 100%;
  }
  .search-input-header {
    width: 100%;
    flex: 1;
  }
  .filters-panel.search-panel .filters-header {
    flex-wrap: wrap;
  }
  .filters-panel.search-panel .filters-header-right {
    width: 100%;
  }
  .search-input-header {
    width: 100%;
    flex: 1;
  }
  
}

/* Keep the Reset button tight to the right edge of the row */
.numeric-filter .numeric-row .chart-button {
  justify-self: end;
  white-space: nowrap;
}

/* Pale/inactive state should affect the label too (we moved label inside the row) */
.numeric-filter.inactive .numeric-row label {
  color: var(--theme-text-muted);
  font-weight: 500;
}

/* (Optional) tighter row spacing now that it's inline */
.numeric-filter {
  margin: 0.6rem 0 0.8rem 0;
}

/* If you previously had this, it’s now overridden by the rule above: 
   .numeric-filter .noUi-target { margin: 0.25rem 1rem 0.5rem 1rem; max-width: calc(100% - 3rem); } 
*/

/* One filter per row: Label (fixed) | Select (fixed) */
.inline-filter-row{
  display: grid;
  grid-template-columns: var(--filter-label-w) var(--filter-select-w);
  column-gap: 0.8rem;
  align-items: center;
  margin: 0.5rem 0;
}

/* Match label look/spacing to slider labels */
.inline-filter-row > label{
  justify-self: start;       /* left-justify */
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;          /* same visual weight as your numeric labels */
  color: var(--theme-text-dark);
}

/* Keep selects a fixed, tidy width (don’t stretch full line) */
.inline-filter-row > select{
  width: var(--filter-select-w);
  max-width: 100%;
}

/* Make this container stack its children vertically (one filter per line) */
.filter-row.stack{
  display: block;            /* override your default flex row */
}



/* ---- sortable table headers ---- */
th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.sortable .sort-ind {
  display: inline-block;
  margin-left: 6px;
  opacity: 0.6;
  font-size: 0.85em;
}
th.sortable[data-dir="desc"] .sort-ind::after { content: "▼"; }
th.sortable[data-dir="asc"]  .sort-ind::after { content: "▲"; }

/* Column select dropdown */
#columnMenu.column-menu,
#plotListColumnMenu.column-menu {
    background: var(--theme-bg-white);
    border: 1px solid var(--theme-border-grey);
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.12);
    padding: 0.75rem;
    min-width: 220px;
    z-index: 1000;
  }
  .column-menu-title {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--theme-text-dark);
  }
  .column-menu-list {
    max-height: 260px;
    overflow: auto;
    padding-right: 0.25rem;
  }
  .column-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0;
    color: var(--theme-text-dark);
  }
  .column-menu-item label {
    color: var(--theme-text-dark);
  }
  .column-menu-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 0.5rem;
  }

  /* Outer panel that visually wraps the whole Filters area */
.filters-panel{
  border: 1px solid var(--theme-border-grey);
  border-radius: 10px;
  background: var(--theme-bg-darkest);
  padding: 1rem;
  box-shadow: 0 6px 18px rgba(0,0,0,0.06);
  margin-bottom: 1.25rem;
}

.filters-header {
  color: var(--theme-text-dark);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

/* Text Search panel: keep controls next to the heading on the left */
.filters-panel.search-panel .filters-header {
  justify-content: flex-start;          /* 👈 key change */
  gap: 0.75rem;                         /* space between h3 and controls */
}

.filters-header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.filters-header h3{
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.filters-subtext{
  margin: 0 0 0.75rem 0;
  font-size: 0.9rem;
  color: var(--theme-text-secondary);
}

.filters-body{
  display: block;
}

/* Add space under the Filters header */
.filters-panel .filters-header {
  margin-bottom: 0.75rem;   /* tweak: .5–1rem */
}

/* Make search panel look/behave like the filters panel */
.search-input {
  width: 100%;
  max-width: 420px;   /* tweak to taste */
}

/* Nice, responsive width for the input */
.search-input-header {
  width: clamp(220px, 28vw, 420px);
  /* make height match your .chart-button nicely */
  padding: 0.4rem 0.55rem;
  line-height: 1.2;
}

/* A11y helper so label exists but stays invisible */
.visually-hidden {
  position: absolute !important;
  height: 1px; width: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); overflow: hidden;
}

/* Anchor overlay to the actual chart container */
.chart-canvas-wrap {
  position: relative;                 /* key: make it the positioning context */
}

/* Make the overlay exactly cover the chart area */
.chart-canvas-wrap > .chart-loading-overlay {
  position: absolute;
  inset: 0;                           /* top/right/bottom/left: 0 */
  width: 100%;
  height: 100%;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.75);
  pointer-events: none;
}

/* (Optional) neutralize the old fixed offsets if they still exist earlier */
.chart-loading-overlay {
  top: 0 !important;
  left: 0 !important;
  height: 100% !important;
}

.is-hidden { display: none !important; }

/* Kill the inner box if a .filters-panel accidentally gets nested */
.filters-panel .filters-panel {
  border: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
  padding: 0 !important;
  margin: 0 !important;
}

/* Row for custom date zoom controls */
.custom-zoom-row {
  margin: .5rem 0 .75rem;
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  flex-wrap: wrap;
}

/* --- Portfolio Builder --- */
#portfolioBuilder.is-hidden { display: none; }
#portfolioBuilder .portfolio-controls {
  display:flex; gap:.75rem; flex-wrap:wrap; align-items:center; margin-bottom:.5rem;
}

#portfolioTable { 
  table-layout: fixed;
  width:auto; 
  border-collapse: collapse; 
}

#portfolioTable th, #portfolioTable td { padding:.4rem .5rem; border:none; border-bottom:1px solid var(--theme-border-grey); }
#portfolioTable tfoot td { font-weight:600; }
/* Make dividers win over the base table borders */
#portfolioTable th.pf-divider,
#portfolioTable td.pf-divider{
  border-top: 1px solid var(--pf-divider);
  border-bottom: 1px solid var(--pf-divider);
}
.weight-input { width: 6rem; text-align:right; }
.weight-error { color:#b91c1c; font-weight:600; }

/* --- Weighting dropdown --- */
.menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: .35rem;
  min-width: 220px;
  background: var(--theme-bg-dark);
  border: 1px solid var(--theme-border-grey);
  border-radius: .5rem;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
  padding: .25rem;
  z-index: 50;
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: .5rem .75rem;
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: .4rem;
  font: inherit;
  color: var(--theme-text-light);
}
.menu-item:hover, .menu-item:focus {
  background: var(--theme-bg-medium);
  outline: none;
}
.menu-sep {
  height: 1px;
  background: var(--theme-border-grey);
  margin: .25rem 0;
}

  /* Name conflict modal */
  #nameConflictBackdrop{
    position: fixed;
    inset: 0;
    display: none;             /* default hidden */
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,.6);
    z-index: 10000;
  }
  #nameConflictBackdrop.show{
    display: flex;             /* toggle visible */
  }
  #nameConflictDialog{
    width: min(480px, 92vw);
    background: var(--theme-bg-dark);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,.4);
    padding: 16px 18px;
    color: var(--theme-text-light);
    border: 1px solid var(--theme-border-grey);
  }

  /* Generic modal */
  #uiModalBackdrop{
    position:fixed; inset:0; display:none; align-items:center; justify-content:center;
    background:rgba(0,0,0,.6); z-index:10000;
  }
  #uiModalBackdrop.show{ display:flex; }
  #uiModalBox{
    width:min(520px,92vw); background:var(--theme-bg-darkest); border-radius:12px;
    box-shadow:0 10px 40px rgba(0,0,0,.4);
    padding:16px 18px; border:1px solid var(--theme-border-grey);
    font-family: inherit;
  }
  #uiModalTitle{ margin:0 0 .5rem; font-weight:600; color: var(--theme-text-light); }
  #uiModalMsg{ margin:.25rem 0 .75rem; color:var(--theme-text-light); }
  #uiModalInput{ width:100%; padding:.5rem; border:1px solid var(--theme-border-grey); border-radius:.5rem; margin-top:.25rem; color: var(--theme-text-light); background: var(--theme-bg-dark); }
  #uiModalActions{ display:flex; gap:.5rem; justify-content:flex-end; margin-top:1rem; }
  #uiModalActions .chart-button{ min-width:96px; }
  #uiModalActions .btn{ min-width:96px; }

    /* Portfolio builder layout polish */
  .pf-section-cell { background:var(--theme-bg-dark); font-weight:600; text-align:right; }
  .pf-section-label {
    text-align:right;
    border: none;
  }
  .pf-subsection { background:var(--theme-bg-dark); text-align:center; font-weight:600; }
  .pf-row-label {
    font-weight:600;
    text-align:right;
    border: none;
  }
  .pf-name-input { width:100%; }

  .pf-select, .pf-num { width:100%; box-sizing:border-box; }
  .pf-th-center { text-align:center; }

  .pf-weight-cell { text-align:center; }
  .pf-weight-input { text-align:center; width:6.2rem; }

  .pf-total-label { text-align:right; font-weight:600; }
  .pf-total { text-align:center; cursor:pointer; }

  /* Doughnut chart cells */
  .pf-chart-cell {
    padding: 1rem;
    text-align: center;
    vertical-align: top;
  }

  .pf-doughnut-chart {
    max-width: 200px;
    max-height: 200px;
    margin: 0 auto;
  }
  /* Dynamic portfolio columns (one per portfolio) */
  .pf-left {
    width: 300px;  /* Accommodates delete button + color chip + name column */
    min-width: 300px;
  }

  /* Ensure both tables sync row heights properly */
  .pf-left th,
  .pf-left td,
  .pf-right th,
  .pf-right td {
    vertical-align: middle;
    box-sizing: border-box;
  }
  
  .pf-col-instrument {
    width: 30%;
  }
  .pf-col-name {
    width: 65%;
  }

  /* Color chip column */
  .pf-col-color {
    width: 40px;
    text-align: center;
    vertical-align: middle;
    padding: 0.5rem;
    border-left: 1px solid var(--theme-border-grey);
    border-right: 1px solid var(--theme-border-grey);
  }

  /* Combined name column */
  .pf-col-name-combined {
    width: 95%;
    max-width: 210px;
    padding: 0.5rem;
    border-left: 1px solid var(--theme-border-grey);
    border-right: 1px solid var(--theme-border-grey);
  }

  .pf-name-container {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .pf-name-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .pf-col-name-combined.expanded .pf-name-text {
    white-space: normal;
    word-break: break-word;
  }

  .pf-name-toggle {
    flex-shrink: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--theme-text-secondary);
    transition: color 0.2s, transform 0.2s;
  }

  .pf-name-toggle:hover {
    color: #374151;
  }

  .pf-col-name-combined.expanded .pf-name-toggle svg {
    transform: rotate(180deg);
  }

  /* Narrow delete column with a red ×; whole cell is clickable */
  .pf-col-remove {
    width: 5%;
    text-align: center;
    cursor: pointer;
    border-left: 1px solid var(--theme-border-grey);
    border-right: 1px solid var(--theme-border-grey);
  }

  /* Ensure remove header has same border as color/name dividers */
  .pf-col-remove.pf-divider {
    border-top: 1px solid var(--pf-divider);
    border-bottom: 1px solid var(--pf-divider);
  }
  .pf-col-remove .pf-x {
    display: inline-block;
    background: var(--theme-bg-dark);
    border-radius: 6px;
    width: 28px;
    height: 28px;
    line-height: 28px;
    font-weight: 700;
    pointer-events: none;     /* so clicks land on the cell */
    font-size: 16px;
    transition: background 0.2s;
    color: var(--theme-text-light);
  }
  .pf-col-remove:hover .pf-x { background: var(--theme-bg-medium); }

  .pf-col {
    width: 240px;          /* 👈 tweak to taste (240–300px works well) */
    min-width: 220px;
    max-width: 280px;
    border-left: 1px solid var(--theme-border-grey);
    border-right: 1px solid var(--theme-border-grey);
  }

  /* Keep inputs tidy inside fixed-width columns */
  .pf-name-input,
  .pf-select,
  .pf-num,
  .pf-weight-input {
    width: 100%;
    box-sizing: border-box;
  }
  /* If many portfolios, allow horizontal scroll rather than squashing */
  .portfolio-table-wrap {
    overflow-x: auto;
  }
  .weight-error { color:#d32f2f; font-weight:600; }

/* --- Portfolio builder control baseline ------------------------------ */
:root{
  --pf-font-size: 14px;          /* tweak to taste */
  --pf-font-family: inherit;     /* or something like ui-sans-serif, system-ui */
  --pf-h: 38px;                  /* control height */
  --pf-pad-x: 10px;
  --pf-pad-y: 6px;
  --pf-border: var(--theme-border-grey);
  --pf-border-focus: var(--theme-accent);
  --pf-bg: var(--theme-bg-dark);
  --pf-radius: 6px;
  --pf-shadow-focus: 0 0 0 3px rgba(102, 126, 234, 0.15);
  --pf-divider: var(--theme-border-grey);
  --pf-radius: .5rem;
  --pf-icon-size: 30px;
  --pf-pill-pad: 4px;
}

/* Apply a consistent baseline to all builder inputs/selects */
.pf-name-input,
.pf-select,
.pf-num,
.pf-weight-input{
  font-family: var(--pf-font-family);
  font-size: var(--pf-font-size);
  line-height: 1.2;
  height: var(--pf-h);
  padding: var(--pf-pad-y) var(--pf-pad-x);
  border: 1px solid var(--pf-border);
  border-radius: var(--pf-radius);
  background: var(--pf-bg);
  color: inherit;
  box-sizing: border-box;
}

.pf-divider{
  border-top: 1px solid var(--pf-divider);
  border-bottom: 1px solid var(--pf-divider);
}

.pf-divider-dead{
  border: none;
  border-top: 1px solid var(--pf-divider);
  border-bottom: 1px solid var(--pf-divider);
}

/* Focus state */
.pf-name-input:focus,
.pf-select:focus,
.pf-num:focus,
.pf-weight-input:focus{
  outline: none;
  border-color: var(--pf-border-focus);
  box-shadow: var(--pf-shadow-focus);
}

/* Disabled state (if used) */
.pf-name-input:disabled,
.pf-select:disabled,
.pf-num:disabled,
.pf-weight-input:disabled{
  opacity: .65;
  cursor: not-allowed;
}

/* Control-specific tweaks */
.pf-weight-input{ text-align: center; }  /* weights centered */
.pf-num{ text-align: left; }             /* drift band left (or center if preferred) */

/* Make selects match input height visually; leave room for arrow */
.pf-select{
  padding-right: calc(var(--pf-pad-x) + 18px);
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    right 12px center,
    right 6px center;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

/* Remove number spinners for a cleaner, consistent look */
.pf-num::-webkit-outer-spin-button,
.pf-num::-webkit-inner-spin-button,
.pf-weight-input::-webkit-outer-spin-button,
.pf-weight-input::-webkit-inner-spin-button{
  -webkit-appearance: none; margin: 0;
}
.pf-num[type=number],
.pf-weight-input[type=number]{ -moz-appearance: textfield; }

/* Make the whole cell clickable without affecting row height */
.pf-select-cell {
  position: relative;               /* anchor the overlay */
}

.pf-select-input {
  position: relative;
  z-index: 2;                       /* keep the real checkbox on top for focus */
  margin: 0;                        /* align neatly in the cell */
}

.pf-select-hit {
  position: absolute;
  inset: 0;                         /* cover entire cell */
  z-index: 1;                       /* sits behind the checkbox */
  cursor: pointer;
  display: block;                   /* no min-height; take the cell’s natural height */
  /* padding inherits naturally from the <th>, so visual height stays consistent */
}



/* --- Add-Instrument row --------------------------------------------------- */
.pf-add-row .pf-add-cell {
  padding: .4rem .5rem;
}

.pf-add-wrap {
  position: relative;
}

.pf-add-input {
  width: 100%;
  box-sizing: border-box;
  padding: .45rem .6rem;
  border: 1px solid var(--pf-border);
  border-radius: .5rem;
  background: var(--theme-bg-dark);
  color: var(--theme-text-light);
  font-size: 0.95rem;
}

.pf-suggest-list {
  position: fixed !important;         /* attach to viewport instead of scroll box */
  left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px 0;
  list-style: none;
  background: var(--theme-bg-dark);
  border: 1px solid var(--theme-border-grey);
  border-radius: .5rem;
  max-height: 280px;
  overflow: auto;
  overflow-y: auto;
  z-index: 3000 !important;           /* above all menus */
  color: var(--theme-text-light);
}

/* Mirrors .topbar-suggest-item grid so portfolio / optimizer search look
   identical to the top-bar global search — ticker | name | currency | type.
   Actions column from the top-bar version is omitted; this picker is a
   single-purpose "pick one to add", no secondary actions needed. */
.pf-suggest-item {
  display: grid;
  grid-template-columns: minmax(60px, 0.9fr) 3fr minmax(30px, 0.5fr) minmax(70px, 0.9fr);
  gap: 0.75rem;
  align-items: center;
  padding: 0.55rem 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  font-size: 0.95rem;
}
.pf-suggest-item:hover,
.pf-suggest-item[aria-selected="true"] {
  background: var(--theme-bg-medium);
}

.pf-suggest-ticker {
  font-weight: 700;
  letter-spacing: .2px;
  color: #60a5fa;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pf-suggest-name {
  font-weight: 500;
  color: var(--theme-text-light);
  overflow: hidden;
  text-overflow: ellipsis;
}

.pf-suggest-ccy {
  justify-content: flex-end;
  font-size: 0.85rem;
  color: var(--theme-text-secondary);
  font-variant: all-small-caps;
  letter-spacing: .3px;
}

.pf-suggest-type {
  display: inline-flex;
  justify-content: flex-end;
  font-size: 0.85rem;
  color: var(--theme-text-muted);
  text-transform: capitalize;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Distinct badge-like colour for Collections so users can pick them out
   at a glance in a mixed list of stocks/ETFs/funds. */
.pf-suggest-type[data-type="collection"],
.suggest-type[data-type="collection"] {
  color: var(--theme-positive);
  font-weight: 600;
}

/* Make the Add-Instrument search box use the same focus styling */
.pf-add-input {
  border: 1px solid var(--pf-border);        /* align with other controls */
  background: var(--pf-bg);
  color: var(--theme-text-light);
}

.pf-add-input:focus {
  outline: none;
  border-color: var(--pf-border-focus);
  box-shadow: var(--pf-shadow-focus);
}

.controls-sep {
  width: 1px;
  height: 28px;
  background: var(--pf-border, #2a2a2a);
  margin: 0 .5rem;
}

.selected-controls {
  display: inline-flex;
  gap: .5rem;
  align-items: center;
}

.saved-controls {
  display: inline-flex;
  gap: .5rem;
  align-items: center;
}

/* Put saved controls on their own row above the builder controls */
#portfolioBuilder .portfolio-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
}

/* Move saved-controls to the top and make it span the full row */
#portfolioBuilder .portfolio-controls .saved-controls {
  order: -1;            /* appear before the other buttons */
  flex-basis: 100%;     /* take a whole line */
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
  margin-bottom: .25rem; /* tiny spacing to the row below */
}

/* Keep the select a sensible width */
#portfolioBuilder .saved-controls #savedPfSelect {
  min-width: 260px;
}
/* Put the hint line between saved-controls (top) and the buttons row */
#portfolioBuilder .portfolio-controls .filters-subtext {
  order: 0;              /* after saved-controls (which is -1) */
  flex-basis: 100%;      /* take a full line */
  margin: .125rem 0 .25rem;
}

/* Make the action buttons/separator/selected-controls come after the hint */
#portfolioBuilder .portfolio-controls > button,
#portfolioBuilder .portfolio-controls > .controls-sep,
#portfolioBuilder .portfolio-controls > .selected-controls {
  order: 1;
}

/* Guarantee left alignment for the buttons row */
#portfolioBuilder .portfolio-controls {
  justify-content: flex-start;   /* explicit left-justify */
}

/* Ensure the two buttons are the first items on that row */
#portfolioBuilder .portfolio-controls #btnAddPortfolio,
#portfolioBuilder .portfolio-controls #btnClearBuilder {
  order: 1;
}

/* Make the rest of the row (separator + selected-controls) come after */
#portfolioBuilder .portfolio-controls .controls-sep,
#portfolioBuilder .portfolio-controls .selected-controls {
  order: 2;
}

/* (Optional) If you want the right-hand group pushed to the far right: */
/* #portfolioBuilder .portfolio-controls .selected-controls {
  margin-left: auto;
} */


/* Keep totals/× column alignment you added earlier */
#portfolioTable th.pf-col-remove,
#portfolioTable td.pf-col-remove { text-align:center; }
#portfolioTable tfoot td.pf-total-label { text-align:right; }
#portfolioTable tfoot tr > td.pf-total-label:first-child { text-align:right; }

/* Portfolio Builder sub-boxes use the same look as filter sections */
#portfolioBuilder .filter-section { margin-bottom: 1rem; }
#portfolioBuilder .filter-section .filter-content { display: block; } /* keep open */
#portfolioBuilder .filter-section .filter-header { margin-bottom: .35rem; }

/* Ensure the controls row remains left-justified */
#portfolioBuilder .portfolio-controls { justify-content: flex-start; }

/* Make sure the table is inside a scrollable wrapper */
#portfolioBuilder .portfolio-table-wrap { overflow-x: auto; }

#portfolioBuilder .portfolio-table-wrap {
  display: flex;
  gap: 0;
  overflow: hidden; /* horizontal scroll only on the right pane */
}

#portfolioBuilder .pf-freeze {
  flex: 0 0 auto;
  overflow: hidden;
  border-right: none;
  background: var(--panel-bg, transparent);
  /* width: 454px;  tweak to fit your name column */
}

#portfolioBuilder .pf-scroll {
  flex: 1 1 auto;
  overflow-x: auto;
  overflow-y: visible;
}

#portfolioBuilder .portfolio-table {
  border-collapse: collapse;
  border-spacing: 0;
  table-layout: fixed;
  width: auto;
  border-top: 1px solid var(--theme-border-grey);
  border-left: 1px solid var(--theme-border-grey);
}

#portfolioBuilder .portfolio-table th,
#portfolioBuilder .portfolio-table td {
  white-space: nowrap;
  padding: 8px 10px;
  line-height: 1.25;
  height: 38px;
  border: none;
  border-bottom: 1px solid var(--theme-border-grey);
  background: var(--theme-bg-darkest);
  color: var(--theme-text-light);
}

#portfolioBuilder .portfolio-table thead th {
  background: var(--theme-bg-darkest);
  font-weight: 600;
}

/* Column header row (X, Name, Weights %) - slightly lighter background */
#portfolioBuilder .portfolio-table thead tr.pf-column-header-row th {
  background: var(--theme-bg-dark);
}

/* Restore right borders on portfolio columns (left comes from previous column's right border) */
#portfolioBuilder .portfolio-table th.pf-col,
#portfolioBuilder .portfolio-table td.pf-col {
  border-left: none;
  border-right: 1px solid var(--theme-border-grey);
}

/* Remove column - no left border (it's the leftmost visible column) */
#portfolioBuilder .portfolio-table th.pf-col-remove,
#portfolioBuilder .portfolio-table td.pf-col-remove {
  border-left: none;
  border-right: 1px solid var(--theme-border-grey);
}

/* Color and name columns */
#portfolioBuilder .portfolio-table th.pf-col-color,
#portfolioBuilder .portfolio-table td.pf-col-color,
#portfolioBuilder .portfolio-table th.pf-col-name-combined,
#portfolioBuilder .portfolio-table td.pf-col-name-combined {
  border-left: 1px solid var(--theme-border-grey);
  border-right: 1px solid var(--theme-border-grey);
}

#portfolioBuilder .pf-col-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

#pf-add-suggest.pf-suggest-list { position: fixed !important; z-index: 3000 !important; }

#portfolioBuilder .pf-left thead th.pf-dead,
#portfolioBuilder .pf-left tbody td.pf-dead {
  border: none !important;
  border-bottom: 1px solid var(--theme-border-grey) !important;
  background: var(--theme-bg-darkest) !important;
  box-shadow: none !important;
}


/* === Per-column weighting menu (pops from Total cell) === */
.pf-total-menu {
  position: fixed;                /* escape scroll containers */
  z-index: 3001;                  /* above tables and suggests */
  min-width: 180px;
  max-width: 260px;
  background: var(--theme-bg-dark);
  color: var(--theme-text-light);
  border: 1px solid var(--theme-border-grey);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  padding: 6px 0;
  display: none;                  /* default hidden */
}
.pf-total-menu.open { display: block; }

.pf-total-menu button {
  display: block;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: var(--theme-text-light);
}
.pf-total-menu button:hover { background: var(--theme-bg-medium); }

/* Make the total cell look “actionable” */
.pf-total[data-has-menu="1"] {
  position: relative;
  cursor: pointer;
}
.pf-total[data-has-menu="1"]::after {
  content: "▾";
  font-size: .9em;
  padding-left: .4em;
  opacity: .7;
}

/* Portfolio Builder panel - remove border since header provides visual container */
#portfolioBuilder.filters-panel {
  border: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  overflow: hidden;  /* ensure header corners clip properly */
}

/* Portfolio Builder header bar (matches comparison chart style) */
.pf-builder-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--theme-bg-darkest);
  border-radius: 8px 8px 0 0;
  border-bottom: 1px solid var(--theme-bg-dark);
  margin: -1rem -1rem 1rem -1rem;  /* extend to panel edges */
  flex-wrap: wrap;
  gap: 0.75rem;
}

.pf-builder-subtext {
  margin: 0;
  font-size: 0.9rem;
  color: var(--theme-text-light);
  opacity: 0.9;
  flex: 1;
  min-width: 200px;
}

.pf-builder-header-buttons {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.pf-header-btn {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--theme-border-grey);
  border-radius: 6px;
  background: var(--theme-bg-dark);
  color: var(--theme-text-light);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
}

.pf-header-btn:hover {
  background: var(--theme-bg-darkest);
  border-color: var(--theme-text-light);
}

/* Name row: input + actions */
.pf-name-wrap { display: flex; align-items: flex-start; gap: .35rem; }
/* dock input + dropdown */
.pf-name-inputwrap {
  display:flex;
  align-items:stretch;
  flex:1 1 auto;            /* lets this block grow */
  min-width: 200px;         /* tweak to your taste */
}
/* textarea: remove right radius so it merges with dropdown */
.pf-name-input {
  flex:1 1 auto;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  margin: 0;                /* ensure no gap */
  border-right: 0;            /* kill the phantom divider */
  border-radius: var(--pf-radius) 0 0 var(--pf-radius);
  resize: none;             /* disable manual resize handle */
  overflow: hidden;         /* hide scrollbar during auto-resize */
  min-height: var(--pf-h);  /* minimum one line height */
  line-height: 1.3;
}
.pf-name-actions { display: inline-flex; align-items: center; gap: .25rem; }
.pf-icon-btn {
  display: inline-flex; 
  align-items: center; 
  justify-content: center;
  width: calc(var(--pf-icon-size) + (var(--pf-pill-pad) * 2));
  height: calc(var(--pf-icon-size) + (var(--pf-pill-pad) * 2));
  border: 1px solid var(--pf-border);
  border-radius: .5rem;
  background: var(--pf-bg);
  color: inherit;
  cursor: pointer;
}
.pf-icon-btn:hover { background: var(--theme-bg-medium); }
.pf-icon-btn.pf-danger:hover { background: rgba(220, 53, 69, .2); }
/* dropdown gets the outer right radius and stretches with textarea */
.pf-name-dropdown {
  display: inline-flex; align-items: center; justify-content: center;
  align-self: stretch;          /* stretch to match textarea height */
  min-height: var(--pf-h);      /* minimum height matches input */
  width: 38px;                  /* a touch wider feels like native selects */
  border: 1px solid var(--pf-border);
  border-left: 0;
  border-radius: 0 var(--pf-radius) var(--pf-radius) 0;  /* ← rounded right */
  background: var(--pf-bg);
  cursor: pointer;
  box-sizing: border-box;       /* ensure border doesn't add to height */
}
/* single chevron, larger like native select */
.pf-name-dropdown::after {
  content: '▾';
  font-size: 1.15rem;   /* was 0.9rem – adjust until it matches your theme */
  line-height: 1;
  transform: translateY(1px); /* tiny nudge to center vertically */
  color: var(--theme-text-light);
}


/* Floating menu (fixed so it never gets clipped by the scrollable pane) */
.pf-name-menu {
  position: fixed; z-index: 3002; min-width: 220px; max-width: 360px; max-height: 320px;
  overflow: auto; background: var(--theme-bg-dark); color: var(--theme-text-light);
  border: 1px solid var(--theme-border-grey); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  padding: 6px 0; display: none;
}
.pf-name-menu.open { display: block; }
.pf-name-menu .pf-name-menu-search {
  width: calc(100% - 16px); margin: 4px 8px 6px; padding: 6px 8px;
  border: 1px solid var(--theme-border-grey); border-radius: 4px;
  background: var(--theme-bg-darkest); color: var(--theme-text-light);
}
.pf-name-menu .pf-name-menu-item {
  display: block; width: 100%; padding: 8px 12px; background: none; border: 0;
  text-align: left; cursor: pointer; font: inherit; white-space: nowrap; text-overflow: ellipsis; overflow: hidden;
  color: var(--theme-text-light);
}
.pf-name-menu .pf-name-menu-item:hover { background: var(--theme-bg-medium); }

/* Actions row layout & look */
.pf-actions-cell { text-align: center; }
.pf-actions-wrap {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
}

/* Remove button - matches other icon buttons with white background */
.pf-icon-btn.pf-remove-btn {
  font-weight: 700;
  font-size: 16px;          /* size of the × */
  line-height: 1;
}

/* Remove all instruments header - matches plotlist style */
.pf-remove-all-header {
  font-size: 16px;
  font-weight: 700;
  background: var(--theme-bg-dark);
}
.pf-remove-all-header:hover {
  background: var(--theme-bg-medium);
}
.pf-remove-all-header.disabled {
  cursor: not-allowed;
  pointer-events: none;
  background: var(--theme-bg-dark) !important;
  color: transparent;
}

#portfolioEditorSection .portfolio-controls { display: none !important; }

/* Header actions on the far right of the section title */
#portfolioEditorSection .filter-header {
  display: flex; align-items: center; justify-content: space-between;
}
#portfolioEditorSection .filter-header-actions {
  display: inline-flex; gap: .5rem; align-items: center;
}

/* The trailing “add column” lane: fixed width so header/body/footer align */
.pf-add-col, .pf-add-spacer, .pf-add-spacer-cell {
  width: 150px; min-width: 150px;
}
.pf-actions-cell { text-align: center; }
.pf-add-col-btn { width: 100%; }

/* Make the trailing add-column lane compact so the icon doesn't sit in a big empty bay */
.pf-add-col, .pf-add-spacer, .pf-add-spacer-cell {
  width: 160px; min-width: 160px;  /* roughly doubled from 56px */
  border-left: 1px solid var(--theme-border-grey);
  border-right: 1px solid var(--theme-border-grey);
}

/* Optional: hover for the add (+) icon (keeps the family look) */
.pf-icon-btn:hover svg { opacity: .9; }

.pf-icon-btn svg {
  width: var(--pf-icon-size);
  height: var(--pf-icon-size);
  fill: currentColor;   /* icon color follows text color */
}

/* Chart-style buttons with inline SVGs */
.chart-button svg {
  margin-right: .35rem;
  width: 16px;
  height: 16px;
  vertical-align: -2px; /* tweak alignment next to text */
}

/* Rebalancing toggle in the section header (right table) */
.pf-rebalance-toggle {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: none;
  border: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  padding: 0;
}

/* Caret: ▶ when collapsed, ▶ rotated to ▼ when expanded */
.pf-rebalance-toggle .pf-caret {
  display: inline-block;
  width: 0; height: 0;
  border-left: 6px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transform: rotate(0deg);
  transition: transform .15s ease;
  margin-right: .2rem;
}
.pf-rebalance-toggle[aria-expanded="true"] .pf-caret {
  transform: rotate(90deg);
}

/* Add-row layout: input + Advanced button, side-by-side */
.pf-add-row-flex {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.pf-add-wrap {          /* let the input stretch */
  flex: 1 1 auto;
}

.pf-advanced-btn {
  white-space: nowrap;  /* keep the label on one line */
}

.plotlist-title { font-size: 16px; margin: 12px 0 6px; color: var(--theme-text-dark); }
.plotlist-table { width: 100%; border-collapse: collapse; }
.plotlist-table th, .plotlist-table td { padding: 6px 8px; border-bottom: 1px solid var(--theme-border-grey); color: var(--theme-text-dark); }
.plotlist-table th { background: var(--theme-sub-table-background); }
.plotlist-remove { border: 0; background: var(--theme-sub-table-background); width: 28px; height: 28px; border-radius: 6px; cursor: pointer; }
.plotlist-remove:hover { background: #f0e0e0; }
td.plotlist-remove-cell, th.plotlist-remove-cell { text-align: center; }
.plotlist-swatch { display:inline-flex; align-items:center; gap:8px; }
.plotlist-colorchip { width: 32px; height: 14px; border-radius: 3px; border:1px solid var(--theme-border-grey); display:inline-block; vertical-align:middle; }
.plotlist-meta { color:var(--theme-text-secondary); font-size: 11px; margin-left: 6px; }
td.plotlist-color-cell { text-align: center; }
td.plotlist-name-cell {
  transition: background 0.2s;
  cursor: pointer;
  position: relative;
}
td.plotlist-name-cell:hover {
  background: #f8f9fa;
  text-decoration: underline;
}
td.plotlist-name-cell::after {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-left: 6px;
  opacity: 0;
  transition: opacity 0.2s;
  vertical-align: middle;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 235 235"><path fill="%23333" d="M33.137,235h168.727V38.451L163.411,0H33.137V235z M48.137,15h109.061l29.665,29.664V220H48.137V15z M72,60h91v15H72V60z M72,110h91v15H72V110z M72,160h41v15H72V160z"/></svg>');
  background-size: contain;
  background-repeat: no-repeat;
}
td.plotlist-name-cell:hover::after {
  opacity: 0.6;
}

/* Instrument table name cell - same style as plotlist */
td.instrument-name-cell {
  cursor: pointer;
  position: relative;
}
/* When name cell is in a hovered row (via :has selector), add underline */
#instrumentTable tbody tr:has(td:not(.instrument-select-cell):hover) td.instrument-name-cell {
  text-decoration: underline;
}
td.instrument-name-cell::after {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-left: 6px;
  opacity: 0;
  transition: opacity 0.2s;
  vertical-align: middle;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 235 235"><path fill="%23333" d="M33.137,235h168.727V38.451L163.411,0H33.137V235z M48.137,15h109.061l29.665,29.664V220H48.137V15z M72,60h91v15H72V60z M72,110h91v15H72V110z M72,160h41v15H72V160z"/></svg>');
  background-size: contain;
  background-repeat: no-repeat;
}
/* Show icon when row is hovered (via :has selector) */
#instrumentTable tbody tr:has(td:not(.instrument-select-cell):hover) td.instrument-name-cell::after {
  opacity: 0.6;
}

/* Keep select cell clickable without datasheet navigation */
td.instrument-select-cell {
  cursor: pointer;
}


/* Keep the Add-Instrument row the same height as other rows */
#portfolioBuilder .pf-add-row td { 
  height: 38px;                 /* match table cell height */
  padding: 8 10px;              /* match generic th/td padding */
}

#portfolioBuilder .pf-add-row .pf-add-cell {
  padding: 8 10px;              /* kill the extra .4/.5 rem padding */
}

/* Make the input/button align to the 34px control baseline */
#portfolioBuilder .pf-add-input {
  height: var(--pf-h);          /* 34px from your root vars */
  padding: var(--pf-pad-y) var(--pf-pad-x);
  line-height: calc(var(--pf-h) - 2px); /* Safari: ensures consistent box height */
  -webkit-appearance: none;     /* Safari: avoid odd intrinsic sizing */
}

#portfolioBuilder .pf-add-row-flex {
  display: flex;
  align-items: center;          /* vertically center input + button */
  gap: .5rem;
}

/* Make the “Advanced” button match the row height visually */
#portfolioBuilder .pf-advanced-btn {
  display: inline-flex;
  align-items: center;
  height: var(--pf-h);
  line-height: var(--pf-h);
  padding: 0 .6rem;
  background: var(--theme-bg-darkest);
  border: none;
  color: var(--theme-text-light);
}

#portfolioBuilder .pf-advanced-btn:hover {
  background: var(--theme-bg-dark);
}

/* Active Column Highlighting - only cell backgrounds, not inputs */
.pf-col.pf-col-active {
  background: color-mix(in srgb, var(--theme-bg-light) 95%, transparent) !important;
}

/* Header cells get slightly stronger highlight */
th.pf-col.pf-col-active {
  background: color-mix(in srgb, var(--theme-bg-light) 95%, transparent) !important;
}

/* Column Action Dropdown */
.pf-col-actions-container {
  position: relative;
  display: inline-flex;
  align-items: center;
}

/* Dropdown trigger - matches .pf-icon-btn styling */
.pf-col-actions-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: calc(var(--pf-icon-size) + (var(--pf-pill-pad) * 2));
  height: calc(var(--pf-icon-size) + (var(--pf-pill-pad) * 2));
  padding: 0;
  background: var(--pf-bg);
  border: 1px solid var(--pf-border);
  border-radius: .5rem;
  color: inherit;
  cursor: pointer;
}

.pf-col-actions-trigger:hover {
  background: var(--theme-bg-medium);
}

.pf-col-actions-trigger svg {
  width: var(--pf-icon-size);
  height: var(--pf-icon-size);
  fill: currentColor;
}

.pf-col-actions-menu {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  min-width: 180px;
  background: var(--theme-bg-darkest);
  border: 1px solid var(--theme-border-grey);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 1100;
  display: none;
  margin-top: 4px;
}

.pf-col-actions-menu.open {
  display: block;
}

.pf-col-actions-menu.dropdown-above {
  top: auto;
  bottom: 100%;
  margin-top: 0;
  margin-bottom: 4px;
}

.pf-col-actions-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: none;
  border: none;
  text-align: left;
  font-size: 0.8rem;
  color: var(--theme-text-light);
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.pf-col-actions-item:hover:not(:disabled) {
  background: var(--theme-bg-medium);
}

.pf-col-actions-item:disabled {
  color: var(--theme-text-muted);
  cursor: not-allowed;
}

.pf-col-actions-item svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.pf-col-actions-item.danger {
  color: var(--theme-danger, #ef4444);
}

.pf-col-actions-item.danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.1);
}

.pf-col-actions-divider {
  height: 1px;
  margin: 0.25rem 0;
  background: var(--theme-border-grey);
}

/* ========================================
   My Portfolios Section
   ======================================== */

.my-portfolios-section {
  margin-bottom: 1rem;
}

/* Outer wrapper with dark background (like trades-summary) */
.my-portfolios-outer {
  background: var(--theme-bg-darkest);
  border-radius: 8px;
  padding: 1rem;
}

.my-portfolios-container {
  border-radius: 8px;
  background: var(--theme-bg-darkest);
  /* overflow: visible needed for dropdown to escape container */
}

.my-portfolios-container.collapsed .my-portfolios-table-wrapper {
  display: none;
}

.my-portfolios-container.collapsed .my-portfolios-header {
  border-radius: 8px;
}

/* Hide column selector when collapsed */
.my-portfolios-container.collapsed .column-selector-container {
  display: none;
}

.my-portfolios-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--theme-bg-medium);
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  transition: background 0.15s;
  position: relative;
  z-index: 10;
  overflow: visible;
}

.my-portfolios-header:hover {
  background: var(--theme-hover-light);
}

.my-portfolios-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--theme-text-light);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.my-portfolios-header .expand-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  transition: transform 0.2s ease;
}

.my-portfolios-container.collapsed .expand-chevron {
  transform: rotate(-90deg);
}

.portfolio-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 20px;
  padding: 0 6px;
  background: var(--theme-bg-dark);
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--theme-text-muted);
}

.my-portfolios-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.my-portfolios-actions .btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 32px;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  background: var(--theme-bg-dark);
  border: 1px solid var(--theme-border-grey);
  border-radius: 4px;
  color: var(--theme-text-light);
}

.my-portfolios-actions .btn:hover {
  border-color: var(--theme-text-light);
  background: var(--theme-bg-medium);
}

.my-portfolios-actions .btn.btn-primary {
  background: var(--theme-bg-dark);
  border-color: var(--theme-border-grey);
  color: var(--theme-text-light);
}

.my-portfolios-actions .btn.btn-primary:hover {
  background: var(--theme-bg-medium);
  border-color: var(--theme-text-light);
}

/* Column Selector Dropdown (shared) */
.column-selector-container {
  position: relative;
}

.column-selector-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 32px;
  padding: 0.4rem 0.75rem;
  background: var(--theme-bg-dark);
  border: 1px solid var(--theme-border-grey);
  border-radius: 4px;
  color: var(--theme-text-light);
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.column-selector-trigger:hover {
  border-color: var(--theme-text-light);
  background: var(--theme-bg-medium);
}

.column-selector-menu {
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 180px;
  max-height: 350px;
  overflow-y: auto;
  background: var(--theme-bg-dark);
  border: 1px solid var(--theme-border-grey);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  z-index: 99999;
  margin-top: 0;
  display: none;
}

.column-selector-menu.open {
  display: block;
}

/* Fixed menu appended to body - escapes all stacking contexts */
.column-selector-menu-fixed {
  position: fixed;
}

.column-selector-menu.dropdown-above {
  top: auto;
  bottom: 100%;
  margin-top: 0;
  margin-bottom: 2px;
}

.column-selector-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  color: var(--theme-text-light);
  font-size: 0.85rem;
  transition: background 0.15s;
}

.column-selector-item:hover {
  background: var(--theme-bg-medium);
}

.column-selector-item input[type="checkbox"] {
  cursor: pointer;
}

.column-selector-divider {
  height: 1px;
  background: var(--theme-border-grey);
  margin: 0.5rem 0;
}

/* Visibility badge */
.visibility-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.visibility-badge.public {
  color: var(--theme-positive);
}

.visibility-badge.private {
  color: var(--theme-text-muted);
}

.my-portfolios-table-wrapper {
  overflow-x: auto;
  max-height: 400px;
  overflow-y: auto;
  color: var(--theme-text-light);
  border-bottom: 1px solid var(--theme-text-light);
  margin-top: 0.75rem;
  position: relative;
  background: var(--theme-bg-darkest);
}

.my-portfolios-table {
  width: 100%;
  border-collapse: collapse;
  border-top: 0;
  font-size: 0.875rem;
  color: var(--theme-text-light);
}

.my-portfolios-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--theme-bg-dark);
}

/* Header cells - box-shadow creates persistent borders that don't bleed through */
.my-portfolios-table th {
  padding: 0.625rem 0.75rem;
  text-align: left;
  font-weight: 600;
  color: var(--theme-text-light);
  background: var(--theme-bg-dark);
  border-top: 0;
  border-bottom: none;
  box-shadow: inset 0 1px 0 var(--theme-border-grey), inset 0 -1px 0 var(--theme-border-grey);
  white-space: nowrap;
}

.my-portfolios-table th.numeric {
  text-align: right;
}

.my-portfolios-table th.col-expand {
  width: 40px;
  text-align: center;
}

.my-portfolios-table th.col-actions {
  width: 60px;
  text-align: center;
}

/* Body - border-top: 0 prevents white line above first row */
.my-portfolios-table tbody {
  border-top: 0;
}

.my-portfolios-table tbody tr {
  transition: background 0.15s;
  cursor: pointer;
  background: var(--theme-bg-darkest);
}

.my-portfolios-table tbody tr:hover {
  background: var(--theme-bg-medium);
}

.my-portfolios-table tbody tr.expanded {
  background: var(--theme-bg-dark);
}

.my-portfolios-table td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--theme-border-grey);
  color: var(--theme-text-light);
  white-space: nowrap;
  background: inherit;
}

.my-portfolios-table td.numeric {
  text-align: right;
}

.my-portfolios-table td.col-expand {
  text-align: center;
}

.my-portfolios-table td.col-actions {
  text-align: center;
}

.my-portfolios-table .col-visibility {
  text-align: center;
}

.my-portfolios-table .col-metric {
  min-width: 80px;
}

.my-portfolios-table .col-return {
  min-width: 80px;
}

/* Expand/collapse toggle */
.expand-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  color: var(--theme-text-muted);
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.15s;
}

.expand-toggle:hover {
  background: var(--theme-bg-light);
  color: var(--theme-text-light);
}

.expand-toggle svg {
  transition: transform 0.2s ease;
}

.expand-toggle.expanded svg {
  transform: rotate(90deg);
}

/* Portfolio name styling */
.portfolio-name-cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.portfolio-name-cell .portfolio-name {
  font-weight: 500;
  color: var(--theme-text-light);
}

.portfolio-name-cell .public-indicator {
  font-size: 0.9rem;
}

/* Return value styling */
.return-positive {
  color: var(--theme-positive);
}

.return-negative {
  color: var(--theme-negative);
}

.return-na {
  color: var(--theme-text-muted);
  font-size: 0.8rem;
}

/* Expanded row details */
.portfolio-details-row {
  background: var(--theme-bg-dark) !important;
}

.portfolio-details-row:hover {
  background: var(--theme-bg-dark) !important;
}

.portfolio-details-row td {
  padding: 0;
  border-bottom: 1px solid var(--theme-border-grey);
}

.portfolio-constituents {
  padding: 0.75rem 1rem 0.75rem 3rem;
  background: var(--theme-bg-darkest);
}

.constituent-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.35rem 0;
}

.constituent-ticker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 50px;
  padding: 0.2rem 0.5rem;
  background: var(--theme-bg-medium);
  border: 1px solid var(--theme-border-grey);
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--theme-text-light);
}

.constituent-name {
  flex: 1;
  min-width: 150px;
  color: var(--theme-text-light);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.constituent-weight {
  min-width: 50px;
  text-align: right;
  font-weight: 500;
  color: var(--theme-text-light);
  font-size: 0.85rem;
}

.constituent-bar-container {
  flex: 1;
  max-width: 200px;
  height: 8px;
  background: var(--theme-bg-dark);
  border-radius: 4px;
  overflow: hidden;
}

.constituent-bar {
  height: 100%;
  background: var(--theme-positive);
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* Row actions dropdown */
.row-actions-container {
  position: relative;
  display: inline-flex;
}

.row-actions-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--theme-text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.row-actions-trigger:hover {
  background: var(--theme-bg-light);
  border-color: var(--theme-border-grey);
  color: var(--theme-text-light);
}

.row-actions-trigger svg {
  width: 16px;
  height: 16px;
}

/* Use fixed positioning to escape overflow:hidden containers */
.row-actions-menu {
  position: fixed;
  min-width: 180px;
  background: var(--theme-bg-darkest);
  border: 1px solid var(--theme-border-grey);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 1100;
  display: none;
}

.row-actions-menu.open {
  display: block;
}

.row-actions-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: none;
  border: none;
  text-align: left;
  font-size: 0.8rem;
  color: var(--theme-text-light);
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.row-actions-item:hover:not(:disabled) {
  background: var(--theme-bg-medium);
}

.row-actions-item:disabled {
  color: var(--theme-text-muted);
  cursor: not-allowed;
}

.row-actions-item svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.row-actions-item.danger {
  color: var(--theme-danger, #ef4444);
}

.row-actions-item.danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.1);
}

.row-actions-divider {
  height: 1px;
  margin: 0.25rem 0;
  background: var(--theme-border-grey);
}

/* Empty state */
.my-portfolios-empty {
  padding: 2rem;
  text-align: center;
  color: var(--theme-text-muted);
}

/* Scrollbar styling */
.my-portfolios-table-wrapper::-webkit-scrollbar {
  height: 8px;
  width: 8px;
}

.my-portfolios-table-wrapper::-webkit-scrollbar-track {
  background: var(--theme-bg-darkest);
  border-radius: 4px;
}

.my-portfolios-table-wrapper::-webkit-scrollbar-thumb {
  background: var(--theme-bg-light);
  border-radius: 4px;
}

.my-portfolios-table-wrapper::-webkit-scrollbar-thumb:hover {
  background: var(--theme-bg-medium);
}
