/* Giao dien dien thoai / may tinh bang (body.m, bat trong mobile.js). Bo cuc theo TradingView mobile:
   thanh tren cuon ngang | thanh ve trai + chart | dock replay | dai tai khoan. Ngang: dock thanh cot phai. */

/* dung chung: chart nhan cu cham (khong de trinh duyet cuon / chon chu / hien menu khi nhan giu) */
.chart, .legend { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.chart { touch-action: none; }
/* cham 2 lan khong phong to trang (mac dinh trinh duyet); chart van tu thu phong bang 2 ngon */
html, body { touch-action: manipulation; }
.mui { display: none; }
.lfold { display: none; }
.tinfo { display: none; }
.dcur .dname { flex: 1; }
.dcur.off .dname { opacity: .5; }
#loupe { position: fixed; z-index: 60; width: 120px; height: 120px; border-radius: 50%; border: 2px solid #f7a600; box-shadow: 0 6px 20px #000c; pointer-events: none; }
#loupe[hidden] { display: none; }

body.m {
  display: grid; height: 100%; overflow: hidden;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "top" "work" "dock" "strip";
  padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px);
  font-size: 14px;
}
body.m header { display: none; }
body.m .mui { display: flex; }
body.m #mhint[hidden] { display: none; }

/* ---- thanh tren */
body.m #mtop {
  grid-area: top; align-items: center; gap: 2px; padding: calc(env(safe-area-inset-top, 0px) + 4px) 6px 4px;
  overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); background: var(--panel);
}
body.m #mtop::-webkit-scrollbar { display: none; }
body.m #mtop .mlogo { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 6px; }
body.m #mtop .mlogo:active { background: var(--hover); }
body.m #mtop button { flex: none; min-width: 36px; height: 34px; padding: 0 8px; border: 0; background: none; font-size: 16px; color: var(--text); }
body.m #mtop button:disabled { color: var(--disabled); }
body.m #mtop button[hidden] { display: none; }
body.m .mpill { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line) !important; border-radius: 17px; background: var(--menu) !important; font-size: 13px !important; font-weight: 600; }
body.m .mctype svg { width: 16px; height: 16px; display: block; }

/* ---- chart */
body.m #work { grid-area: work; min-height: 0; }
body.m #leftbar { width: 42px; gap: 0; padding: 2px 0; }
body.m #leftbar .lb { width: 36px; height: 36px; font-size: 17px; }
body.m #leftbar hr { margin: 3px 0; }
body.m .lbmore { display: none; }
body.m main.grid { padding: 0; gap: 2px; }
body.m .panel { border: 0; }
body.m .panel.active { border: 0; }
body.m .phead { display: none; }
body.m .lgroup { left: 4px; right: 58px; font-size: 11px; }
body.m .lfold { display: inline-block; pointer-events: auto; padding: 0 8px; border: 0; background: none; color: var(--muted); font-size: 13px; line-height: 18px; }
body.m .lrow.lmain { pointer-events: auto; }
body.m .legend.folded .lrow:not(.lmain), body.m .legend.folded .lohlc { display: none; }
body.m .lrow.sel .lbtns { display: inline-flex; gap: 4px; }
body.m .lbtns button { padding: 2px 9px; font-size: 13px; line-height: 20px; }
body.m .golive { width: 38px; height: 38px; }

/* dien thoai: moi lan 1 chart (nut so trang tren thanh tren de chuyen) */
@media (max-width: 599px) {
  body.m main.grid { display: block; }
  body.m main.grid > .panel { height: 100%; }
  body.m main.grid > .panel:not(.active) { display: none; }
}
/* may tinh bang: cac chart canh nhau */
@media (min-width: 600px) {
  body.m main.grid.n2 { grid-template-columns: 1fr 1fr; grid-template-rows: none; grid-auto-rows: auto; }
  body.m main.grid.n3 { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: none; grid-auto-rows: auto; }
  body.m main.grid.n4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
  body.m .panel.active { box-shadow: inset 0 -2px 0 var(--accent); }
}

