:root {
    --bg: #070c17;
    --panel: #0e1626;
    --panel-2: #121d33;
    --border: rgba(255,255,255,0.08);
    --text: #e8edf7;
    --text-dim: #7d8bab;
    --green: #12d9a3;
    --green-soft: rgba(18,217,163,0.14);
    --red: #ff5d7a;
    --red-soft: rgba(255,93,122,0.14);
    --cyan: #29b6f6;
    --cyan-soft: rgba(41,182,246,0.14);
    --blue: #3b82f6;
    --blue-soft: rgba(59,130,246,0.16);
    --gold: #f5a524;
    --gold-soft: rgba(245,165,36,0.15);
}

:root[data-theme="light"] {
    --bg: #eef2f8;
    --panel: #ffffff;
    --panel-2: #f5f8fc;
    --border: #e1e7f0;
    --text: #172234;
    --text-dim: #667089;
    --green: #04a56b;
    --green-soft: #d7f7ea;
    --red: #d8264e;
    --red-soft: #fbdde4;
    --cyan: #0092c7;
    --cyan-soft: #dcf3fc;
    --blue: #2f6fed;
    --blue-soft: #e3ecfe;
    --gold: #b5790a;
    --gold-soft: #fbeed3;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, sans-serif;
    height: 100%;
    overflow-x: hidden;
    transition: background 0.2s ease, color 0.2s ease;
    -webkit-font-smoothing: antialiased;
}

/* ---------------- animated ticker background (subtle) ---------------- */
#ticker-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
    background:
        radial-gradient(ellipse at 15% 15%, rgba(41,182,246,0.06), transparent 55%),
        radial-gradient(ellipse at 85% 85%, rgba(18,217,163,0.05), transparent 55%),
        var(--bg);
}
.ticker-row {
    position: absolute;
    left: 0;
    white-space: nowrap;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    letter-spacing: 1px;
    opacity: 0.045;
    user-select: none;
}
:root[data-theme="light"] .ticker-row { opacity: 0.055; }
.ticker-row span.buy { color: var(--green); }
.ticker-row span.sell { color: var(--red); }
.ticker-row.r1 { top: 8%;  font-size: 20px; animation: scrollLeft 48s linear infinite; }
.ticker-row.r2 { top: 24%; font-size: 15px; animation: scrollRight 62s linear infinite; }
.ticker-row.r3 { top: 42%; font-size: 24px; animation: scrollLeft 75s linear infinite; }
.ticker-row.r4 { top: 61%; font-size: 16px; animation: scrollRight 54s linear infinite; }
.ticker-row.r5 { top: 79%; font-size: 19px; animation: scrollLeft 68s linear infinite; }
.ticker-row.r6 { top: 93%; font-size: 14px; animation: scrollRight 46s linear infinite; }

@keyframes scrollLeft {
    from { transform: translateX(0%); }
    to   { transform: translateX(-50%); }
}
@keyframes scrollRight {
    from { transform: translateX(-50%); }
    to   { transform: translateX(0%); }
}

/* subtle diagonal trend lines, like a faint chart backdrop */
.diag-line {
    position: absolute;
    width: 380px;
    height: 1.5px;
    opacity: 0.12;
}
.diag-line.up { background: linear-gradient(90deg, transparent, var(--green), transparent); }
.diag-line.down { background: linear-gradient(90deg, transparent, var(--red), transparent); }
.diag-line.d1 { top: 10%; left: -20%; transform: rotate(-12deg); animation: diagMoveRight 34s linear infinite; }
.diag-line.d2 { top: 34%; left: -20%; transform: rotate(9deg);   animation: diagMoveRight 42s linear infinite; animation-delay: -10s; }
.diag-line.d3 { top: 58%; left: -20%; transform: rotate(-15deg); animation: diagMoveRight 38s linear infinite; animation-delay: -22s; }
.diag-line.d4 { top: 76%; left: -20%; transform: rotate(11deg);  animation: diagMoveRight 46s linear infinite; animation-delay: -6s; }
.diag-line.d5 { top: 90%; left: -20%; transform: rotate(-9deg);  animation: diagMoveRight 40s linear infinite; animation-delay: -28s; }

@keyframes diagMoveRight {
    from { left: -25%; }
    to   { left: 110%; }
}

/* ---------------- layout ---------------- */
#app {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ---------------- top bar ---------------- */
#topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 28px;
    background: rgba(14,22,38,0.86);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
}
:root[data-theme="light"] #topbar { background: rgba(255,255,255,0.88); }

.brand-row { display: flex; align-items: center; gap: 14px; }
.brand-logo {
    width: 38px; height: 38px; border-radius: 10px;
    background: linear-gradient(135deg, var(--cyan), var(--green));
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; color: #04121c; font-size: 16px;
}
.brand-text .name { font-size: 15px; font-weight: 700; letter-spacing: 0.2px; color: var(--text); }
.brand-text .tag { font-size: 11px; color: var(--text-dim); margin-top: 1px; }

