:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #1e2130;
    --bg-input: #252838;
    --border-color: #2d3148;
    --text-primary: #e8eaed;
    --text-secondary: #9ba1b0;
    --text-tertiary: #6b7185;
    --accent-primary: #3b82f6;
    --accent-primary-hover: #2563eb;
    --accent-success: #22c55e;
    --accent-success-muted: rgba(34, 197, 94, 0.15);
    --accent-danger: #ef4444;
    --accent-danger-muted: rgba(239, 68, 68, 0.15);
    --accent-warning: #f59e0b;
    --accent-warning-muted: rgba(245, 158, 11, 0.15);
    --accent-info: #6366f1;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --radius: 8px;
}

[data-theme="light"] {
    --bg-primary: #f3f4f6;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #f9fafb;
    --border-color: #e0e2e8;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.header-left h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.subtitle {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent-success);
    background: var(--accent-success-muted);
    padding: 3px 10px;
    border-radius: 20px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-tertiary);
}

.status-badge.connected .status-dot { background: var(--accent-success); }
.status-badge.trading .status-dot { background: var(--accent-warning); animation: pulse 1.5s infinite; }
.status-badge.error .status-dot { background: var(--accent-danger); }
.status-badge.connecting .status-dot { background: var(--accent-info); animation: pulse 1s infinite; }

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

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
    background: var(--bg-input);
    color: var(--text-primary);
}

main {
    flex: 1;
    padding: 20px 24px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

.grid-layout {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 20px;
}

@media (max-width: 900px) {
    .grid-layout {
        grid-template-columns: 1fr;
    }
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
}

.card + .card {
    margin-top: 16px;
}

.card-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
}

.card-header h2 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body {
    padding: 16px 18px;
}

.form-group {
    margin-bottom: 14px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.input-group {
    display: flex;
    gap: 6px;
}

.input-group input {
    flex: 1;
}

input, select {
    width: 100%;
    padding: 9px 12px;
    font-size: 0.875rem;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    outline: none;
    transition: border-color 0.15s;
}

input:focus, select:focus {
    border-color: var(--accent-primary);
}

input:disabled, select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.info-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-success);
    padding: 6px 0;
}

.info-hint {
    font-size: 0.7rem;
    color: var(--text-tertiary);
}

.button-row {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.btn {
    flex: 1;
    padding: 10px 16px;
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

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

.btn-primary {
    background: var(--accent-primary);
    color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-primary-hover); }

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
.btn-secondary:hover:not(:disabled) { background: var(--border-color); }

.btn-success {
    background: var(--accent-success);
    color: #fff;
}
.btn-success:hover:not(:disabled) { background: #16a34a; }

.btn-danger {
    background: var(--accent-danger);
    color: #fff;
}
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.error-message {
    padding: 10px 14px;
    margin-bottom: 12px;
    background: var(--accent-danger-muted);
    border: 1px solid var(--accent-danger);
    border-radius: var(--radius);
    color: var(--accent-danger);
    font-size: 0.8rem;
}

.auto-rules {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border-color);
}

.auto-rules h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.rule-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    font-size: 0.825rem;
    color: var(--text-secondary);
}

.rule-icon {
    font-size: 0.65rem;
    width: 16px;
    text-align: center;
}

.profit-icon { color: var(--accent-success); }
.loss-icon { color: var(--accent-danger); }
.max-icon { color: var(--accent-warning); }
.target-icon { color: var(--accent-info); font-size: 0.8rem; }

.strategy-list {
    list-style: none;
    padding: 0;
}

.strategy-list li {
    padding: 6px 0;
    font-size: 0.825rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    padding-left: 14px;
    position: relative;
}

.strategy-list li:last-child {
    border-bottom: none;
}

.strategy-list li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--accent-primary);
}

.target-reached-banner {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    background: var(--accent-success-muted);
    border: 1px solid var(--accent-success);
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.target-reached-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-success);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
    flex-shrink: 0;
}

.target-reached-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent-success);
    margin-bottom: 2px;
}

.target-reached-detail {
    font-size: 0.825rem;
    color: var(--text-secondary);
}

.session-progress-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 16px;
}

.session-progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.session-progress-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.session-progress-values {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
}

.progress-bar-track {
    width: 100%;
    height: 10px;
    background: var(--bg-input);
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent-primary);
    border-radius: 5px;
    transition: width 0.4s ease;
    min-width: 0;
}

.progress-bar-fill.complete {
    background: var(--accent-success);
}

.session-progress-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.session-progress-percent {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent-primary);
}

