/* ---------------------------------------------------
   DROPDOWNS
--------------------------------------------------- */
.dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: max(12px, env(safe-area-inset-right, 0px));
  z-index: 1100;
  background: var(--theme-bg-dropdown);
  border-radius: 6px;
  box-shadow: var(--theme-shadow-dropdown);
  border: 1px solid var(--theme-border-default);
  padding: 10px;
  display: none;
  min-width: 180px;
}

.dropdown p {
  margin: 8px 0;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 4px;
  color: var(--theme-text-dropdown);
}

.dropdown p:hover {
  background: var(--theme-bg-dropdown-row-hover);
  color: var(--theme-text-dropdown-row-hover);
}

.settings-dropdown-menu {
  min-width: 230px;
  padding: 10px;
}

.dropdown-action {
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--theme-text-dropdown);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.92rem;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.dropdown-action:hover {
  background: var(--theme-bg-dropdown-action-hover);
  border-color: var(--theme-border-dropdown-action-hover);
}

.dropdown-divider {
  height: 1px;
  margin: 8px 0;
  background: var(--theme-bg-dropdown-divider);
}

.dropdown-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 6px;
}

.dropdown-row-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--theme-text-dropdown-label);
  font-size: 0.9rem;
}

/* ---------------------------------------------------
   METRICS
--------------------------------------------------- */
.metrics.stacked {
  display: flex;
  gap: 15px; /* space between stacked metrics */
  justify-content: flex-start; /* align left if many */
  margin-top: 10px;
  flex-wrap: wrap; /* allow wrapping if too many */
}

.metric {
  flex: 1;
  min-width: 0;
  text-align: center;
  background: var(--theme-bg-metric);
  padding: 12px 8px;
  border-radius: 8px;
  box-shadow: var(--theme-shadow-metric);
  border: 1px solid var(--theme-border-default);
  color: var(--theme-text-heading);
}

.metric h3 {
  font-size: 0.9rem;
  color: var(--theme-text-subtle);
}

.metric p {
  font-size: 1.2rem;
  font-weight: bold;
  margin: 5px 0 0 0;
  color: var(--theme-text-heading);
}

/* ---------------------------------------------------
   MARKET HEADER
--------------------------------------------------- */
/* Removed duplicate centered market-header */

/* ---------------------------------------------------
   MARKET CARDS
--------------------------------------------------- */
.market-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 12px; /* tightened space */
  padding: 12px; /* tightened spacing */
  justify-content: center; /* center cards */
}

.market-card {
  width: min(240px, 100%);
  background: linear-gradient(
    145deg,
    var(--theme-gradient-card-start) 0%,
    var(--theme-gradient-card-end) 100%
  );
  padding: 14px;
  border-radius: 8px; /* slightly more rounded */
  border: 1px solid var(--theme-border-card);
  color: var(--theme-text-card);
  text-align: center;
  box-shadow: var(--theme-shadow-card);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  position: relative; /* Ensure absolute children position correctly */
}

.market-card .pin-icon {
  opacity: 1 !important;
  z-index: 10; /* Ensure pin is above other elements */
}

.market-card:hover {
  transform: translateY(-4px); /* higher lift */
  box-shadow: var(--theme-shadow-card-hover);
  border-color: var(--theme-border-card-hover);
}

.market-card h3 {
  font-size: 1.0rem;
  font-weight: 800; /* Extra bold */
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  margin-top: 10px;
  border-bottom: 1px solid var(--theme-border-card-title);
  padding-bottom: 8px;
  text-shadow: var(--theme-text-shadow-card);
}

/* Main number/arrow takes majority of box */
.market-card p {
  font-size: 1.4rem;
  font-weight: bold;
  margin: 0;
  text-shadow: var(--theme-text-shadow-value);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* New Market Value Styling (Replaces p) */
.market-value-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 4px 0;
}

.market-value-top {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: bold;
  text-shadow: var(--theme-text-shadow-value);
  margin-bottom: 2px;
}

.market-metric-label {
  font-size: 0.7rem;
  color: var(--theme-text-metric-label);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1.2;
}

/* Optional arrow styling */
.trend-arrow {
  margin-left: 4px;
  font-size: 1.2rem;
}

/* ---------------------------------------------------
   MODAL
--------------------------------------------------- */
#focusedTrendSection {
  margin-top: 20px;
}

.trend-header {
  display: flex;
  align-items: center;
  justify-content: flex-start; /* centers items horizontally */
  gap: 10px;
  margin-bottom: 10px;
  position: relative; /* allows back button to be positioned separately */
}

.market-header {
  display: flex;
  align-items: center;
  font-size: 1.0rem;
  font-weight: 800;
  justify-content: flex-start; /* centers items horizontally */
  gap: 10px;
  margin-bottom: 10px;
  position: relative; 
  text-align: left;
}

