/* ── MOBILE ELEMENTS — hidden on desktop ── */
.mobile-nav,
.mob-quick-trade,
.mob-pos-actions {
  display: none;
}

/* ── MOBILE RESPONSIVE ── */
@media (max-width: 768px) {
  html, body {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    -webkit-overflow-scrolling: touch;
  }

  /* AUTH — fit nicely on small screens */
  .auth-box {
    width: 90%;
    max-width: 340px;
    padding: 20px;
  }

  .auth-title { font-size: 16px; }

  #auth-form input, #keys-form input {
    padding: 12px 10px;
    font-size: 14px;
  }

  .btn-primary {
    padding: 12px;
    font-size: 14px;
  }

  /* TOP BAR — compact */
  .top-bar {
    height: auto;
    min-height: 40px;
    flex-wrap: wrap;
    padding: 4px 6px;
    gap: 4px;
  }

  .top-bar-left {
    order: 1;
    flex: 1;
    min-width: 0;
  }

  .top-bar-center {
    order: 3;
    width: 100%;
    justify-content: space-between;
    padding: 2px 0 0;
  }

  .top-bar-right {
    order: 2;
    gap: 3px;
  }

  .pair-select {
    font-size: 13px;
    padding: 4px 6px;
    max-width: 110px;
  }

  .current-price {
    font-size: 15px;
  }

  .price-change {
    font-size: 12px;
  }

  .exchange-select {
    font-size: 11px;
    padding: 4px 18px 4px 8px;
  }

  .leverage-select {
    font-size: 12px;
    padding: 4px 6px;
  }

  .btn-sm {
    padding: 5px 8px;
    font-size: 11px;
    min-height: 28px;
  }

  /* Hide grid on mobile — single chart forced */
  .grid-toggle-wrap {
    display: none;
  }

  /* Compact button labels on mobile */
  #btn-refresh { font-size: 0; padding: 5px 6px; }
  #btn-refresh::before { content: '↻'; font-size: 14px; }
  #btn-settings { font-size: 0; padding: 5px 6px; }
  #btn-settings::before { content: '⚙'; font-size: 14px; }
  #btn-theme { font-size: 0; padding: 5px 6px; }
  #btn-theme::before { content: '◐'; font-size: 14px; }

  /* TIMEFRAME BAR — scrollable */
  .timeframe-bar {
    padding: 0 6px;
    height: 32px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .timeframe-bar::-webkit-scrollbar { display: none; }

  .tf-btn {
    padding: 6px 10px;
    font-size: 12px;
    white-space: nowrap;
    min-width: 36px;
  }

  .tf-label { display: none; }
  .tf-separator { display: none; }

  /* MAIN LAYOUT — stacked, no sidebar */
  .main-layout {
    flex: 1;
    min-height: 0;
    flex-direction: column;
    position: relative;
    overflow: hidden;
  }

  /* HIDE LEFT TOOLBAR on mobile */
  .left-toolbar {
    display: none;
  }

  /* CHART AREA — full width */
  .chart-area {
    flex: 1;
    min-height: 0;
  }

  /* Force single chart on mobile */
  .chart-grid {
    grid-template-areas: "c1" !important;
    grid-template-columns: 1fr !important;
    grid-template-rows: 1fr !important;
  }

  .chart-panel-wrap:not(#chart-wrap-1) {
    display: none !important;
  }

  .chart-panel-header {
    height: 24px;
    padding: 0 8px;
    font-size: 10px;
  }

  /* POSITIONS BAR — hide on chart tab, shown as own tab */
  .positions-bar {
    height: 0;
    min-height: 0;
    overflow: hidden;
    border: none;
    transition: height 0.2s;
  }

  /* RIGHT PANEL — full-screen overlay, hidden by default */
  .right-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    min-width: 0;
    z-index: 100;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    border-left: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .right-panel.mob-visible {
    transform: translateX(0);
  }

  /* Panel sections — larger touch targets */
  .panel-header {
    padding: 10px 12px;
    font-size: 12px;
  }

  .sl-tp-section {
    padding: 10px 12px;
  }

  .price-input {
    padding: 10px 8px;
    font-size: 14px;
  }

  .btn-sl, .btn-tp {
    padding: 10px 14px;
    font-size: 12px;
  }

  .input-row {
    gap: 6px;
    margin-bottom: 6px;
  }

  .calculator {
    padding: 10px 12px;
  }

  .calc-title { font-size: 11px; }

  .calc-row {
    padding: 3px 0;
    font-size: 13px;
  }

  .calc-row span:first-child { font-size: 12px; }
  .calc-value { font-size: 13px; }
  .volume-color { font-size: 16px; }

  .info-section { padding: 10px 12px; }
  .info-row { padding: 3px 0; font-size: 13px; }
  .info-row span:first-child { font-size: 12px; }
  .info-value { font-size: 13px; }

  .trade-buttons {
    padding: 10px 12px;
    gap: 8px;
  }

  .btn-long, .btn-short {
    padding: 14px 0;
    font-size: 15px;
    border-radius: 6px;
  }

  .action-buttons {
    padding: 6px 12px;
    gap: 6px;
  }

  .btn-action {
    padding: 10px 0;
    font-size: 12px;
    border-radius: 4px;
  }

  /* Watchlist — larger items */
  .watchlist-header {
    padding: 8px 12px;
    font-size: 12px;
  }

  .watchlist-table-header {
    padding: 4px 12px;
    font-size: 10px;
  }

  .wth-price { width: 80px; }
  .wth-change { width: 65px; }

  .wl-section-name {
    padding: 6px 12px;
    font-size: 10px;
  }

  .wl-item {
    padding: 10px 12px;
    font-size: 13px;
    gap: 8px;
    min-height: 40px;
  }

  .wl-symbol { font-size: 12px; }
  .wl-price { font-size: 12px; width: 80px; }
  .wl-change { font-size: 12px; width: 65px; }

  /* STATUS BAR — hide on mobile (replaced by bottom nav) */
  .status-bar {
    display: none;
  }

  /* MOBILE BOTTOM NAV — show */
  .mobile-nav {
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: 52px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
    z-index: 200;
  }

  .mob-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 9px;
    font-family: var(--font);
    cursor: pointer;
    padding: 4px 0;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
  }

  .mob-tab svg {
    width: 20px;
    height: 20px;
  }

  .mob-tab.active {
    color: var(--accent);
    border-bottom: 2px solid var(--accent);
    font-weight: 700;
  }

  .mob-tab:active {
    color: var(--text-primary);
  }

  /* MOBILE QUICK-TRADE BAR */
  .mob-quick-trade {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    gap: 8px;
  }

  .mqt-info {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    min-width: 0;
    overflow: hidden;
  }

  .mqt-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--red);
    flex-shrink: 0;
  }

  .mqt-dot.connected {
    background: var(--green);
  }

  .mqt-pair {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 11px;
    color: var(--text-primary);
    white-space: nowrap;
  }

  .mqt-price {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 12px;
    color: var(--accent);
    white-space: nowrap;
  }

  .mqt-balance {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-secondary);
    white-space: nowrap;
  }

  .mqt-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
  }

  .mqt-long, .mqt-short {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    font-family: var(--font);
    letter-spacing: 0.5px;
    -webkit-tap-highlight-color: transparent;
  }

  .mqt-long {
    background: var(--green);
    color: white;
  }

  .mqt-short {
    background: var(--red);
    color: white;
  }

  .mqt-long:active, .mqt-short:active {
    opacity: 0.8;
  }

  /* MOBILE POSITION ACTIONS */
  .mob-pos-actions {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
  }

  .mob-pos-actions .btn-action {
    padding: 12px 0;
    font-size: 13px;
    border-radius: 4px;
  }

  /* Position close button — larger touch targets on mobile */
  .pos-close-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 3px;
    padding: 4px 8px;
    font-size: 10px;
    cursor: pointer;
    margin-left: 6px;
    -webkit-tap-highlight-color: transparent;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .order-cancel-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 4px 8px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
  }

  .pos-close-btn:active {
    background: var(--red-bg);
    border-color: var(--red);
    color: var(--red);
  }

  /* MODAL — full width on mobile */
  .modal-content {
    width: 92%;
    max-width: 360px;
    max-height: 85vh;
  }

  .modal-body input {
    padding: 10px;
    font-size: 14px;
  }

  .modal-body label {
    font-size: 12px;
    margin-top: 10px;
  }

  /* GRID SELECTOR — full width if shown */
  .grid-selector {
    width: 95vw;
    left: 50%;
    transform: translateX(-50%);
    right: auto;
  }

  /* Mobile tab: positions view */
  .positions-bar.mob-visible {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: auto;
    z-index: 100;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border: none;
  }

  .positions-bar.mob-visible .positions-header {
    padding: 8px 12px;
    font-size: 13px;
  }

  .positions-bar.mob-visible .pos-tabs {
    gap: 0;
    flex-wrap: wrap;
  }

  .positions-bar.mob-visible .pos-tab {
    font-size: 12px;
    padding: 6px 10px;
  }

  .positions-bar.mob-visible .position-item {
    padding: 10px 12px;
    font-size: 12px;
    gap: 6px;
    min-height: 44px;
  }

  .positions-bar.mob-visible .pos-main-row {
    gap: 8px;
  }

  .positions-bar.mob-visible .pos-detail-row {
    font-size: 10px;
    gap: 10px;
    flex-wrap: wrap;
  }

  .positions-bar.mob-visible .pos-symbol { font-size: 12px; }
  .positions-bar.mob-visible .pos-side { font-size: 11px; padding: 2px 6px; }
  .positions-bar.mob-visible .pos-pnl { font-size: 13px; }

  .positions-bar.mob-visible .order-item {
    padding: 10px 12px;
    font-size: 12px;
    gap: 8px;
    min-height: 40px;
    flex-wrap: wrap;
  }

  .positions-bar.mob-visible .income-item {
    padding: 10px 12px;
    font-size: 12px;
    gap: 8px;
  }

  .positions-bar.mob-visible .no-positions {
    font-size: 13px;
    padding: 20px;
  }

  /* Watchlist as full panel */
  .right-panel.mob-watchlist-only > *:not(.watchlist):not(.panel-header) {
    display: none;
  }

  .right-panel.mob-watchlist-only .panel-header {
    display: none;
  }

  .right-panel.mob-watchlist-only .watchlist {
    flex: 1;
  }

  /* Add scroll indicator at bottom of trade panel */
  .right-panel.mob-visible {
    padding-bottom: 10px;
  }

  /* SL/TP actions on mobile */
  .sl-tp-actions {
    gap: 6px;
    margin-top: 6px;
  }

  .btn-click-set {
    padding: 10px 8px;
    font-size: 12px;
  }

  .btn-click-clear {
    padding: 10px 12px;
    font-size: 12px;
  }

  .gsl-row {
    margin-top: 8px;
    padding-top: 6px;
  }

  .gsl-toggle {
    width: 36px;
    height: 18px;
  }

  .gsl-toggle .gs-toggle-slider:before {
    width: 14px;
    height: 14px;
  }

  .gsl-toggle input:checked + .gs-toggle-slider:before {
    transform: translateX(18px);
  }

  .gsl-label {
    font-size: 12px;
  }

  .gsl-hint {
    width: 18px;
    height: 18px;
    font-size: 11px;
  }

  /* Click mode badge on mobile */
  .click-mode-badge {
    top: 8px;
    font-size: 13px;
    padding: 8px 20px;
  }

  /* Keyboard avoidance — keep focused inputs visible */
  input:focus {
    scroll-margin-bottom: 200px;
  }

  .right-panel.mob-visible input:focus {
    position: relative;
    z-index: 200;
  }

  /* Backdrop for positions overlay on mobile */
  .positions-bar.mob-visible::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
  }
}

