/* ========================================
   Trading Panel — Dark Pro Theme
   ======================================== */

:root {
    /* Core palette */
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a2235;
    --bg-card-hover: #1f2a40;
    --bg-elevated: #243049;

    /* Text */
    --text-primary: #f0f4f8;
    --text-secondary: #8899a6;
    --text-muted: #556677;

    /* Accent */
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --accent-soft: rgba(99, 102, 241, 0.12);

    /* Status */
    --green: #22c55e;
    --green-soft: rgba(34, 197, 94, 0.12);
    --green-glow: rgba(34, 197, 94, 0.4);
    --red: #ef4444;
    --red-soft: rgba(239, 68, 68, 0.12);
    --orange: #f59e0b;
    --orange-soft: rgba(245, 158, 11, 0.12);
    --cyan: #06b6d4;

    /* Gradients */
    --gradient-card: linear-gradient(135deg, #1a2235 0%, #162032 100%);
    --gradient-accent: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --gradient-green: linear-gradient(135deg, #22c55e 0%, #10b981 100%);
    --gradient-red: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);

    /* Shape */
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;

    /* Telegram overrides */
    --tg-bg: var(--tg-theme-bg-color, var(--bg-primary));
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    padding: 0 16px 100px;
    position: relative;
}

/* ========= Animated background glow ========= */
.bg-glow {
    position: fixed;
    top: -120px;
    left: 50%;
    transform: translateX(-50%);
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(99,102,241,0.15) 0%, rgba(99,102,241,0.05) 40%, transparent 70%);
    pointer-events: none;
    z-index: 0;
    animation: glowPulse 6s ease-in-out infinite alternate;
}

@keyframes glowPulse {
    0% { opacity: 0.6; transform: translateX(-50%) scale(1); }
    100% { opacity: 1; transform: translateX(-50%) scale(1.15); }
}

/* ========= Header ========= */
.header {
    position: relative;
    z-index: 1;
    padding: 20px 0 16px;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.logo-icon {
    color: var(--accent);
    filter: drop-shadow(0 0 8px var(--accent-glow));
}

.header-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    background: var(--green-soft);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    color: var(--green);
}

.pulse-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 var(--green-glow); }
    50% { box-shadow: 0 0 0 6px transparent; }
}

/* Balance Hero */
.balance-hero {
    text-align: center;
    padding: 28px 0 8px;
}

.balance-label {
    font-size: 13px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 500;
    margin-bottom: 8px;
}

.balance-amount {
    font-size: 42px;
    font-weight: 800;
    letter-spacing: -1.5px;
    line-height: 1;
    margin-bottom: 6px;
}

.balance-currency {
    font-size: 28px;
    color: var(--text-secondary);
    font-weight: 600;
    vertical-align: top;
    margin-right: 2px;
}

.balance-change {
    font-size: 14px;
    font-weight: 600;
}

/* ========= Navigation ========= */
.nav {
    display: flex;
    gap: 4px;
    padding: 4px;
    margin: 16px 0;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    position: relative;
    z-index: 1;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 10px 4px 8px;
    border: none;
    border-radius: 12px;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
}

.nav-item:active { transform: scale(0.95); }

.nav-item.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 15px var(--accent-glow);
}

.nav-item svg { transition: transform 0.2s; }
.nav-item.active svg { transform: scale(1.1); }

/* ========= Tab Content ========= */
.tab-content {
    display: none;
    position: relative;
    z-index: 1;
    animation: fadeIn 0.3s ease;
}

.tab-content.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ========= Bot Cards (Dashboard) ========= */
.bot-card {
    background: var(--gradient-card);
    border: 1px solid rgba(255,255,255,0.04);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 14px;
    transition: all 0.25s ease;
    position: relative;
    overflow: hidden;
}

.bot-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius) var(--radius) 0 0;
}

.bot-card.running::before { background: var(--gradient-green); }
.bot-card.stopped::before { background: var(--gradient-red); }

