:root {
    --bg: #f0f2f5;
    --card: #ffffff;
    --primary: #4a90d9;
    --primary-dark: #3a7bc8;
    --success: #27ae60;
    --danger: #e74c3c;
    --warning: #f39c12;
    --purple: #8e44ad;
    --text: #2c3e50;
    --text-light: #7f8c8d;
    --border: #e1e8ed;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --radius: 12px;
}

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

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

/* ── Header ── */
.header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.header h1 { font-size: 18px; font-weight: 600; }

/* ── Draw Info Bar (reference image style) ── */
.draw-bar {
    background: #fff;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 72px;
    gap: 16px;
}

/* Left — flag + period */
.draw-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 200px;
}
.draw-flag {
    width: 48px; height: 48px;
    border-radius: 50%;
    background: #f5f5f5;
    border: 2px solid #e0e0e0;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px;
}
.draw-period-info { display: flex; flex-direction: column; gap: 2px; }
.draw-period-title { font-size: 11px; color: var(--text-light); font-weight: 500; }
.draw-period-row { display: flex; align-items: baseline; gap: 4px; }
.draw-period-label { font-size: 12px; color: var(--text-light); }
.draw-period-num {
    font-size: 18px; font-weight: 700; color: var(--text);
    letter-spacing: 0.5px;
}

/* Center — countdown */
.draw-bar-center {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    justify-content: center;
}
.draw-cd-label { font-size: 13px; color: var(--text-light); white-space: nowrap; }
.draw-cd-box {
    display: flex;
    align-items: center;
    gap: 6px;
}
.draw-cd-digit {
    background: #2aa198;
    color: #fff;
    font-size: 26px;
    font-weight: 700;
    width: 52px; height: 52px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-variant-numeric: tabular-nums;
    letter-spacing: -1px;
    transition: background 0.3s;
}
.draw-cd-digit.pulse { background: #e74c3c; animation: cd-pulse 1s infinite; }
@keyframes cd-pulse { 0%,100%{opacity:1} 50%{opacity:0.6} }
.draw-cd-unit { font-size: 13px; color: var(--text-light); font-weight: 500; }
.draw-cd-waiting {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--warning);
    font-weight: 600;
    font-size: 14px;
    animation: cd-pulse 1.2s infinite;
}