/* cum SELL | lot | BUY (kieu vien manh, chung voi PC): to hon de cham; o lot cham de mo banh xe cuon */
body.m .ttrade { margin: 4px 0 2px; }
body.m .tone { gap: 8px; }
body.m .tone .tsell, body.m .tone .tbuy { min-width: 64px; min-height: 34px; padding: 4px 12px; font-size: 13px; }
body.m .tlot input { width: 52px; font-size: 16px; padding: 3px 0; caret-color: transparent; cursor: pointer; }
body.m .tone .tset { display: none; } /* cai dat giao dich nam trong menu ☰ */
body.m .tconfirm { justify-content: flex-start; gap: 6px; width: min(calc(100vw - 110px), 420px); }
body.m .tconfirm .tinfo { display: block; width: 100%; padding: 5px 9px; border-radius: 6px; background: color-mix(in srgb, var(--menu) 94%, transparent); font-size: 12px; font-variant-numeric: tabular-nums; }
body.m .tinfo .buy { color: var(--up); }
body.m .tinfo .sell { color: var(--down); }
body.m .tconfirm button { padding: 9px 12px; }

/* ---- banh xe chon lot (kieu dat gio bao thuc iPhone) */
#lotwheel { position: fixed; inset: 0; z-index: 45; }
#lotwheel .wback { position: absolute; inset: 0; background: #0009; opacity: 0; transition: opacity .15s; }
#lotwheel .wsheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 520px; margin: 0 auto; padding: 4px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  border: 1px solid var(--line); border-radius: 16px 16px 0 0; background: var(--menu); box-shadow: 0 -10px 30px var(--shadow);
  transform: translateY(100%); transition: transform .2s ease-out;
}
#lotwheel.on .wback { opacity: 1; }
#lotwheel.on .wsheet { transform: none; }
#lotwheel .whead { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; }
#lotwheel .whead b { font-size: 15px; }
#lotwheel .whead button { border: 0; background: none; padding: 8px 6px; font-size: 16px; color: var(--muted); }
#lotwheel .whead .wok { color: #f7a600; font-weight: 700; }
#lotwheel .wval { text-align: center; font: 600 13px ui-monospace, Menlo, Consolas, monospace; color: var(--muted); }
#lotwheel .wwrap { position: relative; display: flex; justify-content: center; align-items: center; height: 200px; margin-top: 4px; }
#lotwheel .wband { position: absolute; left: 0; right: 0; top: 80px; height: 40px; border-radius: 10px; background: var(--hover); pointer-events: none; }
#lotwheel .wcol {
  position: relative; width: 84px; height: 200px; overflow-y: auto; scroll-snap-type: y mandatory; scrollbar-width: none;
  padding: 80px 0; overscroll-behavior: contain; touch-action: pan-y; outline: none;
  -webkit-mask-image: linear-gradient(transparent, #000 32%, #000 68%, transparent); mask-image: linear-gradient(transparent, #000 32%, #000 68%, transparent);
}
#lotwheel .wcol::-webkit-scrollbar { display: none; }
#lotwheel .wcol:focus-visible { box-shadow: inset 0 0 0 1px var(--accent); border-radius: 10px; }
#lotwheel .wi { height: 40px; line-height: 40px; scroll-snap-align: center; text-align: center; font: 500 22px ui-monospace, Menlo, Consolas, monospace; color: var(--muted); font-variant-numeric: tabular-nums; cursor: pointer; }
#lotwheel .wi.on { color: var(--strong); font-weight: 600; }
#lotwheel .wi.off { color: var(--disabled); text-decoration: line-through; }
#lotwheel .wdot { position: relative; width: 18px; text-align: center; font: 700 26px ui-monospace, Menlo, monospace; color: var(--strong); }
#lotwheel .wnote { text-align: center; font-size: 11px; color: var(--muted); margin-top: 6px; }

/* ---- dock replay */
body.m #mdock { grid-area: dock; align-items: center; gap: 6px; padding: 5px 8px; border-top: 1px solid var(--line); background: var(--panel); }
body.m #mdock button { height: 38px; min-width: 40px; padding: 0 10px; font-size: 15px; }
body.m #mdock .mplay { min-width: 52px; background: #f7a600; border-color: #f7a600; color: #1b1405; font-size: 17px; }
body.m #mdock .mpill { height: 32px; }
body.m .mwhen { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; justify-content: center; line-height: 1.15; border: 0 !important; background: none !important; font-variant-numeric: tabular-nums; }
body.m .mwhen b { font-size: 14px; }
body.m .mwhen small { color: var(--muted); font-size: 11px; }

