/* ISAFX TERMINAL v3 - full parity Mini App (Controller v2.01) */
:root{
  --bg:#050607;--gold:#d6b46a;--gold2:#e5ca8c;--text:#f3efe5;--muted:#8e9298;
  --line:rgba(214,180,106,.20);--green:#42d392;--red:#d86a5c;--redbg:rgba(170,42,42,.22);
  --safe-top:calc(var(--tg-safe-area-inset-top,0px) + var(--tg-content-safe-area-inset-top,0px));
  --safe-bottom:max(env(safe-area-inset-bottom,0px),var(--tg-safe-area-inset-bottom,0px));
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{margin:0;height:100%;height:100dvh;overflow:hidden;background:radial-gradient(circle at 50% -10%,rgba(214,180,106,.10),transparent 32%),linear-gradient(180deg,#08090a,#030404);background-color:#050607;color:var(--text);font-family:-apple-system,BlinkMacSystemFont,"SF Pro Display","Segoe UI",Roboto,sans-serif}
button{font:inherit;color:inherit;cursor:pointer}
button:disabled{opacity:.38;cursor:default}
input{font:inherit}

/* ---------- shell: fills the whole Fold7 screen, folded + unfolded ---------- */
.shell{width:100%;height:100dvh;display:flex;flex-direction:column;
  padding:calc(max(10px,env(safe-area-inset-top,0px)) + var(--safe-top)) clamp(10px,2.4vw,22px) max(10px,var(--safe-bottom))}
.brand{flex:none;text-align:center;padding:10px 0 8px}
.brand h1{margin:0;font-family:Georgia,serif;color:var(--gold2);font-size:clamp(16px,2.6vw,22px);font-weight:500;letter-spacing:2.6px}
.brand span{display:block;margin-top:4px;color:#777b80;font-size:8px;letter-spacing:3px}
.targets{flex:none;display:grid;grid-template-columns:repeat(4,1fr);gap:7px;margin-bottom:8px}
.targets button,.tabs button,.seg button{height:40px;border:1px solid rgba(214,180,106,.17);border-radius:7px;background:linear-gradient(180deg,#111315,#090a0b);color:#96999d;font-size:11px;font-weight:700;letter-spacing:.7px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding:0 4px}
.targets button.active,.tabs button.active,.seg button.active{color:#ebd298;border-color:rgba(214,180,106,.6);box-shadow:inset 0 0 18px rgba(214,180,106,.06)}
.targets span{color:var(--green);font-size:8px;margin-left:3px}
.status{flex:none;display:flex;align-items:center;justify-content:space-between;gap:10px;padding:8px 14px;margin-bottom:8px;border:1px solid rgba(214,180,106,.16);border-radius:8px;background:linear-gradient(180deg,#0e1011,#090a0b)}
.status b{display:block;color:#e4c783;font-family:Georgia,serif;font-size:15px;letter-spacing:1.5px}
.status small{display:block;margin-top:3px;color:#74787d;font-size:8px;letter-spacing:1.5px}
.pill{flex:none;padding:6px 11px;border:1px solid rgba(214,180,106,.2);border-radius:20px;color:#a8aaad;background:#08090a;font-size:9px;font-weight:700;letter-spacing:1px}
.pill.ok{color:var(--green);border-color:rgba(66,211,146,.35)}
.pill.bad{color:var(--red);border-color:rgba(216,106,92,.45)}
.pill.busy{color:#ebd298;border-color:rgba(214,180,106,.5)}
.tabs{flex:none;display:grid;grid-template-columns:repeat(5,1fr);gap:6px;margin-bottom:8px}
.tabs button{height:clamp(40px,6vh,52px);font-size:9.5px}
.tabs button i{display:block;font-style:normal;font-size:14px;margin-bottom:2px}
.main{flex:1;min-height:0;display:flex;flex-direction:column;overflow-y:auto;overflow-x:hidden;-webkit-overflow-scrolling:touch;overscroll-behavior:contain}
.screen{display:none}
.screen.on{display:flex;flex-direction:column;flex:1;min-height:0}

/* ---------- common blocks ---------- */
.title{display:flex;justify-content:space-between;align-items:center;margin:12px 2px 8px;gap:8px}
.title span{font-size:11px;font-weight:800;color:#d7b86a;letter-spacing:1.4px}
.title small{font-size:8px;color:rgba(255,255,255,.38);letter-spacing:1px}
.title .mini{height:26px;padding:0 10px;border:1px solid var(--line);border-radius:6px;background:#0d0f10;color:#c9b17a;font-size:9px;font-weight:700;letter-spacing:1px}
.seg{display:grid;grid-template-columns:repeat(3,1fr);gap:6px;margin-bottom:8px;flex:none}
.seg.two{grid-template-columns:1fr 1fr}
.seg.five{grid-template-columns:repeat(5,1fr)}
.seg button{height:34px;font-size:10px}
.seg.five button{font-size:9px;letter-spacing:.3px}
.grid{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.grid button,.btn{min-height:56px;padding:7px 5px;border:1px solid rgba(214,180,106,.2);border-radius:8px;background:linear-gradient(145deg,rgba(21,23,24,.98),rgba(8,9,10,.98));text-align:center}
.grid button strong,.btn strong{display:block;color:#d9c183;font-family:Georgia,serif;font-size:12px;font-weight:500;letter-spacing:.6px}
.grid button small,.btn small{display:block;margin-top:5px;color:#666a6f;font-size:7px;letter-spacing:.75px}
.grid .trade strong{font-size:19px;letter-spacing:2px}
.buy{background:radial-gradient(circle at 50% 0,rgba(44,180,112,.18),transparent 72%),linear-gradient(145deg,rgba(16,46,34,.96),rgba(7,15,11,.98))!important;border-color:rgba(65,205,135,.55)!important;box-shadow:inset 0 1px 0 rgba(120,255,180,.06),0 0 18px rgba(35,180,105,.08)}
.buy strong{color:#62d99a!important}
.sell{background:radial-gradient(circle at 50% 0,rgba(205,60,60,.18),transparent 72%),linear-gradient(145deg,rgba(51,20,20,.96),rgba(17,7,7,.98))!important;border-color:rgba(220,76,76,.55)!important;box-shadow:inset 0 1px 0 rgba(255,130,130,.05),0 0 18px rgba(200,45,45,.08)}
.sell strong{color:#e46f69!important}
.full{grid-column:1 / -1}
.card{padding:11px 12px;margin-bottom:8px;border:1px solid var(--line);border-radius:9px;background:linear-gradient(145deg,rgba(18,20,21,.98),rgba(6,7,8,.98))}
.card.tap{cursor:pointer}
.card.tap:active{border-color:rgba(214,180,106,.55)}
.card .row{display:flex;justify-content:space-between;align-items:center;gap:8px}
.card b{font-family:Georgia,serif;color:#e5ca8c;font-weight:500;font-size:13px;letter-spacing:.8px}
.card small{color:#7c8085;font-size:9px;letter-spacing:.6px}
.card pre{margin:0;white-space:pre-wrap;word-break:break-word;font-family:inherit;font-size:12px;line-height:1.5;color:#d6d3cb}
.tag{flex:none;font-size:8px;font-weight:800;letter-spacing:1px;padding:3px 7px;border-radius:10px;border:1px solid var(--line);color:#c9b17a}
.tag.b{color:var(--green);border-color:rgba(66,211,146,.35)}
.tag.s{color:var(--red);border-color:rgba(216,106,92,.4)}
.bar{height:4px;border-radius:3px;background:#1a1c1e;margin-top:8px;overflow:hidden}
.bar i{display:block;height:100%;background:linear-gradient(90deg,#8f7138,#d6b46a)}
.empty{padding:22px 8px;text-align:center;color:#6d7176;font-size:11px;letter-spacing:.5px}
.note{font-size:10px;color:#8b7f63;margin:6px 2px 4px;line-height:1.5}
.note.warn{color:#d9a35f}

/* ---------- form fields ---------- */
.field{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:8px 0;border-bottom:1px solid rgba(214,180,106,.08);font-size:12px}
.field:last-child{border-bottom:0}
.field label{color:#a9acb0;letter-spacing:.4px;min-width:0}
.field label small{display:block;color:#666a6f;font-size:9px;margin-top:2px}
.field.changed label{color:#ebd298}
.field.changed .inp,.field.changed .step input{border-color:rgba(235,210,152,.85)}
.step{display:flex;align-items:center;gap:6px;flex:none}
.step button{width:32px;height:32px;border:1px solid var(--line);border-radius:6px;background:#0d0f10;color:#d9c183;font-size:15px}
.step input,.inp{width:84px;height:32px;text-align:center;border:1px solid rgba(214,180,106,.3);border-radius:6px;background:#07080a;color:var(--text);font-size:13px;outline:none}
.inp.wide{width:120px}
.toggle{flex:none;width:46px;height:26px;border-radius:13px;border:1px solid var(--line);background:#0d0f10;position:relative;padding:0}
.toggle.on{background:rgba(214,180,106,.25);border-color:rgba(214,180,106,.6)}
.toggle:after{content:"";position:absolute;top:4px;left:4px;width:16px;height:16px;border-radius:50%;background:#7c8085;transition:.15s}
.toggle.on:after{left:24px;background:#e5ca8c}
.save{width:100%;height:46px;margin-top:8px;border:1px solid rgba(214,180,106,.55);border-radius:8px;background:linear-gradient(180deg,rgba(214,180,106,.18),rgba(214,180,106,.05));color:#ebd298;font-weight:800;letter-spacing:1.5px;font-size:11px}
.save.danger{border-color:rgba(220,76,76,.6);background:linear-gradient(180deg,rgba(170,42,42,.35),rgba(60,12,12,.6));color:#fff}
.tplist{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:6px 12px;margin-top:6px}
.tprow{display:flex;align-items:center;justify-content:space-between;gap:6px;font-size:11px;color:#a9acb0}
.tprow .inp{width:86px}
.tprow em{font-style:normal;color:#666a6f;font-size:9px}

/* ---------- TRADE tab: fills every pixel that is left ---------- */
#trade .sets{flex:1;min-height:0;display:flex;gap:12px}
#trade .set{flex:1;min-height:0;display:none;flex-direction:column}
#trade .set.show{display:flex}
#trade .set .grid{flex:1;min-height:0;grid-template-rows:repeat(4,1fr)}
#trade .grid button{min-height:0;height:auto}
#trade .grid button strong{font-size:clamp(11px,1.9vh,15px);white-space:nowrap}
#trade .grid .trade strong{font-size:clamp(17px,3.2vh,26px)}
#trade .grid button small{font-size:clamp(6.5px,1vh,8px)}
#trade .extra{flex:none;margin-top:8px;display:grid;grid-template-columns:1fr 1.3fr 1fr;gap:8px}
#trade .extra button{min-height:clamp(42px,6vh,56px)}
#trade .extra strong{font-size:11px!important}
.sethead{display:none;justify-content:space-between;padding:0 4px 6px;letter-spacing:.14em}
.sethead span{font-size:11px;font-weight:800;color:#d7b86a}
.sethead small{font-size:8px;color:rgba(255,255,255,.38)}

/* ---------- dock ---------- */
.dock{flex:none;padding:8px 0 0}
.feedback{display:flex;justify-content:space-between;gap:10px;margin:0 2px 6px;color:#7d8186;font-size:9px;letter-spacing:.6px;cursor:pointer}
.feedback span:first-child{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
.feedback span:last-child{flex:none;color:#5e6266}
.dock .in{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.dock .in button{min-height:clamp(54px,7.5vh,70px);border-radius:12px;border:1px solid rgba(74,143,214,.45);background:linear-gradient(145deg,rgba(28,72,120,.58),rgba(8,18,30,.95));color:#fff}
.dock .in button strong{display:block;font-size:13px;font-weight:800;letter-spacing:.3px}
.dock .in button small{display:block;font-size:8px;margin-top:6px;letter-spacing:.2px;color:#e8eef5}
.dock .in .kill{border-color:rgba(220,76,76,.48);background:linear-gradient(145deg,rgba(104,25,25,.58),rgba(30,8,8,.95))}

/* ---------- sheets ---------- */
.sheet{position:fixed;inset:0;z-index:50;display:none;align-items:flex-end;justify-content:center;background:rgba(0,0,0,.72);backdrop-filter:blur(6px);-webkit-backdrop-filter:blur(6px)}
.sheet.on{display:flex}
.sheet .box{width:min(100%,560px);max-height:88dvh;overflow:auto;padding:18px 16px calc(22px + var(--safe-bottom));border:1px solid rgba(214,180,106,.4);border-bottom:0;border-radius:16px 16px 0 0;background:linear-gradient(160deg,#151719,#070808)}
.sheet h2{margin:0 0 4px;font-family:Georgia,serif;font-weight:500;color:#e1c47e;letter-spacing:1px;font-size:17px;padding-right:30px}
.sheet p{margin:0 0 12px;color:#999da1;font-size:11px;line-height:1.5}
.sheet pre{margin:0 0 12px;white-space:pre-wrap;word-break:break-word;font-family:inherit;font-size:12px;line-height:1.5;color:#d6d3cb}
.close{float:right;border:0;background:none;color:#888;font-size:24px;line-height:1;margin-top:-6px;padding:4px 6px}
.danger{border-color:rgba(192,73,73,.55)!important;background:linear-gradient(145deg,var(--redbg),rgba(16,7,7,.94))!important}
.danger strong{color:#f0b8ae!important}
.lv{display:grid;grid-template-columns:repeat(auto-fill,minmax(42px,1fr));gap:5px;margin:10px 0}
.lv div{padding:6px 0;text-align:center;border-radius:6px;border:1px solid var(--line);font-size:10px;color:#8e9298}
.lv div.f{color:#0b0c0d;background:#d6b46a;border-color:#d6b46a;font-weight:800}
.kv{display:grid;grid-template-columns:1fr auto;gap:6px 10px;font-size:12px;margin-bottom:10px}
.kv span{color:#8e9298}
.kv b{font-family:inherit;color:var(--text);font-weight:600;text-align:right}
.table{width:100%;border-collapse:collapse;font-size:11px;margin:4px 0 12px}
.table td{padding:5px 4px;border-bottom:1px solid rgba(214,180,106,.08)}
.table td:last-child{text-align:right;color:#e5ca8c}

/* ---------- UNFOLDED (wide): SET 1 and SET 2 side by side ---------- */
@media (min-width:620px){
  #trade .seg{display:none}
  #trade .set{display:flex}
  .sethead{display:flex}
  .tabs button{font-size:11px}
  #trade .grid button strong{font-size:clamp(11px,1.65vw,15px)}
  .wide2{display:grid;grid-template-columns:1fr 1fr;gap:0 14px}
  .wide2 > .card{margin-bottom:8px}
}
@media (max-height:640px){ .brand{padding:4px 0 4px} .brand span{display:none} }

/* v3.1: 30% lighter (readability on the Fold7) */
.shell,.sheet .box{filter:brightness(1.3)}
.grid button small,.btn small,.card small,.status small,.title small,.field label small,.tprow em,.brand span,.feedback span:last-child{color:#9a9ea4!important}
.field label,.kv span,.sheet p{color:#c4c7cb}
.empty{color:#9a9ea4}

/* v3.2: split-screen / narrow window - columns may shrink, text scales with width too */
.targets,.tabs{grid-template-columns:repeat(4,minmax(0,1fr))}
.tabs{grid-template-columns:repeat(5,minmax(0,1fr))}
.grid,.seg.two{grid-template-columns:repeat(2,minmax(0,1fr))}
.seg{grid-template-columns:repeat(3,minmax(0,1fr))}
.seg.five{grid-template-columns:repeat(5,minmax(0,1fr))}
#trade .extra{grid-template-columns:minmax(0,1fr) minmax(0,1.3fr) minmax(0,1fr)}
button{min-width:0}
.grid button,.btn,.dock .in button{overflow:hidden}
#trade .grid button strong{white-space:normal;line-height:1.15;overflow-wrap:anywhere;font-size:clamp(10px,min(1.9vh,3.4vw),15px)}
#trade .grid .trade strong{font-size:clamp(15px,min(3.2vh,6.5vw),26px)}
#trade .grid button small,.grid button small{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-size:clamp(6px,min(1vh,1.9vw),8px)}
#trade .extra strong{font-size:clamp(9px,2.6vw,11px)!important}
.tabs button{font-size:clamp(7.5px,2.2vw,9.5px)}
.targets button{font-size:clamp(9px,2.6vw,11px)}
.dock .in button strong{font-size:clamp(11px,3.2vw,13px)}
.dock .in button small{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.shell{width:100vw;max-width:100%;overflow:hidden}
@media (min-width:620px){ #trade .grid button strong{font-size:clamp(11px,min(1.9vh,1.65vw),15px)} }

/* v3.3: SET choice also when unfolded (default SET 1 full width; SET 1 + 2 optional) */
#trade .seg.tsets{display:grid;grid-template-columns:repeat(2,minmax(0,1fr))}
#trade .seg .wideonly{display:none}
#trade .sets.both .set[data-set="1"]{display:flex}
@media (min-width:620px){
  #trade .seg.tsets{display:grid;grid-template-columns:repeat(3,minmax(0,1fr))}
  #trade .seg .wideonly{display:block}
  #trade .set{display:none}
  #trade .set.show,#trade .sets.both .set{display:flex}
  .sethead{display:none}
  #trade .sets.both .sethead{display:flex}
}

/* v3.4: use the full screen - no double safe-area padding, brand sits in Telegram's button band */
html,body{height:var(--app-h,100dvh)}
.shell{height:var(--app-h,100dvh);
  padding:calc(var(--tg-safe-area-inset-top,0px) + 2px) clamp(8px,2vw,20px) max(4px,var(--tg-safe-area-inset-bottom,0px))}
.brand{min-height:var(--tg-content-safe-area-inset-top,0px);display:flex;flex-direction:column;justify-content:center;padding:4px 0 6px}
.brand h1{line-height:1.05}
.targets{margin-bottom:6px}
.targets button{height:36px}
.status{padding:6px 12px;margin-bottom:6px}
.tabs{margin-bottom:6px}
.tabs button{height:clamp(38px,5.4vh,50px)}
.seg{margin-bottom:6px}
.dock{padding-top:6px}
.feedback{margin-bottom:4px}
/* readable sub-labels on every button, incl. BUY / SELL */
#trade .grid button small,.grid button small,.btn small{font-size:clamp(8px,1.25vh,10px)!important;color:#c3c7cc!important;letter-spacing:.8px;margin-top:6px}
#trade .grid .buy small,.grid .buy small{color:#bff3d6!important}
#trade .grid .sell small,.grid .sell small{color:#f7c9c4!important}
.dock .in button small{font-size:clamp(8px,1.2vh,10px)}

/* v3.5: structure buttons removed - SL / TP PER GRID full width */
#trade .extra{grid-template-columns:1fr}

/* v3.6: live balance in the status bar */
.bal{flex:1;min-width:0;text-align:center;cursor:pointer;padding:0 4px}
.bal b{display:block;font-family:Georgia,serif;color:#f3efe5;font-size:clamp(13px,3.6vw,17px);letter-spacing:.6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.bal small{display:block;margin-top:3px;font-size:clamp(7.5px,2.1vw,9px);letter-spacing:.8px;color:#9a9ea4;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.bal .pos{color:#62d99a}.bal .neg{color:#e46f69}
/* v3.6b: balance never truncates - the left block gives way first */
.status > div:first-child{flex:1 1 auto;min-width:0}
.status > div:first-child b,.status > div:first-child small{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.bal{flex:0 0 auto;max-width:58%}

/* v3.7: three balances, quiet - the selected account is gold */
.bal3{flex:1 1 auto;min-width:0;display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:4px;cursor:pointer}
.bal3 > div{text-align:center;min-width:0;padding:2px 0;border-radius:6px}
.bal3 small{display:block;font-size:clamp(7px,1.9vw,8.5px);letter-spacing:1.2px;color:#8e9298}
.bal3 b{display:block;margin-top:2px;font-family:Georgia,serif;font-weight:500;font-size:clamp(11px,3.1vw,15px);color:#d6d3cb;letter-spacing:.3px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.bal3 .sel small{color:#d7b86a}
.bal3 .sel b{color:#ebd298}
/* the account name block is shown by the gold column now (kept on wide screens) */
.status > div:first-child{display:none}
@media (min-width:620px){ .status > div:first-child{display:block;flex:0 0 auto} }

/* v3.8: status lights next to each balance - green = open positions, yellow = pending orders */
.bal3 .led{display:inline-block;width:6px;height:6px;margin-left:4px;border-radius:50%;vertical-align:1px;background:#2b2e31;box-shadow:inset 0 0 0 1px rgba(255,255,255,.06)}
.bal3 .led.o.on{background:#3ddc84;box-shadow:0 0 6px rgba(61,220,132,.75)}
.bal3 .led.p.on{background:#f2c94c;box-shadow:0 0 6px rgba(242,201,76,.7)}

/* v3.9: two-word tab labels (NEW PENDING / MANAGE GRIDS) wrap instead of being cut off */
.tabs button{white-space:normal;line-height:1.08;text-overflow:clip;padding:0 2px}

/* v3.10: Node / gateway status row */
.sysrow{flex:none;display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:4px;margin:-2px 0 8px;padding:5px 8px;border:1px solid rgba(214,180,106,.12);border-radius:8px;background:rgba(12,13,14,.85);cursor:pointer}
.sysrow span{display:flex;align-items:center;justify-content:center;gap:4px;min-width:0;font-size:clamp(7px,2vw,9px);letter-spacing:.9px;color:#8e9298;white-space:nowrap;overflow:hidden}
.sysrow b{color:#d6d3cb;font-weight:600;letter-spacing:.3px}
.sysrow .led{display:inline-block;flex:none;width:6px;height:6px;border-radius:50%;background:#2b2e31}
.sysrow .led.g{background:#3ddc84;box-shadow:0 0 6px rgba(61,220,132,.7)}
.sysrow .led.y{background:#f2c94c;box-shadow:0 0 6px rgba(242,201,76,.7)}
.sysrow .led.r{background:#ff5c5c;box-shadow:0 0 6px rgba(255,92,92,.7)}

/* v3.11: COMPACT MODE (app height < 560 px, e.g. 3 apps on the Fold) - 8 trade buttons + BREAK EVEN / KILL only */
.cmini{display:none}
html.compact .brand,html.compact .targets,html.compact .status,html.compact .sysrow,html.compact .tabs,
html.compact #trade .seg,html.compact #trade .sethead,html.compact #trade .extra,html.compact #trade .cpl{display:none!important}
html.compact .cmini{display:block;flex:none;margin:0 2px 5px;text-align:center;font-size:9px;letter-spacing:1.4px;color:#d7b86a}
html.compact .main{overflow:hidden}
html.compact .screen{display:none!important}
html.compact #trade{display:flex!important;flex-direction:column;flex:1;min-height:0}
html.compact #trade .sets{flex:1;min-height:0}
html.compact #trade .set{display:none!important}
html.compact #trade .set.show{display:flex!important}
html.compact #trade .sets.both .set[data-set="2"]{display:none!important}
html.compact #trade .set .grid{flex:1;min-height:0;gap:6px;grid-template-rows:repeat(4,minmax(0,1fr))}
html.compact #trade .grid button{padding:3px 4px}
html.compact #trade .grid button strong{font-size:clamp(10px,3.4vh,15px)}
html.compact #trade .grid .trade strong{font-size:clamp(14px,5.5vh,24px)}
html.compact #trade .grid button small{font-size:clamp(6.5px,1.9vh,9px)!important;margin-top:3px}
html.compact .dock{padding-top:4px}
html.compact .feedback{margin-bottom:3px}
html.compact .dock .in button{min-height:clamp(36px,10vh,52px)}
html.compact .dock .in button small{display:none}