.global-status-pill {
    display: inline-flex; align-items: center; gap: 8px;
    font-size: 12.5px; font-weight: 500; padding: 7px 14px; border-radius: 20px;
    border: 1px solid var(--border); color: var(--text-dim); margin-left: 22px;
}
.global-status-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); }
.global-status-pill.on { color: var(--green); border-color: var(--green-soft); background: var(--green-soft); }
.global-status-pill.on .dot { background: var(--green); animation: pulse 1.6s infinite; }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.icon-btn {
    width: 38px; height: 38px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    background: var(--panel-2); border: 1px solid var(--border);
    cursor: pointer; color: var(--text-dim); font-size: 15px; position: relative;
    transition: color 0.15s, border-color 0.15s;
}
.icon-btn:hover { color: var(--cyan); border-color: var(--cyan); }
#alerts-btn {
    width: auto; padding: 0 12px; gap: 6px; font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.notif-badge {
    position: absolute; top: -5px; right: -5px;
    background: var(--red); color: #fff; font-size: 10px; font-weight: 700;
    min-width: 17px; height: 17px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
    padding: 0 3px;
}
.clock { color: var(--text-dim); font-size: 12.5px; margin-left: 4px; }

.dropdown-panel {
    position: absolute; top: 54px; right: 28px; width: 340px; max-height: 420px; overflow-y: auto;
    background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: 0 14px 40px rgba(0,0,0,0.35);
    display: none; z-index: 40; padding: 8px 0;
}
.dropdown-panel.open { display: block; }
.dropdown-panel h4 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); padding: 8px 16px; margin: 0; font-weight: 600; }
.notif-item { padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.notif-item:last-child { border-bottom: none; }
.notif-item .ev { font-weight: 700; font-size: 11.5px; letter-spacing: 0.3px; }
.notif-item .ev.pos { color: var(--green); }
.notif-item .ev.neg { color: var(--red); }
.notif-item .ev.neutral { color: var(--cyan); }
.notif-item .detail { color: var(--text-dim); margin-top: 3px; line-height: 1.4; }
.notif-item .time { color: var(--text-dim); font-size: 11px; margin-top: 4px; opacity: 0.8; }

/* ---------------- app body layout ---------------- */
#body-wrap { display: flex; flex: 1; width: 100%; }

#sidebar {
    width: 230px;
    flex-shrink: 0;
    background: rgba(14,22,38,0.7);
    border-right: 1px solid var(--border);
    backdrop-filter: blur(6px);
    display: flex;
    flex-direction: column;
    padding: 18px 0;
}
:root[data-theme="light"] #sidebar { background: rgba(255,255,255,0.7); }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    cursor: pointer;
    color: var(--text-dim);
    font-size: 13.5px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all 0.15s ease;
}
.nav-item:hover { color: var(--text); background: rgba(127,127,127,0.06); }
.nav-item.active { color: var(--cyan); border-left-color: var(--cyan); background: var(--cyan-soft); }
.nav-item .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--text-dim); flex-shrink: 0;
}
.nav-item .dot.live { background: var(--green); animation: pulse 1.6s infinite; }
.nav-item .dot.off { background: var(--red); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

#main {
    flex: 1;
    min-width: 0;
    padding: 24px 28px 40px;
    overflow-y: auto;
    overflow-x: hidden;
}

.view-title {
    font-size: 19px;
    font-weight: 700;
    margin: 0 0 18px 0;
    color: var(--text);
}

/* summary cards */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px 20px;
    cursor: default;
    transition: transform 0.15s ease, border-color 0.15s ease;
}
.card.clickable { cursor: pointer; }
.card.clickable:hover { transform: translateY(-2px); border-color: var(--cyan); }
.card .top-row { display: flex; align-items: center; gap: 10px; }
.card .icon {
    width: 38px; height: 38px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; flex-shrink: 0;
}
.card:nth-child(1) .icon { background: var(--blue-soft); }
.card:nth-child(2) .icon { background: var(--cyan-soft); }
.card:nth-child(3) .icon { background: var(--gold-soft); }
.card:nth-child(4) .icon { background: var(--red-soft); }
.card:nth-child(5) .icon { background: var(--green-soft); }
.card .label { font-size: 12.5px; color: var(--text-dim); font-weight: 500; }
.card .value { font-size: 24px; font-weight: 700; margin-top: 12px; letter-spacing: -0.3px; }
.card .sub { font-size: 11.5px; color: var(--text-dim); margin-top: 5px; }
.value.pos { color: var(--green); }
.value.neg { color: var(--red); }
.value.neutral { color: var(--text); }