.session-progress-remaining {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.balance-banner {
    display: none;
    background: linear-gradient(135deg, var(--bg-card), rgba(59, 130, 246, 0.12));
    border: 1px solid var(--accent-primary);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 14px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.balance-banner::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-success));
}

.balance-banner-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.balance-banner-value {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--accent-primary);
    line-height: 1.2;
}

.balance-banner-account {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 2px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

@media (max-width: 700px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 14px 16px;
    text-align: center;
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-tertiary);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
}

.trade-time {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    white-space: nowrap;
}

.stat-value.positive { color: var(--accent-success); }
.stat-value.negative { color: var(--accent-danger); }

.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

thead th {
    text-align: left;
    padding: 8px 10px;
    font-weight: 600;
    color: var(--text-tertiary);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

tbody td {
    padding: 8px 10px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

tbody tr:last-child td {
    border-bottom: none;
}

.empty-row td {
    text-align: center;
    color: var(--text-tertiary);
    padding: 24px;
}

.trade-won { color: var(--accent-success) !important; }
.trade-lost { color: var(--accent-danger) !important; }

.log-container {
    max-height: 260px;
    overflow-y: auto;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', monospace;
    font-size: 0.75rem;
}

.log-entry {
    padding: 5px 10px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
    line-height: 1.5;
}

.log-entry:last-child {
    border-bottom: none;
}

.log-info { color: var(--text-secondary); }
.log-warning { color: var(--accent-warning); }
.log-error { color: var(--accent-danger); }
.log-success { color: var(--accent-success); }

.log-time {
    color: var(--text-tertiary);
    margin-right: 8px;
}

footer {
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.disclaimer {
    max-width: 700px;
    margin: 0 auto 8px;
    padding: 12px 18px;
    background: var(--accent-warning-muted);
    border: 1px solid var(--accent-warning);
    border-radius: var(--radius);
}

.disclaimer strong {
    display: block;
    color: var(--accent-warning);
    font-size: 0.8rem;
    margin-bottom: 4px;
}

.disclaimer p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.footer-meta {
    font-size: 0.7rem;
    color: var(--text-tertiary);
}

.password-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.3s ease;
}

.password-overlay.hiding {
    animation: fadeOut 0.4s ease forwards;
}

.password-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 48px 40px;
    text-align: center;
    box-shadow: var(--shadow);
    max-width: 400px;
    width: 90%;
    animation: slideUp 0.4s ease;
}

.lock-icon {
    color: var(--accent-primary);
    margin-bottom: 20px;
}

.password-card h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.password-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

.password-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.password-input-group input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.password-input-group input:focus {
    border-color: var(--accent-primary);
}

.password-error {
    color: var(--accent-danger);
    font-size: 0.85rem;
    margin-bottom: 12px;
    animation: shake 0.4s ease;
}

.password-submit {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    margin-top: 8px;
}

.congrats-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    animation: fadeIn 0.3s ease;
}

.congrats-overlay.hiding {
    animation: fadeOut 0.4s ease forwards;
}

.confetti-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.congrats-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 48px 40px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    max-width: 420px;
    width: 90%;
    position: relative;
    z-index: 1;
    animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.congrats-checkmark {
    color: var(--accent-success);
    margin-bottom: 20px;
}

.checkmark-circle {
    stroke-dasharray: 166;
    stroke-dashoffset: 166;
    animation: drawCircle 0.6s ease forwards 0.2s;
}

.checkmark-check {
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
    animation: drawCheck 0.4s ease forwards 0.6s;
}

.congrats-title {
    font-size: 1.8rem;
    color: var(--text-primary);
    margin-bottom: 8px;
    animation: fadeSlideUp 0.5s ease forwards 0.3s;
    opacity: 0;
}

.congrats-text {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-bottom: 28px;
    line-height: 1.5;
    animation: fadeSlideUp 0.5s ease forwards 0.5s;
    opacity: 0;
}

.congrats-btn {
    padding: 12px 32px;
    font-size: 1rem;
    animation: fadeSlideUp 0.5s ease forwards 0.7s;
    opacity: 0;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

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

@keyframes popIn {
    from { transform: scale(0.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

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

@keyframes drawCircle {
    to { stroke-dashoffset: 0; }
}

@keyframes drawCheck {
    to { stroke-dashoffset: 0; }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

@keyframes shimmer {
    0% { background-position: -200% center; }
    100% { background-position: 200% center; }
}

.log-container::-webkit-scrollbar {
    width: 6px;
}

.log-container::-webkit-scrollbar-track {
    background: transparent;
}

.log-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.table-container::-webkit-scrollbar {
    height: 6px;
}

.table-container::-webkit-scrollbar-track {
    background: transparent;
}

.table-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}
