/* main.css - TradingView Light Theme & RTL Architecture */
:root {
  /* TradingView Official Light Mode Palette */
  --bg-primary: #ffffff;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f0f3fa;
  --bg-card: #ffffff;
  --bg-hover: #f0f3fa;
  --bg-active: #e8f0fe;
  
  --text-primary: #131722;
  --text-secondary: #787b86;
  --text-muted: #9598a1;
  
  --accent-blue: #2962ff;
  --accent-blue-hover: #1e53e5;
  --accent-blue-subtle: rgba(41, 98, 255, 0.1);
  
  /* Candles: Teal Bullish & Dark Black/Slate Bearish matching user TradingView setup */
  --bullish-green: #089981;
  --bullish-green-bg: rgba(8, 153, 129, 0.12);
  --bearish-dark: #131722;
  --bearish-red: #f23645;
  --bearish-red-bg: rgba(242, 54, 69, 0.12);
  
  --purple-rsi: #7e57c2;
  --purple-rsi-band: rgba(126, 87, 194, 0.12);
  --gold-accent: #ff9800;
  --yellow-sma: #ffb300;
  
  --border-color: #e0e3eb;
  --border-light: #f0f3fa;
  --grid-line-color: #f0f3fa;
  
  --font-main: -apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif;
  --font-mono: 'JetBrains Mono', Consolas, 'Courier New', monospace;
  
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

  /* Panels float on a gray shell */
  --bg-shell: #e3e6ec;
  --bg-panel: #ffffff;
  --bg-pressed: #e0e3eb;
  --bg-inverse: #131722;
  --bg-glass: rgba(255, 255, 255, 0.88);
  --text-inverse: #ffffff;
  --scroll-thumb: #c1c5cd;
  --scroll-thumb-hover: #a0a4ae;
  --panel-gap: 6px;
  --panel-radius: 8px;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg-shell: #2a2e39;
  --bg-panel: #131722;
  --bg-primary: #131722;
  --bg-secondary: #131722;
  --bg-tertiary: #1e222d;
  --bg-card: #1e222d;
  --bg-hover: #2a2e39;
  --bg-active: rgba(41, 98, 255, 0.22);
  --bg-pressed: #363a45;
  --bg-inverse: #d1d4dc;
  --bg-glass: rgba(19, 23, 34, 0.88);

  --text-primary: #d1d4dc;
  --text-secondary: #9598a1;
  --text-muted: #787b86;
  --text-inverse: #131722;

  --border-color: #363a45;
  --border-light: #2a2e39;
  --grid-line-color: #2a2e39;

  --scroll-thumb: #434651;
  --scroll-thumb-hover: #5d606b;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  background-color: var(--bg-shell);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 13px;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  user-select: none;
  direction: rtl; /* RTL Support */
  text-align: right;
}

input, button, select, textarea {
  font-family: inherit;
}

/* App Shell Structure */
#appRoot {
  display: flex;
  flex-direction: column;
  gap: var(--panel-gap);
  height: 100vh;
  width: 100vw;
  padding-bottom: var(--panel-gap);
  background: var(--bg-shell);
}

#topbarArea {
  height: 48px;
  min-height: 48px;
  background: var(--bg-secondary);
  z-index: 100;
}

/* Main Workspace layout:
   In TradingView Arabic:
   Left: Drawing toolbar
   Center: Chart canvas
   Right: Watchlist sidebar
   Far Right: TV Vertical icons bar
*/
#mainWorkspace {
  display: flex;
  flex: 1;
  gap: var(--panel-gap);
  min-height: 0;
  padding: 0 var(--panel-gap);
  position: relative;
  overflow: hidden;
  direction: ltr; /* Workspace container keeps left-to-right pane flow to match TV layout */
}

#leftToolbarArea {
  width: 52px;
  min-width: 52px;
  background: var(--bg-secondary);
  border-radius: var(--panel-radius);
  z-index: 90;
  direction: rtl;
}

#chartCenterArea {
  flex: 1;
  min-width: 0;
  position: relative;
  background: transparent;
  border-radius: var(--panel-radius);
  overflow: hidden;
  direction: ltr; /* Canvas time axis flows left-to-right chronologically */
}

#rightSidebarArea {
  width: 320px;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  z-index: 90;
  direction: ltr; /* Keeps Watchlist on left of the sidebar and vertical icons strip at extreme right */
  transition: width 0.2s ease, min-width 0.2s ease;
}

#rightSidebarArea.collapsed {
  width: 42px;
  min-width: 42px;
}

#rightSidebarArea.collapsed .watchlist-main-panel {
  display: none;
}

#bottomBarArea {
  height: 30px;
  min-height: 30px;
  margin: 0 var(--panel-gap);
  background: var(--bg-secondary);
  border-radius: var(--panel-radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-size: 11px;
  color: var(--text-secondary);
  direction: rtl;
}

.time-range-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  padding: 2px 7px;
  line-height: 1.4;
  transition: all 0.15s ease;
  font-family: inherit;
}

.time-range-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.time-range-btn.active {
  background: var(--bg-pressed) !important;
  color: var(--text-primary) !important;
  font-weight: 700;
  border-color: var(--border-color);
}

.scale-toggle-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 7px;
  line-height: 1.4;
  font-family: inherit;
}

.scale-toggle-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.scale-toggle-btn.active {
  background: var(--accent-blue-subtle);
  color: var(--accent-blue);
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
}
::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
}

/* Tooltip System */
[data-tooltip] {
  position: relative;
}
[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  top: 50%;
  left: calc(100% + 8px);
  transform: translateY(-50%);
  background: var(--bg-inverse);
  color: var(--text-inverse);
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10000;
  box-shadow: var(--shadow-md);
  opacity: 0;
  animation: fadeInTooltip 0.15s ease forwards 0.3s;
}

@keyframes fadeInTooltip {
  to { opacity: 1; }
}