/* bot account card */
.bot-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px 26px;
    margin-bottom: 20px;
    position: relative;
    overflow: hidden;
}
.bot-card::before {
    content: "";
    position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
    background: var(--red);
}
.bot-card.live::before { background: var(--green); }

.bot-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 10px; }
.bot-name {
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    color: var(--text);
    transition: color 0.15s;
}
.bot-name:hover { color: var(--cyan); }
.bot-sub { color: var(--text-dim); font-size: 12px; margin-top: 4px; }

.status-badge {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
    padding: 6px 14px;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.status-badge.live { color: var(--green); background: var(--green-soft); }
.status-badge.off { color: var(--red); background: var(--red-soft); }
.status-badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-badge.live .dot { animation: pulse 1.4s infinite; }

.bot-stats { display: flex; gap: 30px; margin-top: 16px; flex-wrap: wrap; }
.stat .label { font-size: 11.5px; color: var(--text-dim); font-weight: 500; }
.stat .val { font-size: 18px; font-weight: 700; margin-top: 4px; }
.stat .val.pos { color: var(--green); }
.stat .val.neg { color: var(--red); }
.stat .val.neutral { color: var(--text); }

.bot-stats.outcome-row { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); gap: 26px; }
.stat.clickable { cursor: pointer; border-radius: 8px; padding: 4px 8px; margin: -4px -8px; transition: background 0.15s; }
.stat.clickable:hover { background: var(--panel-2); }

/* clickable trade rows + inline "why" panel */
.trade-row { cursor: pointer; }
.trade-row:hover td { background: rgba(127,127,127,0.07); }
.reason-row td { padding: 0; border-bottom: 1px solid var(--border); }
.reason-box { background: var(--panel-2); padding: 12px 16px; font-size: 12.5px; }
.reason-box.empty { color: var(--text-dim); font-style: italic; }
.reason-fields { color: var(--text); margin-bottom: 6px; line-height: 1.7; }
.reason-text { color: var(--text-dim); line-height: 1.6; }

