/* ======== BASE STYLES ======== */
body {
  background-color: #121212;
  color: #e0e0e0;
  font-family: Arial, sans-serif;
  padding: 0;
  margin: 0;
}

h2 {
  margin-bottom: 0.5rem;
  color: #ffffff;
  text-align: center;
  font-size: 1.5rem;
}

.container {
  max-width: 80vw;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-top: 0.5rem;
}

.main-content {
  display: flex;
  justify-content: center;
  padding: 0.5rem 0;
  box-sizing: border-box;
}

/* ======== BUTTON STYLES ======== */
.button-container {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.25rem 0;
}

.mode-button {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: bold;
  background-color: #1e1e1e;
  color: #ffffff;
  border: 1px solid #333;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.mode-button.active {
  background-color: #2e7d32;
}

.mode-button:hover:not(.active) {
  background-color: #333;
}

/* ======== PRICE STYLES ======== */
.price-editable {
  cursor: pointer;
  padding: 0.2rem;
  border-radius: 3px;
}

.price-editable:hover {
  background-color: #2a2a2a;
}

.price-editable:focus {
  outline: none;
  background-color: #1e1e1e;
  border: 1px solid #555;
}

/* Placeholder-like behavior for price fields */
#priceHeader [contenteditable]:empty:not(:focus):before {
  content: attr(data-placeholder);
  color: #888;
}

/* ======== STRUCTURE ======== */
.grid {
  display: flex;
  gap: 2rem;
  width: 100%; /* Ensure the grid takes up the full width */
}

.section-title {
  font-weight: bold;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 1.3rem;
  color: #ffffff;
  display: inline-flex;
  align-items: baseline;
}

.section-title > span:not(#setupValue) {
  text-decoration: underline;
}

#setupValue {
  text-decoration: none;
  color: #a0a0a0; /* Light grey */
}

.asset-group {
  margin-bottom: 1rem;
  border-bottom: 1px solid #333; /* Optional separator between assets */
  padding-bottom: 1rem;
}

.row {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-start; /* Align columns to the left */
  align-items: center; /* Vertically center contents */
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

.half {
  flex: 0 0 calc(50% - 0.25rem); /* 50% of the parent width minus half the gap */
  display: flex;
  flex-direction: column;
}

label {
  font-weight: bold;
  display: block;
  margin-bottom: 0.25rem;
  color: #ffffff;
  font-size: 1rem;
}

input,
select {
  width: 100%;
  padding: 0.6rem;
  font-size: 1.6rem;
  background-color: #1e1e1e;
  color: #ffffff;
  border: 1px solid #333;
  border-radius: 4px;
  box-sizing: border-box;
  margin: 0;
}

select {
  appearance: none;
}

/* Style for ticker dropdowns in Portfolio section */
#portfolio-content .ticker-select {
  width: 100%;
  padding: 0.6rem 1.5rem 0.6rem 0.5rem; /* Adjusted padding for dropdown arrow */
  font-size: 1.2rem;
  font-weight: bold;
  text-transform: uppercase;
  background-color: #2a2a2a;
  color: #ffffff;
  border: 1px solid #444;
  border-radius: 4px;
  box-sizing: border-box;
  margin-bottom: 0.5rem;
  text-align: center;
  /* Add a dropdown arrow */
  background-image: url('data:image/svg+xml;utf8,<svg fill="#ffffff" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>');
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 1rem;
  -webkit-appearance: none; /* Remove default browser styling */
  -moz-appearance: none;
  appearance: none;
  height: 40px; /* Fixed height for consistency */
  line-height: 1; /* Prevent line-height from affecting height */
}

/* Style for price spans and manual price inputs in Portfolio section */
#portfolio-content .price-display,
#portfolio-content .manual-price {
  width: 100%;
  padding: 0.6rem;
  font-size: 1.6rem;
  background-color: #1e1e1e;
  color: #ffffff;
  border: 1px solid #333;
  border-radius: 4px;
  box-sizing: border-box;
  display: block;
  text-align: center;
  height: 40px; /* Fixed height for consistency */
  line-height: 1; /* Prevent line-height from affecting height */
  margin-bottom: 0.5rem;
}