/* ---- dai tai khoan (cham / keo len mo bang lenh) */
body.m #mstrip {
  grid-area: strip; justify-content: space-between; align-items: center; gap: 8px; width: 100%;
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px)); border: 0; border-top: 1px solid var(--line); border-radius: 0;
  background: var(--panel); color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums;
}
body.m #mstrip b { color: var(--text); }
body.m #mstrip .buy { color: var(--up); font-weight: 600; }
body.m #mstrip .sell { color: var(--down); font-weight: 600; }

/* ---- bang lenh: sheet keo len */
body.m #tradepanel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 18; height: 52vh; max-height: 92vh; display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: 14px 14px 0 0; box-shadow: 0 -8px 30px var(--shadow);
  padding-bottom: env(safe-area-inset-bottom, 0px); transform: translateY(105%); transition: transform .22s ease-out, height .18s ease-out;
}
body.m.tp-open #tradepanel { transform: none; }
body.m .tpgrip { position: static; flex: none; height: 28px; cursor: grab; touch-action: none; }
body.m .tphead, body.m .tphead * { touch-action: pan-x; } /* keo doc tren dau sheet (ca hang tab cuon ngang) = keo sheet; tab van cuon ngang duoc */
body.m #tradepanel.dragging { transition: none; }
body.m .tpgrip::after { content: ""; display: block; width: 40px; height: 4px; margin: 9px auto 0; border-radius: 2px; background: var(--disabled); }
body.m .tpgrip:hover { background: none; }
body.m .tphead { flex-wrap: wrap; gap: 6px; padding: 0 10px 8px; }
body.m .tptabs { order: 1; flex: 1 1 100%; display: flex; overflow-x: auto; scrollbar-width: none; }
body.m .tptabs button { padding: 6px 10px; white-space: nowrap; }
body.m .tphead [data-tp="csv"] { display: none; }
body.m .tphead [data-tp="closeall"] { order: 2; margin-right: auto; }
body.m .tphead [data-tp="account"] { order: 2; }
body.m .tphead [data-tp="toggle"] { order: 2; }
body.m .tpsum { order: 3; width: 100%; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 4px; }
body.m .tpsum span { display: flex; flex-direction: column; padding: 4px 8px; border-radius: 6px; background: var(--menu); }
body.m .tpsum small { color: var(--muted); font-size: 10px; }
body.m .tpbody { flex: 1; height: auto !important; min-height: 0; overflow: auto; -webkit-overflow-scrolling: touch; }
.tcard { border-bottom: 1px solid var(--menu); touch-action: pan-y; }
.tcard[data-hist] { cursor: pointer; }
.tcin { display: flex; justify-content: space-between; gap: 10px; padding: 9px 12px; transition: transform .12s; }
.tcl, .tcr { min-width: 0; font-variant-numeric: tabular-nums; }
.tcl small, .tcr small { display: block; color: var(--muted); font-size: 11px; }
.tcl b small { display: inline; }
.tcr { text-align: right; flex: none; }
.tcr b { font-size: 15px; }
.tcacts { display: none; justify-content: flex-end; gap: 8px; padding: 0 12px 10px; }
.tcard.open .tcacts { display: flex; }
.tcard.open { background: var(--menu); }
.tcacts button { padding: 8px 16px; }
.tcacts .danger { background: var(--down); border-color: var(--down); color: #fff; }
.tcsv { padding: 6px 12px; text-align: right; }
.tcard .buy, .tcsv .buy { color: var(--up); }
.tcard .sell { color: var(--down); }
body.m .tpstats { flex-direction: column; }
body.m .stables { flex-wrap: wrap; }
body.m .scharts { width: 100%; grid-template-columns: 1fr; }

/* ---- hop thoai = sheet duoi man hinh; menu chuot phai = sheet */
/* top / height theo vung nhin thay (visualViewport): ban phim ao hien thi hop thoai nam tren ban phim */
body.m #dlg { align-items: flex-end; padding: 0; top: var(--vvt, 0px); bottom: auto; height: var(--vvh, 100%); }
/* hop thoai co o nhap (SL / TP, cai dat...): nam giua vung nhin thay, khong bi ban phim che */
body.m #dlg:has(input[type="number"], input[type="text"], input:not([type]), textarea) { align-items: center; padding: 8px; }
body.m #dlg:has(input[type="number"], input[type="text"], input:not([type]), textarea) .dlg { border-radius: 14px; max-height: calc(var(--vvh, 100vh) - 16px); padding-bottom: 0; }
body.m #dlg:has(input[type="number"], input[type="text"], input:not([type]), textarea) .dbody { overflow-y: auto; }
body.m .dlg { width: 100%; max-width: 640px; max-height: 88vh; border-radius: 14px 14px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
body.m .dlg input, body.m .dlg select, body.m .dlg textarea, body.m #mstart input { font-size: 16px; } /* iOS khong tu phong to khi go */
body.m .dlg .dhead button { font-size: 20px; padding: 2px 10px; }
body.m .dform { gap: 10px; }
body.m .dform label { gap: 10px; }
body.m .dform input[type="checkbox"] { width: 22px; height: 22px; }
body.m .ditem { padding: 11px 6px; }
body.m .dcur { padding: 7px 6px; }
body.m .dcur button { padding: 4px 10px; font-size: 16px; }
body.m .dkeys td { padding: 6px 8px; vertical-align: top; }
body.m #ctxmenu:not(.anchored) {
  left: 0; right: 0; top: auto; bottom: 0; width: 100%; max-height: 70vh; border-radius: 14px 14px 0 0;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom, 0px)); box-shadow: 0 -8px 30px var(--shadow);
}
body.m #ctxmenu button { padding: 11px 18px; font-size: 15px; }
body.m #ctxmenu.anchored { max-height: 70vh; }
body.m #floatbar { max-width: calc(100vw - 8px); overflow-x: auto; scrollbar-width: none; }
body.m #floatbar button, body.m #floatbar select { min-height: 34px; padding: 4px 9px; font-size: 15px; }
body.m #floatbar .swatch { width: 32px; height: 32px; }
body.m #palette { grid-template-columns: repeat(8, 30px); gap: 5px; }
body.m #palette button { width: 30px; height: 30px; }
body.m #toast { top: calc(env(safe-area-inset-top, 0px) + 50px); max-width: 92vw; text-align: center; }

