/* ── Reset & Variables ──────────────────────────────────── */
:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-card: #1c2128;
    --bg-hover: #252c35;
    --border: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent: #58a6ff;
    --green: #3fb950;
    --red: #f85149;
    --yellow: #d29922;
    --green-bg: rgba(63, 185, 80, 0.15);
    --red-bg: rgba(248, 81, 73, 0.15);
    --sidebar-width: 220px;
    --radius: 8px;
    --transition: 0.2s ease;
}

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

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

/* ── Sidebar ───────────────────────────────────────────── */
#sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.logo {
    padding: 20px;
    font-size: 1.2em;
    font-weight: 700;
    border-bottom: 1px solid var(--border);
}

#sidebar ul {
    list-style: none;
    padding: 12px 0;
    flex: 1;
}

#sidebar li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: var(--transition);
    font-size: 0.9em;
}

#sidebar li a:hover,
#sidebar li a.active {
    color: var(--text-primary);
    background: var(--bg-hover);
}

#sidebar li a.active {
    border-right: 3px solid var(--accent);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

/* ── Main Content ──────────────────────────────────────── */
#content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 24px;
    max-width: 1400px;
}

/* ── Buttons ───────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.85em;
    transition: var(--transition);
}

.btn:hover { background: var(--bg-hover); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { opacity: 0.9; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 4px 10px; font-size: 0.8em; }

/* ── Cards ─────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

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

.card-header h3 {
    font-size: 0.95em;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ── Metrics Bar ───────────────────────────────────────── */
.metrics-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

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

.metric-card .label {
    font-size: 0.75em;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.metric-card .value {
    font-size: 1.5em;
    font-weight: 700;
}

.metric-card .value.positive { color: var(--green); }
.metric-card .value.negative { color: var(--red); }

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

.dashboard-grid .full-width {
    grid-column: 1 / -1;
}

/* ── Table ─────────────────────────────────────────────── */
.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85em;
}

th, td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th {
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75em;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    background: var(--bg-card);
    cursor: pointer;
}

th:hover { color: var(--text-secondary); }

tr:hover { background: var(--bg-hover); }

.pnl-positive { color: var(--green); }
.pnl-negative { color: var(--red); }

.side-long {
    color: var(--green);
    background: var(--green-bg);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: 600;
}

.side-short {
    color: var(--red);
    background: var(--red-bg);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: 600;
}

.status-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: 600;
}

.status-CLOSED { background: rgba(88, 166, 255, 0.15); color: var(--accent); }
.status-OPEN { background: var(--green-bg); color: var(--green); }
.status-BREAKEVEN { background: rgba(210, 153, 34, 0.15); color: var(--yellow); }

tr.clickable { cursor: pointer; }

/* ── Group rows ───────────────────────────────────────── */
.group-header {
    background: var(--bg-secondary);
    font-weight: 500;
}
.group-header:hover {
    background: var(--bg-tertiary);
}
.group-chevron {
    display: inline-block;
    width: 16px;
    text-align: center;
    font-size: 11px;
    color: var(--text-secondary);
    transition: transform 0.15s;
}
.group-child td:first-child {
    border-left: 3px solid var(--border);
}
.badge {
    background: var(--accent);
    color: #fff;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
}
.trade-select {
    cursor: pointer;
    accent-color: var(--accent);
}

/* ── Filters Bar ───────────────────────────────────────── */
.filters-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.filters-bar input,
.filters-bar select {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    padding: 6px 12px;
    font-size: 0.85em;
}

.filters-bar input:focus,
.filters-bar select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ── Modal ─────────────────────────────────────────────── */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hidden { display: none !important; }
.modal.hidden { display: none; }

.modal-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 90%;
    max-width: 1100px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 1.1em; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5em;
    cursor: pointer;
}

.modal-close:hover { color: var(--text-primary); }

.modal-body { padding: 24px; }

/* ── Trade Detail ──────────────────────────────────────── */
.trade-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin: 20px 0;
}

