/* =========================================================
   Minwexry — MNX/USD  |  style.css
   TradingView-style dark theme, mobile-first
   ========================================================= */
:root {
  --bg: #131722;
  --panel: #1e222d;
  --panel2: #252a37;
  --border: #2a2e39;
  --text: #d1d4dc;
  --muted: #787b86;
  --accent: #2962ff;
  --up: #26a69a;
  --down: #ef5350;
  --radius: 8px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
input { font: inherit; color: inherit; }
.hidden { display: none !important; }

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  position: relative;
}

/* ---------------- Top bar ---------------- */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 46px;
  padding: 0 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 6px; min-width: 0; }
.logo {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #2962ff, #7c4dff);
  color: #fff; font-weight: 800;
}
.sym { display: flex; flex-direction: column; line-height: 1.1; }
.sym b { font-size: 13px; color: #fff; }
.sym small { font-size: 10px; color: var(--muted); display: none; }

.price-block { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.1; margin-left: 2px; }
.tick-price { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tick-chg { font-size: 10.5px; font-variant-numeric: tabular-nums; color: var(--muted); }
.tick-price.up, .tick-chg.up { color: var(--up); }
.tick-price.down, .tick-chg.down { color: var(--down); }

.tf {
  margin-left: auto;
  display: flex;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 2px;
}
.tf button {
  min-width: 36px; height: 30px; padding: 0 8px;
  border-radius: 6px; color: var(--muted); font-weight: 600;
}
.tf button.active { background: var(--accent); color: #fff; }

.icon-btn {
  position: relative;
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--radius);
}
.icon-btn:active { background: var(--panel2); }
.icon-btn.small { width: 30px; height: 30px; font-size: 22px; }
.icon-btn svg, .tool svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.badge {
  position: absolute; top: 2px; right: 0;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700; display: grid; place-items: center;
}

/* ---------------- Stats strip ---------------- */
.stats {
  flex: none;
  display: flex;
  gap: 14px;
  height: 28px;
  padding: 0 10px;
  align-items: center;
  overflow-x: auto;
  white-space: nowrap;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}
.stats::-webkit-scrollbar { display: none; }
.chip { display: flex; gap: 5px; align-items: baseline; font-size: 11px; }
.chip span { color: var(--muted); }
.chip b { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------------- Main ---------------- */
.main { flex: 1; min-height: 0; display: flex; position: relative; overflow: hidden; }

.toolbar {
  flex: none;
  width: 42px;
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 6px 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.tool {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: 6px; color: #9598a1;
}
.tool.txt { font-size: 20px; font-weight: 500; }
.tool:active { background: var(--panel2); }
.tool.active { background: var(--accent); color: #fff; }
.sep { width: 22px; height: 1px; background: var(--border); margin: 3px 0; flex: none; }

.chart-wrap { flex: 1; min-width: 0; min-height: 0; position: relative; background: var(--bg); }
#chart { position: absolute; left: 0; top: 0; display: block; touch-action: none; cursor: crosshair; }

.hint {
  position: absolute; top: 44px; left: 50%; transform: translateX(-50%);
  background: rgba(30, 34, 45, .95); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 20px; font-size: 12px; pointer-events: none; white-space: nowrap;
}
.latest {
  position: absolute; right: 70px; bottom: 36px;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 20px; line-height: 1;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .5);
}

/* ---------------- Right panel ---------------- */
.panel {
  display: flex; flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--border);
  min-height: 0;
  /* mobile: slide-over sheet */
  position: absolute; right: 0; top: 0; bottom: 0;
  width: min(340px, 90vw);
  transform: translateX(105%);
  transition: transform .22s ease;
  z-index: 20;
  box-shadow: -8px 0 24px rgba(0, 0, 0, .45);
}
.panel.open { transform: none; }

.panel-head { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 12px; border-bottom: 1px solid var(--border); }

.acct { flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); border-bottom: 1px solid var(--border); }
.acct div { background: var(--panel); padding: 8px 12px; display: flex; flex-direction: column; }
.acct span { font-size: 10.5px; color: var(--muted); }
.acct b { font-size: 14px; font-variant-numeric: tabular-nums; }

.tabs { flex: none; display: flex; border-bottom: 1px solid var(--border); }
.tabs button { flex: 1; height: 38px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tabs button.active { color: #fff; border-bottom-color: var(--accent); }
.tabs span { background: var(--panel2); border-radius: 8px; padding: 1px 6px; font-size: 10.5px; margin-left: 3px; }

.list { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; -webkit-overflow-scrolling: touch; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }

.pos { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 9px 10px; }
.pos-top { display: flex; align-items: center; gap: 8px; }
.side { font-size: 10.5px; font-weight: 800; padding: 2px 7px; border-radius: 4px; color: #fff; }
.side.buy { background: var(--up); }
.side.sell { background: var(--down); }
.pos-lot { color: var(--muted); }
.pos-pnl { margin-left: auto; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.pos-mid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; margin: 8px 0; font-size: 11.5px; color: var(--muted); }
.pos-mid b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }
.pos-act { display: flex; gap: 6px; }
.pos-act button { height: 36px; border-radius: 6px; font-weight: 700; }
.pos-act .edit { flex: none; padding: 0 12px; background: var(--panel2); color: var(--text); }
.pos-act .cut { flex: 1; background: var(--accent); color: #fff; }
.pos-act .cut:active { filter: brightness(.85); }

.hist { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; font-size: 11.5px; }
.hist .row1 { display: flex; align-items: center; gap: 8px; }
.hist .row2 { color: var(--muted); margin-top: 4px; display: flex; justify-content: space-between; gap: 6px; font-variant-numeric: tabular-nums; }
.hist .pnl { margin-left: auto; font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }
.reason { font-size: 10px; padding: 1px 6px; border-radius: 4px; background: var(--panel2); color: var(--muted); }

.panel-foot { flex: none; display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--border); }
.btn { flex: 1; height: 34px; border-radius: 6px; font-weight: 600; font-size: 12px; }
.btn.ghost { background: var(--panel2); color: var(--text); }
.btn.ghost:active { filter: brightness(1.3); }
.btn.danger { color: var(--down); }

/* ---------------- Bottom trading bar ---------------- */
.tradebar {
  flex: none;
  display: flex; flex-direction: column; gap: 8px;
  padding: 8px 10px calc(8px + var(--safe-b));
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.fields { display: grid; grid-template-columns: 1.5fr 1fr 1fr; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.field > span { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.field input {
  width: 100%; height: 36px; padding: 0 8px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  outline: none; font-variant-numeric: tabular-nums; -webkit-user-select: text; user-select: text;
}
.field input:focus { border-color: var(--accent); }
.stepper { display: flex; align-items: stretch; }
.stepper input { text-align: center; border-radius: 0; min-width: 0; }
.stepper button { width: 36px; flex: none; background: var(--panel2); font-size: 18px; font-weight: 600; }
.stepper button:first-child { border-radius: 6px 0 0 6px; }
.stepper button:last-child { border-radius: 0 6px 6px 0; }
.stepper button:active { background: var(--border); }

.tb-info { margin-top: 5px; font-size: 10.5px; color: var(--muted); min-height: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }

.tb-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.trade {
  height: 54px; border-radius: 10px; color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.15;
  transition: transform .06s, filter .1s;
}
.trade span { font-size: 13px; font-weight: 800; letter-spacing: .02em; }
.trade b { font-size: 12px; font-weight: 500; opacity: .9; font-variant-numeric: tabular-nums; }
.trade.buy { background: var(--up); }
.trade.sell { background: var(--down); }
.trade:active { transform: scale(.97); filter: brightness(.88); }

/* ---------------- Toasts ---------------- */
.toasts { position: absolute; top: 84px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 50; pointer-events: none; width: min(92vw, 360px); }
.toast {
  background: var(--panel2); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  padding: 9px 12px; border-radius: 6px; box-shadow: 0 6px 18px rgba(0, 0, 0, .5);
  animation: tin .18s ease; font-size: 12.5px;
}
.toast.ok { border-left-color: var(--up); }
.toast.err { border-left-color: var(--down); }
@keyframes tin { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------------- Larger screens ---------------- */
@media (min-width: 480px) {
  .sym small { display: block; }
  .tick-price { font-size: 17px; }
  .tick-chg { font-size: 11.5px; }
  .tf { margin-left: 16px; }
  .topbar .icon-btn:last-child { margin-left: auto; }
}

@media (min-width: 900px) {
  .toolbar { width: 46px; }
  /* panel docks as a column and collapses with the top-bar button */
  .panel {
    position: relative; transform: none; width: 0; border-left-width: 0;
    overflow: hidden; box-shadow: none; transition: width .2s ease;
    flex: none;
  }
  .panel.open { width: 330px; border-left-width: 1px; }
  .panel > * { min-width: 329px; }
  #btnPanelClose { display: none; }

  .tradebar { flex-direction: row; align-items: center; gap: 24px; padding-top: 10px; }
  .tb-inputs { flex: 1; max-width: 560px; }
  .tb-buttons { width: 400px; margin-left: auto; }
  .latest { right: 80px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .trade { height: 44px; }
  .field input { height: 32px; }
}
