/* ================================
   Global Reset & Base
================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

html, body {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

body {
  background: linear-gradient(180deg, #0f1115, #0b0d11);
  color: #e6e6e6;
  min-height: 100vh;
}

/* ================================
   Header (Desktop)
================================ */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 28px;
  background: #161a22;
  border-bottom: 1px solid #2a2f3a;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo {
  width: 36px;
  height: 36px;
  border-radius: 50%;
}

.brand-name {
  font-family: "Teko", system-ui, sans-serif;
  font-size: 22px;
  font-weight: 600;
  color: #e6e6e6;
}

.change-mode-link {
  margin-left: 12px;
  font-size: 12px;
  color: #9aa0a6;
  text-decoration: none;
  padding: 6px 10px;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  background: #252b38;
}

.main-menu-link {
  margin-left: 8px;
  font-size: 12px;
  color: #9aa0a6;
  text-decoration: none;
  padding: 6px 10px;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  background: #252b38;
}

.change-mode-link:hover {
  color: #e6e6e6;
  background: #2a2f3a;
}

.main-menu-link:hover {
  color: #e6e6e6;
  background: #2a2f3a;
}

.header-nav {
  display: flex;
  gap: 8px;
}

.nav-tab {
  padding: 8px 16px;
  background: #252b38;
  color: #9aa0a6;
  text-decoration: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  border: none;
  cursor: pointer;
}

.nav-tab:hover {
  background: #2a2f3a;
  color: #e6e6e6;
}

.nav-tab.active {
  background: #3a86ff;
  color: #fff;
}

.header-right {
  display: flex;
  gap: 28px;
}

.metric {
  text-align: center;
  min-width: 120px;
}

.metric .label {
  font-size: 12px;
  color: #9aa0a6;
}

