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

:root {
    --bg: #0f0f1a;
    --bg-card: #1a1a2e;
    --bg-input: #16213e;
    --text: #e0e0e0;
    --text-muted: #8888aa;
    --primary: #4361ee;
    --primary-hover: #3a56d4;
    --success: #06d6a0;
    --danger: #ef476f;
    --warning: #ffd166;
    --border: #2a2a4a;
    --radius: 8px;
}

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Navbar === */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
}
.nav-brand:hover { text-decoration: none; }

.nav-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
}

.nav-user {
    color: var(--text-muted);
}

.btn-logout {
    color: var(--danger);
    font-size: 0.85rem;
}

/* === Container === */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* === Flash Messages === */
.flash-messages { margin-bottom: 1rem; }
.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}
.flash-error { background: rgba(239, 71, 111, 0.15); border: 1px solid var(--danger); color: var(--danger); }
.flash-success { background: rgba(6, 214, 160, 0.15); border: 1px solid var(--success); color: var(--success); }

/* === Buttons === */
.btn {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    text-align: center;
    transition: background 0.2s;
    color: white;
}
.btn:hover { text-decoration: none; }

.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #000; }
.btn-danger { background: var(--danger); }
.btn-warning { background: var(--warning); color: #000; }
.btn-full { width: 100%; }
.btn-large { padding: 0.8rem 2rem; font-size: 1.1rem; }
.btn-small { padding: 0.35rem 0.7rem; font-size: 0.8rem; }

/* === Forms === */
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.form-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}
.form-row .form-group { flex: 1; min-width: 120px; }
.form-row .form-group-wide { flex: 2; }

.radio-group {
    display: flex;
    gap: 1.5rem;
    padding-top: 0.3rem;
}
.radio-group label {
    color: var(--text);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/* === Auth === */
.auth-container {
    max-width: 400px;
    margin: 4rem auto;
    text-align: center;
}
.auth-container h1 {
    font-size: 1.8rem;
    margin-bottom: 0.3rem;
}
.auth-subtitle {
    color: var(--text-muted);
    margin-bottom: 2rem;
}
.auth-form {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius);
    text-align: left;
}
.auth-link {
    margin-top: 1rem;
    font-size: 0.85rem;
}

/* === Stats Grid === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--bg-card);
    padding: 1.2rem;
    border-radius: var(--radius);
    text-align: center;
}
.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
}
.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

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

/* === Dashboard === */
.dashboard h1 {
    margin-bottom: 1.5rem;
}

.session-control {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    text-align: center;
}
.session-control h2 {
    margin-bottom: 0.75rem;
    font-size: 1.2rem;
}
.session-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1rem;
}
.recommended-assets {
    color: var(--text-muted);
    margin-bottom: 1rem;
}

/* === Session Timer === */
.session-timer {
    font-size: 2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.timer-warning { color: var(--warning); }
.timer-expired { color: var(--danger); }

.timer-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-card);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
}

/* === Tables === */
.trades-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.trades-table th,
.trades-table td {
    padding: 0.6rem 0.8rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.trades-table th {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.8rem;
}

.badge-rec {
    background: var(--primary);
    color: white;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 600;
}
.badge-online {
    background: var(--success);
    color: #000;
    padding: 0.1rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* === Checklist === */
.checklist {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
}
.checklist h2 {
    margin-bottom: 1rem;
}

.checklist-progress {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.progress-bar {
    flex: 1;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.3s;
}

.step {
    padding: 0.75rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
}
.step.completed {
    color: var(--text-muted);
    font-size: 0.85rem;
}
.step-check {
    color: var(--success);
    margin-right: 0.5rem;
}
.step.active {
    background: var(--bg-input);
    padding: 1.5rem;
}
.step.active h3 {
    margin-bottom: 0.5rem;
}
.step-hint {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.direction-form {
    display: flex;
    gap: 1rem;
}

.monitoring-alerts {
    margin-bottom: 1.5rem;
}
.alert-item {
    background: rgba(255, 209, 102, 0.1);
    border-left: 3px solid var(--warning);
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 0.9rem;
}

.mm-rules {
    background: var(--bg);
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
    white-space: pre-line;
}

.exit-form .form-group { margin-bottom: 1rem; }

/* === New Trade === */
.new-trade-section {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
}
.new-trade-section h2 { margin-bottom: 1rem; }

.asset-selection {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1rem;
}
.asset-option input { display: none; }
.asset-chip {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}
.asset-option input:checked + .asset-chip {
    background: var(--primary);
    border-color: var(--primary);
}
.custom-asset input {
    padding: 0.5rem 0.8rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    width: 150px;
}

/* === Card === */
.card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}
.card h2 { margin-bottom: 1rem; font-size: 1.1rem; }

/* === Admin === */
.admin-page h1 { margin-bottom: 1.5rem; }
.admin-page h2 { margin-top: 1.5rem; margin-bottom: 0.75rem; }

.config-form {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
}
.config-form h2 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
.config-form h2:first-of-type {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

.trader-email { color: var(--text-muted); margin-bottom: 1.5rem; }
.stat-extra { margin-bottom: 1.5rem; color: var(--text-muted); }

.invite-link {
    font-size: 0.75rem;
    word-break: break-all;
}

/* === Chat Widget === */
.chat-widget {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 200;
}
.chat-toggle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.chat-panel {
    position: absolute;
    bottom: 60px;
    right: 0;
    width: 340px;
    max-height: 450px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.chat-panel.hidden { display: none; }

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.9rem;
}
.chat-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.3rem;
    cursor: pointer;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    max-height: 300px;
    min-height: 150px;
}
.chat-msg {
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
    line-height: 1.4;
}
.chat-msg.user {
    text-align: right;
}
.chat-msg .bubble {
    display: inline-block;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    max-width: 85%;
    text-align: left;
}
.chat-msg.user .bubble {
    background: var(--primary);
}
.chat-msg.assistant .bubble {
    background: var(--bg-input);
}

.chat-form {
    display: flex;
    padding: 0.5rem;
    border-top: 1px solid var(--border);
    gap: 0.5rem;
}
.chat-form input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.85rem;
}
.chat-form button {
    padding: 0.5rem 0.75rem;
    background: var(--primary);
    border: none;
    border-radius: var(--radius);
    color: white;
    cursor: pointer;
    font-size: 1rem;
}

/* === Pagination === */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* === Empty State === */
.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

/* === Responsive === */
@media (max-width: 600px) {
    .navbar { flex-direction: column; gap: 0.5rem; }
    .nav-right { flex-wrap: wrap; justify-content: center; }
    .container { padding: 1rem; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .form-row { flex-direction: column; }
    .chat-panel { width: calc(100vw - 2rem); right: -0.5rem; }
    .session-actions { flex-direction: column; }
    .trades-table { font-size: 0.8rem; }
    .trades-table th, .trades-table td { padding: 0.4rem; }
}
