/* ─── Telegram safe-area & env ──────────────────────────────── */
:root {
    --tg-safe-top:    env(safe-area-inset-top, 0px);
    --tg-safe-bottom: env(safe-area-inset-bottom, 0px);
}
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
* { -webkit-tap-highlight-color: transparent; }

/* ── Reset & tokens ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:          var(--tg-theme-bg-color, #090b0f);
    --bg2:         var(--tg-theme-secondary-bg-color, #0f1318);
    --bg3:         #161c24;
    --text:        var(--tg-theme-text-color, #e8edf5);
    --text2:       var(--tg-theme-hint-color, #5a6478);
    --accent:      var(--tg-theme-button-color, #3b82f6);
    --accent-glow: rgba(59,130,246,.25);
    --buy:         #16c784;
    --buy-dim:     rgba(22,199,132,.12);
    --sell:        #ea3943;
    --sell-dim:    rgba(234,57,67,.12);
    --border:      rgba(255,255,255,.06);
    --border2:     rgba(255,255,255,.1);
    --radius:      16px;
    --radius-sm:   10px;
    --sheet-z:     300;
    --overlay-z:   200;
    --menu-z:      400;
    --toast-z:     500;
    font-size: 15px;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── Top Bar ──────────────────────────────────────────────────── */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
}
.logo-block { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }
.logo-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--buy);
    box-shadow: 0 0 8px var(--buy);
    animation: pulse-dot 2.5s ease-in-out infinite;
}
@keyframes pulse-dot {
    0%,100% { opacity: 1; box-shadow: 0 0 8px var(--buy); }
    50%      { opacity: .6; box-shadow: 0 0 14px var(--buy); }
}
.logo-text {
    font-family: 'Space Mono', monospace;
    font-size: 13px; font-weight: 700;
    letter-spacing: 2px; color: var(--text);
}

/* pair selector */
.pair-selector-wrap { position: relative; flex: 1; max-width: 180px; }
.pair-selector-wrap select {
    width: 100%; appearance: none;
    background: var(--bg3); color: var(--text);
    border: 1px solid var(--border2); border-radius: var(--radius-sm);
    padding: 7px 28px 7px 12px;
    font-family: 'DM Sans', sans-serif; font-size: 14px; font-weight: 600;
    outline: none; cursor: pointer; letter-spacing: .3px;
}
.select-arrow {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    width: 10px; height: 6px; color: var(--text2); pointer-events: none;
}

/* hamburger */
.hamburger-btn {
    background: none; border: none; padding: 6px; cursor: pointer;
    display: flex; flex-direction: column; gap: 4.5px; justify-content: center;
    flex-shrink: 0;
}
.hamburger-btn span {
    display: block; width: 22px; height: 2px;
    background: var(--text); border-radius: 2px;
    transition: transform .25s, opacity .25s;
}
.hamburger-btn.open span:nth-child(1) { transform: translateY(6.5px) rotate(45deg); }
.hamburger-btn.open span:nth-child(2) { opacity: 0; }
.hamburger-btn.open span:nth-child(3) { transform: translateY(-6.5px) rotate(-45deg); }

/* ── Ticker Bar ───────────────────────────────────────────────── */
.ticker-bar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 14px;
    background: var(--bg); border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.ticker-price { display: flex; align-items: baseline; gap: 8px; }
.price-value {
    font-family: 'Space Mono', monospace;
    font-size: 20px; font-weight: 700; letter-spacing: -.5px;
    transition: color .2s;
}
.price-value.flash-up   { color: var(--buy); }
.price-value.flash-down { color: var(--sell); }

.price-change {
    font-size: 12px; font-weight: 600;
    padding: 2px 6px; border-radius: 6px;
}
.price-change.up     { color: var(--buy);  background: var(--buy-dim); }
.price-change.down   { color: var(--sell); background: var(--sell-dim); }
.price-change.neutral{ color: var(--text2); background: transparent; }

.ticker-stats { display: flex; gap: 16px; }
.stat { display: flex; flex-direction: column; align-items: flex-end; }
.stat-label { font-size: 10px; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; }
.stat-val   { font-family: 'Space Mono', monospace; font-size: 12px; color: var(--text); }

