:root {
  color-scheme: light;
  --bar-height: 56px;
  --bg: #f6f7f9;
  --card: #ffffff;
  --field: #ffffff;
  --fg: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --err-bg: #fef2f2;
  --err-fg: #b91c1c;
  --warn-bg: #fffbeb;
  --warn-fg: #92400e;
  --pos: #15803d;
  --neg: #b91c1c;
  /* Telegram's own chat colours */
  --chat-bg: #dfe7ee;
  --bubble: #ffffff;
  --bubble-out: #e3fcd6;
  --chat-link: #168acd;
  --code-bg: rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0b0f14;
    --card: #111821;
    --field: #0b0f14;
    --fg: #e6edf3;
    --muted: #8b98a5;
    --line: #223041;
    --accent: #3b82f6;
    --accent-fg: #ffffff;
    --err-bg: #2c1215;
    --err-fg: #fca5a5;
    --warn-bg: #2b2111;
    --warn-fg: #fcd34d;
    --pos: #4ade80;
    --neg: #f87171;
    --chat-bg: #0e1621;
    --bubble: #182533;
    --bubble-out: #2b5278;
    --chat-link: #6ab3f3;
    --code-bg: rgba(255, 255, 255, 0.08);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: -0.01em; }
h2 { margin: 0 0 12px; font-size: 18px; }
p { margin: 0 0 8px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
}
.narrow { max-width: 400px; }

form { display: grid; gap: 14px; margin: 16px 0 0; }
label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }

