/* ═══════════════════════════════
   RESET & BASE
═══════════════════════════════ */

/* Main content wrapper */
.main-wrap {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
*, *::before, *::after {
  margin: 0; padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html, body {
  height: 100%;
  font-family: 'Nunito', sans-serif;
  overflow: hidden;
  background: #0d1117;
  color: #e6edf3;
}

/* Theme vars cascade from #app div */
#app {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s, color 0.3s;
}

/* ═══════════════════════════════
   APP SHELL
═══════════════════════════════ */
.app {
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ═══════════════════════════════
   MOBILE TOPBAR
═══════════════════════════════ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
.topbar-logo { display: flex; align-items: center; gap: 8px; }
.logo-mark {
  width: 30px; height: 30px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Syne', sans-serif;
  font-weight: 800; font-size: 12px; color: #000;
}
.logo-name {
  font-family: 'Syne', sans-serif;
  font-weight: 700; font-size: 16px; color: var(--text);
}
.logo-name em { color: var(--accent); font-style: normal; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

/* ═══════════════════════════════
   LIVE BADGE
═══════════════════════════════ */
.live-badge {
  display: flex; align-items: center; gap: 5px;
  background: var(--accent-dim);
  border: 1px solid rgba(0,200,150,0.2);
  border-radius: 20px; padding: 4px 10px;
  font-family: 'DM Mono', monospace;
  font-size: 10px; color: var(--accent);
}
.live-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent);
  animation: blink 2s infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.3} }

/* ═══════════════════════════════
   THEME SWITCHER
═══════════════════════════════ */
.theme-sw {
  display: flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px; padding: 2px; gap: 2px;
}
.theme-btn {
  width: 26px; height: 22px;
  border: none; background: none; cursor: pointer;
  border-radius: 12px; font-size: 11px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text2); transition: all 0.2s;
}
.theme-btn.active { background: var(--surface3); color: var(--accent); }