/* WS status dot */
.ws-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--text2); flex-shrink: 0;
    transition: background .3s;
}
.ws-dot.connected    { background: var(--buy); box-shadow: 0 0 6px var(--buy); }
.ws-dot.connecting   { background: #f59e0b; animation: pulse-dot 1s ease-in-out infinite; }
.ws-dot.disconnected { background: var(--sell); }

/* ── Chart Container ──────────────────────────────────────────── */
#chart-container {
    flex: 1; width: 100%; position: relative;
    overflow: hidden; background: var(--bg);
}
.chart-loading {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 12px; color: var(--text2); font-size: 13px;
    z-index: 5; background: var(--bg); transition: opacity .4s;
}
.loading-pulse {
    width: 36px; height: 36px;
    border: 2px solid var(--border2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.chart-loading.hidden { opacity: 0; pointer-events: none; }

/* ── Bottom Controls ──────────────────────────────────────────── */
.controls {
    background: var(--bg2); border-top: 1px solid var(--border);
    padding: 10px 14px env(safe-area-inset-bottom, 10px);
    flex-shrink: 0;
}
.controls-inner { display: flex; align-items: center; gap: 10px; }
.balance-hint {
    display: flex; align-items: center; gap: 5px;
    font-size: 12px; color: var(--text2); flex: 1;
    white-space: nowrap; overflow: hidden;
}
.balance-hint svg { width: 14px; height: 14px; flex-shrink: 0; }
.balance-hint strong { color: var(--text); font-weight: 600; }
.btn-row { display: flex; gap: 8px; }
.ctrl-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 12px 20px; border: none; border-radius: var(--radius-sm);
    font-family: 'Space Mono', monospace; font-size: 14px; font-weight: 700;
    letter-spacing: 1px; cursor: pointer;
    transition: opacity .15s, transform .1s;
}
.ctrl-btn svg { width: 18px; height: 18px; }
.ctrl-btn:active { transform: scale(.97); opacity: .85; }
.ctrl-btn.buy  { background: var(--buy);  color: #fff; }
.ctrl-btn.sell { background: var(--sell); color: #fff; }

/* ── Overlay ──────────────────────────────────────────────────── */
.overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.55); backdrop-filter: blur(2px);
    z-index: var(--overlay-z);
    opacity: 0; pointer-events: none;
    transition: opacity .3s;
}
.overlay.show { opacity: 1; pointer-events: all; }

/* ── Side Menu ────────────────────────────────────────────────── */
.side-menu {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: 260px; background: var(--bg2);
    border-left: 1px solid var(--border);
    z-index: var(--menu-z);
    transform: translateX(100%);
    transition: transform .3s cubic-bezier(.4,0,.2,1);
    display: flex; flex-direction: column;
    padding: calc(var(--tg-safe-top) + 16px) 0 16px;
    overflow-y: auto;
}
.side-menu.show { transform: translateX(0); }

.side-menu-header {
    display: flex; align-items: center; gap: 12px;
    padding: 0 16px 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}
.side-user-avatar {
    width: 42px; height: 42px; border-radius: 50%;
    background: var(--accent-glow); border: 1.5px solid var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 700; color: var(--accent);
    flex-shrink: 0;
}
.side-user-name  { font-size: 15px; font-weight: 600; color: var(--text); }
.side-user-id    { font-size: 12px; color: var(--text2); margin-top: 2px; }

.side-nav { display: flex; flex-direction: column; padding: 0 8px; }
.side-nav button {
    display: flex; align-items: center; gap: 12px;
    padding: 13px 10px; background: none; border: none;
    color: var(--text); font-family: 'DM Sans', sans-serif; font-size: 15px;
    font-weight: 500; cursor: pointer; border-radius: var(--radius-sm);
    transition: background .15s;
    text-align: left;
}
.side-nav button svg { width: 20px; height: 20px; color: var(--text2); flex-shrink: 0; }
.side-nav button:hover { background: var(--bg3); }

/* ── Bottom Sheet ─────────────────────────────────────────────── */
.bottom-sheet {
    position: fixed; left: 0; right: 0; bottom: 0;
    background: var(--bg2);
    border-radius: var(--radius) var(--radius) 0 0;
    border-top: 1px solid var(--border);
    z-index: var(--sheet-z);
    transform: translateY(100%);
    transition: transform .35s cubic-bezier(.4,0,.2,1);
    max-height: 80vh; display: flex; flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottom-sheet.tall { max-height: 90vh; }
.bottom-sheet.show { transform: translateY(0); }

.sheet-drag-handle {
    width: 36px; height: 4px; border-radius: 2px;
    background: var(--border2); margin: 10px auto 4px; flex-shrink: 0;
}
.sheet-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 16px 12px; flex-shrink: 0;
    border-bottom: 1px solid var(--border);
}
.sheet-header h2 { font-size: 17px; font-weight: 700; }
.close-btn {
    width: 30px; height: 30px; background: var(--bg3);
    border: none; border-radius: 50%; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--text2);
}
.close-btn svg { width: 14px; height: 14px; }
.sheet-content { overflow-y: auto; padding: 16px; flex: 1; }

