/* =====================================================
   Market terminal — MT5-style light theme
   Full viewport — overrides dashboard phone-frame / sidebar grid
   ===================================================== */

html.market-page,
body.market-page {
  width: 100%;
  max-width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overflow-x: clip;
  background: #ffffff;
  overscroll-behavior-x: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation;
}

body.market-page {
  display: block !important;
  grid-template-columns: none !important;
  min-height: 100dvh;
  height: 100dvh;
  max-height: 100dvh;
}

body.market-page .market-app.app {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  overflow: hidden;
  display: grid;
  grid-template-rows:
    auto
    auto
    auto
    minmax(0, 1fr)
    auto
    minmax(160px, 28vh);
  background: #ffffff;
  color: #1a1a1a;
  z-index: 1;
}

@media (max-width: 899px) {
  body.market-page {
    background: #ffffff !important;
  }
  body.market-page .market-app.app {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
  }
}

@media (min-width: 600px) and (max-width: 899px) {
  body.market-page .market-app.app {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
  }
}

@media (min-width: 900px) {
  body.market-page .market-app.app {
    width: 100% !important;
    max-width: none !important;
    padding: 0 !important;
    grid-template-rows:
      auto
      auto
      auto
      minmax(0, 1fr)
      auto
      minmax(200px, 26vh);
  }
}

@media (min-width: 1280px) {
  body.market-page .market-app.app {
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }
}

.market-app .topbar {
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
  background: #ffffff;
}

/* Pair tabs */
.pair-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid #e0e0e0;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
  background: #fafafa;
}
.pair-tabs::-webkit-scrollbar { display: none; }

