*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}

:root {
    --bg: #0d1117;
    --panel: #161b22;
    --card: #1c2128;
    --card-hover: #272d36;
    --border: #30363d;
    --text: #e6edf3;
    --text-dim: #8b949e;
    --text-muted: #484f58;
    --green: #22c55e;
    --green-bg: rgba(34, 197, 94, .08);
    --green-glow: rgba(34, 197, 94, .25);
    --red: #ef4444;
    --red-bg: rgba(239, 68, 68, .08);
    --gold: #f0b832;
    --purple: #8b5cf6;
    --purple-bg: rgba(139, 92, 246, .12);
}

html { font-size: 14px; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}

/* TG WebApp safe area */
body.tg-webapp .terminal-header,
html.tg-webapp .terminal-header {
    margin-top: 70px;
    top: 70px;
}

/* ═══ Header ═══ */
.terminal-header {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    padding: 0 22px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    min-height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.header-logo-link {
    text-decoration: none;
    display: flex;
    align-items: center;
}
.header-logo-img {
    height: 100%;
    max-height: 56px;
    width: auto;
    display: block;
    object-fit: contain;
    filter: drop-shadow(0 0 6px rgba(245, 166, 35, 0.4));
}
.header-divider {
    color: var(--border);
    font-size: 18px;
    font-weight: 300;
}
.header-subtitle {
    color: #787b86;
    font-size: 15px;
    font-weight: 500;
}
.header-nav {
    display: flex;
    align-items: center;
    gap: 6px;
}
.header-nav-link {
    padding: 7px 16px;
    background: #1e222d;
    color: #d1d4dc;
    text-decoration: none;
    border-radius: 5px;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.15s ease;
    border: 1px solid var(--border);
}
.header-nav-link:hover {
    background: rgba(245, 166, 35, 0.12);
    border-color: rgba(245, 166, 35, 0.4);
    color: #f5a623;
}

@keyframes pulse-dot {
    0%,100% { opacity: 1; box-shadow: 0 0 8px var(--green-glow); }
    50% { opacity: .5; box-shadow: 0 0 16px var(--green-glow); }
}
.lm-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.lm-status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); transition: background .3s; }
.lm-status-dot.connected { background: var(--green); box-shadow: 0 0 6px var(--green-glow); }
.lm-status-dot.connecting { background: #f59e0b; animation: pulse-dot 1s ease infinite; }
.lm-status-dot.error { background: var(--red); }

/* ═══ Stats bar ═══ */
.lm-stats-bar { display: flex; gap: 2px; padding: 0 24px; background: var(--panel); border-bottom: 1px solid var(--border); }
.lm-stat { display: flex; align-items: center; gap: 8px; padding: 8px 18px; font-size: 13px; }
.lm-stat-label { color: var(--text-muted); text-transform: uppercase; font-size: 10px; font-weight: 600; letter-spacing: .5px; }
.lm-stat-value { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.lm-stat-deals .lm-stat-value { color: var(--green); }

/* ═══ Toolbar ═══ */
.lm-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 24px; background: var(--panel); border-bottom: 1px solid var(--border); }
.lm-filter-group { display: flex; gap: 2px; background: var(--bg); border-radius: 6px; padding: 2px; }
.lm-filter-btn {
    padding: 5px 14px; border: none; background: transparent; color: var(--text-dim);
    font-size: 12px; font-weight: 600; cursor: pointer; border-radius: 5px; transition: all .15s;
}
.lm-filter-btn:hover { color: var(--text); }
.lm-filter-btn.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.lm-toolbar-right { display: flex; gap: 6px; }
.lm-btn-pause, .lm-btn-clear {
    width: 32px; height: 32px; border: 1px solid var(--border); background: var(--card);
    color: var(--text-dim); border-radius: 6px; cursor: pointer; font-size: 14px;
    display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.lm-btn-pause:hover, .lm-btn-clear:hover { border-color: var(--text-muted); color: var(--text); }
.lm-btn-pause.paused { background: rgba(239,68,68,.15); border-color: var(--red); color: var(--red); }

/* ═══ Table header ═══ */
.lm-table-header {
    display: grid;
    grid-template-columns: 44px 60px 1fr 110px 80px 90px 60px 110px;
    gap: 8px; padding: 8px 24px; background: var(--bg);
    border-bottom: 1px solid var(--border); position: sticky; top: 49px; z-index: 90;
}
.lm-th {
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .5px; color: var(--text-muted); display: flex; align-items: center;
}
.lm-th-price, .lm-th-discount, .lm-th-median, .lm-th-sales { justify-content: flex-end; }
.lm-th-confidence { justify-content: center; }

/* ═══ Feed ═══ */
.lm-feed {
    padding: 4px 24px 24px; max-height: calc(100vh - 220px); overflow-y: auto;
    scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.lm-feed::-webkit-scrollbar { width: 6px; }
.lm-feed::-webkit-scrollbar-track { background: transparent; }
.lm-feed::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.lm-placeholder { text-align: center; padding: 60px 20px; color: var(--text-muted); font-size: 15px; }

/* ═══ Feed row ═══ */
.lm-row {
    display: grid;
    grid-template-columns: 44px 60px 1fr 110px 80px 90px 60px 110px;
    gap: 8px; padding: 6px 0; border-bottom: 1px solid rgba(48,54,61,.4);
    align-items: center; animation: row-in .35s ease; transition: opacity .2s, background .2s;
    cursor: pointer;
}
.lm-row:hover { background: rgba(255,255,255,.03); }

@keyframes row-in {
    from { opacity: 0; transform: translateY(-12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Deal row */
.lm-row.deal {
    background: var(--green-bg); border-left: 3px solid var(--green);
    padding-left: 8px; border-radius: 4px; margin-bottom: 2px;
}
.lm-row.deal:hover { background: rgba(34,197,94,.12); }
.lm-row.deal .lm-col-collection { color: var(--text); font-weight: 600; }
.lm-row.deal.flash { animation: row-in .35s ease, deal-flash 1.5s ease; }
@keyframes deal-flash {
    0% { box-shadow: 0 0 20px var(--green-glow), inset 0 0 20px var(--green-bg); }
    100% { box-shadow: none; }
}

/* Non-deal row */
.lm-row.nodeal { opacity: .4; }
.lm-row.nodeal:hover { opacity: .65; }

/* ═══ Columns ═══ */
.lm-col-img {
    width: 36px; height: 36px; border-radius: 6px; object-fit: contain;
    background: var(--card); flex-shrink: 0;
}
.lm-col-img-placeholder {
    width: 36px; height: 36px; border-radius: 6px; background: var(--card); flex-shrink: 0;
}
.lm-col-time { font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.lm-col-info { display: flex; flex-direction: column; gap: 1px; overflow: hidden; min-width: 0; }
.lm-col-collection { font-size: 13px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lm-col-model { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lm-col-tags { display: flex; gap: 3px; margin-top: 1px; flex-wrap: nowrap; overflow: hidden; }
.lm-tag {
    padding: 0 4px; background: rgba(139,92,246,.08); border: 1px solid rgba(139,92,246,.15);
    border-radius: 3px; font-size: 9px; color: var(--text-muted); white-space: nowrap;
    line-height: 16px;
}

.lm-col-price { text-align: right; min-width: 0; }
.lm-price-main { font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums; font-size: 13px; }
.lm-price-main .ton { font-weight: 400; color: var(--text-muted); font-size: 10px; margin-left: 2px; }
.lm-price-diff { font-size: 10px; font-variant-numeric: tabular-nums; margin-top: 1px; }
.lm-price-diff.positive { color: var(--green); }
.lm-price-diff.negative { color: var(--red); }
.lm-price-diff.neutral { color: var(--text-muted); }

.lm-col-discount {
    text-align: right; font-weight: 700; font-size: 13px;
    font-variant-numeric: tabular-nums; padding: 2px 6px; border-radius: 4px;
}
.lm-col-discount.positive { color: var(--green); background: var(--green-bg); }
.lm-col-discount.negative { color: var(--red); background: var(--red-bg); }
.lm-col-discount.neutral { color: var(--text-muted); }

.lm-col-median { text-align: right; font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.lm-col-sales { text-align: right; font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.lm-col-confidence { display: flex; align-items: center; gap: 6px; justify-content: center; }
.lm-conf-bar { width: 60px; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.lm-conf-fill { height: 100%; border-radius: 2px; transition: width .3s; }
.lm-conf-fill.high { background: var(--green); }
.lm-conf-fill.mid { background: #f59e0b; }
.lm-conf-fill.low { background: var(--red); }
.lm-conf-pct { font-size: 11px; font-weight: 600; color: var(--text-muted); min-width: 28px; text-align: right; font-variant-numeric: tabular-nums; }

.lm-row.hidden { display: none; }

/* ═══════════════════════════════════════════
   Modal
   ═══════════════════════════════════════════ */
.lm-modal-overlay {
    display: none; position: fixed; inset: 0; z-index: 9000;
    background: rgba(0,0,0,.72); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    justify-content: center; align-items: flex-start; padding: 40px 16px; overflow-y: auto;
}
.lm-modal-overlay.open { display: flex; }

.lm-modal-popup {
    width: 100%; max-width: 520px; background: #0f0f0f;
    border: 1px solid #2a2a2a; border-radius: 16px; position: relative;
    animation: modal-in .2s ease;
}
@keyframes modal-in {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.lm-modal-close {
    position: absolute; top: 12px; right: 12px; width: 32px; height: 32px;
    border-radius: 50%; background: #1a1a1a; border: 1px solid #2a2a2a;
    color: #b0b0b0; font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; z-index: 1; transition: background .15s;
}
.lm-modal-close:hover { background: #2a2a2a; color: #e0e0e0; }

/* Hero */
.lm-modal-hero { display: flex; align-items: center; gap: 14px; padding: 16px; border-bottom: 1px solid #2a2a2a; }
.lm-modal-img {
    width: 80px; height: 80px; border-radius: 10px; object-fit: contain;
    background: #1a1a1a; flex-shrink: 0;
}
.lm-modal-hero-info { flex: 1; min-width: 0; }
.lm-modal-coll { font-size: 18px; font-weight: 700; color: var(--gold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lm-modal-model { font-size: 14px; color: #e0e0e0; margin-top: 2px; }
.lm-modal-number { font-size: 12px; color: #666; font-family: 'SF Mono','Fira Code',monospace; margin-top: 1px; }
.lm-modal-props { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.lm-modal-prop {
    padding: 1px 7px; background: #2a2a2a; border: 1px solid #333;
    border-radius: 5px; font-size: 10px; color: #b0b0b0;
}

/* Price block */
.lm-modal-price-block { padding: 16px; border-bottom: 1px solid #2a2a2a; }
.lm-modal-price-main { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.lm-modal-price-val { font-size: 28px; font-weight: 800; color: #a78bfa; font-variant-numeric: tabular-nums; }
.lm-modal-price-currency { font-size: 16px; font-weight: 500; color: #787b86; }
.lm-modal-price-badge {
    padding: 3px 10px; border-radius: 6px; font-size: 14px; font-weight: 700;
}
.lm-modal-price-badge.positive { color: var(--green); background: var(--green-bg); }
.lm-modal-price-badge.negative { color: var(--red); background: var(--red-bg); }

/* Price compare */
.lm-pc { margin-top: 10px; padding: 10px 0 4px; }
.lm-pc-cols { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 6px; }
.lm-pc-col { display: flex; flex-direction: column; }
.lm-pc-col.left { align-items: flex-start; }
.lm-pc-col.center { align-items: center; flex: 1; padding: 0 8px; }
.lm-pc-col.right { align-items: flex-end; }
.lm-pc-price { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; color: #d1d4dc; }
.lm-pc-col.left .lm-pc-price { color: #a78bfa; }
.lm-pc-col.right .lm-pc-price { color: #f5a623; }
.lm-pc-sub { font-size: 10px; color: #666; text-transform: uppercase; letter-spacing: .3px; margin-top: 1px; }
.lm-pc-diff-val { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: center; white-space: nowrap; }
.lm-pc-diff-val.positive { color: #26a69a; }
.lm-pc-diff-val.negative { color: #ef5350; }
.lm-pc-bar { position: relative; height: 6px; background: #1e222d; border-radius: 3px; margin: 2px 0; }
.lm-pc-dot { position: absolute; width: 12px; height: 12px; border-radius: 50%; top: -3px; transform: translateX(-50%); z-index: 2; }
.lm-pc-dot.lot { background: #8b5cf6; border: 2px solid #a78bfa; }
.lm-pc-dot.avg { background: #f5a623; border: 2px solid #fbbf24; }
.lm-pc-range { position: absolute; height: 6px; background: linear-gradient(90deg, rgba(139,92,246,.3), rgba(245,166,35,.3)); border-radius: 3px; top: 0; }


/* Sections */
.lm-modal-section { padding: 12px 16px; border-bottom: 1px solid #2a2a2a; }
.lm-section-title { font-size: 12px; font-weight: 600; color: #666; text-transform: uppercase; letter-spacing: .5px; }

/* Floor */
.lm-floor-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.lm-floor-adv { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.lm-floor-adv.positive { color: #26a69a; }
.lm-floor-adv.negative { color: #ef5350; }
.lm-floor-list { display: flex; gap: 6px; flex-wrap: wrap; }
.lm-floor-item { padding: 3px 8px; background: #1a1a1a; border: 1px solid #2a2a2a; border-radius: 6px; font-size: 12px; font-variant-numeric: tabular-nums; color: #d1d4dc; }
.lm-floor-item.first { border-color: #26a69a; color: #26a69a; }

/* Chart */
.lm-chart-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.lm-chart-point { font-size: 12px; font-weight: 600; color: #a78bfa; font-variant-numeric: tabular-nums; }
.lm-chart-canvas-wrap { position: relative; height: 320px; zoom: 0.909091; }
.lm-chart-footer { display: flex; gap: 16px; justify-content: center; padding: 6px 0 0; font-size: 11px; color: #787b86; font-variant-numeric: tabular-nums; }

/* ═══ Auth Popup ═══ */
.auth-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
    backdrop-filter: blur(4px);
}
.auth-popup {
    background: #1e222d;
    border: 1px solid #2a2e39;
    border-radius: 16px;
    padding: 32px 28px;
    max-width: 360px;
    width: 100%;
    text-align: center;
    position: relative;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}
.auth-close {
    position: absolute;
    top: 12px;
    right: 14px;
    background: none;
    border: none;
    color: #787b86;
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    transition: color 0.15s;
}
.auth-close:hover { color: #d1d4dc; }
.auth-icon { margin-bottom: 16px; }
.auth-title { color: #d1d4dc; font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.auth-text { color: #787b86; font-size: 14px; line-height: 1.5; margin-bottom: 20px; }
.auth-link {
    display: inline-block;
    padding: 10px 24px;
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 8px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.15s ease;
}
.auth-link:hover {
    background: rgba(139, 92, 246, 0.25);
    border-color: #8b5cf6;
    color: #c4b5fd;
}

/* ═══ Responsive ═══ */
@media (max-width: 900px) {
    .lm-table-header, .lm-row {
        grid-template-columns: 36px 50px 1fr 85px 65px;
        gap: 6px;
    }
    .lm-th-median, .lm-th-sales, .lm-th-confidence,
    .lm-col-median, .lm-col-sales, .lm-col-confidence { display: none; }
    .terminal-header { padding: 0 14px; }
    .lm-stats-bar { padding: 0 14px; flex-wrap: wrap; }
    .lm-toolbar { padding: 8px 14px; }
    .lm-table-header { padding: 8px 14px; }
    .lm-feed { padding: 4px 14px 14px; }
    .lm-col-img, .lm-col-img-placeholder { width: 30px; height: 30px; }
    .lm-col-tags { display: none; }
}
@media (max-width: 520px) {
    .terminal-header {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
        align-items: center;
        padding: 8px 10px;
        min-height: auto;
    }
    .header-logo-img { height: 36px; }
    .header-subtitle { font-size: 12px; }
    .header-nav { gap: 4px; margin-left: auto; }
    .header-nav-link { padding: 5px 10px; font-size: 12px; }
    .lm-table-header, .lm-row {
        grid-template-columns: 32px 42px 1fr 60px 50px;
        gap: 4px;
    }
    .lm-stat { padding: 6px 10px; }
    .lm-stat-label { font-size: 9px; }
    .lm-stat-value { font-size: 12px; }
    .lm-price-main { font-size: 12px; }
    .lm-col-discount { font-size: 11px; padding: 1px 4px; }
    .lm-modal-overlay { padding: 16px 6px; }
    .lm-modal-price-val { font-size: 22px; }
    .lm-modal-img { width: 60px; height: 60px; }
    .lm-modal-coll { font-size: 15px; }
}
