/* Custom styling for Portfolio Analyzer Dash app */
:root {
  --sidebar-width: 380px;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.08);
  --muted: #6b7280;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #f59e0b;
  --card-bg: #ffffff;
  --page-bg: #f5f7fa;
  --border-subtle: rgba(15, 23, 42, 0.06);
  --shadow-soft: 0 6px 18px rgba(15, 23, 42, 0.06);
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--page-bg);
  color: #0f172a;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
}

.app-container {
  max-width: 1400px;
  margin: 12px auto;
  padding: 12px;
}

/* Top split: sidebar + main content */
.top-split {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: 20px;
  align-items: stretch; /* match heights */
  margin-bottom: 12px;
  height: calc(100vh - 200px); /* leave room for regime chips and margins */
  max-height: 700px; /* reasonable desktop max */
}

.sidebar,
.main-panel {
  background: var(--card-bg);
  padding: 16px;
  border-radius: 12px;
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden; /* prevent content overflow */
}

/* Optional subtle blur on left panel */
.sidebar {
  backdrop-filter: blur(8px);
}

.sidebar > h2:first-child {
  flex-shrink: 0; /* keep title fixed */
}

/* Weights controls container with scroll when needed */
#weights-controls {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  margin-top: 12px;
  padding-right: 4px;
}

/* Performance metrics at bottom of sidebar */
#portfolio-metrics-display {
  flex-shrink: 0;
  margin-top: auto; /* push to bottom */
}

/* Headings */
h1 {
  font-size: 22px;
  margin: 4px 0 16px 0;
}

h2 {
  font-size: 16px;
  margin: 14px 0 8px;
  color: #0b2447;
}

h3,
.section-title {
  font-size: 14px;
  margin: 8px 0;
}

/* Generic buttons and inputs */
button, .dash-button {
  background: var(--accent) !important;
  color: #fff !important;
  border: none !important;
  padding: 8px 12px !important;
  border-radius: 6px !important;
  cursor: pointer !important;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.15);
  font-size: 13px !important;
}

button:hover, .dash-button:hover {
  filter: brightness(0.97);
}

input[type="text"],
input[type="number"],
.field-input,
.Select,
.Select input,
.Select .Select-control,
.dash-dropdown {
  border-radius: 6px !important;
  border: 1px solid var(--border-subtle) !important;
  font-size: 13px !important;
}

/* Tables */
.dash-table-container .dash-spreadsheet {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.04);
}

/* ===============================
   Weights mode card + tabs
   =============================== */

.return-view-tabs-container {
  display: flex;
}

.return-view-tabs {
  margin-top: 12px;
  border-bottom: 1px solid var(--border-subtle) !important;
  display: flex !important;
  flex-direction: row !important;
}

.return-view-tab {
  padding: 6px 12px !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  margin-right: 6px !important;
  border-radius: 0 !important;
  border: none !important;
  background: transparent !important;
  color: var(--muted) !important;
  border-bottom: 2px solid transparent !important;
}

.return-view-tab--selected {
  background: transparent !important;
  color: #111827 !important;
  font-weight: 600 !important;
  border-bottom-color: #dc2626 !important; /* Red to match the drawdown theme */
}

.frontier-view-container {
  display: none;
  margin-top: 12px;
}

.frontier-view-container--visible {
  display: flex !important;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  width: 100%;
}

.sidebar-view-tabs {
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle) !important;
}

.sidebar-view-tab {
  padding: 8px 16px !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  margin-right: 8px !important;
  border-radius: 0 !important;
  border: none !important;
  background: transparent !important;
  color: var(--muted) !important;
  border-bottom: 2px solid transparent !important;
}

.sidebar-view-tab--selected {
  background: transparent !important;
  color: #111827 !important;
  font-weight: 600 !important;
  border-bottom-color: var(--accent) !important;
}

.weights-mode-card {
  padding: 10px 10px 8px;
  border-radius: 10px;
  background: #f9fafb;
  border: 1px solid var(--border-subtle);
  margin-bottom: 10px;
}

.weights-tabs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.weights-tabs-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-top: 4px;
}

.weights-tabs-container {
  margin-top: 4px;
  flex: 1;
}

.weights-tabs {
  border-bottom: none !important;
}

/* Rectangular, sharp-edged tabs */
.weights-tab {
  padding: 4px 10px !important;
  font-size: 12px !important;
  margin-right: 4px !important;
  border-radius: 0 !important;
  border: none !important;
  background: transparent !important;
  color: var(--muted) !important;
  border-bottom: 2px solid transparent !important;
}

