/* The panel's design system: docs/panel-design.md. Colours come from Telegram's theme (--tg-theme-*), the
   fallbacks (--fb-*) serve a browser outside Telegram, light or dark by the system. */

:root {
  --fb-page: #efeff4; --fb-section: #ffffff; --fb-text: #000000; --fb-hint: #8e8e93; --fb-sep: #c8c7cc;
  --fb-accent: #2481cc; --fb-button: #2481cc; --fb-button-text: #ffffff; --fb-danger: #e53935;
  --c-live: #34c759; --c-paused: #ff9500; --c-off: #8e8e93; --c-profit: #248a3d;
  --c-live-ink: #248a3d; --c-paused-ink: #b25000;  /* the state colours as text: readable on white */
  --t-live: rgba(52, 199, 89, 0.15); --t-paused: rgba(255, 149, 0, 0.16); --t-off: rgba(142, 142, 147, 0.16);
  --t-danger: rgba(229, 57, 53, 0.13); --t-accent: rgba(36, 129, 204, 0.13);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --fb-page: #000000; --fb-section: #1c1c1d; --fb-text: #ffffff; --fb-hint: #8e8e93; --fb-sep: #38383a;
    --fb-accent: #3e88f7; --fb-button: #3e88f7; --fb-danger: #ff453a; --c-profit: #30d158;
    --c-live-ink: #30d158; --c-paused-ink: #ff9f0a;
    color-scheme: dark;
  }
}
:root[data-scheme="dark"] { --c-profit: #30d158; --c-live-ink: #30d158; --c-paused-ink: #ff9f0a;
  --t-accent: rgba(100, 160, 240, 0.18); color-scheme: dark; }

:root {
  --c-page: var(--tg-theme-secondary-bg-color, var(--fb-page));
  --c-section: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-section)));
  --c-text: var(--tg-theme-text-color, var(--fb-text));
  --c-hint: var(--tg-theme-hint-color, var(--fb-hint));
  --c-subtitle: var(--tg-theme-subtitle-text-color, var(--c-hint));
  --c-section-head: var(--tg-theme-section-header-text-color, var(--c-hint));
  --c-sep: var(--tg-theme-section-separator-color, var(--fb-sep));
  --c-accent: var(--tg-theme-accent-text-color, var(--tg-theme-link-color, var(--fb-accent)));
  --c-button: var(--tg-theme-button-color, var(--fb-button));
  --c-button-text: var(--tg-theme-button-text-color, var(--fb-button-text));
  --c-danger: var(--tg-theme-destructive-text-color, var(--fb-danger));
  --c-bar: var(--tg-theme-bottom-bar-bg-color, var(--c-section));

  --fs-display: 28px; --lh-display: 34px; --fs-title: 20px; --lh-title: 25px; --fs-body: 16px; --lh-body: 21px;
  --fs-sub: 14px; --lh-sub: 19px; --fs-caption: 13px; --lh-caption: 17px; --fs-micro: 11px; --lh-micro: 13px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px;
  --r-section: 12px; --r-tile: 14px; --r-sheet: 16px; --r-chip: 999px;
  --tab-h: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--c-page); color: var(--c-text); }
body {
  font: var(--fs-body)/var(--lh-body) -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + var(--s4));
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }
.profit { color: var(--c-profit); } .loss { color: var(--c-danger); } .hint { color: var(--c-hint); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round;
  stroke-linejoin: round; flex: none; }

main { max-width: 640px; margin: 0 auto; padding: var(--s3) var(--s4) 0; }

/* page title row */
.pagehead { display: flex; align-items: center; gap: var(--s2); margin: var(--s2) 0 var(--s3); }
.pagehead h1 { flex: 1; margin: 0; font-size: var(--fs-title); line-height: var(--lh-title); font-weight: 600; }
.iconbtn { width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; color: var(--c-accent); }
.iconbtn:active { background: var(--t-accent); }
.iconbtn.back { margin-left: -10px; }
.iconbtn.back svg.i { transform: scaleX(-1); }

/* hero: the state of trading */
.hero { background: var(--c-section); border-radius: var(--r-section); padding: var(--s4); margin-bottom: var(--s3); }
.hero .top { display: flex; align-items: center; gap: var(--s3); }
.hero .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c-off); flex: none;
  box-shadow: 0 0 0 4px var(--t-off); }
.hero.live .dot { background: var(--c-live); box-shadow: 0 0 0 4px var(--t-live); }
.hero.paused .dot { background: var(--c-paused); box-shadow: 0 0 0 4px var(--t-paused); }
.hero.offline .dot { background: var(--c-danger); box-shadow: 0 0 0 4px var(--t-danger); }
.hero .title { flex: 1; font-size: var(--fs-title); line-height: var(--lh-title); font-weight: 600; }
.hero .sub { margin-top: var(--s2); font-size: var(--fs-sub); line-height: var(--lh-sub); color: var(--c-subtitle); }
.hero .chips { display: flex; flex-wrap: wrap; gap: var(--s1); margin-top: var(--s3); }
.hero .chips.first { margin-top: 0; }
.hero .action { margin-top: var(--s3); }
.textbtn { color: var(--c-accent); font-size: var(--fs-sub); font-weight: 500; padding: var(--s2) var(--s1); }
.textbtn.danger { color: var(--c-danger); }

