/* General Reset */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { display: flex; font-family: Arial, sans-serif; background-color: #000000; }

/* Loading message style */
.loading-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 20px;
  color: white;
  text-align: center;
}
@keyframes pulse {
  0% { opacity: 0.3; }
  50% { opacity: 1; }
  100% { opacity: 0.3; }
}
.loading-message span {
  display: inline-block;
  animation: pulse 1.5s infinite;
}

/* Sidebar Styling */
#sidebar {
  background-color: #000000;
  color: white;
  width: 13.33%;
  min-width: 250px;
  height: 100vh;
  overflow-y: auto;
  transition: width 0.3s ease;
  font-family: Arial, sans-serif;
  font-size: 11px;
  position: relative;
  padding-bottom: 10px;
}
#collapse-btn { padding: 10px; text-align: center; cursor: pointer; background-color: #334455; }
#collapse-btn:hover { background-color: #556677; }

/* Titolo della sidebar */
#sidebar-title {
  width: 100%;
  padding: 12px 0;
  text-align: center;
  font-size: 16px;
  font-weight: bold;
  color: white;
}

/* New search box styling – replaced the single input with a container */
#sidebar-search-container {
  position: relative;
  margin: 10px;
}
#sidebar-search {
  width: calc(100% - 30px);
  padding: 5px 10px;
  border: none;
  border-radius: 4px;
}
#sidebar-search-clear {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: white;
  cursor: pointer;
}
#sidebar ul { list-style: none; padding: 10px; }
#sidebar ul li { padding: 10px; cursor: pointer; }
.sub-list li:nth-child(odd) { background-color: #000000; }
.sub-list li:nth-child(even) { background-color: #222222; }
#sidebar li.selected { color: #FFA500; }
#sidebar ul li:not(.expandable):hover { background-color: #334455; }
.expandable:hover { background-color: transparent; }
.expandable > .toggle-btn:hover { background-color: #334455; }
.sub-list li:not(.expandable):hover { background-color: #334455; }
.expandable > .toggle-btn {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.expandable > .sub-list { display: none; padding-left: 15px; }
.expandable.expanded > .sub-list { display: block; }

/* Main Content Styling (Dashboard) */
#main-content {
  flex-grow: 1;
  width: 80%;
  max-width: 80vw;
  background-color: #000000;
  padding: 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: calc(((80vw - 20px) * 9) / 32) calc(((80vw - 20px) * 9) / 32);
  gap: 20px;
  justify-items: center;
  align-items: center;
}

/* Portfolio Builder Template */
#portfolio-builder-template {
  flex-grow: 1;
  width: 80%;
  max-width: 1200px;
  margin: 10px auto;
  background: #000000;
  padding: 20px;
  display: none;
}

/* Thematic Portfolio Template */
#thematic-portfolio-template {
  flex-grow: 1;
  width: 80%;
  max-width: 1200px;
  margin: 10px auto;
  background: #000000;
  padding: 20px;
  display: none;
}

/* Wrap Block1 for full screen button */
#block1-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
}

/* Dashboard Blocks */
#block1, #block2, #block3, #block4 {
  width: 100%;
  height: 100%;
  background-color: #000000;
  border: 1px solid #444444;
  padding: 0;
  overflow: visible;
}
#block2 { padding: 10px; }
#block3, #block4 { font-family: Arial, sans-serif; font-size: 12px; }
#block3 table, #block3 th, #block3 td {
  font-family: Arial, sans-serif;
  font-size: 12px;
}
/* Block3 trendscore table */
#block3-trendscore table {
  width: 100%;
  height: 100%;
  border-collapse: collapse;
  color: white;
}
#block3-trendscore th, #block3-trendscore td {
  border: none;
  padding: 6px;
  text-align: left;
  white-space: nowrap;
}
#block3-trendscore th:nth-child(2), #block3-trendscore td:nth-child(2) {
  border-right: 1px solid #444444;
}
#block3-trendscore tr:nth-child(odd) { background-color: #000000; }
#block3-trendscore tr:nth-child(even) { background-color: #222222; }
#block3-tabs {
  display: flex;
  background-color: #334455;
}
#block3-tabs button {
  flex: 1;
  background: #334455;
  color: white;
  padding: 8px;
  border: none;
  cursor: pointer;
  font-size: 10px;
  font-family: Arial, sans-serif;
}
#block3-tabs button:hover { background: #556677; }
#block3-tabs button.active-tab { background: #778899; font-weight: bold; }
#block3-content {
  width: 100%;
  height: calc(100% - 30px);
  position: relative;
}
#block3-trendscore, #block3-tradingview {
  width: 100%;
  height: 100%;
  display: none;
}
#block4 { position: relative; }
#block4chart { width: 100%; height: 100%; }