.weights-tab--selected {
  background: transparent !important;
  color: #111827 !important;
  font-weight: 600 !important;
  border-bottom-color: var(--accent) !important;
}

/* Return optimiser inline controls */
.return-optimizer-controls {
  margin-top: 6px;
  display: none; /* shown via callback */
}

.field-label {
  font-size: 12px;
  color: var(--muted);
  display: block;
  margin-bottom: 2px;
}

.field-input {
  width: 90px !important;
  padding: 4px 8px !important;
}

.optimize-status {
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
}

/* ===============================
   Weight rows + sliders
   =============================== */

.weight-row {
  display: grid;
  grid-template-columns: 44px 70px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.weight-row--add {
  margin-top: 12px;
}

.asset-label {
  font-weight: 600;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 4px;
  line-height: 18px;
  width: 100%;
}

/* Remove button for each asset: subtler outline */
.asset-remove-btn {
  background: transparent !important;
  color: rgba(55, 65, 81, 0.55) !important;
  border: 0px solid rgba(55, 65, 81, 0.12) !important;
  padding: 6px 8px !important;
  border-radius: 8px !important;
  min-width: 32px !important;
  height: 32px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  /* No shadow */
  box-shadow: none !important;
}

/* Add ticker input + plus button inside last cell */
.add-asset-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Add asset circular button, lighter */
.asset-add-btn {
  background: transparent !important;
  color: #166534 !important;
  border: 1px solid rgba(22, 101, 52, 0.35) !important;
  padding: 6px !important;
  border-radius: 999px !important;
  min-width: 32px !important;
  height: 32px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* Add ticker input styled like pill */
.asset-add-input {
  background: #f9fafb;
  border-left: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  border-top: 1px solid var(--border-subtle);
  padding: 7px 10px;
  border-radius: 999px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
  font-size: 13px;
}

.asset-add-input:focus {
  box-shadow: 0 0 0 2px rgba(22, 101, 52, 0.18);
}

.weight-slider {
  width: 100% !important;
  padding: 0 !important;
  margin: 0 !important;
  height: 100%;
}

/* Slider layout */
.weight-slider-container {
  width: 100%;
  height:100%;
  padding-top: 2px;
  padding-bottom: 2px;
}

.weight-slider-shell {
  position: relative;
  width: 100%;
  height: 100%;
}

/* rc-slider core */
.weight-slider-shell .rc-slider {
  margin: 0;
  padding: 0;
  height: 100%;
}

/* Rectangular track with slight rounding */
.weight-slider-shell .rc-slider-rail {
  background-color: #e5e7eb;
  height: 100%;
  border-radius: 6px;
}

.weight-slider-shell .rc-slider-track {
  background-color: var(--accent);
  height: 100%;
  border-radius: 6px;
}

.weight-slider-shell .rc-slider-step {
  display: none;
}

/* Handle is small rectangular block */
.weight-slider-shell .rc-slider-handle {
  width: 10px;
  height: 100%;
  margin-top: 0;
  border-radius: 4px;
  border: none;
  background-color: #1d4ed8;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.2);
}

.weight-slider-shell .rc-slider-handle:hover,
.weight-slider-shell .rc-slider-handle-dragging {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

/* Hide rc-slider tooltip bubble completely */
.weight-slider-shell .rc-slider-tooltip {
  display: none !important;
}

/* Percentage overlay left-aligned inside bar */
.weight-slider-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-left: 10px;
  pointer-events: none;
  font-size: 12px;
  font-weight: 600;
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(15, 23, 42, 0.45);
  line-height: 100%;
}

/* ===============================
   Max Drawdown Slider (Red Theme)
   =============================== */

.maxdd-slider {
  width: 100% !important;
  padding: 0 !important;
  margin: 0 !important;
}

.maxdd-slider .rc-slider {
  margin: 8px 0;
}

.maxdd-slider .rc-slider-rail {
  background-color: #fee2e2;
  height: 8px;
  border-radius: 4px;
}

.maxdd-slider .rc-slider-track {
  background: linear-gradient(90deg, #ef4444, #dc2626);
  height: 8px;
  border-radius: 4px;
}

.maxdd-slider .rc-slider-handle {
  width: 16px;
  height: 16px;
  margin-top: -4px;
  border-radius: 50%;
  border: 2px solid #fff;
  background-color: #dc2626;
  box-shadow: 0 2px 4px rgba(220, 38, 38, 0.3);
}

.maxdd-slider .rc-slider-handle:hover,
.maxdd-slider .rc-slider-handle-dragging {
  box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.2);
}

.maxdd-slider .rc-slider-mark-text {
  font-size: 11px;
  color: var(--muted);
}

/* ===============================
   Portfolio metrics card (right side)
   =============================== */

#portfolio-metrics-display {
  /* margin-top: 20px; */
}

.metrics-card {
  border-radius: 10px;
  padding: 10px 12px;
  background: #f9fafb;
  border: 1px solid var(--border-subtle);
}

.metrics-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}