/* metric tiles */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); margin-bottom: var(--s3); }
.tile { background: var(--c-section); border-radius: var(--r-tile); padding: var(--s3) var(--s3) var(--s3) var(--s4); min-height: 84px; }
.tile .label { font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--c-hint); }
.tile .value { font-size: 22px; line-height: 28px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .value small { font-size: var(--fs-sub); font-weight: 500; color: var(--c-hint); }
.tile .note { font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--c-hint); margin-top: 2px; }
.tile .note.warn { color: var(--c-paused-ink); }
.bar { height: 4px; border-radius: 2px; background: var(--t-off); margin-top: var(--s2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--c-accent); border-radius: 2px; }

/* grouped sections */
.section { margin-bottom: var(--s5); }
.section > h2 { margin: 0 var(--s4) 6px; font-size: var(--fs-caption); line-height: var(--lh-caption); font-weight: 400;
  text-transform: uppercase; letter-spacing: 0.02em; color: var(--c-section-head); }
.section > .box { background: var(--c-section); border-radius: var(--r-section); overflow: hidden; }
.section > .foot { margin: 6px var(--s4) 0; font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--c-hint); }

.row { display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 44px; padding: 11px var(--s4);
  text-align: left; position: relative; }
.row + .row::before { content: ""; position: absolute; top: 0; right: 0; left: var(--sep-left, var(--s4));
  border-top: 0.5px solid var(--c-sep); }
.box.icons .row { --sep-left: 60px; }
button.row:active, .row.tap:active { background: var(--t-off); }
.row .ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; flex: none;
  background: var(--t-accent); color: var(--c-accent); }
.row .ic svg.i { width: 18px; height: 18px; }
.row .ic.paused { background: var(--t-paused); color: var(--c-paused); }
.row .ic.danger { background: var(--t-danger); color: var(--c-danger); }
.row .ic.live { background: var(--t-live); color: var(--c-live); }
.row .body { flex: 1; min-width: 0; }
.row .t { font-size: var(--fs-body); line-height: var(--lh-body); overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row .st { font-size: var(--fs-sub); line-height: var(--lh-sub); color: var(--c-subtitle); margin-top: 1px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row .st.full { display: block; white-space: pre-wrap; color: var(--c-text); }
.row .v { font-size: var(--fs-sub); line-height: var(--lh-sub); color: var(--c-hint); text-align: right; flex: none;
  font-variant-numeric: tabular-nums; max-width: 46%; }
.row .v b { display: block; font-size: var(--fs-body); line-height: var(--lh-body); font-weight: 500; color: var(--c-text); }
.row .v b.profit { color: var(--c-profit); } .row .v b.loss { color: var(--c-danger); }
.row .v b.soft { font-weight: 400; color: var(--c-hint); }
.row .v b small { font-size: var(--fs-sub); font-weight: 400; color: var(--c-hint); }
.row .chev { color: var(--c-hint); opacity: 0.6; }
.row .chev svg.i { width: 16px; height: 16px; }
.row .chev.check { color: var(--c-accent); opacity: 1; }
.row .chev.check svg.i { width: 20px; height: 20px; stroke-width: 2.2; }
.row.danger .t { color: var(--c-danger); }
.row.accent .t { color: var(--c-accent); }

/* chips */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: var(--r-chip);
  font-size: var(--fs-micro); line-height: var(--lh-micro); font-weight: 500; background: var(--t-off); color: var(--c-hint); }
.chip.live { background: var(--t-live); color: var(--c-live-ink); }
.chip.paused { background: var(--t-paused); color: var(--c-paused-ink); }
.chip.loss, .chip.danger { background: var(--t-danger); color: var(--c-danger); }
.chip.profit { background: var(--t-live); color: var(--c-profit); }
.chip.info { background: var(--t-accent); color: var(--c-accent); }

/* segmented control */
.seg { display: grid; grid-auto-columns: 1fr; grid-auto-flow: column; gap: 2px; padding: 2px; margin-bottom: var(--s4);
  border-radius: 9px; background: var(--t-off); }
.seg button { padding: 6px 4px; border-radius: 7px; font-size: var(--fs-caption); font-weight: 500; color: var(--c-text); }
.seg button[aria-selected="true"] { background: var(--c-section); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

/* bottom tabs */
nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--c-bar); border-top: 0.5px solid var(--c-sep); }
nav.tabs button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--c-hint); font-size: var(--fs-micro); line-height: var(--lh-micro); font-weight: 500; }
nav.tabs button[aria-current="page"] { color: var(--c-accent); }
nav.tabs svg.i { width: 24px; height: 24px; }
nav.tabs[hidden] { display: none; }

/* bottom sheet */
.scrim { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.4); display: flex; align-items: flex-end;
  justify-content: center; animation: fade 0.18s ease; }