/* ── Profile Sheet ────────────────────────────────────────────── */
.profile-avatar-big {
    width: 64px; height: 64px; border-radius: 50%;
    background: var(--accent-glow); border: 2px solid var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 26px; font-weight: 700; color: var(--accent);
    margin: 0 auto 10px;
}
.profile-name   { text-align: center; font-size: 18px; font-weight: 700; }
.profile-handle { text-align: center; font-size: 13px; color: var(--text2); margin-bottom: 20px; }
.profile-stats-grid {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 1px; background: var(--border);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    overflow: hidden; margin-bottom: 16px;
}
.pstat {
    display: flex; flex-direction: column; align-items: center;
    padding: 12px 8px; background: var(--bg3);
}
.pstat-val   { font-family: 'Space Mono', monospace; font-size: 16px; font-weight: 700; }
.pstat-label { font-size: 10px; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }

.wallet-card {
    background: var(--bg3); border-radius: var(--radius-sm);
    border: 1px solid var(--border); padding: 16px;
}
.wallet-label  { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.wallet-amount { font-family: 'Space Mono', monospace; font-size: 22px; font-weight: 700; margin-bottom: 14px; }
.wallet-row    { display: flex; gap: 8px; }
.wallet-btn {
    flex: 1; padding: 11px; border-radius: var(--radius-sm);
    font-family: 'DM Sans', sans-serif; font-size: 14px; font-weight: 600;
    cursor: pointer; border: none;
    background: var(--accent); color: #fff; transition: opacity .15s;
}
.wallet-btn.outline {
    background: transparent; border: 1px solid var(--border2); color: var(--text);
}

/* ── Settings Sheet ───────────────────────────────────────────── */
.settings-section { margin-bottom: 20px; }
.settings-label   { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 10px; }
.chip-group { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
    padding: 7px 14px; background: var(--bg3);
    border: 1px solid var(--border); border-radius: 20px;
    font-family: 'DM Sans', sans-serif; font-size: 13px; font-weight: 500;
    color: var(--text2); cursor: pointer; transition: all .15s;
}
.chip.active {
    background: var(--accent-glow); border-color: var(--accent);
    color: var(--accent); font-weight: 600;
}
.toggle-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 0; border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.toggle { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
    position: absolute; inset: 0; border-radius: 13px;
    background: var(--bg3); border: 1px solid var(--border2);
    transition: background .2s;
    cursor: pointer;
}
.toggle-track::after {
    content: ''; position: absolute;
    left: 3px; top: 3px;
    width: 18px; height: 18px; border-radius: 50%;
    background: var(--text2); transition: transform .2s, background .2s;
}
.toggle input:checked + .toggle-track { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(18px); background: #fff; }

/* ── History Sheet ────────────────────────────────────────────── */
.history-list { display: flex; flex-direction: column; gap: 6px; }
.history-row {
    display: flex; align-items: center; gap: 12px;
    background: var(--bg3); border-radius: var(--radius-sm);
    padding: 12px; border: 1px solid var(--border);
}
.history-side {
    font-family: 'Space Mono', monospace; font-size: 11px; font-weight: 700;
    padding: 3px 8px; border-radius: 6px; flex-shrink: 0;
}
.history-side.buy  { background: var(--buy-dim);  color: var(--buy); }
.history-side.sell { background: var(--sell-dim); color: var(--sell); }
.history-pair { font-size: 14px; font-weight: 600; }
.history-meta { font-size: 11px; color: var(--text2); margin-top: 2px; }
.history-amount { margin-left: auto; text-align: right; }
.history-amount strong { font-family: 'Space Mono', monospace; font-size: 13px; display: block; }
.history-amount small  { font-size: 11px; color: var(--text2); }

/* ── Help / About Sheets ──────────────────────────────────────── */
.faq-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 16px; }
.faq-item {
    background: var(--bg3); border-radius: var(--radius-sm);
    border: 1px solid var(--border); overflow: hidden;
}
.faq-item summary {
    padding: 13px 14px; font-size: 14px; font-weight: 500;
    cursor: pointer; list-style: none;
    display: flex; justify-content: space-between; align-items: center;
}
.faq-item summary::after {
    content: '+'; font-size: 18px; color: var(--text2);
    transition: transform .2s;
}
.faq-item[open] summary::after { transform: rotate(45deg); }
.faq-item p { padding: 0 14px 13px; font-size: 13px; color: var(--text2); line-height: 1.5; }

.sheet-primary-btn {
    width: 100%; padding: 14px; border: none;
    border-radius: var(--radius-sm); background: var(--accent);
    color: #fff; font-family: 'DM Sans', sans-serif; font-size: 15px;
    font-weight: 600; cursor: pointer; transition: opacity .15s;
}

.about-logo {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    font-family: 'Space Mono', monospace; font-size: 22px; font-weight: 700;
    margin-bottom: 10px;
}
.about-dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--buy); box-shadow: 0 0 10px var(--buy);
}
.about-tagline { text-align: center; font-size: 14px; color: var(--text2); margin-bottom: 6px; }
.about-version { text-align: center; font-size: 12px; color: var(--text2); margin-bottom: 20px; }
.about-links { display: flex; flex-direction: column; gap: 6px; }
.about-links button {
    width: 100%; padding: 12px; background: var(--bg3);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text); font-family: 'DM Sans', sans-serif; font-size: 14px;
    cursor: pointer; transition: border-color .15s;
}
.about-links button:hover { border-color: var(--border2); }

