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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #0b0e11;
    color: #eaecef;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 20px;
}

.container {
    width: 100%;
    max-width: 480px;
}

h1 {
    text-align: center;
    margin-bottom: 24px;
    font-size: 20px;
    color: #f0b90b;
}

.card {
    background: #1e2329;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 16px;
}

.card h2 {
    font-size: 16px;
    margin-bottom: 16px;
    color: #f0b90b;
}

/* Toggle switch for trading mode */
.mode-toggle {
    display: flex;
    background: #2b3139;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 16px;
}

.mode-toggle label {
    flex: 1;
    text-align: center;
    padding: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
    color: #848e9c;
}

.mode-toggle input[type="radio"] {
    display: none;
}

.mode-toggle input[type="radio"]:checked + label {
    background: #f0b90b;
    color: #0b0e11;
}

/* Form rows */
.form-group {
    margin-bottom: 14px;
}

.form-group > label {
    display: block;
    font-size: 12px;
    color: #848e9c;
    margin-bottom: 6px;
}

.form-row {
    display: flex;
    gap: 10px;
}

.form-row .form-group {
    flex: 1;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="date"],
select {
    width: 100%;
    padding: 10px 12px;
    background: #2b3139;
    border: 1px solid #3c4043;
    border-radius: 6px;
    color: #eaecef;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

input:focus, select:focus {
    border-color: #f0b90b;
}

/* Inline input + select row */
.input-with-select {
    display: flex;
    gap: 8px;
}

.input-with-select input {
    flex: 1;
}

.input-with-select select {
    width: 140px;
    flex-shrink: 0;
}

/* Read-only info rows */
.info-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 13px;
    border-bottom: 1px solid #2b3139;
}

.info-row .info-label {
    color: #848e9c;
}

.info-row .info-value {
    color: #eaecef;
    font-weight: 500;
}

/* Collapsible section */
.collapsible-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 12px 0;
    user-select: none;
}

.collapsible-header h3 {
    font-size: 14px;
    color: #848e9c;
}

.chevron {
    font-size: 12px;
    color: #848e9c;
    transition: transform 0.3s;
}

.chevron.open {
    transform: rotate(180deg);
}

.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.collapsible-content.open {
    max-height: 800px;
}

/* Checkbox rows */
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 13px;
}

.checkbox-row input[type="checkbox"] {
    accent-color: #f0b90b;
    width: 16px;
    height: 16px;
}

.sub-fields {
    margin-left: 24px;
    margin-bottom: 10px;
}

.sub-fields .form-group {
    margin-bottom: 8px;
}

/* Buttons */
.btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    margin-bottom: 8px;
}

.btn:hover {
    opacity: 0.85;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: #f0b90b;
    color: #0b0e11;
}

.btn-secondary {
    background: #2b3139;
    color: #eaecef;
    border: 1px solid #3c4043;
}

.btn-connect {
    background: #02c076;
    color: #fff;
}

/* Status indicators */
.status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    margin-bottom: 12px;
}

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

.status-dot.green {
    background: #02c076;
}

