:root {
  --bg: #f4f6f9; --card: #fff; --text: #1c2430; --muted: #6b7684; --line: #e3e7ed;
  --primary: #2457d6; --green: #0f9d58; --red: #d93025; --amber: #b26a00;
  --green-bg: #e6f4ea; --red-bg: #fce8e6; --amber-bg: #fff4e0; --blue-bg: #e8effc;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b; --card: #1a2029; --text: #e6e9ee; --muted: #8b95a3; --line: #2a323d;
    --primary: #6d9cff; --green: #3ddc84; --red: #ff6b5e; --amber: #ffb84d;
    --green-bg: #12301f; --red-bg: #3a1714; --amber-bg: #352711; --blue-bg: #1b2a47;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }
h1 { font-size: 18px; margin: 0; white-space: nowrap; }
h2 { font-size: 15px; margin: 22px 0 8px; }
h3 { font-size: 14px; margin: 16px 0 4px; }
a { color: var(--primary); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.hint { margin: -4px 0 10px; font-size: 13px; }
.error { color: var(--red); min-height: 1.2em; margin: 8px 0 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.pad { padding: 12px; }
.spacer { flex: 1; }

.btn { border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; white-space: nowrap; }
.btn:hover { border-color: var(--primary); }
.btn:disabled { opacity: .6; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { color: var(--red); }
.btn.wide { width: 100%; margin-top: 16px; }

input, select, textarea { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; font-size: 16px; }
label { display: block; margin: 10px 0; font-size: 13px; color: var(--muted); }
label input, label textarea, label select { margin-top: 4px; color: var(--text); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; margin: 0; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; padding: 24px; text-align: center; }
.login-card img { border-radius: 14px; }
.login-card h1 { margin: 8px 0; }
.login-card label { text-align: left; }
.login-card .btn { width: 100%; margin-top: 8px; padding: 11px; }
.link-btn { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; font-size: 14px; padding: 6px; }
.login-msg { color: var(--green); margin: 8px 0 0; }

/* top bar + nav */
.topbar { display: flex; align-items: center; gap: 14px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.nav { display: flex; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px; color: var(--muted); position: relative; }
.nav a.active { background: var(--blue-bg); color: var(--primary); font-weight: 600; }
.nav a:hover { color: var(--primary); }
.ico { font-size: 15px; }
.dot { position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 99px; background: var(--blue-bg); color: var(--primary); white-space: nowrap; }
.pill.live { background: var(--green-bg); color: var(--green); }
.pill.err { background: var(--red-bg); color: var(--red); }
.bottom-nav { display: none; }
/* HQ "View screen" bar; edit controls are hidden while viewing (view only) */
.view-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 16px; background: var(--amber-bg); color: var(--amber); border-bottom: 1px solid var(--line); font-size: 14px; }
.view-bar span { flex: 1; min-width: 200px; }
/* HQ working in a client app: chatting as the client is not allowed */
.acting-client #chatForm { display: none !important; }
.alerts-banner { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; max-width: 1168px; width: calc(100% - 32px); margin: 12px auto 0; padding: 10px 14px; box-sizing: border-box; }
.alerts-banner span { flex: 1; min-width: 200px; }
.disclaimer { font-size: 11px; color: var(--muted); margin: 8px 12px; }
.login-card .disclaimer { margin: 10px 0 0; }

main { max-width: 1200px; margin: 0 auto; padding: 16px; padding-bottom: 40px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat { padding: 14px; display: flex; flex-direction: column; gap: 2px; }
.stat span { color: var(--muted); font-size: 12px; }
.stat b { font-size: 21px; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.split textarea { margin-bottom: 8px; }
.toolbar { display: flex; align-items: center; gap: 10px; margin: 20px 0 10px; flex-wrap: wrap; }
.toolbar h2 { margin: 0; }
.search-in { width: 220px; }
.back { display: inline-block; margin-bottom: 6px; }
.client-head h2 { margin: 4px 0 2px; font-size: 20px; }
.client-head { margin-bottom: 12px; }
.row-link { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--text); }
.row-link:last-child { border-bottom: 0; }
.row-link:hover { background: var(--bg); }
.loss-row { flex-wrap: wrap; }
.loss-row .grow { flex: 1; min-width: 180px; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 500; }
.left { text-align: left; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--bg); }
tr.faded td { opacity: .55; }
td.note { white-space: normal; min-width: 140px; max-width: 240px; text-align: left; color: var(--muted); }
td.holders { white-space: normal; min-width: 180px; }
small.sub { display: block; font-size: 12px; }
.stk { display: inline-flex; align-items: baseline; gap: 4px; flex-wrap: wrap; }
.stk b { font-size: 15px; }
.stk small { color: var(--muted); font-size: 11px; }
.up { color: var(--green); }
.down { color: var(--red); }
.actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty { padding: 22px; text-align: center; margin: 0; }
.flash-up { animation: fu 1s; } .flash-down { animation: fd 1s; }
@keyframes fu { from { background: var(--green-bg); } }
@keyframes fd { from { background: var(--red-bg); } }
.copy { border: 1px solid var(--line); background: none; color: var(--muted); font: inherit; font-size: 12px; line-height: 1; padding: 3px 6px; border-radius: 6px; cursor: pointer; }
.copy:hover { color: var(--primary); border-color: var(--primary); }
.copy.done { color: var(--green); border-color: var(--green); }
.closed-wrap summary { cursor: pointer; list-style: none; }
.closed-wrap summary h2 { display: inline-block; }
.closed-wrap summary::before { content: '▸ '; color: var(--muted); }
.closed-wrap[open] summary::before { content: '▾ '; }

/* badges */
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.badge.TARGET_HIT { background: var(--green-bg); color: var(--green); }
.badge.SL_HIT { background: var(--red-bg); color: var(--red); }
.badge.BUY_ZONE { background: var(--amber-bg); color: var(--amber); }
.badge.CANCELLED { background: var(--line); color: var(--muted); }
.badge.msg { background: var(--primary); color: #fff; }
.badge.HOLD, .badge.adv.HOLD { background: var(--blue-bg); color: var(--primary); }
.badge.adv.SELL_NOW, .badge.adv.EXIT_SL { background: var(--red); color: #fff; }
.badge.adv.SELL_AT { background: var(--red-bg); color: var(--red); }
.badge.adv.BUY_MORE { background: var(--green-bg); color: var(--green); }

/* advice */
.advice-panel { margin-top: 16px; padding: 4px 0; border-color: var(--amber); }
.advice-panel h2 { margin: 10px 14px 4px; font-size: 13px; color: var(--amber); }
.advice-panel ul { list-style: none; margin: 0; padding: 0; }
.advice-panel li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 9px 14px; border-top: 1px solid var(--line); }
.advice-panel li.hot { background: var(--amber-bg); }
.advice-panel .grow { flex: 1; min-width: 160px; }

/* activity + chat */
.activity { list-style: none; margin: 0; padding: 0; max-height: 380px; overflow-y: auto; }
.activity li { padding: 9px 14px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; }
.activity li:last-child { border-bottom: 0; }
.activity time { color: var(--muted); font-size: 12px; white-space: nowrap; min-width: 92px; }
.activity .by { color: var(--primary); font-weight: 600; }
.activity .sys .by { color: var(--amber); }
.chat ul { list-style: none; margin: 0; padding: 12px; height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.chat li { display: flex; }
.chat li.mine { justify-content: flex-end; }
.bubble { max-width: 85%; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; overflow-wrap: anywhere; white-space: pre-wrap; }
.mine .bubble { background: var(--blue-bg); border-color: transparent; }
.empty-chat { margin: auto; }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; min-width: 0; }
/* share / advice card inside chat */
.bubble.card-msg { white-space: normal; min-width: 240px; }
.stock-card { display: flex; flex-direction: column; gap: 6px; padding: 4px 0 2px; }
.stock-card .sc-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 15px; }
.stock-card .sc-line { font-weight: 600; }
.stock-card .sc-act { display: flex; gap: 6px; flex-wrap: wrap; }

/* modal */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: min(460px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.search { position: relative; }
.results { position: absolute; left: 0; right: 0; top: 100%; z-index: 10; background: var(--card); border: 1px solid var(--line); border-radius: 8px; max-height: 240px; overflow-y: auto; margin-top: -6px; box-shadow: 0 6px 20px rgba(0,0,0,.15); }
.results div { padding: 9px 10px; cursor: pointer; }
.results div:hover, .results div.sel { background: var(--blue-bg); }
.results small { color: var(--muted); }
.picked { margin: 0; font-size: 13px; color: var(--green); }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 10px 0; }
.choices label { margin: 0; display: flex; align-items: center; gap: 8px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); cursor: pointer; }
.choices input { width: auto; margin: 0; }
.choices label:has(input:checked) { border-color: var(--primary); background: var(--blue-bg); }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 100; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: calc(100vw - 32px); }

/* ---------- phone ---------- */
/* Chats (staff): client list + chat */
.chats { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; }
.chat-side { display: flex; flex-direction: column; gap: 10px; }
.chat-side #bcForm { display: flex; flex-direction: column; gap: 6px; }
.chat-side #bcForm textarea { margin: 0; }
.chat-side .search-in { width: 100%; box-sizing: border-box; order: 0 !important; }
.chat-people { max-height: 60vh; overflow-y: auto; padding: 4px; }
.person { display: flex; gap: 8px; align-items: center; padding: 9px 10px; border-radius: 8px; color: var(--text); }
.person:hover { background: var(--blue-bg); }
.person.sel { background: var(--blue-bg); }
.person .grow { flex: 1; min-width: 0; }
.person .sub { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person .meta { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.chat-main .toolbar { margin-top: 0; }

@media (max-width: 760px) {
  .chats { grid-template-columns: 1fr; }
  .chats.has-sel .chat-side { display: none; }
  .chats:not(.has-sel) .chat-main { display: none; }
  .topbar { padding-left: 12px; padding-right: 12px; gap: 8px; }
  .topbar h1 { font-size: 16px; }
  .nav { display: none; }
  #userBtn { max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 7px 0 6px; color: var(--muted); font-size: 11px; position: relative; }
  .bottom-nav a .ico { font-size: 19px; }
  .bottom-nav a.active { color: var(--primary); font-weight: 600; }
  .bottom-nav .dot { top: 4px; right: calc(50% - 16px); }
  main { padding: 12px; padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat b { font-size: 17px; }
  .split { grid-template-columns: 1fr; }
  .row3 { grid-template-columns: 1fr 1fr; }
  .search-in { width: 100%; order: 5; }
  .chat ul { height: 50vh; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }

  /* tables become cards */
  table.rt thead { display: none; }
  table.rt, table.rt tbody, table.rt tr, table.rt td { display: block; }
  table.rt tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  table.rt tr:last-child { border-bottom: 0; }
  table.rt td { border: 0; padding: 0; text-align: left; white-space: normal; min-width: 0; max-width: none; }
  table.rt td::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); }
  table.rt td[data-label=""]::before, table.rt td:first-child::before { display: none; }
  table.rt td:first-child, table.rt td.note, table.rt td.holders, table.rt td:last-child { grid-column: 1 / -1; }
  table.rt td:empty, table.rt td.note:empty { display: none; }
  table.rt td:first-child .stk b { font-size: 16px; }
  .actions { justify-content: flex-start; flex-wrap: wrap; }
  .actions .btn.small { padding: 7px 12px; }
}