.back-button {
  background: none;
  border: none;
  color: var(--theme-text-back);
  font-size: 2.5rem;
  font-weight: bold;
  cursor: pointer;
  /* margin-right: 15px; */
  /* margin-bottom handled by specific contexts if needed */
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  transition: transform 0.2s ease, color 0.2s ease;
  z-index: 10;
}

.back-button:hover {
    color: var(--theme-text-back-hover);
    transform: scale(1.1);
}

#focusedTrendTitle {
  font-size: 1rem;
  font-weight: 600;
  color: var(--theme-text-focused-title);
  margin: 0;
  text-align: center; /* ensures title is centered */
  flex: 1;
  text-shadow: var(--theme-text-shadow-title-sub);
}

/* Old modal styles removed */

.auth-input {
  width: 90%;
  padding: 10px;
  margin: 10px 0;
  border-radius: 5px;
  border: 1px solid var(--theme-border-input-generic);
  background: var(--theme-bg-surface);
  color: var(--theme-text-modal-input);
}

/* ---------------------------------------------------
   COMPARE & FILTERS
--------------------------------------------------- */
.compare-main-btn {
    background-color: var(--theme-bg-compare-btn);
    color: var(--theme-text-on-filled-primary);
    border: 1px solid var(--theme-border-compare);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
}

.compare-main-btn:hover {
    background-color: var(--theme-bg-compare-btn-hover);
}

.compare-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    width: 220px;
    background-color: var(--theme-bg-compare-menu);
    border: 1px solid var(--theme-border-compare);
    border-radius: 6px;
    z-index: 1000;
    box-shadow: var(--theme-shadow-modal);
    margin-top: 4px;
    max-height: 300px;
    overflow-y: auto;
}

.compare-dropdown-item {
    padding: 10px 16px;
    cursor: pointer;
    color: var(--theme-text-compare-item);
    font-size: 0.9rem;
    border-bottom: 1px solid var(--theme-border-compare-item);
}

.compare-dropdown-item:last-child {
    border-bottom: none;
}

.compare-dropdown-item:hover {
    background-color: var(--theme-bg-compare-item-hover);
    color: var(--theme-text-compare-item-hover);
}

/* ---------------------------------------------------
   SHARED PIN & METRICS
--------------------------------------------------- */
.pin-icon {
  position: absolute;
  top: 5px;
  right: 5px;
  font-size: 16px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease, color 0.2s ease;
  color: var(--theme-accent-primary);
}

.pin-icon.filled,
.pin-icon.filled i {
  color: var(--theme-accent-primary) !important;
}

.pin-icon.outline,
.pin-icon.outline i {
  color: #888 !important;
}

@keyframes pinPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.4); }
  100% { transform: scale(1.2); }
}

.pin-icon.pinning {
  animation: pinPop 0.3s ease forwards;
}

.metric-card {
  background: var(--theme-bg-metric-card);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-card.compact {
  padding: 8px 12px;
  background: var(--theme-bg-metric-card-compact);
  border-radius: 6px;
  margin-bottom: 0;
}

.metric-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.metric-title-compact {
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.metric-main-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--theme-text-metric-value);
  line-height: 1.2;
}

.metric-sub-row {
  display: flex;
  align-items: center;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.change-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--theme-bg-change-pill);
  font-weight: 500;
}

.change-pill.up {
  color: var(--theme-success);
  background: var(--theme-success-soft);
}

.change-pill.down {
  color: var(--theme-danger);
  background: var(--theme-danger-soft);
}

.metric-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--theme-border-metric-footer);
  font-size: 0.75rem;
  color: var(--theme-text-muted);
}

.range-item {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.range-item .label {
  font-size: 0.65rem;
  text-transform: uppercase;
  opacity: 0.6;
}

.range-bar {
  flex-grow: 1;
  height: 4px;
  background: var(--theme-bg-range-bar);
  border-radius: 2px;
  position: relative;
  margin: 0 4px;
}

.range-bar .fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: var(--theme-bg-range-fill);
  border-radius: 2px;
}

/* ---------------------------------------------------
   SHARED BUTTONS & INPUTS
--------------------------------------------------- */
.action-btn {
    padding: 10px 24px;
    background: var(--theme-bg-action);
    color: var(--theme-text-action);
    border: none;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover {
    background: var(--theme-accent-hover);
}

.action-btn.secondary {
    background: var(--theme-bg-btn-secondary);
    color: var(--theme-text-btn-secondary);
}

.action-btn.secondary:hover {
    background: var(--theme-bg-btn-secondary-hover);
    color: var(--theme-text-btn-secondary-hover);
}

/* ---------------------------------------------------
   SHARED CONTAINERS
--------------------------------------------------- */
.sparkline-container {
  width: 100%;
  height: 40px;
  margin: 8px 0 0 0;
}

.filter-group {
  min-width: 180px;
  max-width: 240px;
  flex-shrink: 0;
  border: 1px solid var(--theme-border-filter);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--theme-bg-filter);
}