/* ── TABLET BREAKPOINT (769px–1024px) ── */
@media (max-width: 1024px) and (min-width: 769px) {
  /* Right panel — narrower on tablet */
  .right-panel {
    width: 200px;
  }

  /* Slightly smaller fonts throughout */
  .top-bar {
    padding: 4px 8px;
  }

  .pair-select {
    font-size: 13px;
  }

  .current-price {
    font-size: 16px;
  }

  .price-change {
    font-size: 12px;
  }

  .btn-sm {
    padding: 5px 8px;
    font-size: 11px;
  }

  .tf-btn {
    padding: 6px 10px;
    font-size: 12px;
  }

  /* Panel sections — slightly compressed */
  .panel-header {
    padding: 8px 10px;
    font-size: 11px;
  }

  .price-input {
    padding: 8px 6px;
    font-size: 13px;
  }

  .btn-long, .btn-short {
    padding: 10px 0;
    font-size: 13px;
  }

  .calc-row {
    font-size: 12px;
  }

  .info-row {
    font-size: 12px;
  }

  /* Positions bar — slightly smaller text */
  .position-item {
    font-size: 10px;
  }

  .pos-detail-row {
    font-size: 9px;
  }

  /* Watchlist — tighter */
  .wl-item {
    padding: 6px 10px;
    font-size: 12px;
  }

  .wl-symbol {
    font-size: 11px;
  }

  .wl-price, .wl-change {
    font-size: 11px;
  }
}

/* Extra small screens (iPhone SE, etc.) */
@media (max-width: 380px) {
  .top-bar-center {
    gap: 4px;
  }

  .current-price { font-size: 13px; }

  .tf-btn {
    padding: 5px 8px;
    font-size: 11px;
    min-width: 30px;
  }

  .btn-long, .btn-short {
    padding: 12px 0;
    font-size: 14px;
  }
}

/* Landscape mobile */
@media (max-width: 768px) and (orientation: landscape) {
  .top-bar {
    min-height: 32px;
  }

  .top-bar-center {
    display: none;
  }

  .timeframe-bar {
    height: 28px;
  }

  .tf-btn {
    padding: 4px 8px;
    font-size: 11px;
  }

  .mobile-nav {
    height: 44px;
    padding-bottom: 0;
  }

  .mob-tab {
    flex-direction: row;
    gap: 4px;
    font-size: 10px;
  }

  .mob-tab svg {
    width: 16px;
    height: 16px;
  }
}

/* ===== LIGHT MODE ===== */
@media (max-width: 768px) {
  body.chart-light .mobile-nav {
    background: #ffffff;
    border-top-color: #d5d8de;
  }

  body.chart-light .mob-tab.active {
    color: #2563eb;
  }
}