/* Style for input fields in Portfolio section */
#portfolio-content input {
  width: 100%;
  padding: 0.6rem;
  font-size: 1.6rem;
  background-color: #1e1e1e;
  color: #ffffff;
  border: 1px solid #333;
  border-radius: 4px;
  box-sizing: border-box;
  margin: 0;
  height: 40px; /* Fixed height for consistency */
  line-height: 1; /* Prevent line-height from affecting height */
}

/* Style for Add/Remove Asset link */
.toggle-link {
  margin-top: 1rem;
  text-align: center;
}

.toggle-link a {
  color: #ffffff;
  text-decoration: none;
  font-size: 1rem;
  margin: 0 0.5rem;
}

.toggle-link a:hover {
  text-decoration: underline;
}

/* ======== SUMMARY BOXES ======== */
.summary-box {
  display: flex;
  flex-direction: column;
  margin-bottom: 0; /* Reduced margin since each asset group has padding */
}

.summary-box label {
  margin-bottom: 0.25rem;
  font-size: 1rem;
}

.summary-box input {
  font-size: 1.6rem;
}

.summary-label {
  margin-top: 1rem;
  font-size: 1rem;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.5rem;
}

.summary-item {
  flex: 1;
  background-color: #1e1e1e;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-size: 1.8rem;
  text-align: center;
}

/* ======== COLOR CODING ======== */
.increase {
  background-color: #2e7d32;
  color: white;
}

.decrease {
  background-color: #c62828;
  color: white;
}

input[readonly] {
  background-color: #1e1e1e;
  border-color: #333;
  outline: none;
  box-shadow: none;
}

input[readonly].increase {
  background-color: #2e7d32 !important;
  color: white !important;
}

input[readonly].decrease {
  background-color: #c62828 !important;
  color: white !important;
}

/* ======== CONTENT TOGGLE ======== */
.content-section {
  display: none;
}

.content-section.active {
  display: block;
}

/* ======== MOBILE STYLES ======== */
@media (max-width: 1024px) {
  .main-content {
    flex-direction: column;
    align-items: flex-start;
    min-height: auto;
  }

  .grid {
    flex-direction: column;
    align-items: center;
  }

  .grid > div {
    width: 90%;
    border-top: 1px solid #c1c1c1;
    padding-top: 1rem;
  }

  .grid label,
  .grid .summary-box label {
    font-size: 1.6rem;
  }

  input,
  select {
    font-size: 1.8rem; /* Slightly larger font size for mobile readability */
  }

  #portfolio-content .ticker-select {
    font-size: 1.6rem;
    padding: 0.5rem 2rem 0.5rem 0.5rem; /* Adjusted padding for dropdown arrow */
    background-position: right 0.5rem center;
    background-size: 1.2rem;
  }

  #portfolio-content .price-display,
  #portfolio-content .manual-price {
    font-size: 1.8rem;
  }

  .summary-box span {
    font-size: 2.2rem;
  }

  .section-title {
    font-size: 1.8rem;
    margin-bottom: 1rem;
  }

  .mobile-pair {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.2rem;
  }

  .half {
    width: 100%; /* Full width on mobile for stacking */
  }

  .button-container {
    flex-direction: column;
    align-items: center;
  }

  .mode-button {
    width: 90%;
    padding: 1rem;
    font-size: 1.2rem;
  }

  h2 {
    font-size: 1.3rem;
  }
}

/* ======== DESKTOP STYLES ======== */
@media (min-width: 1025px) {
  .main-content {
    align-items: center;
    min-height: calc(100vh - 80px);
  }

  .grid > div:not(:last-child) {
    border-right: 1px solid #333;
    padding-right: 2rem;
  }

  .grid > div {
    flex: 1; /* Ensure the three columns (Portfolio Holdings, Analysis, Summary) share space equally */
    min-width: 0; /* Prevent overflow */
  }

  .section-title {
    margin-bottom: 0.5rem;
  }

  .mobile-pair {
    display: flex;
    flex-direction: row;
    gap: 0.5rem;
    margin-bottom: 1.2rem;
  }

  .half {
    flex: 0 0 calc(50% - 0.25rem); /* 50% of the parent width minus half the gap */
    display: flex;
    flex-direction: column;
  }

  .mobile-pair .summary-box {
    margin-bottom: 0;
  }
}