input {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--fg);
  min-width: 0;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button, .button {
  font: inherit;
  font-weight: 600;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-block;
}
button.secondary { background: transparent; color: var(--fg); border-color: var(--line); padding: 6px 12px; font-size: 14px; }
button:focus-visible, .button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 16px; }
.actions form { margin: 0; display: block; }
.fields { max-width: 420px; }
.steps { margin: 8px 0 0; padding-left: 22px; }
.steps li { margin-bottom: 4px; }
details { margin-top: 16px; }
summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.qr { background: #ffffff; padding: 10px; border-radius: 10px; width: fit-content; margin: 16px auto 8px; }
.qr svg { display: block; width: 220px; height: 220px; }

.code {
  margin: 12px 0;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  font: 600 28px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.08em;
  text-align: center;
  user-select: all;  /* one click selects the whole code for copying */
}

.search { display: flex; gap: 8px; }
.search input { flex: 1; }
.chats { list-style: none; margin: 16px 0 0; padding: 0; }
.chats li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.chats form { margin: 0; display: block; }
.chat { min-width: 0; overflow-wrap: anywhere; }
.tag {
  flex: none;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 12px;
  font-weight: 600;
}

.notice { margin: 12px 0; padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.notice.error { background: var(--err-bg); color: var(--err-fg); }
.notice.warn { background: var(--warn-bg); color: var(--warn-fg); }
.notice.pos-note { background: rgba(22, 163, 74, 0.12); color: var(--pos); }

h3 { margin: 20px 0 8px; font-size: 15px; }
.row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 12px; margin-top: 12px; }
.stats div { padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.stats .label { display: block; color: var(--muted); font-size: 13px; }
.stats strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 12px 8px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-size: 12px; font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }

/* Signed-in pages */
.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--bar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.bar form { margin: 0; display: block; }
.brand { color: var(--fg); font-weight: 700; text-decoration: none; }
/* The tabs: a white panel down the left edge on wider screens, a row under the header on phones. */
.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  overflow-x: auto;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.tabs a {
  flex: none;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}
.tabs a:hover { color: var(--fg); background: var(--bg); }
.tabs a[aria-current="page"] { color: var(--fg); background: var(--bg); }
.tabs a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* minmax(0, 1fr): wide tables scroll inside their card instead of widening the page. */
.page { max-width: 900px; padding: 16px 16px 24px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }

.page.wide { max-width: none; }

@media (min-width: 760px) {
  .tabs {
    position: fixed;
    top: var(--bar-height);
    bottom: 0;
    left: 0;
    width: 200px;
    flex-direction: column;
    padding: 16px 12px;
    border-bottom: 0;
    border-right: 1px solid var(--line);
  }
  .page { margin-left: 200px; padding: 24px; }
}

/* Chat analysis: the chat on the left, the trade chart on the right; on
   narrower screens the chart sits above the chat. */
.analysis { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.chat-column { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; min-width: 0; }
.chart-panel {
  order: -1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 560px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
}
@media (min-width: 1100px) {
  .analysis { grid-template-columns: minmax(0, 1fr) minmax(420px, 1fr); }
  .chart-panel { order: 0; position: sticky; top: calc(var(--bar-height) + 24px); height: calc(100vh - var(--bar-height) - 48px); }
}
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.panel-head h2 { margin: 0; font-size: 16px; }
.timeframes { display: flex; gap: 4px; }
.timeframes button { padding: 4px 8px; font-size: 13px; }
.timeframes button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.trade { max-height: 40%; overflow-y: auto; font-size: 14px; }
.trade .fact { display: flex; gap: 10px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.trade .fact > .muted:first-child { flex: none; width: 128px; }
.trade p { margin: 4px 0; }
.chart { flex: 1; min-height: 220px; }
.attribution { margin: 0; }

/* Stat analysis: the period, the totals, and the trades, each opening on a
   click to show the same chart panel as Chat analysis. */
.periods { display: flex; flex-wrap: wrap; gap: 4px; margin: 12px 0 0; }
.periods a {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--fg);
  font-size: 14px;
  text-decoration: none;
}
.periods a[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.note { margin-top: 12px; }
.trade-list { font-size: 14px; font-variant-numeric: tabular-nums; }
.trade-line {
  display: grid;
  grid-template-columns: 150px minmax(110px, 1fr) repeat(5, minmax(76px, 104px));
  gap: 8px;
  align-items: baseline;
  padding: 9px 8px;
}
.trade-line.head { padding-top: 0; color: var(--muted); font-size: 12px; font-weight: 600; }
.trade-line .num { text-align: right; }
.trade-row { border-top: 1px solid var(--line); }
.trade-row > summary { cursor: pointer; list-style: none; border-radius: 8px; }
.trade-row > summary::-webkit-details-marker { display: none; }
.trade-row > summary:hover, .trade-row[open] > summary { background: var(--bg); }
.trade-row > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
/* Strategy: the table of every stop and target tried, coloured by result. */
.heat { margin-top: 12px; }
.heat table { font-size: 12px; }
.heat th, .heat td { padding: 4px 6px; text-align: right; }
.heat td.hp1 { background: rgba(22, 163, 74, 0.10); }
.heat td.hp2 { background: rgba(22, 163, 74, 0.22); }
.heat td.hp3 { background: rgba(22, 163, 74, 0.38); }
.heat td.hp4 { background: rgba(22, 163, 74, 0.55); }
.heat td.hn1 { background: rgba(220, 38, 38, 0.10); }
.heat td.hn2 { background: rgba(220, 38, 38, 0.22); }
.heat td.hn3 { background: rgba(220, 38, 38, 0.38); }
.heat td.hn4 { background: rgba(220, 38, 38, 0.55); }
.heat td.pick { outline: 2px solid var(--accent); outline-offset: -2px; font-weight: 700; }

.chart-panel[hidden] { display: none; }
.trade-detail .chart-panel { position: static; order: 0; height: 720px; margin: 8px 0 12px; }
@media (max-width: 759px) {
  /* Phones: date, trade and result; the rest is in the opened trade. */
  .trade-line { grid-template-columns: 1fr 1fr auto; }
  .trade-line > :nth-child(n+3):not(:last-child) { display: none; }
  .trade-detail .chart-panel { height: 640px; padding: 12px; }
}
.signal {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--code-bg);
  color: var(--fg) !important;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}
.signal.pos { background: rgba(22, 163, 74, 0.14); color: var(--pos) !important; }
.signal.neg { background: rgba(220, 38, 38, 0.12); color: var(--neg) !important; }
.msg.focused { box-shadow: 0 0 0 2px var(--accent); }

/* Chat analysis: the followed chat, drawn the way Telegram draws it. */
.chatlog {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 12px;
  background: var(--chat-bg);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.day, .service, .pager {
  align-self: center;
  max-width: 90%;
  margin: 8px 0 2px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}
.service { font-weight: 400; }
.msg {
  align-self: flex-start;
  max-width: min(560px, 88%);
  padding: 6px 10px;
  border-radius: 14px 14px 14px 4px;
  background: var(--bubble);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
  overflow-wrap: anywhere;
  scroll-margin-top: calc(var(--bar-height) + 16px);
}
.msg.out { align-self: flex-end; border-radius: 14px 14px 4px 14px; background: var(--bubble-out); }
.msg.deleted { opacity: 0.6; }
.msg a { color: var(--chat-link); }
.who { margin-bottom: 2px; font-size: 14px; font-weight: 600; }
.who.c0 { color: #e17076; } .who.c1 { color: #eda86c; } .who.c2 { color: #a695e7; } .who.c3 { color: #7bc862; }
.who.c4 { color: #6ec9cb; } .who.c5 { color: #65aadd; } .who.c6 { color: #ee7aae; }
.fwd { margin-bottom: 4px; color: var(--chat-link); font-size: 13px; }
.reply {
  display: block;
  margin: 2px 0 6px;
  padding: 2px 8px;
  border-left: 3px solid var(--chat-link);
  border-radius: 4px;
  background: var(--code-bg);
  color: var(--fg) !important;
  font-size: 13px;
  text-decoration: none;
}
.reply strong { display: block; color: var(--chat-link); }
.reply span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.body { font-size: 15px; line-height: 1.4; white-space: pre-wrap; }
.body code { padding: 0 3px; border-radius: 4px; background: var(--code-bg); font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; }
.body pre { margin: 4px 0; padding: 8px; border-radius: 6px; background: var(--code-bg); font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }
.body blockquote { margin: 4px 0; padding: 0 8px; border-left: 3px solid var(--chat-link); }
.spoiler { border-radius: 3px; background: var(--muted); color: transparent; }
.spoiler:hover { background: none; color: inherit; }
.hashtag, .mention { color: var(--chat-link); }

.media { margin: 0 -6px 6px; overflow: hidden; border-radius: 10px; }
/* Pictures carry their shape (width/height worked out on the server) and a
   picture message has a fixed width (below), so a picture's room is known
   before it loads and nothing on the page moves when it arrives. */
.media img, .media video { display: block; width: 100%; height: auto; background: rgba(0, 0, 0, 0.1); }
.media.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px; }
.media.grid img, .media.grid video { height: 180px; object-fit: cover; }
/* As in Telegram, a message with one picture is as wide as the picture (its
   caption wraps to fit) and an album takes the full width. The picture spans
   the bubble less 8px, hence the +8. */
.msg.album { width: min(560px, 88%); }
.msg.w280 { width: min(288px, 88%); } .msg.w300 { width: min(308px, 88%); } .msg.w320 { width: min(328px, 88%); }
 .msg.w340 { width: min(348px, 88%); } .msg.w360 { width: min(368px, 88%); } .msg.w380 { width: min(388px, 88%); }
 .msg.w400 { width: min(408px, 88%); } .msg.w420 { width: min(428px, 88%); } .msg.w440 { width: min(448px, 88%); }
 .msg.w460 { width: min(468px, 88%); } .msg.w480 { width: min(488px, 88%); } .msg.w500 { width: min(508px, 88%); }
 .msg.w520 { width: min(528px, 88%); } .msg.w540 { width: min(548px, 88%); }
.media img.sticker, .media video.sticker { width: 160px; height: 160px; object-fit: contain; background: none; }
.media video.round { width: 240px; height: 240px; border-radius: 50%; object-fit: cover; }
.sticker-emoji { font-size: 96px; line-height: 1.1; }
.audio { display: grid; gap: 4px; padding: 4px 6px; font-size: 14px; }
.audio audio { width: 100%; }
.file { display: flex; align-items: center; gap: 10px; padding: 4px 6px; color: var(--fg) !important; text-decoration: none; font-size: 14px; }
.file .icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--chat-link); font-size: 18px; }
.placeholder { padding: 10px 12px; background: var(--code-bg); font-size: 13px; }
.preview { margin-top: 6px; padding: 2px 8px; border-left: 3px solid var(--chat-link); font-size: 14px; }
.preview .site { display: block; color: var(--chat-link); }
.preview p { margin: 2px 0 0; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.poll ul { margin: 6px 0 0; padding-left: 20px; }
.poll, .place, .contact, .dice { display: block; margin-bottom: 6px; font-size: 14px; }
.dice { font-size: 32px; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.reactions span { padding: 1px 8px; border-radius: 999px; background: var(--code-bg); font-size: 13px; }
.meta { display: flex; justify-content: flex-end; gap: 8px; margin-top: 2px; color: var(--muted); font-size: 12px; }
.meta .gone { color: var(--neg); font-weight: 600; }

/* Telegram's arrow to the newest message. As the chat's last item with sticky
   positioning it rides the bottom of the screen at the chat's right edge
   while you scroll up, and settles at the end of the chat. */
.to-bottom {
  position: sticky;
  bottom: 20px;
  z-index: 5;
  align-self: flex-end;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-top: -44px;  /* takes no room of its own at the end */
  border-radius: 50%;
  background: var(--card);
  color: var(--muted);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}
.to-bottom:hover { color: var(--fg); }
.to-bottom:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@supports (animation-timeline: scroll()) {
  /* Where the browser can tell how far down the page is, fade the arrow out
     once the newest messages are on screen. */
  .to-bottom {
    animation: to-bottom-away linear both;
    animation-timeline: scroll(root);
    animation-range: calc(100% - 300px) 100%;
  }
  @keyframes to-bottom-away { to { opacity: 0; visibility: hidden; } }
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}