.bot-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.bot-card-info { flex: 1; }

.bot-card-title {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.3px;
    margin-bottom: 4px;
}

.bot-card-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
}

.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.status-chip.running {
    background: var(--green-soft);
    color: var(--green);
}

.status-chip.stopped {
    background: var(--red-soft);
    color: var(--red);
}

.status-chip-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

.status-chip.running .status-chip-dot {
    background: var(--green);
    box-shadow: 0 0 6px var(--green-glow);
}

.status-chip.stopped .status-chip-dot {
    background: var(--red);
}

/* Position items */
.positions-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.position-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: rgba(255,255,255,0.03);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255,255,255,0.03);
    transition: background 0.2s;
}

.position-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.coin-icon {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
}

.coin-icon.pepe { background: linear-gradient(135deg, #4ade80, #22c55e); }
.coin-icon.doge { background: linear-gradient(135deg, #fbbf24, #f59e0b); }
.coin-icon.wif { background: linear-gradient(135deg, #a78bfa, #8b5cf6); }
.coin-icon.sui { background: linear-gradient(135deg, #38bdf8, #0ea5e9); }
.coin-icon.default { background: linear-gradient(135deg, #64748b, #475569); }

.coin-name {
    font-size: 15px;
    font-weight: 700;
}

.coin-entry {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.position-right { text-align: right; }

.position-status {
    font-size: 12px;
    font-weight: 600;
}

.position-status.active { color: var(--green); }
.position-status.idle { color: var(--text-muted); }

.rebuy-badge {
    display: inline-block;
    margin-top: 3px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    background: var(--orange-soft);
    color: var(--orange);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.empty-state {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
    font-size: 13px;
}

/* PnL display */
.pnl-positive {
    color: var(--green);
    font-size: 13px;
    font-weight: 700;
}

.pnl-negative {
    color: var(--red);
    font-size: 13px;
    font-weight: 700;
}

/* Bot PnL row */
.bot-pnl-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    margin-bottom: 12px;
    background: rgba(255,255,255,0.03);
    border-radius: var(--radius-xs);
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 600;
}

/* Coin price in name */
.coin-price {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
}

/* Coin value */
.coin-value {
    font-size: 11px;
    color: var(--cyan);
    margin-top: 1px;
}

/* Trailing badge */
.trail-badge {
    display: inline-block;
    margin-top: 3px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    background: rgba(6, 182, 212, 0.12);
    color: var(--cyan);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Settings divider */
.settings-divider {
    height: 1px;
    background: rgba(255,255,255,0.06);
    margin: 12px 0;
}

.settings-group-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--cyan);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 8px;
}

/* ========= Bot Detail ========= */
.control-card {
    background: var(--gradient-card);
    border: 1px solid rgba(255,255,255,0.04);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 14px;
}

.control-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.control-title {
    font-size: 18px;
    font-weight: 700;
}

.control-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Toggle */
.toggle {
    position: relative;
    width: 56px;
    height: 32px;
    flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-track {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #334155;
    border-radius: 32px;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle-track::after {
    content: '';
    position: absolute;
    height: 26px;
    width: 26px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.toggle input:checked + .toggle-track {
    background: var(--green);
    box-shadow: 0 0 16px var(--green-glow);
}

.toggle input:checked + .toggle-track::after {
    transform: translateX(24px);
}

/* Section card */
.section-card {
    background: var(--gradient-card);
    border: 1px solid rgba(255,255,255,0.04);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 14px;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.section-title-dot {
    width: 4px;
    height: 16px;
    border-radius: 2px;
    background: var(--gradient-accent);
}

/* Settings rows */
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.setting-row:last-child { border-bottom: none; }

.setting-label {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.setting-input-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.setting-input {
    width: 80px;
    padding: 8px 12px;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-xs);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 600;
    text-align: right;
    outline: none;
    transition: border-color 0.2s;
}

.setting-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.setting-unit {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    min-width: 24px;
}

/* Save button */
.btn-save {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: var(--radius);
    background: var(--gradient-accent);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.3px;
    cursor: pointer;
    transition: all 0.25s;
    box-shadow: 0 4px 20px var(--accent-glow);
    position: relative;
    overflow: hidden;
}

.btn-save::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
    transition: left 0.5s;
}

.btn-save:hover::before { left: 100%; }
.btn-save:active { transform: scale(0.97); }
.btn-save:disabled { opacity: 0.4; cursor: not-allowed; }

/* ========= Logs ========= */
.log-switch {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}

.log-btn {
    flex: 1;
    padding: 10px;
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.log-btn.active {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: rgba(99,102,241,0.3);
}

.log-container {
    background: var(--bg-secondary);
    border: 1px solid rgba(255,255,255,0.04);
    border-radius: var(--radius);
    overflow: hidden;
}

#log-output {
    padding: 16px;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 11px;
    line-height: 1.8;
    max-height: 65vh;
    overflow-y: auto;
    word-wrap: break-word;
    white-space: pre-wrap;
    color: var(--text-secondary);
    margin: 0;
}

#log-output::-webkit-scrollbar { width: 4px; }
#log-output::-webkit-scrollbar-track { background: transparent; }
#log-output::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 4px; }

/* ========= Toast ========= */
.toast {
    position: fixed;
    bottom: -80px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    transition: bottom 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.06);
    backdrop-filter: blur(20px);
}

.toast.show { bottom: 40px; }
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }

/* ========= Loader ========= */
.loader {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    z-index: 9999;
    transition: opacity 0.5s;
}

.loader.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-elevated);
    border-top: 3px solid var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ========= Mini Chart (sparkline) ========= */
.sparkline-container {
    height: 40px;
    margin-top: 12px;
    opacity: 0.6;
}

.sparkline-container canvas {
    width: 100%;
    height: 100%;
}

/* ========= Activity Feed ========= */
.activity-filter {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
}

.activity-filter-btn {
    flex: 1;
    padding: 8px;
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.activity-filter-btn.active {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: rgba(99,102,241,0.3);
}

.activity-item {
    display: flex;
    gap: 12px;
    padding: 14px;
    margin-bottom: 8px;
    background: var(--gradient-card);
    border: 1px solid rgba(255,255,255,0.04);
    border-radius: var(--radius-sm);
    border-left: 3px solid transparent;
    animation: fadeIn 0.3s ease;
}

.activity-buy { border-left-color: var(--green); }
.activity-sell { border-left-color: var(--orange); }
.activity-signal { border-left-color: var(--accent); }
.activity-trail { border-left-color: var(--cyan); }
.activity-error { border-left-color: var(--red); }
.activity-skip { border-left-color: rgba(255,255,255,0.08); }
.activity-start { border-left-color: var(--accent); }
.activity-position { border-left-color: rgba(255,255,255,0.1); }

.activity-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 800;
    flex-shrink: 0;
    color: #fff;
}

.buy-icon { background: linear-gradient(135deg, #22c55e, #10b981); }
.sell-icon { background: linear-gradient(135deg, #f59e0b, #d97706); }
.signal-icon { background: linear-gradient(135deg, #6366f1, #8b5cf6); font-size: 16px; }
.trail-icon-act { background: linear-gradient(135deg, #06b6d4, #0891b2); }
.error-icon { background: linear-gradient(135deg, #ef4444, #dc2626); }
.skip-icon { background: #334155; color: var(--text-muted); }
.start-icon { background: linear-gradient(135deg, #6366f1, #8b5cf6); font-size: 12px; }
.position-icon { background: #1e293b; color: var(--text-secondary); font-size: 16px; }

.activity-body {
    flex: 1;
    min-width: 0;
}

.activity-title {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 3px;
}

.activity-detail {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
    word-break: break-word;
}

.activity-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ========= Responsive ========= */
@media (max-width: 360px) {
    .balance-amount { font-size: 34px; }
    .nav-item span { font-size: 10px; }
}