/* Right — number balls + tags */
.draw-bar-right {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 280px;
    justify-content: flex-end;
}
.dbar-balls {
    display: flex;
    align-items: center;
    gap: 6px;
}
.dbar-num {
    background: #2aa198;
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    width: 38px; height: 38px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.dbar-sep { font-size: 14px; color: #aaa; font-weight: 600; }
.dbar-total {
    font-size: 20px;
    font-weight: 800;
    width: 42px; height: 42px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}
.dbar-total-big   { background: #2c3e50; }
.dbar-total-small { background: #2c3e50; }

.dbar-tags { display: flex; gap: 8px; }
.dbar-tag-size, .dbar-tag-parity {
    width: 36px; height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
}
.tag-big-c   { background: #2aa198; }
.tag-small-c { background: #3498db; }
.tag-odd-c   { background: #e67e22; }
.tag-even-c  { background: #8e44ad; }

/* ── Tabs ── */
.tabs {
    display: flex;
    background: var(--card);
    border-bottom: 2px solid var(--border);
    padding: 0 24px;
    gap: 4px;
}
.tabs button {
    padding: 12px 24px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-light);
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}
.tabs button:hover { color: var(--primary); }
.tabs button.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* ── Main ── */
.main { padding: 20px 24px; max-width: 1400px; margin: 0 auto; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Cards ── */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
}
.card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── Grid ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ── Metric cards ── */
.metrics { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.metric {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 20px;
    flex: 1;
    min-width: 160px;
}
.metric .label { font-size: 12px; color: var(--text-light); margin-bottom: 4px; }
.metric .value { font-size: 22px; font-weight: 700; }
.metric .value.green { color: var(--success); }
.metric .value.red { color: var(--danger); }
.metric .value.blue { color: var(--primary); }
.metric .value.orange { color: var(--warning); }

/* ── Forms ── */
.form-row {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 12px; color: var(--text-light); font-weight: 500; }
.form-group input, .form-group select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    width: 160px;
    outline: none;
    transition: border 0.2s;
}
.form-group input:focus, .form-group select:focus { border-color: var(--primary); }
.form-group input[type="checkbox"] { width: auto; }

.check-group {
    display: flex;
    gap: 16px;
    align-items: center;
}
.check-group label {
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

/* ── Buttons ── */
.btn {
    padding: 8px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #219a52; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #c0392b; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-group { display: flex; gap: 8px; }

/* ── Tables ── */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
th, td {
    padding: 10px 12px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}
th {
    background: #f8f9fa;
    font-weight: 600;
    color: var(--text-light);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
tr:hover { background: #f5f7fa; }
.cell-big { color: var(--danger); font-weight: 600; }
.cell-small { color: var(--primary); font-weight: 600; }
.cell-odd { color: var(--warning); font-weight: 600; }
.cell-even { color: var(--purple); font-weight: 600; }
.cell-win { background: #eafaf1; }
.cell-lose { background: #fdedec; }

/* ── Pagination ── */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    font-size: 14px;
}

/* ── Strategy cards ── */
#worker-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.strategy-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    border-left: 4px solid var(--border);
    transition: border-color 0.3s;
}
.strategy-card.running { border-left-color: var(--success); }
.strategy-card.stopped { border-left-color: var(--text-light); }

.strategy-card .header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.strategy-card .title {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.strategy-card .badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}
.badge-running { background: #eafaf1; color: var(--success); }
.badge-stopped { background: #f5f5f5; color: var(--text-light); }
.badge-real { background: #fdedec; color: var(--danger); }
.badge-sim { background: #eaf2fd; color: var(--primary); }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 500; cursor: default; }
.badge-ok      { background: #eafaf1; color: #27ae60; }
.badge-fail    { background: #fdedec; color: #e74c3c; }
.badge-pending { background: #fef9e7; color: #f39c12; }
.btn-warning   { background: #f39c12; color: #fff; border: none; }
.btn-warning:hover { background: #e67e22; }
.form-hint { font-size: 12px; color: var(--text-light); margin-top: 6px; }

.strategy-card .info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}
.strategy-card .info-item {
    font-size: 13px;
}
.strategy-card .info-item .k { color: var(--text-light); font-size: 11px; }
.strategy-card .info-item .v { font-weight: 600; }

/* ── Log ── */
.log-box {
    background: #1e1e2e;
    color: #cdd6f4;
    border-radius: 8px;
    padding: 12px;
    font-family: 'Menlo', 'Courier New', monospace;
    font-size: 12px;
    max-height: 220px;
    overflow-y: auto;
    line-height: 1.6;
}
.log-box .log-line { white-space: pre-wrap; word-break: break-all; }

/* ── Sequence ── */
.sequence-table td { font-family: 'Menlo', monospace; font-size: 13px; }

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-light);
    font-size: 14px;
}

/* ── Login screen ── */
.login-screen {
    display: none;
    position: fixed; inset: 0;
    background: linear-gradient(135deg, #1a237e 0%, #283593 40%, #1565c0 100%);
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 40px 36px;
    width: 380px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo {
    font-size: 36px; font-weight: 900;
    color: var(--primary);
    text-align: center;
    letter-spacing: 4px;
    margin-bottom: 4px;
}
.login-title {
    text-align: center; font-size: 15px; font-weight: 600;
    color: var(--text); margin-bottom: 4px;
}
.login-subtitle {
    text-align: center; font-size: 13px; color: var(--text-light);
    margin-bottom: 24px;
}
.login-error {
    background: #fdedec; color: var(--danger); border: 1px solid #f5b7b1;
    border-radius: 8px; padding: 8px 12px;
    font-size: 13px; margin-bottom: 8px;
}

/* ── Header user info ── */
.user-info { display:flex; align-items:center; gap:8px; }
.header-uname { font-weight:600; font-size:14px; }
.header-role {
    background:rgba(255,255,255,0.2); padding:2px 8px;
    border-radius:10px; font-size:11px;
}

/* ── Permission checkboxes ── */
.perm-checks {
    display: flex; flex-wrap: wrap; gap: 12px;
    margin-top: 6px;
}
.perm-checks label {
    font-size: 13px; display: flex; align-items: center; gap: 4px; cursor: pointer;
}

/* legacy tag classes kept for draws table */
.tag-big   { background: #e74c3c; color: #fff; }
.tag-small { background: #3498db; color: #fff; }
.tag-odd   { background: #f39c12; color: #fff; }
.tag-even  { background: #8e44ad; color: #fff; }

/* ── Strategy start/stop toggle buttons ── */
.btn-inactive {
    background: #c8cdd2 !important;
    color: #fff !important;
    cursor: not-allowed !important;
    opacity: 0.5;
    pointer-events: none !important;
}

/* ── Modal ── */
.modal-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: 0 8px 40px rgba(0,0,0,0.2);
    width: 480px;
    max-width: 96vw;
    animation: modal-in 0.18s ease;
}
@keyframes modal-in { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-light); padding: 0 4px; }
.modal-close:hover { color: var(--danger); }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px 18px; display: flex; gap: 10px; justify-content: flex-end; }
.mb12 { margin-bottom: 12px !important; }

/* ── Account balance display ── */
.balance-val { font-weight: 700; color: var(--success); }
.balance-time { font-size: 11px; color: var(--text-light); }

/* Toggle switch */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}
.toggle-label input[type="checkbox"] { display: none; }
.toggle-track {
    width: 40px; height: 22px;
    background: #ccc;
    border-radius: 11px;
    position: relative;
    transition: background .2s;
    flex-shrink: 0;
}
.toggle-track::after {
    content: '';
    position: absolute;
    top: 3px; left: 3px;
    width: 16px; height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: left .2s;
}
.toggle-label input:checked + .toggle-track { background: var(--primary); }
.toggle-label input:checked + .toggle-track::after { left: 21px; }
.toggle-text { font-size: 13px; font-weight: 600; color: var(--text); }

/* Mode hint under toggle */
.strat-mode-hint {
    font-size: 11px;
    margin-top: 4px;
    padding: 3px 7px;
    border-radius: 4px;
}
.strat-mode-hint.consecutive { background: #eafaf1; color: #27ae60; }
.strat-mode-hint.non-consecutive { background: #fef9e7; color: #e67e22; }

/* Mode badge in strategy card */
.mode-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
}
.mode-badge.consecutive { background: #eafaf1; color: #27ae60; }
.mode-badge.nonconsec   { background: #fef9e7; color: #e67e22; }

/* Strategy form — chase info panel */
.bet-seq-table {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.bet-seq-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 8px;
    min-width: 52px;
    font-size: 11px;
    gap: 1px;
}
.bet-seq-item b { font-size: 12px; color: var(--primary); }

/* Strategy preview win rate badge */
.strat-preview-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px;
}
.strat-preview-wr {
    font-size: 15px;
    font-weight: 800;
    white-space: nowrap;
}

/* Account scope badge */
.acc-scope-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 600;
}
.acc-scope-badge.admin {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffc107;
}
.acc-scope-badge.admin::before { content: '👑 '; }
.acc-scope-badge.user {
    background: #e8f4fd;
    color: #0c5460;
    border: 1px solid #bee5eb;
}
.acc-scope-badge.user::before { content: '👤 '; }

/* Small owner indicator shown in admin view */
.acc-owner-tag {
    font-size: 10px;
    color: #888;
    background: #f0f0f0;
    border-radius: 3px;
    padding: 1px 4px;
    margin-left: 2px;
}

/* ── Test bet result ── */
.bet-result { padding: 10px 14px; border-radius: 8px; font-size: 14px; font-weight: 500; margin-top: 12px; }
.bet-ok   { background: #eafaf1; color: #27ae60; border: 1px solid #a9dfbf; }
.bet-fail { background: #fdedec; color: #e74c3c; border: 1px solid #f5b7b1; }

/* ── Strategy form sections ── */
.form-section-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    border-left: 3px solid var(--primary);
    padding-left: 8px;
    margin: 14px 0 6px;
}
.form-section-title:first-child { margin-top: 4px; }

/* Strategy preview box */
.strat-preview-box {
    background: linear-gradient(135deg, #f0f4ff 0%, #e8f0fe 100%);
    border: 1px solid #c7d7fc;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--primary);
    font-weight: 500;
    min-height: 36px;
    display: flex;
    align-items: center;
}
.strat-chase-info {
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    min-height: 40px;
}

/* Chase direction badge in strategy cards */
.chase-dir-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
}
.chase-dir-badge.reverse {
    background: #fff3e0;
    color: #e65100;
}
.chase-dir-badge.same {
    background: #e8f5e9;
    color: #2e7d32;
}

/* ── Backtest modal ── */
.bt-modal {
    max-width: 820px;
    width: 95%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}
.bt-modal .modal-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}
.bt-modal .modal-header,
.bt-modal .modal-footer {
    flex-shrink: 0;
}
.bt-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}
.bt-stat {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 10px 8px;
    text-align: center;
    border: 1px solid #e9ecef;
}
.bt-stat-v {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}
.bt-stat-k {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 3px;
}
.bt-extra-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 0;
    background: #f0f4ff;
    border-radius: 7px;
    padding: 7px 12px;
    margin-bottom: 14px;
    font-size: 13px;
}
.bt-ex-item { display: flex; align-items: center; gap: 4px; }
.bt-ex-k { color: var(--text-light); }
.bt-ex-v { font-weight: 700; }
.bt-ex-sep { color: #ccc; margin: 0 10px; }
.bt-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
}
.bt-chart-wrap {
    position: relative;
    height: 200px;
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    margin-bottom: 4px;
}
.bt-trades-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
    margin-bottom: 8px;
}
.bt-trades-filter {
    display: flex;
    gap: 6px;
    align-items: center;
}
.bt-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 0 2px;
    flex-wrap: wrap;
}
.bt-pagination button {
    min-width: 32px;
    height: 30px;
    padding: 0 8px;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    color: var(--text);
    transition: all 0.15s;
}
.bt-pagination button:hover:not(:disabled) {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.bt-pagination button.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    font-weight: 700;
}
.bt-pagination button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.bt-pagination .bt-page-info {
    font-size: 12px;
    color: var(--text-light);
    padding: 0 8px;
}
.es-warn {
    background: #fff8e1;
    border: 1px solid #ffe082;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
    color: #8d6e00;
    margin-bottom: 14px;
    line-height: 1.5;
}
.bt-info-card {
    background: linear-gradient(135deg, #f0f4ff 0%, #f8f9fa 100%);
    border: 1px solid #d6e0f5;
    border-radius: 10px;
    padding: 14px 16px;
}
.bt-info-card .bt-info-name {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
    margin-bottom: 8px;
}
.bt-info-card .bt-info-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
}
.bt-info-card .bt-info-tag {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 600;
    background: #e8edf5;
    color: var(--text);
}
.bt-info-card .bt-info-params {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 4px 12px;
    font-size: 12px;
    color: var(--text-light);
}
.bt-info-card .bt-info-params b {
    color: var(--text);
}

/* ── Worker card chart redesign ── */

/* Compact metrics strip */
.wcard-metrics-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    background: #f8f9fa;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 14px;
    border: 1px solid var(--border);
}
.wms-item {
    flex: 1;
    min-width: 80px;
    padding: 8px 10px;
    text-align: center;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.wms-item:last-child { border-right: none; }
.wms-k {
    font-size: 11px;
    color: var(--text-light);
    margin-bottom: 3px;
    white-space: nowrap;
}
.wms-v {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}
.wms-v.green { color: var(--success); }
.wms-v.red   { color: var(--danger); }

/* Chart section: equity (left) + side panel (right) */
.wcard-chart-section {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 14px;
    min-height: 0;
}

/* Equity curve panel */
.wcard-chart-equity {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
}
.wchart-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.wchart-wrap {
    flex: 1;
    position: relative;
    min-height: 150px;
}
.wchart-wrap canvas { position: absolute; inset: 0; }
.wchart-empty {
    position: absolute; inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    font-size: 13px;
}

/* Stats row below equity chart */
.equity-stats-row {
    display: flex;
    gap: 0;
    margin-top: 8px;
    border-top: 1px solid var(--border);
    padding-top: 8px;
    flex-wrap: wrap;
}
.est-item {
    flex: 1;
    text-align: center;
    padding: 0 8px;
    border-right: 1px solid var(--border);
}
.est-item:last-child { border-right: none; }
.est-k {
    display: block;
    font-size: 10px;
    color: var(--text-light);
    margin-bottom: 2px;
}
.est-v {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
}
.est-v.green { color: var(--success); }
.est-v.red   { color: var(--danger); }

/* Side panel: win rate + recent bets */
.wcard-chart-side {
    width: 100%;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
}

/* Win rate panel */
.winrate-panel {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    flex: 1;
    min-width: 150px;
}
.winrate-donut-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
}
.winrate-canvas-box {
    position: relative;
    width: 90px;
    height: 90px;
    flex-shrink: 0;
}
.winrate-canvas-box canvas { position: absolute; inset: 0; }
.winrate-center-text {
    position: absolute; inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.wr-num {
    font-size: 18px;
    font-weight: 800;
    line-height: 1;
}
.wr-label {
    font-size: 10px;
    color: var(--text-light);
    margin-top: 2px;
}
.winrate-legend { display: flex; flex-direction: column; gap: 6px; }
.wrl-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text); }
.wrl-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* Recent bets panel */
.recent-bets-panel {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    flex: 1;
    min-width: 150px;
    overflow: hidden;
}
.recent-bets-panel .table-wrap table { min-width: unset; }
.row-win { background: #f0faf4; }
.row-lose { background: #fdf3f3; }

/* Log + Martingale row */
.wcard-details-row {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.wcard-log {
    flex: 1;
    min-width: 0;
}
.wcard-martingale {
    width: 100%;
}

/* ── CAPTCHA ── */
.captcha-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}
.captcha-question-box {
    display: flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, #f0f4ff, #e8f0fe);
    border: 1px solid #c7d7fc;
    border-radius: 8px;
    padding: 8px 12px;
    white-space: nowrap;
    flex-shrink: 0;
}
.captcha-q {
    font-size: 17px;
    font-weight: 700;
    color: #1a237e;
    letter-spacing: 1px;
}
.captcha-refresh {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--primary);
    padding: 0 2px;
    line-height: 1;
    transition: transform 0.3s;
}
.captcha-refresh:hover { transform: rotate(180deg); }

/* ── Table wrapper for horizontal scroll ── */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table-wrap table { min-width: 560px; }

/* ── Mobile: base overrides ── */
@media (max-width: 768px) {
    /* Header */
    .header {
        padding: 10px 14px;
        flex-wrap: wrap;
        gap: 6px;
    }
    .header h1 { font-size: 15px; flex: 1; min-width: 0; }
    .user-info { gap: 6px; font-size: 13px; }
    .header-uname { font-size: 13px; }

    /* Draw bar — stack layout */
    .draw-bar {
        flex-wrap: wrap;
        height: auto;
        padding: 10px 12px;
        gap: 8px 16px;
    }
    .draw-bar-left  { min-width: unset; flex: 1; }
    .draw-bar-right { min-width: unset; flex: 1; justify-content: flex-end; }
    .draw-bar-center {
        order: 3;
        width: 100%;
        justify-content: center;
        padding: 4px 0;
        border-top: 1px solid var(--border);
    }
    .draw-cd-digit  { width: 40px; height: 40px; font-size: 20px; }
    .draw-flag      { width: 36px; height: 36px; font-size: 18px; }
    .dbar-num       { width: 30px; height: 30px; font-size: 14px; }
    .dbar-total     { width: 34px; height: 34px; font-size: 16px; }
    .dbar-sep       { font-size: 12px; }
    .dbar-tag-size, .dbar-tag-parity { width: 30px; height: 30px; font-size: 12px; }

    /* Tabs — horizontal scroll */
    .tabs {
        padding: 0 10px;
        gap: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .tabs::-webkit-scrollbar { display: none; }
    .tabs button {
        padding: 10px 14px;
        font-size: 13px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Main padding */
    .main { padding: 10px 10px; }

    /* Cards */
    .card { padding: 14px; }
    .card h3 { font-size: 14px; }

    /* Grids */
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .metrics { gap: 10px; }
    .metric  { padding: 12px 14px; min-width: unset; }
    .metric .value { font-size: 20px; }

    /* Forms — single column */
    .form-row {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .form-group input,
    .form-group select { width: 100%; box-sizing: border-box; }

    /* Strategy cards */
    #worker-cards { grid-template-columns: 1fr; }
    .strategy-card { padding: 14px; }
    .strategy-card .header-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .strategy-card .title { font-size: 14px; flex-wrap: wrap; }
    .strategy-card .btn-group { flex-wrap: wrap; gap: 6px; }
    .strategy-card .info-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Worker card charts */
    .wms-item { min-width: 33.3%; }
    .winrate-panel, .recent-bets-panel { flex: 1; min-width: 150px; }
    .equity-stats-row { gap: 4px; }
    .est-item { min-width: 45%; }

    /* Login */
    .login-card {
        width: calc(100vw - 32px);
        padding: 28px 20px;
    }
    .captcha-row { flex-direction: row; }
    .captcha-row .form-group { flex: 1; }

    /* Buttons */
    .btn-sm { padding: 7px 10px; font-size: 12px; }

    /* Modals — near fullscreen on mobile */
    .modal {
        width: calc(100vw - 16px) !important;
        max-width: unset !important;
        max-height: 90vh;
        overflow-y: auto;
        border-radius: 12px 12px 0 0;
        margin-top: auto;
    }
    .bt-modal {
        overflow-y: hidden;
    }
    .modal-overlay { align-items: flex-end; }
    @keyframes modal-in { from { transform: translateY(60px); opacity:0; } to { transform: translateY(0); opacity:1; } }

    /* Backtest stats */
    .bt-stats-grid { grid-template-columns: repeat(2, 1fr); }
    .bt-extra-row { font-size: 12px; }
    .bt-ex-sep { margin: 0 6px; }
    .bt-chart-wrap { height: 160px; }

    /* Form section title */
    .form-section-title { margin-top: 10px; }
}

/* ── Very small screens (≤ 400px) ── */
@media (max-width: 400px) {
    .draw-bar-right { justify-content: flex-start; }
    .dbar-num { width: 26px; height: 26px; font-size: 12px; }
    .dbar-total { width: 30px; height: 30px; font-size: 14px; }
    .header h1 { font-size: 13px; }
    .tabs button { padding: 8px 11px; font-size: 12px; }
}