/* External Full Screen Button */
.external-fullscreen-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  padding: 4px 6px;
  font-size: 14px;
  background-color: #334455;
  color: white;
  border: none;
  cursor: pointer;
  z-index: 10;
  border-radius: 3px;
}
.external-fullscreen-btn:hover { background-color: #556677; }
.external-fullscreen-btn .arrow {
  display: inline-block;
  font-size: 10px;
  line-height: 1;
  margin: 0 1px;
}

/* TradingView widget override */
.tradingview-widget-container,
.tradingview-widget-container__widget {
  background-color: #000000 !important;
}

/* YouTube Popup */
#youtube-popup {
  display: none;
  position: fixed;
  top: 50px;
  left: 50px;
  width: 320px;
  height: 240px;
  background-color: #000000;
  border: 1px solid #444444;
  z-index: 1000;
  padding: 10px;
}
#youtube-popup-header {
  cursor: move;
  color: white;
  font-weight: bold;
  margin-bottom: 10px;
}
#youtube-popup-close {
  float: right;
  background: transparent;
  border: none;
  color: white;
  font-size: 16px;
  cursor: pointer;
}
#youtube-popup input[type="text"] { width: 100%; margin-bottom: 5px; }
#youtube-popup button { width: 100%; margin-bottom: 5px; }

/* --- SPREAD Chart Block --- */
#block5 {
  grid-column: 1 / -1;      /* span full width */
  grid-row:    1 / -1;      /* span both rows */
  width:       100%;        /* full within that area */
  height:      100%;        /* full within that area */
  background-color: #000000;
  border: 1px solid #444444;
}
#spread-chart {
  width: 100%;
  height: 100%;
}

/* Portfolio Builder Page Styles */
#portfolio-builder-page {
  width: 90%;
  max-width: 1200px;
  margin: 10px auto;
  background: #000000;
  padding: 20px;
  position: relative;
}
#portfolio-builder-steps { margin-bottom: 10px; }
#portfolio-builder-instructions {
  text-align: center;
  font-size: 16px;
  color: #cccccc;
}
#add-filter-btn {
  font-size: 20px;
  margin-right: 10px;
  cursor: pointer;
  background: transparent;
  border: none;
  color: #FFA500;
}
.filter-step {
  background: #222222;
  border: 1px solid #444444;
  border-radius: 4px;
  padding: 10px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #ffffff;
}
.filter-step select, .filter-step input {
  margin-left: 10px;
  padding: 4px;
  font-size: 14px;
  border: 1px solid #444444;
  background: #000000;
  color: #ffffff;
  border-radius: 3px;
}
.remove-filter-btn {
  background: transparent;
  border: none;
  color: #ff4444;
  font-size: 16px;
  cursor: pointer;
}
#portfolio-builder-actions {
  text-align: center;
  margin-top: 20px;
}
#generate-portfolio-btn {
  padding: 12px 20px;
  font-size: 16px;
  background: #334455;
  color: #ffffff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.3s ease;
}
#generate-portfolio-btn:hover { background: #556677; }
#portfolio-results {
  margin-top: 20px;
  clear: both;
  width: 100%;
  color: #ffffff; /* ensure plain text messages are visible */
}
#portfolio-results table {
  width: 100%;
  border-collapse: collapse;
  background-color: #000000;
  border: 1px solid #112233;
  border-radius: 4px;
  overflow: hidden;
}
#portfolio-results th, #portfolio-results td {
  padding: 12px;
  text-align: center;
  border: 1px solid #112233;
  color: white;
  font-size: 12px;
}
#portfolio-results th {
  background-color: #112233;
  color: white;
  font-weight: bold;
}
#portfolio-results tr:nth-child(even) {
  background-color: rgba(255, 165, 0, 0.1);
}

/* Two-section layout for Portfolio Builder page */
#portfolio-builder-container {
  display: flex;
  gap: 20px;
  margin-top: 10px;
  align-items: flex-start;
}
#portfolio_builder1 {
  width: 40%;
  padding: 20px;
  border: 1px solid #444444;
  background-color: #000000;
  border-radius: 8px;
  flex-shrink: 0;
}
#portfolio_builder2 {
  width: 60%;
  padding: 20px;
  border: 1px solid #444444;
  background-color: #000000;
  border-radius: 8px;
  overflow-y: auto;
  max-height: 600px;
  flex-shrink: 0;
}