/* ---- sheet tu mobile.js */
.mlist { display: flex; flex-direction: column; }
.mrow { display: flex; justify-content: space-between; align-items: center; padding: 11px 6px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: none; text-align: left; }
.mrow.on b { color: #f7a600; }
.mchip { display: inline-block; padding: 2px 9px; border: 1px solid var(--line); border-radius: 12px; background: var(--menu); color: var(--muted); font-size: 12px; }
button.mchip { color: var(--text); font-size: 13px; padding: 6px 11px; }
.mchips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.mseg { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 4px; }
.mseg button { flex: 1; min-width: 52px; padding: 8px 4px; }
.mseg button.on { border-color: #f7a600; color: #f7a600; }
.mlink { margin-top: 12px; border: 0; background: none; color: var(--accent); text-align: left; padding: 6px 0; }
.mdate { width: 100%; padding: 9px 10px; color-scheme: dark; }
.mgo { width: 100%; margin-top: 8px; padding: 11px; background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ---- thanh goi y khi ve */
#mhint { position: fixed; z-index: 16; left: 50px; right: 8px; bottom: calc(var(--mbottom, 92px) + 8px); align-items: center; gap: 8px; padding: 6px 8px 6px 12px; border-radius: 10px; background: #f7a600; color: #1b1405; font-size: 13px; font-weight: 600; box-shadow: 0 4px 14px #0009; }
#mhint span { flex: 1; min-width: 0; }
#mhint button { flex: none; padding: 7px 12px; border: 0; background: #1b1405; color: #f7a600; font-weight: 700; }

/* ---- menu ☰ */
#mdrawer { position: fixed; inset: 0; z-index: 25; }
#mdrawer .mdback { position: absolute; inset: 0; background: #0009; opacity: 0; transition: opacity .15s; }
#mdrawer .mdpanel {
  position: absolute; left: 0; top: 0; bottom: 0; width: min(84vw, 330px); overflow-y: auto; display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 0 calc(env(safe-area-inset-bottom, 0px) + 10px) env(safe-area-inset-left, 0px);
  background: var(--panel); border-right: 1px solid var(--line); transform: translateX(-100%); transition: transform .18s ease-out;
}
#mdrawer.on .mdback { opacity: 1; }
#mdrawer.on .mdpanel { transform: none; }
#mdrawer .mdh { padding: 14px 18px 4px; color: #f7a600; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
#mdrawer button { padding: 12px 18px; border: 0; border-radius: 0; background: none; text-align: left; font-size: 15px; }
#mdrawer button:active { background: var(--hover); }
#mdrawer .mdcredit { margin-top: auto; padding: 16px 18px 4px; color: var(--disabled); font-size: 11px; text-decoration: none; }

/* ---- man hinh bat dau */
#mstart { position: fixed; inset: 0; z-index: 22; overflow-y: auto; background: var(--bg); }
#mstart .msin { max-width: 480px; margin: 0 auto; padding: calc(env(safe-area-inset-top, 0px) + 18px) 16px calc(env(safe-area-inset-bottom, 0px) + 24px); display: flex; flex-direction: column; gap: 12px; }
#mstart .mslogo { display: flex; justify-content: space-between; align-items: center; font-size: 26px; font-weight: 800; color: var(--strong); }
#mstart .mslogo i { font-style: normal; color: #f7a600; }
#mstart .mslogo a { color: inherit; text-decoration: none; }
#mstart .msx { border: 0; background: none; font-size: 22px; }
#mstart .mscard { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
#mstart .mscard > b { font-size: 16px; }
#mstart small { color: var(--muted); }
#mstart small.warn { color: #f7a600; }
#mstart .msrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
#mstart .msrow label { flex: 1; flex-direction: column; align-items: stretch; gap: 4px; font-size: 12px; }
#mstart .msrow input { width: 100%; padding: 8px 10px; }
#mstart .mlink { margin-top: 0; }
#mstart .primary { margin-top: 6px; padding: 12px; border-color: #f7a600; background: #f7a600; color: #1b1405; font-size: 15px; font-weight: 700; }
#mstart .msresume .primary { border-color: var(--accent); background: var(--accent); color: #fff; }
#mstart .buy { color: var(--up); }
#mstart .sell { color: var(--down); }

/* ---- dien thoai nam ngang: chart tran man hinh, dock thanh cot phai */
@media (orientation: landscape) and (max-height: 520px) {
  body.m {
    grid-template-columns: minmax(0, 1fr) 118px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "top dock" "work dock" "work strip";
  }
  body.m #mtop { padding-top: 2px; padding-bottom: 2px; }
  body.m #mtop button { height: 30px; }
  body.m #mdock { flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 5px; padding: 6px; border-top: 0; border-left: 1px solid var(--line); overflow-y: auto; }
  body.m #mdock button { height: 34px; }
  body.m .mwhen { margin: 4px 0 0; align-items: center; }
  body.m #mstrip { flex-direction: column; align-items: flex-start; gap: 2px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px)); border-left: 1px solid var(--line); font-size: 11px; }
  body.m #tradepanel { left: auto; width: min(460px, 70vw); height: 100vh; max-height: none; border-radius: 14px 0 0 14px; transform: translateX(105%); }
  body.m.tp-open #tradepanel { transform: none; }
  body.m .tpgrip { display: none; }
  #mhint { bottom: 8px; right: 126px; }
}

/* giao dien may tinh co thanh duoi, khe giua cac khoi: dien thoai giu bo cuc rieng */
body.m #botbar { display: none; }
body.m #leftbar { width: 42px; margin-right: 0; border-right: 1px solid var(--line); background: var(--panel); }
body.m #tradepanel { margin-top: 0; }
body.m .chartwrap > .pclose { display: none; }