.trade-meta .field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.trade-meta .field .label {
    font-size: 0.75em;
    color: var(--text-muted);
    text-transform: uppercase;
}

.trade-meta .field .value {
    font-size: 1em;
    font-weight: 600;
}

.notes-section {
    margin-top: 20px;
}

.notes-section h3 {
    color: var(--text-secondary);
    font-size: 0.9em;
    margin-bottom: 8px;
}

.notes-section textarea {
    width: 100%;
    min-height: 120px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    padding: 12px;
    font-family: inherit;
    font-size: 0.9em;
    resize: vertical;
}

.notes-section textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.notes-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

/* ── Calendar Heatmap ──────────────────────────────────── */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.calendar-cell {
    aspect-ratio: 1;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 0.7em;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
}

.calendar-cell:hover {
    border-color: var(--accent);
}

.calendar-cell .day { color: var(--text-muted); }
.calendar-cell .pnl { font-weight: 600; font-size: 0.85em; }
.calendar-cell.positive { background: var(--green-bg); }
.calendar-cell.negative { background: var(--red-bg); }
.calendar-cell.empty { background: var(--bg-secondary); cursor: default; }
.calendar-cell.empty:hover { border-color: transparent; }

.calendar-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 8px;
}

.calendar-header span {
    text-align: center;
    font-size: 0.75em;
    color: var(--text-muted);
    font-weight: 600;
}

/* ── Settings ──────────────────────────────────────────── */
.settings-form {
    max-width: 600px;
}

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

.form-group label {
    display: block;
    font-size: 0.85em;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input,
.form-group select {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    padding: 10px 12px;
    font-size: 0.9em;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
}

.account-list {
    margin-top: 20px;
}

.account-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
}

.account-item .name { font-weight: 600; }
.account-item .type { color: var(--text-muted); font-size: 0.85em; }

/* ── Daily Review ──────────────────────────────────────── */
.review-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: var(--transition);
}

.review-card:hover { border-color: var(--accent); }

.review-card .date {
    font-weight: 700;
    margin-bottom: 8px;
}

.review-card .grades {
    display: flex;
    gap: 12px;
    font-size: 0.85em;
    color: var(--text-secondary);
}

/* ── Toast ─────────────────────────────────────────────── */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 20px;
    font-size: 0.85em;
    animation: slideIn 0.3s ease;
    max-width: 400px;
}

.toast.success { border-left: 4px solid var(--green); }
.toast.error { border-left: 4px solid var(--red); }
.toast.info { border-left: 4px solid var(--accent); }

@keyframes slideIn {
    from { opacity: 0; transform: translateX(100px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ── Interval selector ────────────────────────────────── */
.interval-selector {
    display: flex;
    gap: 4px;
}

.interval-selector button {
    padding: 4px 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.75em;
    transition: var(--transition);
}

.interval-selector button:hover { color: var(--text-primary); }
.interval-selector button.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ── Loading spinner ──────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-muted);
    gap: 12px;
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 768px) {
    #sidebar { width: 60px; }
    #sidebar .logo { font-size: 0; padding: 16px; }
    #sidebar .logo::after { content: '📊'; font-size: 1.5em; }
    #sidebar li a span:not(.icon) { display: none; }
    #sidebar li a { justify-content: center; padding: 12px; }
    .sidebar-footer { display: none; }
    #content { margin-left: 60px; padding: 16px; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .modal-content { width: 98%; }
}

/* ── Poller Status Indicator ───────────────────────────── */
.poller-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: 6px;
    background: var(--bg-tertiary);
    cursor: pointer;
    transition: background 0.2s;
    font-size: 12px;
    color: var(--text-secondary);
}
.poller-status:hover {
    background: var(--bg-secondary);
}
.poller-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.poller-dot.active {
    background: #3fb950;
    box-shadow: 0 0 6px rgba(63, 185, 80, 0.6);
    animation: poller-pulse 2s infinite;
}
.poller-dot.inactive {
    background: #6e7681;
}
@keyframes poller-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
.poller-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