.filter-group h4 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.7;
  margin-bottom: 6px;
  white-space: nowrap;
}

.compare-group {
  background: var(--theme-bg-compare-group);
  border-radius: 6px;
  padding: 8px;
}

/* ---------------------------------------------------
   TIME RANGE SELECTOR
--------------------------------------------------- */
.time-range-selector {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 10px;
}

.time-range-selector button {
  background: var(--theme-bg-time-range);
  border: 1px solid var(--theme-border-time-range);
  color: var(--theme-text-time-range);
  font-weight: 600; /* Semi-bold to match others */
  font-size: 0.85rem; /* Explicit size to match Legend/Metric */
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 6px;
  transition: all 0.2s ease;
  line-height: 1.2;
}

.time-range-selector button:hover {
  background: var(--theme-bg-time-range-hover);
  color: var(--theme-text-time-range-hover);
  border-color: var(--theme-border-time-range-hover);
}

.time-range-selector button.active {
  background-color: var(--theme-bg-time-range-active);
  color: var(--theme-text-time-range-active);
  border-color: var(--theme-border-time-range-active);
}

/* ---------------------------------------------------
   ANALYSIS SELECTORS
--------------------------------------------------- */
.analysis-selectors {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
    background: var(--theme-bg-analysis-toolbar);
    padding: 15px;
    border-radius: 12px;
}

.selector-group {
    flex: 1;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.selector-group label {
    font-size: 0.8rem;
    color: var(--theme-text-muted);
    text-transform: uppercase;
    font-weight: 600;
}

.analysis-dropdown {
    width: 100%;
    padding: 10px;
    background: var(--theme-bg-analysis-dropdown);
    border: 1px solid var(--theme-border-muted);
    color: var(--theme-text-modal-input);
    border-radius: 6px;
    font-size: 0.9rem;
}

/* ---------------------------------------------------
   MODAL (Unified)
--------------------------------------------------- */
.modal, .modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--theme-bg-modal-overlay);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    opacity: 0;
    pointer-events: none; /* Prevent clicks when hidden/opacity 0 */
    transition: opacity 0.3s ease;
}

/* Helper to show modal with transition */
.modal.show, .modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

/* Fallback for JS that uses display:block/flex directly */
.modal[style*="display: block"], 
.modal[style*="display: flex"],
.modal-overlay[style*="display: block"], 
.modal-overlay[style*="display: flex"] {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--theme-bg-modal);
    padding: 24px;
    border-radius: 12px;
    width: 90%;
    max-width: 450px;
    box-shadow: var(--theme-shadow-modal);
    display: flex;
    flex-direction: column;
    gap: 0; /* Managed by header/body/footer */
    position: relative;
    border: 1px solid var(--theme-border-modal);
    transform: translateY(20px) scale(0.95);
    transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.modal.show .modal-content, 
.modal-overlay.show .modal-content,
.modal[style*="display: block"] .modal-content, 
.modal[style*="display: flex"] .modal-content,
.modal-overlay[style*="display: block"] .modal-content, 
.modal-overlay[style*="display: flex"] .modal-content {
    transform: translateY(0) scale(1);
}

/* Header: Title + Close Button */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 0;
}

.modal-header h2, .modal-header h3 {
    margin: 0;
    color: var(--theme-text-modal-heading);
    font-size: 1.4rem;
    font-weight: 600;
    flex-grow: 1;
}

/* Close Button Styling */
.close-modal-btn {
    background: transparent;
    border: none;
    color: var(--theme-text-close);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-left: 16px;
    flex-shrink: 0;
}

.close-modal-btn:hover {
    background: var(--theme-bg-close-hover);
    color: var(--theme-text-heading);
    transform: rotate(90deg);
}

.close-modal-btn:focus {
    outline: 2px solid var(--theme-accent-primary);
    outline-offset: 2px;
}

.close-modal-btn i {
    font-size: 1.2rem;
}

/* Body Content */
.modal-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-body .auth-modal-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin: 0;
    width: 100%;
}

.modal-content p {
    margin: 0;
    color: var(--theme-text-modal-body);
    font-size: 0.95rem;
    line-height: 1.5;
}

.modal-content label {
    color: var(--theme-text-modal-label);
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 6px;
    display: block;
}