/* ── Order Sheet ──────────────────────────────────────────────── */
.order-type-chips { margin-bottom: 16px; }
.field-row { margin-bottom: 14px; }
.field-label {
    display: flex; justify-content: space-between; align-items: baseline;
    font-size: 12px; color: var(--text2);
    text-transform: uppercase; letter-spacing: .5px;
    margin-bottom: 6px;
}
.field-balance { font-weight: 500; }
.field-input-wrap {
    display: flex; align-items: center; gap: 8px;
    background: var(--bg3); border: 1px solid var(--border2);
    border-radius: var(--radius-sm); padding: 10px 12px;
}
.field-input-wrap:focus-within { border-color: var(--accent); }
.field-input {
    flex: 1; background: none; border: none; outline: none;
    color: var(--text); font-family: 'Space Mono', monospace;
    font-size: 15px; min-width: 0;
}
.field-input::placeholder { color: var(--text2); opacity: .5; }
.field-suffix { color: var(--text2); font-size: 13px; font-weight: 600; flex-shrink: 0; }
.max-btn {
    background: var(--accent-glow); border: 1px solid rgba(59,130,246,.3);
    border-radius: 6px; color: var(--accent);
    font-size: 11px; font-weight: 700; padding: 5px 9px;
    cursor: pointer; letter-spacing: .5px; flex-shrink: 0;
}

.quick-percents { display: flex; gap: 8px; margin-bottom: 18px; }
.quick-percents button {
    flex: 1; background: var(--bg3); border: 1px solid var(--border);
    border-radius: 8px; color: var(--text2); font-size: 13px;
    padding: 8px 0; cursor: pointer; transition: all .15s;
}
.quick-percents button:active {
    background: var(--accent-glow); border-color: var(--accent); color: var(--accent);
}

.order-summary {
    background: var(--bg3); border-radius: var(--radius-sm);
    padding: 12px 14px; margin-bottom: 18px;
    display: flex; flex-direction: column; gap: 8px;
}
.summary-row {
    display: flex; justify-content: space-between;
    font-size: 13px; color: var(--text2);
}
.total-row {
    padding-top: 8px; border-top: 1px solid var(--border);
    font-size: 15px; font-weight: 700; color: var(--text);
}

.execute-btn {
    width: 100%; padding: 16px; border: none;
    border-radius: var(--radius-sm);
    font-family: 'Space Mono', monospace;
    font-size: 15px; font-weight: 700; letter-spacing: 1px;
    color: #fff; cursor: pointer;
    transition: opacity .15s, transform .1s;
    margin-bottom: 4px;
}
.execute-btn.buy  { background: var(--buy); }
.execute-btn.sell { background: var(--sell); }
.execute-btn:active { transform: scale(.99); }
.execute-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── Toast ────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    top: env(safe-area-inset-top, 0);
    left: 50%; transform: translate(-50%, -80px);
    background: var(--bg2); color: var(--text);
    padding: 11px 20px 11px 14px; border-radius: 12px;
    font-size: 13px; font-weight: 500;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
    border: 1px solid var(--border2);
    z-index: var(--toast-z); opacity: 0; pointer-events: none;
    transition: transform .35s cubic-bezier(.4,0,.2,1), opacity .35s;
    display: flex; align-items: center; gap: 10px;
    white-space: nowrap; max-width: 90vw;
}
.toast.show { transform: translate(-50%, 14px); opacity: 1; }
.toast-icon { width: 18px; height: 18px; flex-shrink: 0; }
.toast.success .toast-icon { color: var(--buy); }
.toast.error   .toast-icon { color: var(--sell); }
.toast.info    .toast-icon { color: var(--accent); }

/* ── Empty state ──────────────────────────────────────────────── */
.empty-state {
    display: flex; flex-direction: column; align-items: center;
    gap: 10px; padding: 40px 0; color: var(--text2); font-size: 13px;
}
.empty-state svg { width: 48px; height: 48px; opacity: .4; }
