/* Combat web terminal. Own design (no MT5 look: licence CCMLS-01 5.10). */
:root {
  --bg: #0b0e13; --panel: #12161d; --panel2: #181d26; --line: #252c37;
  --text: #e6e9ee; --muted: #8b95a3; --accent: #d4a537; --ink: #1a1405;
  --buy: #2f9e74; --sell: #d9534f; --pos: #3fb97f; --neg: #e5534b;
  --r: 8px; --font: Vazirmatn, Tahoma, "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 13px/1.5 var(--font); }
[hidden] { display: none !important; }
.ltr, .num, input[type=number] { direction: ltr; unicode-bidi: isolate; }
.hint { color: var(--muted); font-size: 12px; }
.spacer { flex: 1; }

.top { display: flex; align-items: center; gap: 14px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; white-space: nowrap; } .brand b { color: var(--accent); }
.acct { display: flex; gap: 18px; flex-wrap: wrap; }
.acct label { display: block; font-size: 11px; color: var(--muted); }
.acct b { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.pill { background: var(--panel2); border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; font-size: 12px; }
.pill.warn { color: var(--accent); border-color: #6b5420; }
.pill.sim { color: var(--accent); border-color: #6b5420; font-weight: 700; cursor: help; }
.sim-note { border-top: 1px solid var(--line); padding-top: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--neg); }
.dot.on { background: var(--pos); }

.btn { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: var(--r); padding: 7px 12px; cursor: pointer; font: inherit; }
.btn:hover { border-color: var(--muted); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.primary { background: var(--accent); color: var(--ink); border-color: var(--accent); font-weight: 700; }
.btn.danger { color: var(--neg); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

input, select { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: var(--r); padding: 6px 8px; font: inherit; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 6px 0 3px; }
.err { color: var(--neg); min-height: 18px; font-size: 12px; margin: 6px 0; }

.login { max-width: 360px; margin: 12vh auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
.login h2 { margin: 0 0 8px; }

.grid { display: grid; height: calc(100vh - 54px); gap: 6px; padding: 6px;
  grid-template-columns: 230px 1fr 290px; grid-template-rows: 1fr 260px;
  grid-template-areas: "watch chart ticket" "bottom bottom ticket"; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.panel-h { padding: 8px 12px; border-bottom: 1px solid var(--line); font-weight: 700; }
.watch { grid-area: watch; overflow: auto; } .chart { grid-area: chart; } .ticket { grid-area: ticket; padding-bottom: 10px; overflow: auto; } .bottom { grid-area: bottom; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 6px 8px; text-align: start; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--panel); }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; }
.wl tr { cursor: pointer; } .wl tr:hover td { background: var(--panel2); } .wl tr.sel td { background: #1f2630; }
.up { color: var(--pos); } .down { color: var(--neg); }
.pos { color: var(--pos); } .neg { color: var(--neg); }

.chart-bar { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tfs { display: flex; gap: 2px; direction: ltr; }
.tfs button { background: none; border: 0; color: var(--muted); padding: 3px 8px; border-radius: 6px; cursor: pointer; font: inherit; }
.tfs button.active { background: var(--panel2); color: var(--text); }
#chart { flex: 1; min-height: 0; position: relative; direction: ltr; }
#chart.dragging { cursor: ns-resize; touch-action: none; }
.qbar, .mnav { display: none; }

.ticket > *:not(.panel-h) { margin-inline: 12px; }
.sides { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px !important; }
.side { border: 2px solid transparent; border-radius: var(--r); padding: 8px; cursor: pointer; color: #fff; font: inherit; display: flex; flex-direction: column; align-items: center; opacity: .55; }
.side b { font-size: 17px; font-variant-numeric: tabular-nums; }
.side.buy { background: var(--buy); } .side.sell { background: var(--sell); }
.side.active { opacity: 1; border-color: #fff3; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.calc { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); padding: 8px; margin-top: 10px !important; font-size: 12px; }
.calc div { display: flex; justify-content: space-between; } .calc b { direction: ltr; unicode-bidi: isolate; }

.tabs { display: flex; align-items: center; gap: 2px; padding: 4px 6px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs > button { background: none; border: 0; color: var(--muted); padding: 6px 12px; border-radius: 6px; cursor: pointer; font: inherit; }
.tabs > button.active { background: var(--panel2); color: var(--text); }
.bulk { display: flex; gap: 4px; }
.tab-body { overflow: auto; flex: 1; }
.tab-body tr.sel td { background: #1f2630; }
.tab-body input { width: 92px; padding: 2px 6px; }
.empty { color: var(--muted); text-align: center; padding: 24px; }
.acts { display: flex; gap: 4px; justify-content: flex-end; }

.toast { position: fixed; bottom: 16px; inset-inline-start: 16px; background: var(--panel2); border: 1px solid var(--line); padding: 10px 14px; border-radius: var(--r); display: none; z-index: 9; max-width: 380px; }
.toast.ok { border-color: var(--pos); } .toast.bad { border-color: var(--neg); }

/* Tablet: one column, everything stacked. */
@media (max-width: 980px) and (min-width: 761px) {
  .grid { height: auto; grid-template-columns: 1fr; grid-template-rows: auto;
    grid-template-areas: "chart" "ticket" "bottom" "watch"; }
  .chart { height: 58vh; } .bottom { min-height: 260px; } .watch { max-height: 320px; }
  .acct { gap: 10px; order: 3; width: 100%; } .acct label { font-size: 10px; }
}

/* Phone: one view at a time (body[data-view]), bottom navigation bar. */
@media (max-width: 760px) {
  body.term { --nav-h: calc(58px + env(safe-area-inset-bottom)); padding-bottom: var(--nav-h); }
  .term .top { gap: 8px; padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top)); }
  .term .top .brand span, .term #login { display: none !important; }
  .term .top .btn.small { padding: 3px 8px; }
  .term .pill.sim { font-size: 11px; padding: 1px 8px; }
  .term .acct { order: 3; width: 100%; gap: 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    margin: 0 -10px; padding: 2px 10px 0; }
  .term .acct > div { flex: 0 0 auto; padding-inline-end: 14px; }
  .term .acct label { font-size: 10px; } .term .acct b { font-size: 13px; }
  .term .grid { display: block; height: auto; padding: 6px; }
  .term .grid > .panel { display: none; }
  /* --top-h: header height, measured by app.js */
  body.term[data-view="chart"] .grid > .chart { display: flex; height: calc(100dvh - var(--top-h, 110px) - var(--nav-h) - 12px); }
  body.term[data-view="trade"] .grid > .ticket { display: flex; }
  body.term[data-view="positions"] .grid > .bottom { display: flex; min-height: calc(100dvh - var(--top-h, 110px) - var(--nav-h) - 12px); }
  body.term[data-view="watch"] .grid > .watch { display: flex; }
  .term .chart-bar { gap: 6px; padding: 6px 8px; }
  .term .chart-bar .hint { display: none; }
  .term .tfs { overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .term .tfs button { padding: 6px 9px; }
  .term .qbar { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 6px; border-top: 1px solid var(--line); }
  .term .qbar .side { opacity: 1; padding: 6px; }
  .term .qbar .side b { font-size: 16px; }
  .term .ticket .hint { display: none; }
  .term .tabs { gap: 0; } .term .bulk { width: 100%; padding: 4px 0; overflow-x: auto; }
  .term .wl td, .term .wl th { padding: 12px 10px; font-size: 15px; }
  .term input, .term select { font-size: 16px; padding: 9px 10px; } /* 16px: no iOS zoom on focus */
  .term .btn.primary.wide { padding: 13px; font-size: 15px; }
  /* Positions and orders as cards instead of wide tables. */
  .term .ptab thead, .term .otab thead, .term .ptab td:nth-child(1), .term .otab td:nth-child(1) { display: none; }
  .term .ptab tr, .term .otab tr { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .term .ptab td, .term .otab td { border: 0; padding: 0; text-align: start; white-space: nowrap; align-self: center; }
  .term .ptab td[data-l]::before { content: attr(data-l) " "; color: var(--muted); font-size: 11px; }
  .term .ptab td:nth-child(2) { grid-area: 1 / 1; } .term .ptab td:nth-child(3) { grid-area: 1 / 2; }
  .term .ptab td:nth-child(4) { grid-area: 1 / 3; } .term .ptab td:nth-child(9) { grid-area: 1 / 4; text-align: end; font-size: 15px; font-weight: 700; }
  .term .ptab td:nth-child(5) { grid-area: 2 / 1 / 3 / 3; } .term .ptab td:nth-child(6) { grid-area: 2 / 3 / 3 / 5; text-align: end; }
  .term .ptab td:nth-child(7) { grid-area: 3 / 1 / 4 / 3; } .term .ptab td:nth-child(8) { grid-area: 3 / 3 / 4 / 5; }
  .term .ptab td:nth-child(10), .term .otab td:nth-child(9) { grid-column: 1 / 5; }
  .term .otab td:nth-child(6) { grid-area: 2 / 1 / 3 / 3; } .term .otab td:nth-child(7) { grid-area: 2 / 3; } .term .otab td:nth-child(8) { grid-area: 2 / 4; }
  .term .tab-body .ptab input, .term .tab-body .otab input { width: 100%; }
  .term .acts { justify-content: stretch; } .term .acts .btn { flex: 1; }
  .term .side { padding: 12px 8px; }
  .term .tab-body .acts .btn { padding: 7px 10px; }
  .term .toast { bottom: calc(var(--nav-h) + 10px); inset-inline: 10px; max-width: none; }
  .term .login { margin: 6vh 12px; }
  .term .ind-pop { position: fixed; top: auto; bottom: calc(var(--nav-h) + 8px); inset-inline: 8px; width: auto; }
  .mnav { position: fixed; bottom: 0; inset-inline: 0; z-index: 8; display: grid; grid-template-columns: repeat(4, 1fr);
    background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .mnav[hidden] { display: none !important; }
  .mnav button { background: none; border: 0; color: var(--muted); font: inherit; font-size: 11px; height: 58px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative; cursor: pointer; }
  .mnav button .ic { font-size: 19px; line-height: 1; }
  .mnav button.active { color: var(--accent); }
  .mnav .badge { position: absolute; top: 6px; inset-inline-start: 56%; background: var(--accent); color: var(--ink);
    border-radius: 99px; font-size: 10px; padding: 0 5px; min-width: 16px; }
  .mnav .badge:empty { display: none; }
}
.ticket .btn.wide { width: auto; display: block; }

.ind-wrap { position: relative; }
.ind-pop { position: absolute; top: 30px; inset-inline-end: 0; z-index: 5; background: var(--panel2); border: 1px solid var(--line); border-radius: var(--r); padding: 10px; width: 270px; box-shadow: 0 8px 24px #0008; }
.ind-row { display: flex; justify-content: space-between; gap: 6px; align-items: center; padding: 4px 0; }
.ind-params { display: flex; gap: 4px; direction: ltr; }
.ind-row label { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--text); font-size: 13px; }
.ind-row input[type=checkbox] { width: auto; accent-color: var(--accent); }
.ind-row input[type=number] { width: 52px; padding: 2px 4px; }
.ind-swatch { display: inline-block; width: 10px; height: 3px; border-radius: 2px; }