.metrics-card-title {
  font-size: 13px;
  font-weight: 600;
  color: #111827;
}

.metrics-card-subtitle {
  font-size: 11px;
  color: var(--muted);
}

#frontier-view-container {
  width: 100%;
}

#frontier-mini-chart {
  width: 100%;
}

.metrics-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px; /* more space between white cards */
}

.metrics-item {
  background: #ffffff;
  border-radius: 8px;
  padding: 6px 10px 8px;
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  justify-content: space-between;  /* align bar to bottom */
  min-height: 70px;
}

.metrics-label {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 2px;
}

.metrics-value {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.metrics-bar {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}

.metrics-bar-fill {
  height: 100%;
  border-radius: 999px;
}

.metrics-bar--positive {
  background: linear-gradient(90deg, #22c55e, #15803d);
}

.metrics-bar--neutral {
  background: linear-gradient(90deg, #93c5fd, #3b82f6);
}

.metrics-bar--accent {
  background: linear-gradient(90deg, #a78bfa, #6d28d9);
}

.metrics-bar--negative {
  background: linear-gradient(90deg, #f97316, #dc2626);
}

/* ===============================
   Main panel tweaks
   =============================== */

.main-panel {
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
  padding: 0; /* remove padding to maximize chart space */
}

.main-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px; /* tighten header spacing */
  padding: 10px 10px 4px 10px; /* add padding only to header */
  flex-shrink: 0; /* keep header fixed */
}

/* Ensure the main chart uses all available vertical space */
#main-chart {
  flex: 1; /* fill available space */
  min-height: 0; /* allow flex shrink */
  width: 100%;
  height: 100%;
}

#main-chart > div {
  width: 100% !important;
}

/* Target all children under main-chart to inherit height */
#main-chart * {
  box-sizing: border-box;
}

.js-plotly-plot,
.plot-container,
.plotly,
.svg-container {
  height: 100% !important;
  width: 100% !important;
}

.main-panel-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.regime-back-btn {
  background: transparent !important;
  color: var(--accent) !important;
  border: none !important;
  padding: 4px 8px !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  box-shadow: none !important;
  display: inline-flex;
  align-items: center !important;
  gap: 4px;
}

.regime-back-btn:hover {
  text-decoration: underline;
  filter: none !important;
}

.main-panel-title {
  margin: 0;
  font-size: 16px;
  padding-left: 4px;
}

.main-panel-options {
  display: flex;
  align-items: center;
}

/* Graph area */
#main-chart,
#frontier-chart {
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.85),
    rgba(248, 250, 252, 0.9)
  );
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.05);
}

/* ===============================
   Regime chips (clickable cards)
   =============================== */

.regime-chip {
  transition: all 0.15s ease;
  box-shadow: 0 2px 4px rgba(15, 23, 42, 0.06);
}

.regime-chip:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
  border-color: #888 !important;
}

.regime-chip--selected {
  border: 2px solid var(--accent) !important;
  background: var(--accent-soft) !important;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.regime-chip--selected:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.3);
}

/* Small screens adjustments */
@media (max-width: 900px) {
  .top-split {
    grid-template-columns: minmax(0, 1fr);
    height: auto; /* no fixed height on mobile */
    max-height: none;
  }

  .sidebar {
    order: 2;
    height: auto; /* natural height on mobile */
  }

  .main-panel {
    order: 1;
    min-height: 500px; /* ensure chart has space to render on mobile */
  }

  .metrics-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #weights-controls {
    overflow-y: visible; /* no scroll on mobile */
  }

  #frontier-chart {
    min-height: 400px !important; /* ensure frontier chart renders on mobile */
  }

  .frontier-view-container--visible {
    min-height: 400px; /* ensure frontier mini chart has space on mobile */
  }
}