.metric .value {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.pnl-positive { color: #2ecc71; }
.pnl-negative { color: #e74c3c; }

/* ================================
   Stock Bar (Always Visible)
================================ */
.stock-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1e2430;
  padding: 16px 28px;
  border-bottom: 1px solid #2a2f3a;
}

.stock-bar .stock-info {
  display: flex;
  align-items: center;
  gap: 24px;
}

.stock-bar .stock-info h2 {
  font-size: 18px;
}

.stock-bar .price-box {
  font-size: 28px;
  font-weight: 700;
}

.stock-bar .fundamentals {
  display: flex;
  gap: 16px;
  font-size: 13px;
}

.fundamentals .label { color: #ffffff; }
.fundamentals .eps-value { color: #3a86ff; }
.fundamentals .pe-value { font-weight: 600; }

.pe-up { color: #2ecc71; }
.pe-down { color: #e74c3c; }

#toggle-btn {
  padding: 10px 24px;
  font-size: 14px;
}

/* ================================
   Main Container (Home View)
================================ */
.container {
  max-width: 1000px;
  margin: 32px auto;
  padding: 0 20px;
  display: grid;
  row-gap: 28px;
}

/* ================================
   Chart Section
================================ */
.chart-section {
  background: #1e2430;
  padding: 20px;
  border-radius: 10px;
  border: 1px solid #2a2f3a;
  overflow: hidden;
}

/* Chart toolbar (minimal addition for candle timeframe selector) */
.chart-toolbar {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

/* Live price label next to timeframe selector (display-only) */
.chart-toolbar-price {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #e6e6e6;
}

/* Hide stock info panel + toggle button ONLY in full-screen Chart view */
body[data-view="chart"] .stock-bar {
  display: none;
}

.chart-toolbar-label {
  font-size: 12px;
  color: #9aa0a6;
}

.chart-toolbar-select {
  padding: 8px 10px;
  background: #161a22;
  color: #e6e6e6;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}

/* Indicators selector (dropdown button) */
.indicator-selector {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.indicator-selector-btn {
  appearance: none;
}

.indicator-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 140px;
  background: #161a22;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  padding: 6px;
  z-index: 200;
}

.indicator-menu-item {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #e6e6e6;
  cursor: pointer;
  font-size: 13px;
}

.indicator-menu-item:hover {
  background: #252b38;
}

/* Indicator badge inside chart canvas (TradingView-style) */
.chart-overlay-ui {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

/* Collapse/expand toggle for indicator badge stack (UI-only) */
.indicator-stack-toggle {
  pointer-events: auto;
  width: 26px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  background: rgba(22, 26, 34, 0.92);
  color: #9aa0a6;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
}

.indicator-stack-toggle:hover {
  color: #e6e6e6;
  background: rgba(37, 43, 56, 0.92);
}

.chart-overlay-ui.is-collapsed .indicator-badge {
  display: none;
}

.indicator-badge {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  background: rgba(22, 26, 34, 0.92);
  color: #e6e6e6;
  font-size: 13px;
}

.indicator-badge-name {
  font-weight: 700;
  letter-spacing: 0.2px;
}

.indicator-badge-value {
  font-weight: 800;
}

.indicator-badge.is-hidden .indicator-badge-name {
  text-decoration: line-through;
  opacity: 0.75;
}

/* Eye icon strike-through when indicator is hidden (visual only) */
.indicator-badge.is-hidden .indicator-badge-btn-eye {
  text-decoration: line-through;
  opacity: 0.85;
}

.indicator-badge-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.indicator-badge:hover .indicator-badge-controls,
.indicator-badge.show-controls .indicator-badge-controls {
  opacity: 1;
}

.indicator-badge-btn {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  background: #252b38;
  color: #e6e6e6;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}

.indicator-badge-btn:hover {
  background: #2a2f3a;
}

/* Settings panel (generic container) */
.indicator-settings-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.55);
  z-index: 9998;
  padding: 18px;
}

.indicator-settings-panel {
  width: 100%;
  max-width: 380px;
  background: #1e2430;
  border: 1px solid #2a2f3a;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.45);
}

.indicator-settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.indicator-settings-title {
  font-weight: 800;
  font-size: 14px;
}

.indicator-settings-close {
  border: none;
  background: transparent;
  color: #9aa0a6;
  cursor: pointer;
  font-size: 18px;
}

.indicator-settings-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}

.indicator-settings-row label {
  font-size: 12px;
  color: #9aa0a6;
}

.indicator-settings-row input,
.indicator-settings-row select {
  padding: 8px 10px;
  background: #161a22;
  color: #e6e6e6;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  font-size: 13px;
}

/* overlay=false indicator panels (e.g., RSI) */
.indicator-panels-host {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.indicator-panel {
  border: 1px solid #2a2f3a;
  border-radius: 10px;
  background: #1e2430;
  overflow: hidden;
}

.indicator-panel-chart {
  width: 100%;
}

/* Full-screen Chart view: overlay toolbar controls inside chart canvas */
.chart-overlay-toolbar {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 220;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.chart-overlay-toolbar .chart-toolbar-price {
  background: rgba(22, 26, 34, 0.92);
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  padding: 6px 10px;
}

/* TradingView-style stacked panes splitter (price chart + sub-panels like RSI) */
.chart-pane-splitter {
  width: 100%;
  height: 6px;
  cursor: row-resize;
  background: rgba(15, 17, 21, 0.6);
  border-top: 1px solid #2a2f3a;
  border-bottom: 1px solid #2a2f3a;
}

.chart-pane-splitter:hover {
  background: rgba(37, 43, 56, 0.85);
}

#chart-container {
  width: 100%;
  height: 300px;
  border-radius: 6px;
  overflow: hidden;
}

/* ================================
   Trade Controls & Buttons
================================ */
.trade-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quantity-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.action-buttons {
  display: flex;
  gap: 12px;
  align-self: flex-end;
}

.position-size-selector {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.position-size-selector label {
  font-size: 12px;
  color: #9aa0a6;
}

.position-size-selector select {
  padding: 10px 12px;
  background: #161a22;
  color: #e6e6e6;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  width: 180px;
}

.trade-controls input {
  padding: 10px 12px;
  background: #161a22;
  color: #e6e6e6;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  width: 180px;
}

.percent-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-percent {
  padding: 6px 10px;
  background: #252b38;
  color: #9aa0a6;
  border: 1px solid #2a2f3a;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-percent:hover {
  background: #3a86ff;
  color: #fff;
  border-color: #3a86ff;
}


.btn {
  padding: 10px 18px;
  font-weight: 600;
  border-radius: 6px;
  border: none;
  cursor: pointer;
}

.btn-buy { background: #2ecc71; color: #fff; }
.btn-sell { background: #e74c3c; color: #fff; }
.btn-secondary { background: #3a86ff; color: #fff; }

/* ================================
   Positions Table (Home View)
================================ */
.positions {
  background: #1e2430;
  padding: 20px;
  border-radius: 10px;
  border: 1px solid #2a2f3a;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 12px 10px;
  text-align: center;
}

th {
  color: #9aa0a6;
  border-bottom: 1px solid #2a2f3a;
}

.position-details {
  display: none;
}

/* ================================
   Full View (Chart & Positions)
================================ */
.full-view {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 180px);
  padding: 20px;
}

#full-chart-container {
  flex: 1;
  width: 100%;
  background: #1e2430;
  border-radius: 10px;
  border: 1px solid #2a2f3a;
  overflow: hidden;
}

.full-positions-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #1e2430;
  border-radius: 10px;
  border: 1px solid #2a2f3a;
  overflow: hidden;
}

.positions-summary-bar {
  display: flex;
  gap: 32px;
  padding: 16px 24px;
  border-bottom: 1px solid #2a2f3a;
  background: #1a1f28;
}

.summary-item {
  text-align: center;
}

.summary-item .label {
  font-size: 11px;
  color: #9aa0a6;
  display: block;
}

.summary-item .value {
  font-size: 16px;
  font-weight: 600;
}

.full-positions-table-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 20px;
}

.full-positions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.full-positions-table th,
.full-positions-table td {
  padding: 14px 12px;
  text-align: center;
}

.full-positions-table th {
  color: #9aa0a6;
  border-bottom: 1px solid #2a2f3a;
  font-weight: 500;
  position: sticky;
  top: 0;
  background: #1e2430;
}

.full-positions-table tbody tr {
  border-bottom: 1px solid #2a2f3a;
}

.full-positions-table tbody tr:hover {
  background: #252b38;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #9aa0a6;
}

.empty-state h3 {
  font-size: 18px;
  margin-bottom: 8px;
  color: #e6e6e6;
}

/* ================================
   Mobile View
================================ */
@media (max-width: 768px) {
  .container {
    margin: 16px auto;
    padding: 0 12px;
    row-gap: 16px;
    max-width: 100%;
  }

  .header {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
    padding: 12px;
    max-width: 100%;
  }

  .header-left {
    justify-content: center;
  }

  .header-logo {
    width: 28px;
    height: 28px;
  }

  .brand-name {
    font-size: 18px;
  }

  .header-nav {
    width: 100%;
    justify-content: center;
    order: 2;
  }

  .nav-tab {
    padding: 6px 12px;
    font-size: 12px;
  }

  .header-right {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .metric {
    min-width: unset;
  }

  .metric .label {
    font-size: 10px;
  }

  .metric .value {
    font-size: 13px;
  }

  .stock-bar {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
  }

  .stock-bar .stock-info {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    text-align: left;
  }

  .stock-bar .stock-info h2 {
    font-size: 14px;
    width: 100%;
  }

  .stock-bar .price-box {
    font-size: 20px;
  }

  .stock-bar .fundamentals {
    font-size: 11px;
    gap: 10px;
  }

  #toggle-btn {
    flex-shrink: 0;
    padding: 8px 14px;
    font-size: 12px;
  }

  .full-view {
    height: calc(100vh - 160px);
    padding: 10px;
    overflow: hidden;
  }

  #full-chart-container {
    height: 100%;
    min-height: 0;
  }

  .col-stock, .col-avg, .col-ltp, .col-change {
    display: none !important;
  }

  th, td {
    padding: 10px 5px;
  }

  .position-row {
    cursor: pointer;
  }

  .position-details.active {
    display: table-row !important;
    background: #161a22;
  }

  .position-details td {
    padding: 10px;
  }

  .details-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
    font-size: 12px;
  }

  #toggle-btn {
    padding: 8px 16px;
    font-size: 13px;
  }

  .full-view {
    height: calc(100vh - 220px);
    padding: 12px;
  }

  .positions-summary-bar {
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    padding: 12px 16px;
  }

  .full-positions-table {
    font-size: 12px;
  }

  .full-positions-table th,
  .full-positions-table td {
    padding: 10px 6px;
  }

  .full-positions-table .col-stock,
  .full-positions-table .col-avg,
  .full-positions-table .col-ltp,
  .full-positions-table .col-change {
    display: none !important;
  }

  .trade-controls {
    flex-direction: column;
    align-items: center;
    gap: 12px;
  }

  .quantity-row {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-end;
    gap: 8px;
    width: 100%;
  }

  .position-size-selector {
    flex: 1;
    min-width: 120px;
  }

  .position-size-selector label {
    text-align: center;
  }

  .position-size-selector select {
    width: 100%;
  }

  .trade-controls input {
    flex: 1;
    min-width: 100px;
    width: auto;
  }

  .action-buttons {
    width: 100%;
    justify-content: center;
  }

  .action-buttons .btn {
    flex: 1;
  }

  .percent-buttons {
    justify-content: center;
  }

  .btn-percent {
    flex: 1;
    min-width: 50px;
    text-align: center;
  }
}

/* ================================
   Mode Selector Page
================================ */

.mode-selector-page {
  /* Center card nicely within viewport, below header */
  min-height: calc(100vh - 92px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 36px 20px;
}

.mode-selector-card {
  width: 100%;
  max-width: 720px;
  background: #1e2430;
  border: 1px solid #2a2f3a;
  border-radius: 14px;
  padding: 34px 30px;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0,0,0,0.35);
}

.mode-selector-title {
  font-family: "Teko", system-ui, sans-serif;
  font-size: 34px;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.mode-selector-subtitle {
  color: #9aa0a6;
  font-size: 14px;
  margin-bottom: 20px;
  line-height: 1.5;
}

.mode-selector-buttons {
  display: grid;
  /* 2-up grid for Free/Timed, with Scheduled spanning full row */
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  align-items: stretch;
  justify-content: center;
  max-width: 520px;
  margin: 0 auto;
}

/* Center a third button by spanning full row */
.mode-selector-buttons .mode-btn:nth-child(3) {
  grid-column: 1 / -1;
  justify-self: center;
  width: min(260px, 100%);
}

/* Ensure anchor "buttons" look and feel like buttons */
.mode-selector-buttons .mode-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  padding: 12px 18px;
  font-size: 15px;
}

.mode-selector-note {
  margin-top: 16px;
  color: #9aa0a6;
  font-size: 12px;
  line-height: 1.5;
}

.scheduled-landing {
  margin-top: 10px;
}

.scheduled-landing-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  border: 1px solid #2a2f3a;
  border-radius: 10px;
  background: rgba(15, 17, 21, 0.35);
  margin-top: 10px;
}

.scheduled-landing-label {
  color: #9aa0a6;
  font-size: 13px;
}

.scheduled-landing-value,
.scheduled-landing-countdown {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.scheduled-landing-actions {
  margin-top: 14px;
}

.scheduled-ended {
  margin-top: 12px;
  color: #9aa0a6;
  font-size: 12px;
}

.btn.disabled {
  pointer-events: none;
  opacity: 0.5;
}

@media (max-width: 680px) {
  .mode-selector-card {
    padding: 26px 18px;
  }

  .mode-selector-buttons {
    grid-template-columns: 1fr;
  }
}
