/* PiptrexHub web UI. Light and dark follow the computer's setting. No external fonts or scripts. */
:root {
    --bg: #f3f5f9; --panel: #ffffff; --panel-2: #f8fafc; --text: #0f172a; --muted: #64748b; --line: #e3e8ef; --line-strong: #cbd5e1;
    --accent: #2563eb; --accent-text: #ffffff; --accent-soft: #e8efff;
    --ok: #15803d; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7; --danger: #dc2626; --danger-soft: #fee2e2;
    --side: #0b1324; --side-2: #131d33; --side-text: #9aa8bf; --side-strong: #ffffff; --side-line: #1d2942;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
    --radius: 10px;
    color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0a0f1c; --panel: #111827; --panel-2: #0f1626; --text: #e5e9f0; --muted: #8b98ad; --line: #1e293b; --line-strong: #334155;
        --accent: #3b82f6; --accent-soft: #172554;
        --ok: #4ade80; --ok-soft: #052e16; --warn: #fbbf24; --warn-soft: #3b2405; --danger: #f87171; --danger-soft: #3f0d0d;
        --side: #060a14; --side-2: #0f172a; --side-line: #172036;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.5 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
code { font-family: Consolas, ui-monospace, monospace; font-size: 12.5px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; }
.icon { flex: none; display: block; }

/* ---------- Shell: sidebar + content ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 236px; flex: none; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 16px; color: var(--side-strong); text-decoration: none; font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.brand .mark { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, #3b82f6, #22c55e); display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 15px; box-shadow: 0 4px 12px rgba(59, 130, 246, .35); }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--side-text); letter-spacing: .3px; }
.side-nav { flex: 1; overflow-y: auto; padding: 4px 10px 12px; }
.side-nav .group { margin: 16px 10px 6px; font-size: 10.5px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: #5d6b84; }
.side-nav a { display: flex; align-items: center; gap: 11px; padding: 8px 10px; margin: 1px 0; border-radius: 8px; color: var(--side-text); text-decoration: none; font-weight: 500; }
.side-nav a:hover { background: var(--side-2); color: var(--side-strong); }
.side-nav a.active { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(37, 99, 235, .35); }
.side-foot { border-top: 1px solid var(--side-line); padding: 12px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--side-2); color: var(--side-strong); display: grid; place-items: center; font-weight: 700; text-transform: uppercase; flex: none; }
.side-foot .who { flex: 1; min-width: 0; line-height: 1.25; }
.side-foot .who b { display: block; color: var(--side-strong); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .who span { font-size: 12px; }
.side-foot form { margin: 0; }
.side-foot button { background: transparent; border: 1px solid var(--side-line); color: var(--side-text); padding: 6px; border-radius: 8px; display: grid; place-items: center; }
.side-foot button:hover:not(:disabled) { color: #fff; border-color: #475569; background: var(--side-2); }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--panel) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar .bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 28px; min-height: 56px; }
.topbar .spacer { flex: 1; }
main { padding: 24px 28px 40px; width: 100%; max-width: 1480px; }

/* ---------- Status chips, kill switch, banner ---------- */
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.chip.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; } .chip.ok .dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.chip.danger { color: var(--danger); background: var(--danger-soft); border-color: transparent; } .chip.danger .dot { background: var(--danger); }
.chip.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; } .chip.warn .dot { background: var(--warn); }
.kill-toggle { display: inline-flex; align-items: center; gap: 10px; padding: 5px 6px 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 600; font-size: 13px; user-select: none; }
.kill-toggle:hover { border-color: var(--line-strong); }
.kill-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.kill-toggle .track { width: 38px; height: 22px; border-radius: 999px; background: var(--line-strong); position: relative; transition: background .15s; }
.kill-toggle .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform .15s; }
.kill-toggle.on { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.kill-toggle.on .track { background: var(--danger); }
.kill-toggle.on .track::after { transform: translateX(16px); }
.kill-toggle input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.banner { display: flex; align-items: center; gap: 10px; padding: 9px 28px; background: var(--danger); color: #fff; font-weight: 600; }
.topbar .error { color: var(--danger); font-weight: 500; }

/* ---------- Page headings ---------- */
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 22px; font-weight: 700; letter-spacing: -.2px; margin: 0 0 18px; }
h2 small { font-size: 13px; font-weight: 500; }
h3 { font-size: 15px; font-weight: 650; margin: 26px 0 10px; }
h4 { grid-column: 1 / -1; margin: 12px 0 0; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head h2 { margin: 0; }
.page-head p { margin: 2px 0 0; color: var(--muted); }

/* ---------- Cards and stat tiles ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h3 { margin: 0; }
.card-head .muted { font-size: 12.5px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .empty { padding: 28px 18px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; display: flex; gap: 14px; align-items: flex-start; }
.stat .ico { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.stat .ico.ok { background: var(--ok-soft); color: var(--ok); } .stat .ico.danger { background: var(--danger-soft); color: var(--danger); } .stat .ico.warn { background: var(--warn-soft); color: var(--warn); }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat .value { font-size: 22px; font-weight: 700; letter-spacing: -.3px; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 2px; }
.stat .value small { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 18px; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }

/* ---------- Tables ---------- */
table { border-collapse: separate; border-spacing: 0; width: 100%; background: var(--panel); }
.card > table, .card > .scroll > table { margin: 0; }
th, td { border-bottom: 1px solid var(--line); padding: 10px 14px; text-align: left; vertical-align: middle; }
th { font-size: 11.5px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; white-space: nowrap; background: var(--panel-2); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--accent) 5%, var(--panel)); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.mono td { font-family: Consolas, ui-monospace, monospace; font-size: 13px; }
table.small td { font-size: 12px; padding: 6px 12px; }
table.small th { padding: 7px 12px; }
/* A table on its own gets the card look; inside a card it does not, or the borders double. */
main table:not(.edit) { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 12px; }
main .card table:not(.edit) { border: 0; border-radius: 0; box-shadow: none; margin: 0; }
table.edit { width: auto; min-width: 100%; border: 1px solid var(--line); border-radius: var(--radius); }
table.edit td { padding: 6px 8px; }
table.edit th { padding: 9px 8px; }
table.edit input:not([type=checkbox]), table.edit select { width: 100%; min-width: 110px; }
table.edit input.w { min-width: 210px; }
tr.details td { background: var(--panel-2); }
tr.stale td { color: var(--muted); }
.strong { font-weight: 600; }
.sym { font-weight: 650; letter-spacing: .2px; }
.scroll { overflow-x: auto; }
.nowrap { white-space: nowrap; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok, .badge.buy { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.danger, .badge.sell { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- Text colours ---------- */
.muted { color: var(--muted); } .ok { color: var(--ok); } .warn { color: var(--warn); } .danger, .error { color: var(--danger); }
tr.danger td { color: var(--danger); } tr.warn td { color: var(--warn); }
.notice { padding: 10px 14px; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); border-radius: 8px; color: var(--text); }

/* ---------- Forms and buttons ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line-strong); border-radius: 7px; padding: 7px 10px; outline: none; transition: border-color .12s, box-shadow .12s; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); padding: 0; }
fieldset:disabled input, fieldset:disabled select { background: var(--panel-2); color: var(--muted); }
button, a.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 7px; padding: 7px 14px; cursor: pointer; color: var(--text); text-decoration: none; font-weight: 550; transition: border-color .12s, background .12s; }
button:hover:not(:disabled), a.button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.danger:hover:not(:disabled) { border-color: var(--danger); background: var(--danger-soft); }
button.small { padding: 4px 10px; font-size: 12.5px; }
form.inline { display: inline; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; color: var(--muted); padding: 10px 14px; margin-bottom: -1px; }
.tabs button:hover:not(:disabled) { color: var(--text); border-color: transparent; border-bottom-color: var(--line-strong); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); background: transparent; }
.form { display: grid; gap: 14px; max-width: 680px; }
.card > fieldset > .form:not(.wide) { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); max-width: 1100px; column-gap: 24px; }
.card > fieldset > .form label.check { grid-column: 1 / -1; }
.form.wide { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); max-width: none; }
.form label { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; }
.form label input, .form label select { font-weight: 400; font-size: 14px; }
.form label.check, label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 18px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 14px; }
.toolbar input[type=search], .toolbar input:not([type]) { min-width: 260px; }

/* ---------- Sign-in and setup ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent), radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, #22c55e 14%, transparent), transparent), var(--bg); }
.center-box { width: 100%; max-width: 400px; padding: 32px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 40px rgba(15, 23, 42, .12); }
.center-box .brand { padding: 0 0 6px; color: var(--text); font-size: 20px; }
.center-box .lead { color: var(--muted); margin: 0 0 22px; }
.box { display: grid; gap: 14px; }
.box label { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; }
.box label.check { flex-direction: row; font-weight: 500; }
.box button[type=submit] { background: var(--accent); border-color: var(--accent); color: #fff; padding: 10px; margin-top: 4px; }

/* ---------- Small screens: the sidebar becomes a bar on top ---------- */
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
    .app { flex-direction: column; }
    .sidebar { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
    .brand { padding: 10px 16px; }
    .brand small { display: none; }
    .side-nav { order: 3; flex-basis: 100%; display: flex; gap: 4px; overflow-x: auto; padding: 0 12px 10px; }
    .side-nav .group { display: none; }
    .side-nav a { flex: none; padding: 7px 10px; }
    .side-foot { margin-left: auto; border: 0; padding: 8px 16px; }
    .side-foot .who { display: none; }
    .topbar { position: static; }
    .topbar .bar, .banner { padding-left: 16px; padding-right: 16px; }
    main { padding: 16px; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .stat { padding: 12px; gap: 10px; flex-direction: column; }
    .stat .value { font-size: 19px; }
    th, td { padding: 8px 10px; }
    /* Wide tables scroll inside themselves; the page never scrolls sideways. */
    table { display: block; overflow-x: auto; white-space: nowrap; }
    .toolbar input:not([type]) { min-width: 0; width: 100%; }
}
td.mono { font-family: Consolas, ui-monospace, monospace; font-size: 13px; }

/* ---------- Settings: one card per account ---------- */
/* No overflow clipping: the company search's pop-up list may reach past the card. */
.acct { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; background: var(--panel); }
.acct-head { display: flex; align-items: center; gap: 10px; padding: 12px 18px; background: var(--panel-2); border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; }
.acct > .acct-head:last-child { border-bottom: 0; border-radius: var(--radius); }
.acct-head { flex-wrap: wrap; }
.acct-head b { font-size: 15px; min-width: 0; overflow-wrap: anywhere; }
.acct-head .spacer { flex: 1; }
.acct-section { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.acct-section:last-child { border-bottom: 0; }
.acct-section h4 { margin: 0 0 12px; }
.fields { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px 18px; align-items: start; }
.fields label { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; min-width: 0; }
.fields label input, .fields label select { width: 100%; font-weight: 400; font-size: 14px; }
.fields label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; align-self: end; padding-bottom: 8px; }
.fields label.check input { width: 16px; }
.fields .span-2 { grid-column: span 2; }
.hint { font-weight: 400; font-size: 12px; color: var(--muted); line-height: 1.4; }
.hint code { font-size: 11.5px; }
button.link { border: 0; background: none; padding: 8px 0 0; color: var(--accent); font-weight: 550; }
button.link:hover:not(:disabled) { text-decoration: underline; }
@media (max-width: 1100px) { .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 600px) { .fields { grid-template-columns: 1fr; } .fields .span-2 { grid-column: auto; } }

/* ---------- Company search: a modal window like MetaTrader's "Open an Account" ---------- */
.with-button { display: flex; gap: 6px; }
.with-button input { flex: 1; min-width: 0; }
.modal-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); }
.modal { position: fixed; z-index: 41; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
         display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 24px 64px rgba(15, 23, 42, .35); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0 0 2px; font-size: 17px; }
.modal-head .muted { font-size: 13px; }
.modal-x { border: 0; background: transparent; font-size: 24px; line-height: 1; padding: 2px 8px; color: var(--muted); }
.modal-x:hover:not(:disabled) { color: var(--text); background: var(--panel-2); }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal.confirm { width: min(460px, calc(100vw - 32px)); }
.modal.confirm .modal-body p { margin: 0 0 8px; }
.modal.confirm .modal-body p:last-child { margin-bottom: 0; }
.modal-body .toolbar input { flex: 1; min-width: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--panel-2); border-radius: 0 0 12px 12px; }
/* The list, as in MetaTrader: plain rows, alternate rows shaded, the row under the pointer light blue. */
.pick-box { border: 1px solid var(--line-strong); border-radius: 6px; height: 340px; overflow-y: auto; margin: 4px 0 10px; background: var(--panel); }
.pick-box .empty { padding: 40px 20px; }
.pick-row { display: flex; width: 100%; align-items: center; gap: 10px; border: 0; border-radius: 0; background: transparent;
            padding: 12px 14px; font-weight: 400; font-size: 14.5px; text-align: left; justify-content: flex-start; color: var(--text); }
.pick-row:nth-child(even) { background: var(--panel-2); }
.pick-row:hover:not(:disabled), .pick-row:focus-visible { background: color-mix(in srgb, var(--accent) 14%, var(--panel)); border: 0; outline: none; }
.pick-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-short { color: var(--muted); font-size: 12.5px; }
@media (max-width: 600px) { .pick-box { height: 50vh; } .modal-body .toolbar { flex-direction: column; align-items: stretch; } }

/* Settings: Save stays in view at the bottom of the window however long the page is. */
.save-bar { position: sticky; bottom: 0; z-index: 15; margin: 18px -18px -18px; padding: 12px 18px; background: color-mix(in srgb, var(--panel) 94%, transparent);
            backdrop-filter: blur(6px); border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); box-shadow: 0 -6px 16px rgba(15, 23, 42, .06); }

/* ---------- Bridge page ---------- */
.ticks { display: flex; flex-wrap: wrap; gap: 6px 22px; }
label.inline { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 500; }
label.inline select { width: auto; }
.actions .spacer { flex: 1; }
.acct-head .muted { font-size: 13px; }
label.check.off { color: var(--muted); text-decoration: line-through; }

/* Market Data: candle chart */
svg.candles { width: 100%; height: auto; margin-top: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; }
svg.candles .grid { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
svg.candles .axis { fill: var(--muted); font-size: 11px; }
svg.candles line.up { stroke: var(--ok); stroke-width: 1; vector-effect: non-scaling-stroke; }
svg.candles line.down { stroke: var(--danger); stroke-width: 1; vector-effect: non-scaling-stroke; }
svg.candles rect.up { fill: var(--ok); }
svg.candles rect.down { fill: var(--danger); }
