:root {
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-primary: #3b82f6;
    --accent-success: #22c55e;
    --accent-danger: #ef4444;
    --accent-warning: #eab308;
    --border-color: #334155;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.5;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(to right, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

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

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

.status-badge.online .dot {
    background-color: var(--accent-success);
}

.status-badge.offline .dot {
    background-color: var(--accent-danger);
}

/* Grid Layout */
.grid-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 20px;
}

.main-content {
    grid-template-columns: 350px 1fr;
}

/* Cards */
.card {
    background-color: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--border-color);
}

.card h2,
.card h3 {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
    font-weight: 500;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Forms & Controls */
.form-group {
    margin-bottom: 15px;
}

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

input,
select {
    width: 100%;
    padding: 10px;
    background-color: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: inherit;
}

input[type="date"] {
    background-color: #ffffff !important;
    color: #000000 !important;
    font-weight: 600 !important;
    border: 2px solid var(--accent-primary) !important;
    padding: 12px !important;
    transition: all 0.2s;
    cursor: text;
}

/* Target Chrome/Safari internal date text */
input[type="date"]::-webkit-datetime-edit-text,
input[type="date"]::-webkit-datetime-edit-month-field,
input[type="date"]::-webkit-datetime-edit-day-field,
input[type="date"]::-webkit-datetime-edit-year-field {
    color: #000000 !important;
}

input[type="date"]:hover {
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.4);
    border-color: #60a5fa !important;
}

/* Ensure the calendar icon is visible and dark on the light background */
input[type="date"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    filter: invert(0) !important;
    opacity: 1 !important;
}

.modal-body label {
    color: #f1f5f9 !important;
    /* Much brighter text for better visibility */
    font-weight: 600;
    margin-bottom: 8px;
}

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

.button-group {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.btn {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn:hover {
    opacity: 0.9;
}

.btn.primary {
    background-color: var(--accent-primary);
    color: white;
}

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

.btn.success {
    background-color: var(--accent-success);
    color: white;
}

.btn.full-width {
    width: 100%;
}

/* Results */
.result-box {
    background-color: rgba(59, 130, 246, 0.1);
    border: 1px solid var(--accent-primary);
    border-radius: 8px;
    padding: 15px;
    margin-top: 20px;
}

.hidden {
    display: none;
}

.rec-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 10px 0;
}

.rec-action {
    font-size: 1.25rem;
    font-weight: 700;
}

.rec-action.BUY {
    color: var(--accent-success);
}

.rec-action.SELL {
    color: var(--accent-danger);
}

.rec-action.HOLD {
    color: var(--accent-warning);
}

/* Logs */
.log-container {
    height: 300px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.log-entry {
    padding: 4px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

/* Positions */
.positions-list {
    min-height: 100px;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 20px;
    font-style: italic;
}

/* Chat Widget */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 350px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
}

.chat-header {
    padding: 15px;
    background-color: var(--accent-primary);
    color: white;
    border-radius: 12px 12px 0 0;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    font-weight: 600;
}

.chat-body {
    height: 400px;
    display: flex;
    flex-direction: column;
}

.chat-body.hidden {
    display: none;
}

.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message {
    padding: 10px;
    border-radius: 8px;
    max-width: 80%;
    font-size: 0.9rem;
}

.message.bot {
    background-color: var(--bg-dark);
    align-self: flex-start;
    border: 1px solid var(--border-color);
}

.message.user {
    background-color: var(--accent-primary);
    color: white;
    align-self: flex-end;
}

.chat-input {
    padding: 10px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 5px;
}

.chat-input input {
    flex: 1;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-dark);
    color: var(--text-primary);
}

.chat-input button {
    padding: 8px 12px;
    background-color: var(--accent-primary);
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    /* Align to top to prevent centering cut-off */
    padding: 20px 0;
    overflow-y: auto;
    /* Enable scrolling on the overlay itself */
    z-index: 2000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: var(--bg-card);
    border-radius: 12px;
    width: 500px;
    max-width: 95%;
    margin: 20px auto;
    /* Center horizontally and add vertical margin */
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: relative;
}

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

.modal-header h2 {
    margin: 0;
    color: var(--text-primary);
}

.close {
    font-size: 28px;
    font-weight: bold;
    color: var(--text-secondary);
    cursor: pointer;
}

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

.modal-body {
    padding: 20px;
    /* Remove overflow-y: auto here, let the whole modal scroll if needed */
}

/* Backtest Results */
.backtest-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.summary-item {
    text-align: center;
    padding: 15px;
    background: var(--bg-dark);
    border-radius: 8px;
}

.summary-label {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-bottom: 5px;
}

.summary-value {
    color: var(--text-primary);
    font-size: 1.2rem;
    font-weight: 600;
}

.summary-value.positive {
    color: #22c55e;
}

.summary-value.negative {
    color: #ef4444;
}

/* Trades Table */
.trades-table-container {
    max-height: 400px;
    overflow-y: auto;
}

.trades-table {
    width: 100%;
    border-collapse: collapse;
}

.trades-table th,
.trades-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.trades-table th {
    background: var(--bg-dark);
    color: var(--text-secondary);
    font-weight: 600;
    position: sticky;
    top: 0;
}

.trades-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.trade-type {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
}

.trade-type.BUY {
    background: rgba(34, 197, 94, 0.1);
    color: #22c55e;
}

.trade-type.SELL {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.pnl-positive {
    color: #22c55e;
}

.pnl-negative {
    color: #ef4444;
}

/* Activity Log Styles */
.activity-log-item {
    display: flex;
    gap: 12px;
    padding: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    align-items: flex-start;
    font-family: 'Inter', sans-serif;
}

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

.log-time {
    font-family: monospace;
    color: var(--text-secondary);
    font-size: 0.8rem;
    min-width: 70px;
    padding-top: 2px;
}

.log-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

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

.log-badge {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.log-badge.info {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.log-badge.signal {
    background: rgba(167, 139, 250, 0.1);
    color: #a78bfa;
    border: 1px solid rgba(167, 139, 250, 0.2);
}

.log-badge.order {
    background: rgba(34, 197, 94, 0.1);
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.2);
}

.log-badge.error {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.log-badge.paper {
    background: rgba(234, 179, 8, 0.1);
    color: #eab308;
    border: 1px solid rgba(234, 179, 8, 0.2);
}

.log-msg {
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.4;
}

.log-details {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: monospace;
    background: rgba(0, 0, 0, 0.2);
    padding: 4px 8px;
    border-radius: 4px;
    margin-top: 4px;
}