/* ==========================================================================
   Trading Strategy Tester - Main Stylesheet
   ========================================================================== */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0a0e17;
    color: #e1e4e8;
    min-height: 100vh;
}

/* --- Header --- */
.header {
    background: #161b22;
    border-bottom: 1px solid #30363d;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header h1 { font-size: 1.2rem; color: #58a6ff; }

.header .status {
    display: flex;
    gap: 12px;
    align-items: center;
    font-size: 0.85rem;
    color: #8b949e;
}

.header .status span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* --- Layout --- */
.main {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 0;
    min-height: calc(100vh - 56px);
}

.sidebar {
    background: #161b22;
    border-right: 1px solid #30363d;
    padding: 16px;
    overflow-y: auto;
    max-height: calc(100vh - 56px);
}

.content {
    padding: 16px;
    overflow-y: auto;
}

/* --- Panels --- */
.panel {
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.panel h3 {
    font-size: 0.85rem;
    color: #8b949e;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

label {
    display: block;
    font-size: 0.78rem;
    color: #8b949e;
    margin-bottom: 4px;
    font-weight: 500;
}

/* --- Form Controls --- */
select, input[type="number"] {
    width: 100%;
    padding: 8px 12px;
    background: #1c2128;
    border: 1px solid #30363d;
    border-radius: 6px;
    color: #e1e4e8;
    font-size: 0.85rem;
    margin-bottom: 8px;
    transition: border-color 0.15s;
}

select:focus, input:focus { outline: none; border-color: #58a6ff; }

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    opacity: 1;
}

/* --- Buttons --- */
.btn {
    width: 100%;
    padding: 10px 14px;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 6px;
    transition: opacity 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn:hover { opacity: 0.85; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: #238636; color: white; }
.btn-secondary { background: #21262d; color: #e1e4e8; border: 1px solid #30363d; }
.btn-danger { background: #da3633; color: white; }
.btn-sm { padding: 6px 10px; font-size: 0.78rem; margin-top: 4px; }

.btn-row {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.btn-row .btn { flex: 1; }

/* --- Chart --- */
.chart-container {
    height: 420px;
    margin-bottom: 16px;
    border-radius: 8px;
    overflow: hidden;
}

/* --- Stats Grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.stat-card {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 6px;
    padding: 10px 8px;
    text-align: center;
}

.stat-card .value {
    font-size: 1.15rem;
    font-weight: 700;
    color: #58a6ff;
    word-break: break-all;
}

.stat-card .label {
    font-size: 0.65rem;
    color: #8b949e;
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* --- Signal Display --- */
.signal-display {
    padding: 12px;
    border-radius: 6px;
    margin-top: 8px;
}

.signal-buy { background: rgba(35, 134, 54, 0.12); border: 1px solid #238636; }
.signal-sell { background: rgba(218, 54, 51, 0.12); border: 1px solid #da3633; }
.signal-neutral { background: rgba(139, 148, 158, 0.08); border: 1px solid #30363d; }

.signal-type { font-weight: 700; font-size: 1rem; }
.signal-details { font-size: 0.78rem; color: #8b949e; margin-top: 6px; line-height: 1.5; }

/* --- Risk Table --- */
.risk-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.risk-table th, .risk-table td {
    padding: 6px 10px;
    text-align: right;
    border-bottom: 1px solid #21262d;
}

.risk-table th {
    color: #8b949e;
    font-weight: 600;
    text-align: left;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* --- Trade Log Table --- */
.trade-log-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.trade-log-table th, .trade-log-table td {
    padding: 6px 10px;
    text-align: right;
    border-bottom: 1px solid #21262d;
}

.trade-log-table th {
    color: #8b949e;
    font-weight: 600;
    text-align: left;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    position: sticky;
    top: 0;
    background: #0d1117;
}

.trade-log-table td { color: #c9d1d9; }
.trade-log-table tr:hover td { background: rgba(88, 166, 255, 0.05); }

/* --- Inline Data --- */
.data-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 0.82rem;
    border-bottom: 1px solid #21262d;
}

.data-row:last-child { border-bottom: none; }
.data-label { color: #8b949e; }
.data-value { font-weight: 600; font-family: 'SF Mono', 'Cascadia Code', monospace; }
.positive { color: #3fb950; }
.negative { color: #f85149; }
.muted { color: #8b949e; }

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.68rem;
    font-weight: 600;
    vertical-align: middle;
}

.badge-success { background: rgba(35, 134, 54, 0.2); color: #3fb950; }
.badge-danger { background: rgba(218, 54, 51, 0.2); color: #f85149; }
.badge-warning { background: rgba(187, 128, 9, 0.2); color: #d29922; }
.badge-info { background: rgba(88, 166, 255, 0.2); color: #58a6ff; }
.badge-neutral { background: rgba(139, 148, 158, 0.15); color: #8b949e; }

/* --- Log --- */
.log {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.72rem;
    color: #8b949e;
    background: #1c2128;
    padding: 10px;
    border-radius: 6px;
    max-height: 220px;
    overflow-y: auto;
    margin-top: 8px;
    line-height: 1.6;
}

.log-entry { padding: 1px 0; }
.log-entry.error { color: #f85149; }
.log-entry.warn { color: #d29922; }
.log-entry.success { color: #3fb950; }
.log-entry .time { color: #484f58; margin-right: 6px; }

/* --- Spinner --- */
.spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid #30363d;
    border-top-color: #58a6ff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

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

/* --- Section Headers --- */
.section-title {
    font-size: 0.78rem;
    color: #8b949e;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
    font-weight: 600;
}

/* --- Divider --- */
.divider {
    height: 1px;
    background: #21262d;
    margin: 12px 0;
}

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

@media (max-width: 1000px) {
    .main { grid-template-columns: 1fr; }
    .sidebar {
        border-right: none;
        border-bottom: 1px solid #30363d;
        max-height: none;
    }
    .chart-container { height: 300px; }
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #30363d; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #484f58; }

/* --- Two Column Layout --- */
.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 1200px) {
    .two-col { grid-template-columns: 1fr; }
}

/* --- Backtest Progress --- */
.backtest-progress {
    height: 3px;
    background: #21262d;
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}

.backtest-progress-bar {
    height: 100%;
    background: #238636;
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* --- Tooltip --- */
.tooltip-trigger {
    position: relative;
    cursor: help;
    border-bottom: 1px dashed #484f58;
}

.tooltip-trigger:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #1c2128;
    border: 1px solid #30363d;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.72rem;
    white-space: nowrap;
    z-index: 100;
    color: #e1e4e8;
}