.sheet { width: 100%; max-width: 640px; max-height: 88vh; overflow: auto; background: var(--c-page);
  border-radius: var(--r-sheet) var(--r-sheet) 0 0; padding: var(--s2) var(--s4) calc(var(--s5) + env(safe-area-inset-bottom));
  animation: rise 0.22s ease; }
.sheet .grab { width: 36px; height: 5px; border-radius: 3px; background: var(--c-sep); margin: 0 auto var(--s3); }
.sheet h3 { margin: 0 0 var(--s1); font-size: var(--fs-title); line-height: var(--lh-title); font-weight: 600; }
.sheet .lead { margin: 0 0 var(--s4); font-size: var(--fs-sub); line-height: var(--lh-sub); color: var(--c-subtitle); }
.sheet .box { background: var(--c-section); border-radius: var(--r-section); overflow: hidden; margin-bottom: var(--s3); }
.sheet .box + .lead { margin-top: var(--s1); }
.sheet .row .st { display: block; }  /* what a choice means: in full */
.big-value { text-align: center; font-size: var(--fs-display); line-height: var(--lh-display); font-weight: 600;
  font-variant-numeric: tabular-nums; margin: var(--s2) 0; }
.stepper { display: flex; align-items: center; justify-content: center; gap: var(--s4); margin-bottom: var(--s4); }
.stepper button { width: 48px; height: 44px; border-radius: 12px; background: var(--c-section); font-size: 22px; color: var(--c-accent); }
.presets { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s2); margin-bottom: var(--s4); }
.presets button { padding: 8px 14px; border-radius: var(--r-chip); background: var(--c-section); font-size: var(--fs-sub); }
.presets button[aria-pressed="true"] { background: var(--c-button); color: var(--c-button-text); }
.btn { display: flex; align-items: center; justify-content: center; gap: var(--s2); width: 100%; min-height: 48px;
  border-radius: 12px; background: var(--c-button); color: var(--c-button-text); font-weight: 600; }
.btn.plain { background: var(--c-section); color: var(--c-accent); font-weight: 500; }
.btn + .btn { margin-top: var(--s2); }
.btn:disabled, .stepper button:disabled { opacity: 0.4; cursor: default; }
/* outside Telegram the main action stays in sight above the tabs, as Telegram's MainButton would */
.actions { position: sticky; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); z-index: 5;
  margin: 0 calc(-1 * var(--s4)); padding: var(--s2) var(--s4); background: var(--c-page); }
button:focus-visible { outline: 2px solid var(--c-accent); outline-offset: -2px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + var(--s3)); z-index: 30;
  transform: translateX(-50%); max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: rgba(30, 30, 30, 0.92); color: #fff; font-size: var(--fs-sub); line-height: var(--lh-sub);
  animation: fade 0.18s ease; }

/* empty, skeleton */
.empty { padding: var(--s6) var(--s4); text-align: center; color: var(--c-hint); font-size: var(--fs-sub); }
.empty svg.i { width: 34px; height: 34px; display: block; margin: 0 auto var(--s2); opacity: 0.6; }
.skel { display: block; height: 14px; border-radius: 7px; background: var(--t-off); }
.skel.w60 { width: 60%; } .skel.w40 { width: 40%; margin-top: 8px; height: 12px; }

/* the log: time and source small on top, the text under it; a coloured edge for warnings and errors */
.logline { padding: 9px var(--s4) 10px; }
.logline + .logline { border-top: 0.5px solid var(--c-sep); }
.logline .meta { font-size: var(--fs-micro); line-height: var(--lh-micro); color: var(--c-hint); font-variant-numeric: tabular-nums;
  margin-bottom: 3px; }
.logline .msg { font-size: var(--fs-caption); line-height: var(--lh-caption); white-space: pre-wrap; overflow-wrap: anywhere; }
.logline.warn { box-shadow: inset 3px 0 var(--c-paused); }
.logline.warn .meta { color: var(--c-paused-ink); }
.logline.error { box-shadow: inset 3px 0 var(--c-danger); }
.logline.error .meta, .logline.error .msg { color: var(--c-danger); }
.prose { padding: var(--s3) var(--s4); white-space: pre-wrap; font-size: var(--fs-sub); line-height: var(--lh-sub); }

/* a login in a sheet: one field at a time, the error under it, the QR on white whatever the theme */
.field { display: block; width: 100%; min-height: 48px; padding: 12px 14px; border: 0; border-radius: 12px;
  background: var(--c-section); color: var(--c-text); font: inherit; font-size: 17px; font-variant-numeric: tabular-nums; }
.field:focus { outline: 2px solid var(--c-accent); outline-offset: -2px; }
.field::placeholder { color: var(--c-hint); }
.err { margin: var(--s2) var(--s1) 0; color: var(--c-danger); font-size: var(--fs-sub); line-height: var(--lh-sub); }
.sheet .field + .btn, .sheet .err + .btn { margin-top: var(--s3); }
.sheet .lead.center { text-align: center; }
.qr { display: block; width: 232px; height: 232px; margin: var(--s2) auto var(--s3); padding: 8px; border-radius: 12px;
  background: #fff; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0.6; } }
@media (prefers-reduced-motion: reduce) { .scrim, .sheet, .toast { animation: none; } }