.status-dot.red {
    background: #f6465d;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #3c4043;
    border-top-color: #f0b90b;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

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

/* Result box */
.result-box {
    background: #2b3139;
    border-radius: 6px;
    padding: 12px;
    margin-top: 12px;
    font-size: 13px;
    white-space: pre-wrap;
    word-break: break-all;
}

.result-box.success {
    border-left: 3px solid #02c076;
}

.result-box.error {
    border-left: 3px solid #f6465d;
}

/* Divider */
.divider {
    height: 1px;
    background: #2b3139;
    margin: 20px 0;
}

/* Radio group */
.radio-group {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
}

.radio-group input[type="radio"] {
    accent-color: #f0b90b;
}

.hidden {
    display: none !important;
}

/* Profit display */
.profit-display {
    font-size: 14px;
    color: #02c076;
    font-weight: 500;
    padding: 8px 0;
}

/* TP/SL mode selector */
.tpsl-mode-selector {
    display: flex;
    background: #2b3139;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 10px;
}

.tpsl-mode-selector label {
    flex: 1;
    text-align: center;
    padding: 8px;
    cursor: pointer;
    font-size: 12px;
    color: #848e9c;
    transition: background 0.2s;
}

.tpsl-mode-selector input[type="radio"] {
    display: none;
}

.tpsl-mode-selector input[type="radio"]:checked + label {
    background: #3c4043;
    color: #eaecef;
}

/* Page header with help link */
.page-header {
    position: relative;
    margin-bottom: 24px;
}

.page-header h1 {
    margin-bottom: 0;
}

.help-link {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: 13px;
    color: #848e9c;
    text-decoration: none;
    padding: 6px 12px;
    border: 1px solid #2b3139;
    border-radius: 6px;
    transition: color 0.2s, border-color 0.2s;
}

.help-link:hover {
    color: #f0b90b;
    border-color: #f0b90b;
}

/* Help page (/help) */
.help-container {
    width: 100%;
    max-width: 760px;
    padding: 0 8px;
}

.help-header {
    margin-bottom: 24px;
    text-align: center;
}

.help-back {
    display: inline-block;
    font-size: 13px;
    color: #848e9c;
    text-decoration: none;
    margin-bottom: 12px;
}

.help-back:hover {
    color: #f0b90b;
}

.help-content {
    background: #1e2329;
    border-radius: 12px;
    padding: 32px 36px;
    font-size: 14px;
    line-height: 1.65;
    color: #eaecef;
}

.help-content h1,
.help-content h2,
.help-content h3 {
    color: #f0b90b;
    margin-top: 28px;
    margin-bottom: 12px;
    line-height: 1.3;
}

.help-content h1 { font-size: 22px; margin-top: 0; }
.help-content h2 { font-size: 18px; border-bottom: 1px solid #2b3139; padding-bottom: 6px; }
.help-content h3 { font-size: 15px; color: #eaecef; }

.help-content p {
    margin-bottom: 14px;
}

.help-content ul,
.help-content ol {
    margin: 0 0 14px 22px;
}

.help-content li {
    margin-bottom: 6px;
}

.help-content strong {
    color: #f0b90b;
    font-weight: 600;
}

.help-content code {
    background: #2b3139;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    color: #f0b90b;
}

.help-content pre {
    background: #0b0e11;
    border: 1px solid #2b3139;
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
    margin-bottom: 14px;
}

.help-content pre code {
    background: transparent;
    padding: 0;
    color: #eaecef;
}

.help-content a {
    color: #f0b90b;
    text-decoration: none;
}

.help-content a:hover {
    text-decoration: underline;
}

.help-content blockquote {
    border-left: 3px solid #f0b90b;
    padding: 8px 14px;
    margin: 14px 0;
    background: #2b3139;
    border-radius: 0 6px 6px 0;
    color: #b7bdc6;
}

.help-content hr {
    border: none;
    border-top: 1px solid #2b3139;
    margin: 24px 0;
}

.help-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
    font-size: 13px;
}

.help-content th,
.help-content td {
    padding: 8px 12px;
    border-bottom: 1px solid #2b3139;
    text-align: left;
}

.help-content th {
    color: #f0b90b;
    font-weight: 600;
    background: #2b3139;
}

/* ── Bot console ─────────────────────────────────────────────────── */

.bots-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}

.bots-header h1 {
    margin: 0;
    text-align: left;
    font-size: 22px;
}

.bots-header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.network-pill {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    background: #2b3139;
    color: #848e9c;
}

.network-pill.testnet { background: #2b3a4d; color: #4fa8ff; }
.network-pill.mainnet { background: #3d2326; color: #ff7676; }

.btn-link {
    background: transparent;
    border: 0;
    color: #848e9c;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
    padding: 4px 8px;
}

.btn-link:hover { color: #f0b90b; }

#logout-form { display: inline; margin: 0; padding: 0; }

.btn-secondary {
    background: #2b3139;
    color: #eaecef;
    border: 0;
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
}

.btn-secondary:hover { background: #3a4350; }

.bots-summary-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px 20px;
}

.bots-summary-label {
    font-size: 12px;
    color: #848e9c;
}

.bots-summary-value {
    font-size: 22px;
    font-weight: 600;
    color: #eaecef;
}

.bots-filters {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    margin-bottom: 12px;
    padding-bottom: 4px;
}

.filter-btn {
    background: transparent;
    border: 0;
    color: #848e9c;
    padding: 8px 12px;
    font-size: 14px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}

.filter-btn.active { color: #f0b90b; border-bottom-color: #f0b90b; }

.filter-btn .count {
    margin-left: 4px;
    background: #2b3139;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 11px;
    color: #eaecef;
}

.bots-list { display: flex; flex-direction: column; gap: 12px; }

.bot-card {
    background: #1e2329;
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: background 0.15s;
}

.bot-card:hover { background: #242a32; }

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

.bot-card-symbol {
    font-size: 16px;
    font-weight: 600;
}

.state-pill {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.state-pill.active   { background: #1d3a2c; color: #4caf72; }
.state-pill.inactive { background: #2b3139; color: #848e9c; }
.state-pill.failed   { background: #3d2326; color: #ff7676; }
.state-pill.unknown  { background: #2b3139; color: #848e9c; }

.bot-card-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin: 4px 0;
}

.bot-card-row .label { color: #848e9c; }
.bot-card-row .value { color: #eaecef; }
.value.profit-pos { color: #4caf72; }
.value.profit-neg { color: #ff7676; }

.bot-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.btn-stop {
    flex: 1;
    background: #3d2326;
    color: #ff7676;
    border: 0;
    border-radius: 6px;
    padding: 8px;
    cursor: pointer;
    font-size: 13px;
}

.empty-state {
    text-align: center;
    color: #848e9c;
    padding: 32px;
}

.hidden { display: none !important; }

.ws-status {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: #3d2326;
    color: #ff7676;
    padding: 6px 14px;
    border-radius: 14px;
    font-size: 12px;
}

/* ── Bot detail ──────────────────────────────────────────────────── */

.bot-detail-back {
    margin-bottom: 12px;
    font-size: 13px;
}

.bot-detail-back a { color: #848e9c; text-decoration: none; }

.bot-detail-header {
    padding: 20px;
}

.bot-detail-title {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.bot-detail-title h1 {
    margin: 0;
    font-size: 22px;
    color: #eaecef;
    text-align: left;
}

.bot-detail-badges {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.badge {
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    color: #848e9c;
    background: #2b3139;
}

.badge.badge-long { background: #1d3a2c; color: #4caf72; }
.badge.badge-short { background: #3d2326; color: #ff7676; }

.bot-detail-meta { color: #848e9c; font-size: 12px; }

.bot-detail-actions-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
}

.tab-bar {
    display: flex;
    gap: 4px;
    margin: 16px 0;
    overflow-x: auto;
    border-bottom: 1px solid #2b3139;
}

.tab-btn {
    background: transparent;
    border: 0;
    color: #848e9c;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
}

.tab-btn.active { color: #f0b90b; border-bottom-color: #f0b90b; }

.tab-panel { margin-bottom: 16px; }

.kv-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #2b3139;
    font-size: 14px;
}

.kv-row:last-child { border-bottom: 0; }

.kv-row > span:first-child { color: #848e9c; }
.kv-value { color: #eaecef; font-weight: 500; }

.details-section { padding: 8px 20px; }

.details-subhead {
    font-size: 14px;
    font-weight: 600;
    color: #eaecef;
    margin: 8px 0;
}

.details-footer .kv-value {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 12px;
    word-break: break-all;
}

.orders-grid {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 4px 12px;
    font-size: 13px;
}

.orders-grid .order-side { color: #848e9c; }
.orders-grid .order-side.buy { color: #4caf72; }
.orders-grid .order-side.sell { color: #ff7676; }

.history-list { display: flex; flex-direction: column; gap: 6px; }

.history-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #2b3139;
    font-size: 13px;
}

.history-row:last-child { border-bottom: 0; }

.muted { color: #848e9c; font-size: 13px; }

/* ── Modal ──────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.65);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
}

.modal {
    background: #1e2329;
    border-radius: 12px;
    padding: 24px;
    width: calc(100% - 32px);
    max-width: 400px;
}

.modal h2 { font-size: 18px; margin-bottom: 12px; color: #f0b90b; }
.modal p { font-size: 13px; color: #eaecef; margin-bottom: 12px; line-height: 1.5; }
.modal .modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal input[type=text] {
    width: 100%;
    background: #2b3139;
    border: 1px solid #3a4350;
    color: #eaecef;
    padding: 8px 10px;
    border-radius: 6px;
    margin: 8px 0;
}

/* ── Backtest fills table ────────────────────────────────────────── */

.fills-grid {
    display: grid;
    grid-template-columns: repeat(6, auto);
    gap: 6px 12px;
    font-size: 13px;
}

.fills-pager {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
}

.fills-pager .page-label {
    padding: 6px 8px;
}

.run-status-spacer {
    margin-top: 8px;
}

/* ── Backtest history list ───────────────────────────────────────── */

/*
 * Eight cells per row, each cell rendered as an anchor so the whole row
 * is keyboard-navigable + right-click "open in new tab"-able. Grid layout
 * stays in one shared track so columns align across runs even when one
 * cell wraps.
 */
.history-grid {
    display: grid;
    grid-template-columns:
        auto                  /* compare checkbox */
        auto                  /* started */
        auto                  /* symbol */
        auto                  /* range */
        auto                  /* grids */
        auto                  /* invest */
        auto                  /* span */
        auto                  /* status */
        1fr                   /* matched p&l */
        auto;                 /* download icon */
    gap: 6px 14px;
    font-size: 13px;
    align-items: center;
}

.history-download {
    color: #848e9c;
    text-decoration: none;
    font-size: 16px;
    padding: 0 4px;
}

.history-download:hover { color: #f0b90b; }

.history-download-cell {
    display: flex;
    justify-content: center;
}

.imported-badge-mini {
    margin-right: 4px;
}

.history-row-link {
    color: #eaecef;
    text-decoration: none;
    padding: 2px 0;
    border-bottom: 1px solid transparent;
}

.history-row-link:hover {
    border-bottom-color: #2b3139;
}

.compare-cb-cell {
    display: flex;
    justify-content: center;
}

.compare-cb-cell input[type="checkbox"] {
    accent-color: #f0b90b;
    cursor: pointer;
}

/* Sticky action bar — only visible when 1+ runs are checkbox-selected. */
.compare-bar {
    position: sticky;
    bottom: 16px;
    margin-top: 16px;
    background: #1e2329;
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.compare-bar .btn-primary.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* ── Backtest compare ────────────────────────────────────────────── */

.compare-varies {
    margin-top: 6px;
}

.compare-grid {
    display: grid;
    grid-template-columns: auto auto auto auto auto auto;
    gap: 6px 16px;
    font-size: 13px;
    align-items: center;
}

.compare-best {
    background: #1d3a2c;
    border-radius: 4px;
    padding: 2px 6px;
}

.compare-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    margin-right: 6px;
    vertical-align: middle;
}

.compare-warnings > div {
    margin-bottom: 4px;
}

.compare-warnings code {
    background: #2b3139;
    padding: 1px 4px;
    border-radius: 3px;
}

/* ── Backtest result page: notes + imported badge ──────────────── */

.result-header-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.result-meta {
    margin-top: 4px;
}

.result-actions {
    margin-top: 12px;
}

.imported-badge {
    background: #2b3a4d;
    color: #4fa8ff;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.notes-textarea {
    width: 100%;
    background: #0b0e11;
    color: #eaecef;
    border: 1px solid #2b3139;
    border-radius: 6px;
    padding: 8px;
    font-family: inherit;
    font-size: 13px;
    resize: vertical;
}

.notes-textarea:focus {
    outline: none;
    border-color: #f0b90b;
}

.notes-status {
    margin-top: 6px;
}

/* ── Login screen ────────────────────────────────────────────────── */

.login-container {
    width: 100%;
    max-width: 380px;
    margin: auto;
    background: #1e2329;
    border-radius: 12px;
    padding: 32px 24px;
}

.login-title {
    text-align: center;
    font-size: 24px;
    color: #f0b90b;
    margin-bottom: 4px;
}

.login-subtitle {
    text-align: center;
    color: #848e9c;
    font-size: 13px;
    margin-bottom: 24px;
}

.login-submit {
    width: 100%;
    margin-top: 8px;
}

.error-banner {
    background: #3d2326;
    color: #ff7676;
    border-left: 3px solid #cf304a;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 16px;
}
