/* Paper Trader: mobile pehle, laptop par 2 column. Light/dark dono. */
:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #2563eb;
  --pos: #15803d;
  --neg: #c81e1e;
  --pos-bg: #e6f5ea;
  --neg-bg: #fdecec;
  --wait: #a16207;
  --wait-bg: #fdf4dc;
  --info-bg: #e8f0fe;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06);
  --radius: 14px;
  --nav-h: 60px;
  --rail: 88px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f14;
    --surface: #121821;
    --surface-2: #1a222d;
    --text: #e6eaf0;
    --muted: #8b98a9;
    --line: #243040;
    --accent: #3b82f6;
    --pos: #34d399;
    --neg: #f87171;
    --pos-bg: rgba(52, 211, 153, .13);
    --neg-bg: rgba(248, 113, 113, .13);
    --wait: #fbbf24;
    --wait-bg: rgba(251, 191, 36, .13);
    --info-bg: rgba(59, 130, 246, .15);
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
p { margin: 0; }
code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- controls ---------- */
button, input, select, textarea { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--surface-2);
  font-weight: 600; cursor: pointer; text-decoration: none; color: var(--text);
  white-space: nowrap;
}
.btn:hover { filter: brightness(.97); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.danger { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 35%, var(--line)); background: var(--neg-bg); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 38px; padding: 0 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent;
  color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--surface-2); }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border-radius: 11px; border: 1px solid var(--line); background: var(--surface);
  font-size: 16px; /* iOS zoom na kare */
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .seg button:focus-visible, .tabs button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input:disabled { opacity: .5; }
label.f, .f { display: block; }
label.f > span, .f > .lbl { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.help { margin-top: 6px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.check input { width: 22px; height: 22px; min-height: 0; margin: 1px 0 0; flex: none; accent-color: var(--accent); }
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px;
  background: var(--surface-2); border-radius: 11px; padding: 3px;
}
.seg button {
  min-height: 40px; border: 0; border-radius: 9px; background: transparent;
  font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
.seg button:disabled { opacity: .35; cursor: not-allowed; }
.switch { position: relative; display: inline-block; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.badge {
  display: inline-flex; align-items: center; height: 24px; padding: 0 9px;
  border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: .03em; flex: none;
}
.b-long { background: var(--pos-bg); color: var(--pos); }
.b-short { background: var(--neg-bg); color: var(--neg); }
.b-wait { background: var(--wait-bg); color: var(--wait); }
.b-muted { background: var(--surface-2); color: var(--muted); }
.b-info { background: var(--info-bg); color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; cursor: pointer; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card.list { padding: 0; overflow: hidden; }
.empty { padding: 22px 16px; color: var(--muted); text-align: center; font-size: 14px; }
details summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--accent); padding: 4px 0; }
details > * + * { margin-top: 10px; }
.steps { margin: 8px 0 0; padding-left: 20px; }
.steps li + li { margin-top: 6px; }
.lan { margin: 0; padding: 0; list-style: none; }
.lan li + li { margin-top: 6px; }
.warn { color: var(--wait); background: var(--wait-bg); padding: 8px 10px; border-radius: 9px; margin-top: 8px; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 360px; text-align: center; padding: 26px 22px; }
.auth-card > * + * { margin-top: 14px; }
.auth-card label.f { text-align: left; }
.auth-card input { text-align: center; letter-spacing: .4em; font-size: 22px; }
.brand-mark { width: 52px; height: 52px; border-radius: 14px; background: var(--accent); display: grid; place-items: center; margin: 0 auto; }
.brand-mark svg { width: 30px; height: 30px; fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.brand-mark.sm { width: 28px; height: 28px; border-radius: 8px; margin: 0; }
.brand-mark.sm svg { width: 18px; height: 18px; }

/* ---------- app chrome ---------- */
#app { min-height: 100vh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
.top {
  position: sticky; top: 0; z-index: 40;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
}
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 16px; white-space: nowrap; min-width: 0; }
.pills { display: flex; gap: 6px; align-items: center; flex: none; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
  border-radius: 999px; background: var(--surface-2); border: 0; font-size: 12.5px; font-weight: 600; color: var(--text);
  white-space: nowrap;
}
@media (max-width: 420px) {
  .brand-name { display: none; } /* phone par sirf logo, taaki status pills ek line mein aayein */
}
button.pill { cursor: pointer; }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ok i { background: var(--pos); box-shadow: 0 0 0 3px var(--pos-bg); }
.pill.warn i { background: var(--wait); }
.pill.bad i { background: var(--neg); }
.pill.test { background: var(--wait-bg); color: var(--wait); font-weight: 800; letter-spacing: .05em; }
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.totals div { background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 6px 10px; min-width: 0; }
.totals small { display: block; font-size: 11.5px; color: var(--muted); }
.totals b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn-banner { margin-top: 8px; font-size: 13px; color: var(--wait); background: var(--wait-bg); padding: 6px 10px; border-radius: 9px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: none; color: var(--muted); font-size: 11px; font-weight: 600; cursor: pointer; min-width: 0;
}
.tabs svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tabs button[aria-current="page"] { color: var(--accent); }

main { padding: 14px 12px 28px; max-width: 760px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; min-height: 38px; }

/* ---------- watchlist ---------- */
.search-wrap { position: relative; margin-bottom: 12px; }
.search-results {
  margin-top: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .12); max-height: 55vh; overflow: auto;
}
.sr-item {
  display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; cursor: pointer;
}
.sr-item:hover { background: var(--surface-2); }
.sr-item:last-child { border-bottom: 0; }
.sr-note { padding: 12px 14px; font-size: 13.5px; color: var(--muted); }
.wl-item { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.wl-item:last-child { border-bottom: 0; }
.wl-main {
  flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px;
  padding: 12px 6px 12px 14px; border: 0; background: none; text-align: left; cursor: pointer;
}
.wl-main:hover { background: var(--surface-2); }
.wl-sym { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wl-px { font-weight: 700; font-size: 16px; text-align: right; }
.wl-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wl-chg { font-size: 12.5px; text-align: right; white-space: nowrap; }
@keyframes flashUp { from { background: var(--pos-bg); } to { background: transparent; } }
@keyframes flashDown { from { background: var(--neg-bg); } to { background: transparent; } }
.flash-up { animation: flashUp .7s ease-out; border-radius: 5px; }
.flash-down { animation: flashDown .7s ease-out; border-radius: 5px; }

/* ---------- condition cards ---------- */
.cond > * + * { margin-top: 10px; }
.c-sym { font-weight: 800; font-size: 16px; }
.status { font-size: 14px; }
.lv3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.lv3 > div { background: var(--surface-2); border-radius: 10px; padding: 7px 10px; min-width: 0; }
.lv3 small { display: block; font-size: 11.5px; color: var(--muted); }
.lv3 b { display: block; font-size: 15px; }
.lv3 span { display: block; font-size: 11.5px; color: var(--muted); }
.pnl { font-weight: 800; font-size: 17px; }
.legs { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 10px; }
.legs li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 10px; }
.legs li + li { border-top: 1px solid var(--line); }
.legs li.off { color: var(--muted); }
.legs li.off span:last-child { text-align: right; }
.c-params { line-height: 1.6; }
.actions { gap: 8px; }

/* ---------- trades ---------- */
.day-select { width: auto; min-height: 38px; padding: 6px 10px; font-size: 14px; }
.trade-total { margin: 12px 2px; font-size: 14px; }
.tr-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 2px 10px; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.tr-item:last-child { border-bottom: 0; }
.tr-side { grid-row: span 2; }
.tr-main { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tr-sub { font-size: 12.5px; color: var(--muted); }
.tr-pnl { font-weight: 700; text-align: right; grid-row: span 2; }
.ev-item { padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
.ev-item:last-child { border-bottom: 0; }
.ev-item time { display: block; font-size: 12px; color: var(--muted); }

/* ---------- sheet ---------- */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .5);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 94vh; overflow: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 4px 16px calc(16px + env(safe-area-inset-bottom));
}
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 6px auto 8px; }
.sheet-head { margin-bottom: 8px; }
.preview { background: var(--surface-2); border-radius: 12px; padding: 12px; font-size: 14px; }
.preview > * + * { margin-top: 4px; }
.pv-line { font-size: 15px; }
.ac-row { align-items: center; }
.sheet-actions { position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom)); background: var(--surface); padding: 10px 0 2px; }
@media (min-width: 640px) {
  .sheet-wrap { align-items: center; padding: 20px; }
  .sheet { border-radius: 18px; padding-bottom: 16px; }
  .grab { display: none; }
  .sheet-actions { bottom: -16px; }
}

