/* === Svensk Aktiehandel-Simulator - Trading Dashboard === */

:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a2332;
    --bg-hover: #243044;
    --border: #2a3a50;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --green: #22c55e;
    --green-bg: rgba(34, 197, 94, 0.1);
    --red: #ef4444;
    --red-bg: rgba(239, 68, 68, 0.1);
    --yellow: #eab308;
    --yellow-bg: rgba(234, 179, 8, 0.1);
    --purple: #a855f7;
    --cyan: #06b6d4;
    --orange: #f97316;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

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

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

/* === Header === */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-left: 12px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.connected { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.disconnected { background: var(--red); }
.status-dot.running { background: var(--yellow); animation: pulse 1.5s infinite; }

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

/* === Market Badge in Header === */
.market-badge {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.market-badge.open {
    background: var(--green-bg);
    color: var(--green);
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.market-badge.closed {
    background: rgba(100, 116, 139, 0.1);
    color: var(--text-muted);
    border: 1px solid rgba(100, 116, 139, 0.3);
}

/* === Main === */
main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* === Panel === */
.panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.panel h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* === Config === */
.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.config-field label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.config-field input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: 'JetBrains Mono', monospace;
    transition: border-color 0.2s;
}

.config-field input:focus {
    outline: none;
    border-color: var(--accent);
}

.config-actions {
    display: flex;
    gap: 12px;
}

.btn {
    padding: 10px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

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

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

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-continuous {
    background: var(--purple);
    color: white;
}

.btn-continuous:hover:not(:disabled) {
    background: #9333ea;
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--red);
    color: white;
}

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

/* === Market Status Panel === */
.market-status-panel {
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, rgba(59, 130, 246, 0.05) 100%);
    border-color: rgba(59, 130, 246, 0.2);
}

.market-status-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    align-items: center;
}

.market-info {
    display: flex;
    align-items: center;
    gap: 6px;
}

.market-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.market-phase-text {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.market-time-text {
    font-size: 0.85rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-secondary);
}

.market-trading-text {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.market-trading-text.positive {
    color: var(--green);
}

.market-interval-text {
    font-size: 0.85rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-secondary);
}

/* === Stats === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

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

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.2rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
}

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

/* === Chart === */
#chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    height: 250px;
    position: relative;
}

#portfolio-chart {
    width: 100%;
    height: 100%;
}

/* === Decision Reasoning Panel === */
.decisions-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.decision-card {
    border-color: rgba(249, 115, 22, 0.3);
    background: linear-gradient(135deg, var(--bg-card) 0%, rgba(249, 115, 22, 0.05) 100%);
}

.decisions-feed {
    max-height: 500px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.decision-item {
    padding: 10px 14px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border-left: 4px solid var(--border);
    animation: fadeIn 0.3s ease;
}

.decision-item:hover {
    background: var(--bg-hover);
}

.decision-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 4px;
}

.decision-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

.decision-action {
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
}

.action-buy {
    background: var(--green-bg);
    color: var(--green);
}

.action-sell {
    background: var(--red-bg);
    color: var(--red);
}

.action-stoploss {
    background: var(--red-bg);
    color: var(--red);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.action-takeprofit {
    background: var(--green-bg);
    color: var(--green);
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.action-research {
    background: rgba(168, 85, 247, 0.1);
    color: var(--purple);
}

.decision-ticker {
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
}

.decision-price {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.decision-qty {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.decision-conf {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    font-weight: 600;
}

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

.decision-meta {
    font-size: 0.65rem;
    color: var(--text-muted);
    display: block;
    margin-top: 4px;
}

.outcome-badge {
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
}

.outcome-win {
    background: var(--green-bg);
    color: var(--green);
}

.outcome-loss {
    background: var(--red-bg);
    color: var(--red);
}

/* === Tables === */
.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

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

.table-wrap {
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
}

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

th {
    text-align: left;
    padding: 8px 10px;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
}

td {
    padding: 8px 10px;
    border-bottom: 1px solid rgba(42, 58, 80, 0.5);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
}

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

td.empty {
    text-align: center;
    color: var(--text-muted);
    padding: 24px;
    font-family: inherit;
}

.side-buy { color: var(--green); font-weight: 600; }
.side-sell { color: var(--red); font-weight: 600; }
.pnl-positive { color: var(--green); }
.pnl-negative { color: var(--red); }

/* === Signals === */
.signals-grid {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 16px;
}

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

.signal-bars {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.signal-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.signal-bar-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    width: 100px;
    text-align: right;
    flex-shrink: 0;
}

.signal-bar-track {
    flex: 1;
    height: 20px;
    background: var(--bg-card);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.signal-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
    min-width: 2px;
}

.signal-bar-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    width: 40px;
    font-family: 'JetBrains Mono', monospace;
}

.recent-signals h3 {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.signals-feed {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.signal-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--bg-card);
    border-radius: 4px;
    font-size: 0.75rem;
}

.signal-type-badge {
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-sentiment { background: rgba(168, 85, 247, 0.2); color: var(--purple); }
.badge-macro { background: rgba(6, 182, 212, 0.2); color: var(--cyan); }
.badge-sector_rotation { background: rgba(234, 179, 8, 0.2); color: var(--yellow); }
.badge-event_driven { background: rgba(239, 68, 68, 0.2); color: var(--red); }
.badge-correlation { background: rgba(59, 130, 246, 0.2); color: var(--accent); }
.badge-flow { background: rgba(34, 197, 94, 0.2); color: var(--green); }

.signal-ticker {
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
}

.signal-direction {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
}

.signal-reasoning {
    color: var(--text-muted);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* === Log === */
.log-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    max-height: 300px;
    overflow-y: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    line-height: 1.6;
}

.log-entry {
    padding: 2px 0;
    border-bottom: 1px solid rgba(42, 58, 80, 0.3);
}

.log-tick { color: var(--text-muted); }
.log-signals { color: var(--purple); }
.log-trades { color: var(--yellow); }
.log-value { color: var(--cyan); }
.log-phase { color: var(--accent); font-weight: 600; }

/* === Footer === */
footer {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 0.75rem;
    border-top: 1px solid var(--border);
    margin-top: 20px;
}

/* === AI Panel === */
.ai-status-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.ai-card {
    border-color: rgba(168, 85, 247, 0.3);
    background: linear-gradient(135deg, var(--bg-card) 0%, rgba(168, 85, 247, 0.05) 100%);
}

.regime-text { font-size: 0.9rem; }

.ai-details {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}

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

.ai-section h3 {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.ai-signal-item {
    border-left: 3px solid var(--purple);
}

.ai-conf {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--cyan);
    font-weight: 600;
}

.badge-ai {
    background: rgba(168, 85, 247, 0.3);
    color: var(--purple);
    font-weight: 700;
}

.ai-insights, .ai-warnings {
    max-height: 250px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-insight-item {
    padding: 6px 10px;
    background: var(--bg-card);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    border-left: 3px solid var(--cyan);
    animation: fadeIn 0.3s ease;
}

.ai-warning-item {
    padding: 6px 10px;
    background: var(--red-bg);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--red);
    border-left: 3px solid var(--red);
    animation: fadeIn 0.3s ease;
}

.ai-empty {
    padding: 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-style: italic;
}

.log-ai { color: var(--purple); font-weight: 600; }

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-card); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Animations === */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.signal-item, .log-entry, .decision-item {
    animation: fadeIn 0.3s ease;
}