.bot-actions { margin-top: 18px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.toggle-btn {
    font-weight: 600;
    font-size: 12.5px;
    padding: 10px 22px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: opacity 0.15s;
}
.toggle-btn:hover { opacity: 0.88; }
.toggle-btn.start { background: var(--green); color: #04231b; }
.toggle-btn.stop { background: var(--red); color: #2b0710; }

.link-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 10px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12.5px;
    font-family: 'Inter', sans-serif;
}
.link-btn:hover { color: var(--cyan); border-color: var(--cyan); }

/* ---------------- dashboard 2-col row: positions + trade panel ---------------- */
.dash-row {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
    gap: 16px;
    margin-bottom: 18px;
    align-items: start;
}
@media (max-width: 980px) { .dash-row { grid-template-columns: minmax(0, 1fr); } }

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px 22px;
    min-width: 0;
    overflow-x: auto;
}
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.panel-header h3 { font-size: 14px; font-weight: 700; margin: 0; color: var(--text); }
.panel-header .view-all { font-size: 12px; color: var(--cyan); cursor: pointer; font-weight: 500; }

/* ---------------- manual trade panel ---------------- */
.trade-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.trade-tab {
    flex: 1; text-align: center; padding: 9px 0; border-radius: 8px;
    border: 1px solid var(--border); color: var(--text-dim); cursor: pointer; font-size: 12.5px; font-weight: 600;
}
.trade-tab.active-buy { background: var(--green); color: #04231b; border-color: var(--green); }
.trade-tab.active-sell { background: var(--red); color: #2b0710; border-color: var(--red); }

.field-label { font-size: 11.5px; color: var(--text-dim); font-weight: 500; margin: 12px 0 6px; }
.select, .text-input {
    width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
    padding: 10px 12px; border-radius: 8px; font-family: 'Inter', sans-serif; font-size: 13px;
}
:root[data-theme="light"] .select, :root[data-theme="light"] .text-input { background: #f7f9fd; }
.login-error { color: var(--red); font-size: 12.5px; margin-top: 10px; }
#user-nav-btn.admin-active { color: var(--green); }
#user-nav-btn.admin-active .dot, #user-nav-icon { flex-shrink: 0; }

.order-type-tabs { display: flex; gap: 6px; margin-top: 6px; }
.ot-tab {
    padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border);
    color: var(--text-dim); font-size: 11.5px; font-weight: 500; cursor: pointer;
}
.ot-tab.active { color: var(--cyan); border-color: var(--cyan); background: var(--cyan-soft); }

.pct-row { display: flex; gap: 6px; margin-top: 8px; }
.pct-btn {
    flex: 1; text-align: center; padding: 7px 0; border-radius: 6px;
    border: 1px solid var(--border); color: var(--text-dim); font-size: 11.5px; font-weight: 500; cursor: pointer;
}
.pct-btn:hover { border-color: var(--cyan); color: var(--cyan); }

.place-order-btn {
    width: 100%; margin-top: 16px; padding: 13px 0; border-radius: 10px; border: none;
    font-size: 13.5px; font-weight: 700; cursor: pointer;
}
.place-order-btn.buy { background: var(--green); color: #04231b; }
.place-order-btn.sell { background: var(--red); color: #2b0710; }
.place-order-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.trade-msg { margin-top: 10px; font-size: 12px; text-align: center; min-height: 16px; }
.trade-msg.ok { color: var(--green); }
.trade-msg.err { color: var(--red); }

.sltp-row { display: flex; gap: 10px; }
.sltp-row > div { flex: 1; }

.console-title-row { display: flex; align-items: center; justify-content: space-between; }
.console-title-row .view-title { margin-bottom: 0; }

/* console view */
#console-view {
    background: #050a13;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px;
    height: 70vh;
    overflow-y: auto;
    font-family: 'Roboto Mono', monospace;
    font-size: 12.5px;
    line-height: 1.6;
    white-space: pre-wrap;
    color: #8fe3c0;
}

.log-line { padding: 1px 0; }
.log-trade { color: var(--green); font-weight: 700; }
.log-missed { color: var(--gold); font-weight: 700; }
.log-notrade { color: var(--red); opacity: 0.85; }
.log-order { color: var(--green); font-weight: 700; }
.log-error { color: var(--red); font-weight: 700; }
.log-sep { border-top: 1px solid var(--border); margin: 6px 0; height: 0; }
.log-header { color: var(--cyan); font-weight: 700; margin-top: 4px; }
.log-reason { color: var(--text-dim); padding-left: 6px; }
.log-field { color: #8fe3c0; opacity: 0.9; }

/* modal */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.65);
    display: none; align-items: center; justify-content: center; z-index: 50;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: min(820px, 92vw);
    max-height: 82vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px 28px;
}
.modal-box.wide { width: min(1160px, 96vw); }
#history-content table td, #history-content table th { white-space: nowrap; }
#history-content table td:first-child, #history-content table th:first-child {
    max-width: 170px; overflow: hidden; text-overflow: ellipsis;
}
#accounts-content table td, #accounts-content table th { white-space: nowrap; }
.modal-box h2 {
    font-size: 16px;
    font-weight: 700;
    margin-top: 0;
    color: var(--text);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-close { cursor: pointer; color: var(--text-dim); font-size: 20px; }
.modal-close:hover { color: var(--red); }

table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 6px; }
th { text-align: left; color: var(--text-dim); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.4px; }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
tr:hover td { background: rgba(127,127,127,0.04); }
.pnl-pos { color: var(--green); font-weight: 600; }
.pnl-neg { color: var(--red); font-weight: 600; }
.pill { padding: 3px 10px; border-radius: 5px; font-size: 11px; font-weight: 700; display: inline-block; }
.pill.buy { background: var(--green-soft); color: var(--green); }
.pill.sell { background: var(--red-soft); color: var(--red); }

.close-btn {
    background: var(--red-soft);
    color: var(--red);
    border: 1px solid var(--red);
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    white-space: nowrap;
}
.close-btn:hover { background: var(--red); color: #2b0710; }
.close-btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

/* ---------------- settings modal ---------------- */
.settings-profile { display: flex; align-items: center; gap: 16px; margin: 18px 0 14px; }
.profile-avatar {
    width: 58px; height: 58px; border-radius: 50%; flex-shrink: 0;
    background: linear-gradient(135deg, var(--cyan), var(--green));
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; color: #04121c; font-size: 20px; letter-spacing: 0.5px;
}
.profile-name { font-size: 16px; font-weight: 700; color: var(--text); }
.profile-role { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }
.settings-bio { font-size: 13px; line-height: 1.65; color: var(--text-dim); margin: 0 0 20px; }
.settings-section { margin-bottom: 18px; }
.settings-section h4 {
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim);
    font-weight: 700; margin: 0 0 10px;
}
.settings-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.settings-row:last-child { border-bottom: none; }
.settings-row span:last-child { color: var(--text); font-weight: 600; }
.settings-action-btn {
    display: block; width: 100%; text-align: left; margin-bottom: 8px;
    padding: 10px 14px; border-radius: 8px; font-size: 13px; font-weight: 600;
    background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
    cursor: pointer; transition: border-color 0.15s, color 0.15s;
}
.settings-action-btn:hover { border-color: var(--cyan); color: var(--cyan); }
.settings-action-btn:disabled { opacity: 0.6; cursor: default; color: var(--green); border-color: var(--green-soft); }
.settings-action-btn:last-child { margin-bottom: 0; }