#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px); opacity: 0; transition: opacity .2s, transform .2s;
  background: #111827; color: #fff; padding: 11px 16px; border-radius: 11px;
  z-index: 70; max-width: min(92vw, 480px); font-size: 14px; pointer-events: none; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: #b91c1c; }

/* ---------- laptop: rail + watchlist column + panel ---------- */
@media (min-width: 900px) {
  #app { padding-bottom: 0; }
  .top { padding-left: calc(var(--rail) + 20px); padding-right: 20px; display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
  .top-row { flex: 1; }
  .totals { margin-top: 0; width: 460px; }
  .conn-banner { width: 100%; }
  .tabs {
    top: 0; right: auto; width: var(--rail); height: auto;
    grid-template-columns: none; grid-auto-rows: 74px; align-content: start;
    padding: 76px 0 0; border-top: 0; border-right: 1px solid var(--line);
  }
  .tabs [data-tab="watch"] { display: none; }
  .tabs button { font-size: 11.5px; }
  .tabs button[aria-current="page"] { background: var(--info-bg); }
  main {
    margin-left: var(--rail); max-width: none;
    display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 20px; align-items: start;
    padding: 18px 20px 30px;
  }
  .panel[data-panel="watch"] { display: block; position: sticky; top: 80px; max-height: calc(100vh - 96px); overflow: auto; }
  .panel:not([data-panel="watch"]) { grid-column: 2; grid-row: 1; max-width: 860px; }
  #condList { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; }
  #condList > * + * { margin-top: 0; }
  #toast { bottom: 24px; }
}