.modal-input {
    width: 100%;
    padding: 12px;
    background: var(--theme-bg-modal-input);
    border: 1px solid var(--theme-border-modal-input);
    color: var(--theme-text-modal-input);
    border-radius: 8px;
    font-size: 0.95rem;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.modal-input:focus {
    outline: none;
    border-color: var(--theme-accent-primary);
    box-shadow: var(--theme-shadow-input-focus);
}

select.modal-input,
select.auth-modal-country-select {
    cursor: pointer;
    /* Native <select> often picks up a system cyan/blue border on Windows/Edge; match text inputs instead. */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: var(--theme-bg-modal-input);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none'%3E%3Cpath stroke='%23b0b8cc' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 40px;
    border: 1px solid var(--theme-border-modal-input);
    color: var(--theme-text-modal-input);
    /* Dark palette for the OS-rendered dropdown list (fixes light popup + white text on Windows/Edge). */
    color-scheme: dark;
}

select.modal-input::-ms-expand,
select.auth-modal-country-select::-ms-expand {
    display: none;
}

/* Open list: explicit option colors where the browser allows (Chromium applies; helps contrast). */
select.modal-input option,
select.auth-modal-country-select option {
    background-color: var(--theme-bg-modal-input);
    color: var(--theme-text-modal-input);
}

body.light-mode select.modal-input,
body.light-mode select.auth-modal-country-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none'%3E%3Cpath stroke='%234b5563' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    color-scheme: light;
}

body.light-mode select.modal-input option,
body.light-mode select.auth-modal-country-select option {
    background-color: var(--theme-bg-modal-input);
    color: var(--theme-text-modal-input);
}

.auth-captcha-wrap {
    width: 100%;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--theme-border-auth-captcha);
    background: var(--theme-bg-auth-captcha);
    box-sizing: border-box;
    overflow: hidden;
}

.auth-captcha-message {
    margin-top: -6px;
    color: var(--theme-text-auth-error);
    font-size: 0.85rem;
}

/* Footer / Actions */
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

/* Typography Consistency */
.modal-content h2 { font-size: 1.5rem; }
.modal-content h3 { font-size: 1.25rem; }

/* Animation Fallback for JS display toggling */
@keyframes modalPopIn {
    0% { opacity: 0; transform: translateY(20px) scale(0.95); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

.modal[style*="display: block"] .modal-content,
.modal[style*="display: flex"] .modal-content,
.modal-overlay[style*="display: block"] .modal-content,
.modal-overlay[style*="display: flex"] .modal-content {
    animation: modalPopIn 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
}

/* Responsive */
@media (max-width: 480px) {
    .modal-content {
        width: 95%;
        padding: 20px;
    }
    .modal-header h2, .modal-header h3 {
        font-size: 1.2rem;
    }
}

/* ---------------------------------------------------
   SHARED HEADERS
--------------------------------------------------- */
.tab-header {
  text-align: left;
  font-size: 2.2rem;
  font-weight: 900;
  margin-top: 24px;
  margin-bottom: 24px;
  color: var(--theme-text-tab-header);
  text-transform: uppercase;
  letter-spacing: 2.5px;
  text-shadow: var(--theme-shadow-tab-header);
  position: relative;
  display: block;
  width: 100%;
  padding-bottom: 12px;
  border-bottom: 4px solid var(--carolina-blue);
}

.tab-subheader {
  text-align: left;
  font-size: 1.8rem;
  font-weight: 800;
  margin-top: 16px;
  margin-bottom: 16px;
  color: var(--theme-text-tab-subheader);
  text-transform: uppercase;
  letter-spacing: 2px;
  text-shadow: var(--theme-shadow-tab-subheader);
  position: relative;
  display: block;
  width: 100%;
  padding-bottom: 8px;
  border-bottom: 3px solid var(--carolina-blue);
}

/* ---------------------------------------------------
   SHARED INPUTS
--------------------------------------------------- */
.select-wrapper-small select {
  background: var(--theme-bg-input-alt);
  color: var(--theme-text-input-alt);
  border: 1px solid var(--theme-border-muted);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

.select-wrapper-small select:hover {
  background: var(--theme-bg-select-hover-alt);
  border-color: var(--theme-border-strong);
}
small select:hover {
  background: var(--theme-bg-select-hover-alt);
  border-color: var(--theme-border-strong);
}

/* Tab section cards — same chrome as Home columns (not used on #home / #trends wrappers) */
#product-analysis section.dashboard-section,
#marketanalysis section.dashboard-section,
#item-lookup .item-lookup-card {
  background: var(--theme-tab-surface-bg);
  border: 1px solid var(--theme-tab-surface-border);
  border-radius: var(--theme-tab-surface-radius, 12px);
  box-shadow: var(--theme-tab-surface-shadow);
  padding: 16px 18px 18px;
  box-sizing: border-box;
  overflow: hidden;
}

#product-analysis section.dashboard-section,
#marketanalysis section.dashboard-section {
  margin-bottom: 16px;
}