/* Filter Selector Styling */
.filter-selector {
  margin: 10px auto;
  text-align: center;
  background-color: #222222;
  border: 1px solid #444444;
  border-radius: 4px;
  padding: 8px;
}
.filter-selector select,
.filter-selector input,
.filter-selector button {
  background-color: #000000;
  color: #cccccc;
  border: 1px solid #444444;
  border-radius: 3px;
  padding: 4px 6px;
  font-size: 14px;
  margin: 0 5px;
}
.filter-selector select option {
  background-color: #000000;
  color: #cccccc;
}
.filter-selector button:hover {
  background-color: #334455;
}
.filter-selector span { color: #ffffff; } /* ensure (boolean) is visible */

/* Make instruction text visible */
.portfolio-builder-instruction { color: #ffffff; }

/* Thematic Portfolio Styles */
.thematic-portfolio-section {
  border: 1px solid #112233;
  border-radius: 8px;
  margin-bottom: 30px;
  padding: 20px;
}
.thematic-portfolio-section h2 {
  color: #FFA500;
  margin-bottom: 10px;
  font-size: 22px;
  font-weight: bold;
  border-bottom: 1px solid #112233;
  padding-bottom: 5px;
}
.thematic-portfolio-table-container {
  overflow-x: auto;
}
.thematic-portfolio-table {
  width: 100%;
  border-collapse: collapse;
  background-color: #000000;
}
.thematic-portfolio-table th,
.thematic-portfolio-table td {
  padding: 14px;
  text-align: center;
  border: 1px solid #112233;
  color: white;
  font-size: 14px;
}
.thematic-portfolio-table tr:nth-child(even) {
  background-color: rgba(255, 165, 0, 0.1);
}

/* No-results friendly messaging for empty Portfolio Ideas tabs */
.no-ideas {
  padding: 2rem;
  text-align: center;
  color: #bbb;
  font-style: italic;
  border: 1px dashed #555;
  border-radius: 0.5rem;
  background: #0a1827;
  margin: 20px 0;
}
.no-ideas p {
  margin: 0;
}

/* Thematic Portfolio Tab Navigation */
.thematic-portfolio-nav {
  position: sticky;
  top: 0;
  background-color: #000000;
  z-index: 100;
  padding: 10px 0;
  border-bottom: 1px solid #112233;
}
.thematic-portfolio-nav nav {
  display: flex;
  justify-content: center;
}
.thematic-portfolio-nav button {
  background: none;
  border: none;
  color: white;
  padding: 10px 20px;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.3s ease;
}
.thematic-portfolio-nav button:hover,
.thematic-portfolio-nav button:focus {
  background: #334455;
  outline: none;
}
.thematic-portfolio-nav button.active-tab {
  background: #FFA500;
  color: #000000;
  font-weight: bold;
}
.portfolio-tab-content {
  display: none;
  animation: fadeIn 0.5s;
}
.portfolio-tab-content.active {
  display: block;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Responsive Adjustments for Mobile */
@media screen and (max-width: 768px) {
  body {
    flex-direction: column;
  }
  #sidebar {
    width: 100%;
    min-width: unset;
    height: auto;
  }
  #main-content {
    width: 100%;
    max-width: 100%;
    padding: 10px;
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    gap: 10px;
  }
}
@media screen and (max-width: 480px) {
  body {
    font-size: 14px;
  }
  #sidebar {
    font-size: 10px;
    padding: 5px;
  }
  #main-content {
    padding: 5px;
    gap: 5px;
  }
  #block2 { padding: 5px; }
  .external-fullscreen-btn {
    padding: 2px 4px;
    font-size: 12px;
  }
  table, th, td {
    font-size: 10px;
  }
}

/* Spread title overlay */
#block5 { position: relative; }  /* ensure positioning context */
.chart-title {
  position: absolute;
  top: 8px;
  left: 10px;
  color: #FFA500;
  font-size: 16px;
  font-weight: bold;
  z-index: 5;
  pointer-events: none;
}

/* ─── Custom Scrollbars ─── */

/* WebKit browsers (Chrome, Edge, Safari) */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: #000000;      /* matches your site’s background */
  border-radius: 4px;
}
::-webkit-scrollbar-thumb {
  background: #333333;      /* subtle contrast */
  border-radius: 4px;
  border: 2px solid #000000;/* inset effect */
}
::-webkit-scrollbar-thumb:hover {
  background: #555555;
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: #333333 #000000;
}