/* ═══════════════════════════════
   SCREEN AREA
═══════════════════════════════ */
.screens {
  flex: 1;
  overflow: hidden;
  position: relative;
  min-height: 0;
}
.screen {
  position: absolute; inset: 0;
  overflow-y: auto; overflow-x: hidden;
  opacity: 0; pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  background: var(--bg);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.screen::-webkit-scrollbar { display: none; }
.screen.active {
  opacity: 1; pointer-events: all; transform: translateY(0);
}
.screen-pad { padding: 16px; }
.pb-safe { padding-bottom: 28px; }

/* ═══════════════════════════════
   MOBILE BOTTOM NAV
═══════════════════════════════ */
.bottom-nav {
  display: flex !important;
  flex-direction: row !important;
  flex-shrink: 0 !important;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding: 6px 0;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  width: 100%;
  min-height: 60px;
}
.nav-tab {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; gap: 4px;
  cursor: pointer; padding: 5px 4px;
  border-radius: 10px; transition: all 0.2s;
  position: relative; border: none; background: none;
}
.nav-tab-icon { font-size: 20px; line-height: 1; transition: transform 0.2s; }
.nav-tab-label {
  font-size: 10px;
  font-family: 'DM Mono', monospace;
  letter-spacing: 0.3px;
  color: var(--text3); transition: color 0.2s;
}
.nav-tab.active .nav-tab-label { color: var(--accent); }
.nav-tab.active .nav-tab-icon { transform: translateY(-2px); }
.nav-tab-bar {
  position: absolute; top: 0; left: 50%;
  transform: translateX(-50%);
  width: 20px; height: 2px;
  background: var(--accent);
  border-radius: 0 0 3px 3px;
  opacity: 0; transition: opacity 0.2s;
}
.nav-tab.active .nav-tab-bar { opacity: 1; }

/* ═══════════════════════════════
   DESKTOP SIDEBAR
═══════════════════════════════ */
.sidebar {
  display: none; /* shown via media query */
  flex-direction: column;
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  height: 100vh;
  overflow: visible !important; /* Changed to visible to prevent dropdown menu clipping */
}

.sidebar-header {
  padding: 20px 16px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: #161b22; /* fixed, not theme-following — the wordmark SVG hardcodes white text for "Trade"/" Mentor", which goes invisible against a light-theme surface. A permanently-dark header sidesteps that without needing a second theme-aware logo file. */
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px;
}
.sidebar-brand-mark {
  width: 34px; height: 34px;
  background: var(--accent); border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Syne', sans-serif;
  font-weight: 800; font-size: 13px; color: #000;
}
.sidebar-brand-name {
  font-family: 'Syne', sans-serif;
  font-weight: 700; font-size: 16px; color: var(--text);
}
.sidebar-brand-name em { color: var(--accent); font-style: normal; }

.sidebar-nav { 
  padding: 12px 10px; 
  flex: 1; 
  overflow-y: auto; /* Scroll capability moved here to prevent dropdown clipping */
  scrollbar-width: none;
}
.sidebar-nav::-webkit-scrollbar { display: none; }

.sidebar-tab {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 10px;
  cursor: pointer; margin-bottom: 4px;
  transition: all 0.2s; border: 1px solid transparent;
  background: none; width: 100%; text-align: left;
}
.sidebar-tab:hover { background: var(--surface2); }
.sidebar-tab.active {
  background: var(--accent-dim);
  border-color: rgba(0,200,150,0.15);
}
/* Visual cue while a mandatory trade log is pending — the actual block
   happens in navigateTo() itself; this just makes clear beforehand why
   clicking these will bounce back to the Journal Log tab instead of no-op. */
.sidebar-tab.nav-locked, .nav-tab.nav-locked {
  opacity: 0.4; cursor: not-allowed;
}
.sidebar-tab-icon { font-size: 18px; }
.sidebar-tab-label {
  font-size: 13px; font-family: 'Nunito', sans-serif;
  font-weight: 600; color: var(--text2);
}
.sidebar-tab.active .sidebar-tab-label { color: var(--accent); }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-footer-label {
  font-size: 10px; font-family: 'DM Mono', monospace;
  color: var(--text3); letter-spacing: 1px;
  text-transform: uppercase; margin-bottom: 8px;
}

/* ═══════════════════════════════
   DESKTOP LAYOUT OVERRIDES
═══════════════════════════════ */
@media (min-width: 768px) {
  .topbar     { display: none !important; }
  .bottom-nav { display: none !important; }

  /* ── NAV LEFT (default) ── */
  .app.nav-left {
    flex-direction: row;
  }
  .app.nav-left .sidebar     { display: flex !important; order: 1; width: 220px; border-right: 1px solid var(--border); border-bottom: none; border-top: none; flex-direction: column; height: 100vh; }
  .app.nav-left .main-wrap   { order: 2; flex: 1; flex-direction: column; }

  /* ── NAV RIGHT ── */
  .app.nav-right {
    flex-direction: row;
  }
  .app.nav-right .sidebar    { display: flex !important; order: 2; width: 220px; border-left: 1px solid var(--border); border-right: none; border-bottom: none; border-top: none; flex-direction: column; height: 100vh; }
  .app.nav-right .main-wrap  { order: 1; flex: 1; flex-direction: column; }

  /* ── NAV TOP ── */
  .app.nav-top {
    flex-direction: column;
  }
  .app.nav-top .sidebar      { display: flex !important; flex-direction: row !important; width: 100% !important; height: 68px !important; border-right: none; border-bottom: 1px solid var(--border); padding: 0; align-items: center; }
  .app.nav-top .sidebar-header { border-bottom: none; border-right: 1px solid var(--border); padding: 0 16px; display: flex; align-items: center; flex-direction: row; gap: 8px; min-width: fit-content; height: 100%; }
  .app.nav-top .sidebar-brand  { margin-bottom: 0; }
  .app.nav-top .sidebar-brand-name { display: none; }
  .app.nav-top .sidebar-nav    { display: flex; flex-direction: row; padding: 4px 8px; gap: 2px; flex: 1; align-items: center; justify-content: center; height: 100%; }
  .app.nav-top .sidebar-tab    { margin-bottom: 0; flex-direction: column; padding: 6px 10px; min-width: 44px; justify-content: center; align-items: center; border-radius: 8px; }
  .app.nav-top .sidebar-tab .sidebar-tab-label { display: block; font-size: 11px; margin-top: 2px; }
  .app.nav-top .sidebar-tab .sidebar-tab-icon  { font-size: 18px; display: flex; align-items: center; justify-content: center; }
  .app.nav-top .sidebar-tab .notif-candle svg  { width: 16px; height: 18px; display: block; }
  .app.nav-top .sidebar-footer { border-top: none; border-left: 1px solid var(--border); padding: 0 14px; display: flex; align-items: center; gap: 8px; flex-direction: row; height: 100%; }
  .app.nav-top .sidebar-footer-label { display: none; }
  .app.nav-top .sidebar-footer-name  { display: none; }
  .app.nav-top .main-wrap      { flex: 1; overflow: hidden; }

  /* ── NAV BOTTOM ── */
  .app.nav-bottom {
    flex-direction: column;
  }
  .app.nav-bottom .sidebar    { display: flex !important; flex-direction: row !important; width: 100% !important; height: 68px !important; border-right: none; border-top: 1px solid var(--border); order: 2; padding: 0; align-items: center; }
  .app.nav-bottom .sidebar-header { border-bottom: none; border-right: 1px solid var(--border); padding: 0 16px; display: flex; align-items: center; flex-direction: row; gap: 8px; min-width: fit-content; height: 100%; }
  .app.nav-bottom .sidebar-brand  { margin-bottom: 0; }
  .app.nav-bottom .sidebar-brand-name { display: none; }
  .app.nav-bottom .sidebar-nav    { display: flex; flex-direction: row; padding: 4px 8px; gap: 2px; flex: 1; align-items: center; justify-content: center; height: 100%; }
  .app.nav-bottom .sidebar-tab    { margin-bottom: 0; flex-direction: column; padding: 6px 10px; min-width: 44px; justify-content: center; align-items: center; border-radius: 8px; }
  .app.nav-bottom .sidebar-tab .sidebar-tab-label { display: block; font-size: 11px; margin-top: 2px; }
  .app.nav-bottom .sidebar-tab .sidebar-tab-icon  { font-size: 18px; display: flex; align-items: center; justify-content: center; }
  .app.nav-bottom .sidebar-tab .notif-candle svg  { width: 16px; height: 18px; display: block; }
  .app.nav-bottom .sidebar-footer { border-top: none; border-left: 1px solid var(--border); padding: 0 14px; display: flex; align-items: center; gap: 8px; flex-direction: row; height: 100%; }
  .app.nav-bottom .sidebar-footer-label { display: none; }
  .app.nav-bottom .sidebar-footer-name  { display: none; }
  .app.nav-bottom .main-wrap  { order: 1; flex: 1; overflow: hidden; }

  .screens    { flex: 1; }
  .screen-pad { padding: 28px 36px; }
  .pb-safe    { padding-bottom: 36px; }
}

/* Nav position picker button */
.nav-pos-btn {
  background: none; border: none; cursor: pointer;
  font-size: 14px; padding: 4px 6px; border-radius: 6px;
  color: var(--text2); transition: all 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.nav-pos-btn:hover, .nav-pos-btn.active { background: var(--accent-dim); color: var(--accent); }
.nav-pos-picker {
  display: flex; gap: 3px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 3px;
}

/* ═══════════════════════════════
   MOBILE OVERRIDE — always wins
═══════════════════════════════ */
@media (max-width: 767px) {
  /* Force correct app layout on mobile regardless of nav-pos class */
  .app, .app.nav-left, .app.nav-right, .app.nav-top, .app.nav-bottom {
    flex-direction: column !important;
  }
  /* Always hide desktop sidebar on mobile */
  .sidebar,
  .app.nav-left .sidebar,
  .app.nav-right .sidebar,
  .app.nav-top .sidebar,
  .app.nav-bottom .sidebar {
    display: none !important;
  }
  /* Always show mobile topbar */
  .topbar { display: flex !important; }
  /* Always show bottom nav on mobile */
  .bottom-nav,
  .app.nav-left .bottom-nav,
  .app.nav-right .bottom-nav,
  .app.nav-top .bottom-nav,
  .app.nav-bottom .bottom-nav {
    display: flex !important;
    flex-direction: row !important;
    width: 100% !important;
    height: auto !important;
    border-top: 1px solid var(--border) !important;
    border-right: none !important;
    border-left: none !important;
    order: unset !important;
    position: relative !important;
    flex-shrink: 0 !important;
    padding: 6px 0 !important;
    padding-bottom: max(10px, env(safe-area-inset-bottom)) !important;
    background: var(--surface) !important;
  }
  /* Main wrap always column on mobile */
  .main-wrap,
  .app.nav-left .main-wrap,
  .app.nav-right .main-wrap,
  .app.nav-top .main-wrap,
  .app.nav-bottom .main-wrap {
    flex-direction: column !important;
    order: unset !important;
    flex: 1 !important;
    overflow: hidden !important;
    min-width: 0 !important;
  }
}

/* ═══════════════════════════════
   DISCIPLINE GATE MODAL
═══════════════════════════════ */
.gate-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.78);
  backdrop-filter: blur(6px);
  z-index: 10000; align-items: center; /* Elevated above chart level */
  justify-content: center; padding: 22px;
}
.gate-overlay.open { display: flex; }
.gate-modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-xl);
  padding: 24px; width: 100%; max-width: 340px;
  animation: gateIn 0.26s ease;
}
@keyframes gateIn {
  from { transform: scale(0.93); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}
.gate-emoji  { font-size: 34px; margin-bottom: 9px; }
.gate-title  { font-family: 'Syne', sans-serif; font-size: 18px; font-weight: 800; color: var(--accent); margin-bottom: 7px; }
.gate-text   { font-size: 13px; color: var(--text2); line-height: 1.65; margin-bottom: 18px; }
.gate-btns   { display: flex; flex-direction: column; gap: 7px; }
.gate-btn    { width: 100%; padding: 12px; border-radius: var(--radius-md); border: none; cursor: pointer; font-family: 'Nunito', sans-serif; font-size: 13px; font-weight: 600; transition: all 0.2s; }
.gate-btn.primary   { background: var(--accent); color: #000; }
.gate-btn.secondary { background: var(--surface2); border: 1px solid var(--border2); color: var(--text2); }

/* ── Dynamic Dropdown Overrides for Top & Bottom Navigation Bars ── */
.app.nav-top #desktop-brand-menu {
  position: absolute !important;
  top: 48px !important;
  left: 16px !important;
  width: 220px !important;
  right: auto !important;
  bottom: auto !important;
}
.app.nav-bottom #desktop-brand-menu {
  position: absolute !important;
  bottom: 48px !important;
  top: auto !important;
  left: 16px !important;
  width: 220px !important;
  right: auto !important;
}