.pair-tab {
  flex-shrink: 0;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  color: #666;
  border-bottom: 2px solid transparent;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color .15s, border-color .15s, background .15s;
}
.pair-tab:hover { color: #1a1a1a; background: #f0f0f0; }
.pair-tab.active {
  color: #1a1a1a;
  border-bottom-color: #26a69a;
  background: rgba(38, 166, 154, 0.06);
}
.pair-tab .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #bbb;
}
.pair-tab.active .dot { background: #26a69a; }

/* Chart zone */
.chart-zone {
  display: flex;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  border-bottom: 1px solid #e0e0e0;
  background: #ffffff;
}

.chart-tools-left {
  width: 36px;
  flex-shrink: 0;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  gap: 4px;
  background: #f5f5f5;
}
.chart-tools-left button {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 4px;
  color: #666;
  font-size: 11px;
}
.chart-tools-left button:hover { background: #e8e8e8; color: #1a1a1a; }

.chart-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  position: relative;
  overflow: hidden;
  background: #ffffff;
}

.chart-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid #e8e8e8;
  font-size: 11px;
  color: #666;
  flex-shrink: 0;
  background: #fafafa;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-wrap: nowrap;
}
.chart-toolbar .tb-btn { flex-shrink: 0; white-space: nowrap; }
.chart-toolbar .tb-btn {
  padding: 4px 8px;
  border-radius: 4px;
  background: #eeeeee;
  font-weight: 600;
  font-size: 11px;
  color: #444;
}
.chart-toolbar .tb-btn.active { background: rgba(38, 166, 154, 0.15); color: #26a69a; }
.chart-toolbar .tb-sep { color: #ddd; }
.chart-toolbar .tb-spacer { flex: 1; }
.chart-toolbar .tb-btn-order {
  width: 32px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(38, 166, 154, 0.12);
  color: #26a69a;
  border: 1px solid rgba(38, 166, 154, 0.25);
}
.chart-toolbar .tb-btn-order:hover { background: rgba(38, 166, 154, 0.2); }

.chart-ohlc {
  padding: 6px 12px 2px;
  font-size: 11px;
  color: #666;
  font-family: var(--font-mono);
  flex-shrink: 0;
  line-height: 1.5;
  background: #ffffff;
}
.chart-ohlc .up { color: #26a69a; }
.chart-ohlc .dn { color: #ef5350; }
.chart-ohlc .sym { color: #1a1a1a; font-weight: 600; margin-right: 8px; }

.chart-tools-left button,
.chart-tools-left .tool-btn {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 4px;
  color: #666;
  font-size: 11px;
}
.chart-tools-left .tool-btn:hover,
.chart-tools-left .tool-btn.active {
  background: rgba(38, 166, 154, 0.12);
  color: #26a69a;
}

.chart-canvas-wrap {
  flex: 1 1 auto;
  min-height: 140px;
  height: 100%;
  position: relative;
  overflow: hidden;
  background: #ffffff;
}

#chartContainer {
  width: 100%;
  height: 100%;
}

.draw-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}
.chart-canvas-wrap.tool-active .draw-canvas { pointer-events: auto; cursor: crosshair; }

.measure-tip {
  position: absolute;
  z-index: 12;
  background: rgba(255,255,255,.95);
  border: 1px solid #e0e0e0;
  color: #1a1a1a;
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 6px 8px;
  border-radius: 6px;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

/* Trade panel — always visible, outside chart overflow */
.trade-panel {
  flex-shrink: 0;
  border-bottom: 1px solid #e0e0e0;
  background: #f5f5f5;
  z-index: 10;
  position: relative;
}

.trade-controls input[type="number"] {
  width: 72px;
}

/* Buy / Sell action buttons */
.trade-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.action-btn {
  min-width: 108px;
  padding: 10px 14px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 11px;
  text-align: center;
  line-height: 1.35;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform .1s, filter .1s, opacity .15s;
}
.action-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.action-btn:active:not(:disabled) { transform: scale(0.97); }
.action-btn .lbl { display: block; font-size: 10px; font-weight: 700; letter-spacing: .06em; opacity: 0.9; }
.action-btn .px { display: block; font-family: var(--font-mono); font-size: 13px; font-weight: 600; margin-top: 2px; }

.action-btn.sell {
  background: #ef5350;
  color: #fff;
  border-color: rgba(239, 83, 80, 0.6);
}
.action-btn.sell:hover:not(:disabled) { filter: brightness(1.08); }
.action-btn.buy {
  background: #26a69a;
  color: #fff;
  border-color: rgba(38, 166, 154, 0.6);
}
.action-btn.buy:hover:not(:disabled) { filter: brightness(1.08); }

.spread-hint {
  font-family: var(--font-mono);
  font-size: 10px !important;
  color: #888 !important;
}

/* Trade controls row */
.trade-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #f5f5f5;
  flex-shrink: 0;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.trade-controls::-webkit-scrollbar { display: none; }

.trade-fields {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.trade-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  flex-shrink: 0;
}
.trade-controls label {
  font-size: 10px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
.trade-controls input, .trade-controls select {
  background: #ffffff;
  border: 1px solid #d0d0d0;
  color: #1a1a1a;
  font: 500 12px/1 var(--font-mono);
  padding: 8px 8px;
  border-radius: 4px;
  width: 72px;
  min-height: 34px;
}
.trade-controls .field-grp {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.trade-controls .bal-hint,
.trade-meta .bal-hint {
  font-size: 11px;
  color: #666;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Positions panel */
.positions-panel {
  flex: 0 0 auto;
  background: #ffffff;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-top: 1px solid #e0e0e0;
}

.pos-tabs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
  background: #fafafa;
  padding-right: 10px;
}
.pos-tabs {
  display: flex;
  gap: 0;
  flex: 1;
  min-width: 0;
  border-bottom: 0;
  background: transparent;
}
.pos-tab {
  padding: 10px 18px;
  font-size: 12px;
  font-weight: 600;
  color: #666;
  border-bottom: 2px solid transparent;
}
.pos-tab.active {
  color: #1a1a1a;
  border-bottom-color: #26a69a;
}
.pos-close-all {
  flex-shrink: 0;
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  color: #ef5350;
  background: rgba(239, 83, 80, 0.08);
  border: 1px solid rgba(239, 83, 80, 0.35);
  cursor: pointer;
  white-space: nowrap;
}
.pos-close-all:hover { background: rgba(239, 83, 80, 0.14); }
.pos-close-all:disabled { opacity: 0.55; cursor: wait; }
.pos-tab .cnt {
  margin-left: 4px;
  font-size: 10px;
  color: #999;
}

.pos-table-wrap {
  flex: 1;
  overflow: auto;
  scrollbar-width: thin;
}

.pos-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  white-space: nowrap;
}
.pos-table th {
  text-align: left;
  padding: 8px 10px;
  color: #888;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid #e0e0e0;
  background: #f5f5f5;
  position: sticky;
  top: 0;
  z-index: 1;
}
.pos-table td {
  padding: 10px 10px;
  border-bottom: 1px solid #eeeeee;
  color: #333;
  font-family: var(--font-mono);
  font-size: 11px;
}
.pos-table tr:hover td { background: #f9f9f9; }

.pos-table .sym-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-weight: 600;
}
.sym-icon {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #eeeeee;
  display: grid; place-items: center;
  font-size: 9px;
  color: #666;
  flex-shrink: 0;
}

.type-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-sans);
}
.type-badge.sell { background: rgba(239,83,80,.12); color: #ef5350; }
.type-badge.buy { background: rgba(38,166,154,.12); color: #26a69a; }

.pos-table .pnl-up { color: #26a69a; font-weight: 700; }
.pos-table .pnl-dn { color: #ef5350; font-weight: 700; }

.pos-table .add-link {
  color: #26a69a;
  font-family: var(--font-sans);
  font-size: 10px;
  cursor: pointer;
}
.pos-table .add-link:hover { text-decoration: underline; }

.pos-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
}
.pos-action-cell {
  min-width: 148px;
  position: sticky;
  right: 0;
  background: #fff;
  box-shadow: -8px 0 10px -8px rgba(0,0,0,.12);
}
.pos-act {
  min-width: 58px;
  height: 30px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  background: #eeeeee;
  color: #444;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-sans);
  border: 1px solid #e0e0e0;
}
.pos-act:hover { background: #e0e0e0; color: #1a1a1a; }
.pos-act.close {
  color: #ef5350;
  background: rgba(239, 83, 80, 0.08);
  border-color: rgba(239, 83, 80, 0.35);
}
.pos-act.close:hover { background: rgba(239,83,80,.16); color: #d32f2f; }

.pos-empty {
  text-align: center;
  padding: 32px 20px;
  color: #999;
  font-size: 12px;
}

/* MT5-style mobile position cards */
.pos-mobile-list {
  display: none;
  padding: 0;
}

.pos-m-card {
  padding: 10px 12px;
  border-bottom: 1px solid #eeeeee;
  background: #ffffff;
}
.pos-m-card:active { background: #f9f9f9; }

.pos-m-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.pos-m-sym {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 600;
  font-size: 13px;
  color: #1a1a1a;
}

.pos-m-pnl {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}
.pos-m-pnl.pnl-up { color: #26a69a; }
.pos-m-pnl.pnl-dn { color: #ef5350; }

.pos-m-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px 10px;
  margin-bottom: 8px;
}

.pos-m-grid .k {
  display: block;
  font-size: 9px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 2px;
}

.pos-m-grid .v {
  display: block;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #333;
  font-weight: 500;
}

.pos-m-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.pos-m-meta {
  font-size: 10px;
  color: #888;
  font-family: var(--font-sans);
}

.pos-m-actions {
  display: flex;
  gap: 8px;
  width: 100%;
}

.pos-m-btn {
  flex: 1;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid #e0e0e0;
  background: #f5f5f5;
  color: #444;
}
.pos-m-btn.edit {
  color: #26a69a;
  border-color: rgba(38, 166, 154, 0.35);
  background: rgba(38, 166, 154, 0.08);
}
.pos-m-btn.close {
  color: #fff;
  border-color: #ef5350;
  background: #ef5350;
  font-weight: 800;
}
.pos-m-btn.close:hover { filter: brightness(0.95); }

/* Edit modal */
.modal-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-scrim.open { display: flex; }

.modal-box {
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 32px rgba(0,0,0,.12);
}
.modal-box h3 {
  font-size: 15px;
  color: #1a1a1a;
  margin: 0;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.modal-close {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 8px;
  background: #eeeeee;
  color: #1a1a1a;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: #e0e0e0; }
.modal-hint {
  font-size: 11px;
  color: #888;
  margin: 0 0 14px;
  line-height: 1.45;
}
.modal-box .field { margin-bottom: 12px; }
.modal-box .field-l {
  font-size: 11px;
  color: #888;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.modal-box .input {
  width: 100%;
  background: #fafafa;
  border: 1px solid #d0d0d0;
  color: #1a1a1a;
  padding: 10px 12px;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
}
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.modal-actions button {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
}
.btn-save { background: #26a69a; color: #fff; }
.btn-cancel { background: #eeeeee; color: #444; }

/* MT5-style order sheet (light theme) */
.order-sheet {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.45);
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.order-sheet.open {
  display: flex;
}
.order-sheet-panel {
  width: 100%;
  max-width: 480px;
  max-height: 96dvh;
  background: #ffffff;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
}
.order-sheet-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid #e0e0e0;
  background: #fafafa;
  flex-shrink: 0;
}
.order-sheet-back {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: #eeeeee;
  color: #333;
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
}
.order-sheet-title h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: #1a1a1a;
}
.order-sheet-title p {
  margin: 2px 0 0;
  font-size: 12px;
  color: #888;
}
.order-sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}
.order-exec-label {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #666;
  padding: 8px 12px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  background: #f9f9f9;
  margin-bottom: 16px;
}
.order-lot-stepper {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
}
.order-step {
  padding: 10px 4px;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  background: #f5f5f5;
  color: #26a69a;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.order-lot-val {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  color: #1a1a1a;
}
.order-prices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.order-price {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  padding: 12px 8px;
  border-radius: 8px;
}
.order-price.sell { color: #ef5350; background: rgba(239, 83, 80, 0.08); }
.order-price.buy { color: #26a69a; background: rgba(38, 166, 154, 0.08); }
.order-sltp {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.order-sltp-field {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  align-items: center;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  overflow: hidden;
  background: #fafafa;
}
.order-sltp-field.sl { border-bottom: 2px solid #ef5350; }
.order-sltp-field.tp { border-bottom: 2px solid #26a69a; }
.order-sltp-field input {
  border: none;
  background: transparent;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 10px 4px;
  outline: none;
  width: 100%;
  min-width: 0;
}
.order-step-sm {
  height: 100%;
  min-height: 42px;
  border: none;
  background: #eeeeee;
  color: #26a69a;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}
.order-lev-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  font-size: 12px;
  color: #666;
}
.order-lev-row select {
  flex: 1;
  max-width: 140px;
  padding: 8px 10px;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
}
.order-tick-chart {
  width: 100%;
  height: 120px;
  border: 1px solid #e8e8e8;
  border-radius: 8px;
  background: #fafafa;
  margin-bottom: 12px;
  display: block;
}
.order-warn {
  font-size: 11px;
  color: #888;
  line-height: 1.45;
  margin: 0 0 12px;
  text-align: center;
}
.order-meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #666;
  font-family: var(--font-mono);
}
.order-sheet-foot {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid #e0e0e0;
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.order-foot-btn {
  padding: 16px 12px;
  border: none;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  text-transform: uppercase;
}
.order-foot-btn.sell {
  color: #ef5350;
  background: rgba(239, 83, 80, 0.06);
  border-right: 1px solid #e0e0e0;
}
.order-foot-btn.buy {
  color: #26a69a;
  background: rgba(38, 166, 154, 0.06);
}
.order-foot-btn:disabled { opacity: 0.45; cursor: not-allowed; }

@media (min-width: 520px) {
  .order-sheet { align-items: center; padding: 20px; }
  .order-sheet-panel {
    border-radius: 16px;
    max-height: 90dvh;
  }
}

/* Stats strip */
.market-stats {
  display: flex;
  gap: 16px;
  padding: 6px 14px;
  border-bottom: 1px solid #e0e0e0;
  font-size: 11px;
  color: #666;
  flex-shrink: 0;
  background: #fafafa;
  align-items: center;
  flex-wrap: wrap;
}
.acct-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 4px;
}
.acct-switch-l { color: #888; font-weight: 500; }
.acct-switch-sel {
  max-width: 200px;
  font-size: 11px;
  font-weight: 600;
  color: #1a1a1a;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 3px 6px;
  min-height: 28px;
}
.market-stats .v { color: #1a1a1a; font-weight: 600; font-family: var(--font-mono); }
.market-stats .v.up { color: #26a69a; }
.market-stats .v.dn { color: #ef5350; }

.market-status {
  flex: 1 1 100%;
  font-size: 11px;
  line-height: 1.35;
  padding: 4px 8px;
  border-radius: 6px;
  margin-top: 2px;
}
.market-status.closed {
  background: #fff3e0;
  color: #e65100;
  border: 1px solid #ffcc80;
}
.market-status.warn {
  background: #ffebee;
  color: #c62828;
  border: 1px solid #ef9a9a;
}

.mobile-desktop-note {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 520px);
  background: #fff8e1;
  border: 1px solid #f2d38a;
  color: #6d4c00;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  z-index: 500;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.mobile-desktop-note__text {
  font-size: 12px;
  line-height: 1.35;
}

.mobile-desktop-note__close {
  border: 1px solid #cda85a;
  background: #ffffff;
  color: #6d4c00;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  padding: 7px 10px;
  flex-shrink: 0;
}

@media (min-width: 769px) {
  .pos-mobile-list {
    display: none !important;
  }
  .pos-table-wrap .pos-table {
    display: table;
  }
}

@media (min-width: 769px) and (max-width: 899px) {
  .trade-panel { display: block; }
  body.market-page .market-app.app {
    grid-template-rows:
      auto
      auto
      auto
      minmax(140px, 32dvh)
      auto
      minmax(160px, 1fr);
  }
}

@media (max-width: 768px) {
  .trade-panel { display: none; }

  body.market-page .market-app.app {
    grid-template-rows:
      auto
      auto
      auto
      minmax(160px, 38dvh)
      minmax(180px, 1fr);
  }

  .trade-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 8px 10px;
    overflow-x: visible;
    align-items: stretch;
  }

  .trade-actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    width: 100%;
  }

  .action-btn {
    flex: 1;
    min-width: 0;
    min-height: 54px;
    padding: 10px 8px;
    border-radius: 4px;
  }
  .action-btn .px { font-size: 14px; }

  .trade-fields {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
  }

  .trade-fields .field-grp {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }

  .trade-fields label {
    font-size: 9px;
  }

  .trade-fields input,
  .trade-fields select {
    width: 100%;
    min-width: 0;
    padding: 8px 6px;
    font-size: 12px;
    text-align: center;
  }

  .trade-meta {
    grid-column: 1 / -1;
    margin-left: 0;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    text-align: center;
  }

  .trade-meta .bal-hint {
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .market-stats { gap: 8px; flex-wrap: wrap; font-size: 10px; }

  .pos-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .pos-tab { padding: 10px 14px; font-size: 11px; white-space: nowrap; }

  .pos-table-wrap .pos-table { display: none; }
  .pos-mobile-list { display: block; }

  .modal-scrim { padding: 0; align-items: flex-end; }
  .modal-box {
    max-width: none;
    width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 90dvh;
    overflow-y: auto;
    padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
  }

  .mobile-desktop-note {
    top: max(8px, env(safe-area-inset-top, 0px));
    width: calc(100% - 16px);
    max-width: calc(100% - 16px);
    left: 8px;
    right: 8px;
  }
}

@media (max-width: 600px) {
  .trade-controls .bal-hint {
    margin-left: 0;
    width: auto;
    text-align: inherit;
  }
}

@media (max-width: 899px) {
  html.market-page,
  body.market-page {
    overflow: hidden;
  }

  body.market-page .market-app.app {
    position: fixed;
    inset: 0;
    width: 100% !important;
    min-width: 0;
    max-width: none;
    grid-template-rows:
      auto
      auto
      auto
      minmax(160px, 38dvh)
      minmax(180px, 1fr);
  }

  .trade-controls input, .trade-controls select {
    font-size: 16px;
    min-height: 40px;
  }
  .order-sltp-field input,
  .modal-box .input {
    font-size: 16px;
  }

  .chart-zone {
    min-height: 140px;
    max-height: 32dvh;
  }

  .chart-canvas-wrap {
    min-height: 120px;
  }

  .positions-panel {
    min-height: 0;
    overflow: hidden;
  }

  .pos-table-wrap {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .pair-tabs {
    overflow-x: auto;
  }
}

/* Landscape / desktop mode on phone — wider viewport, full chart */
body.market-page.market-layout-wide .market-app.app {
  grid-template-rows:
    auto
    auto
    auto
    minmax(280px, 1fr)
    auto
    minmax(160px, 24vh);
}

body.market-page.market-layout-wide .chart-zone {
  min-height: 280px;
}

body.market-page.market-layout-wide .chart-canvas-wrap {
  min-height: 220px;
}

@media (min-width: 900px), (hover: hover) and (pointer: fine) {
  .mobile-desktop-note {
    display: none !important;
  }
}

body.market-page.market-layout-wide .mobile-desktop-note {
  display: none !important;
}
