/* InvestPilot Dashboard - Dark Theme, Mobile First */

:root {
    --bg: #0f1118;
    --bg-card: #1a1d2e;
    --bg-input: #252839;
    --border: #2d3148;
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --green: #22c55e;
    --red: #ef4444;
    --blue: #3b82f6;
    --orange: #f59e0b;
    --purple: #a855f7;
    --radius: 12px;
}

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

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

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

.header h1 {
    font-size: 18px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--blue), var(--purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.trading-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toggle-switch {
    position: relative;
    width: 52px;
    height: 28px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-input);
    border-radius: 28px;
    transition: 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--green);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(24px);
}

.toggle-label {
    font-size: 12px;
    color: var(--text-dim);
    font-weight: 600;
    text-transform: uppercase;
}

/* === TABS === */
.tabs {
    display: flex;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab {
    flex: 1;
    min-width: 70px;
    padding: 12px 8px;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dim);
    border: none;
    background: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: 0.2s;
    white-space: nowrap;
}

.tab.active {
    color: var(--blue);
    border-bottom-color: var(--blue);
}

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

/* === CONTENT === */
.content {
    padding: 16px;
    max-width: 800px;
    margin: 0 auto;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* === CARDS === */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.card-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.card-value {
    font-size: 28px;
    font-weight: 700;
}

.card-sub {
    font-size: 14px;
    color: var(--text-dim);
    margin-top: 4px;
}

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

/* === GRID === */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
}

.grid-4 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 12px;
}

/* === POSITIONS TABLE === */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th {
    text-align: left;
    padding: 10px 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tr:hover {
    background: rgba(59, 130, 246, 0.05);
}

/* === BADGES === */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
}

.badge-green { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.badge-red { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.badge-blue { background: rgba(59, 130, 246, 0.15); color: var(--blue); }
.badge-orange { background: rgba(245, 158, 11, 0.15); color: var(--orange); }
.badge-purple { background: rgba(168, 85, 247, 0.15); color: var(--purple); }

/* === REGIME DETAIL === */
.regime-detail-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    background: var(--bg-input);
    border-radius: 8px;
}

/* === SECTOR BAR === */
.sector-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-input);
    border-radius: 8px;
    font-size: 12px;
    white-space: nowrap;
}

.sector-bar-fill {
    height: 6px;
    border-radius: 3px;
    min-width: 8px;
    transition: width 0.3s ease;
}

/* === FORMS (Settings) === */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 16px;
    outline: none;
    -webkit-appearance: none;
}

.form-group input:focus {
    border-color: var(--blue);
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    transition: 0.2s;
}

.btn-primary {
    background: var(--blue);
    color: white;
    width: 100%;
}

.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
    background: transparent;
    color: var(--blue);
    border: 1px solid var(--blue);
    width: 100%;
}
.btn-secondary:hover { background: rgba(96,165,250,0.1); }

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

/* === LOG VIEWER === */
.log-viewer {
    background: #0a0b10;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    line-height: 1.6;
    max-height: 60vh;
    overflow-y: auto;
    color: var(--text-dim);
    white-space: pre-wrap;
    word-break: break-all;
}

.log-viewer .log-error { color: var(--red); }
.log-viewer .log-warn { color: var(--orange); }
.log-viewer .log-info { color: var(--text-dim); }

/* === SCORE BAR === */
.score-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 4px;
}

.score-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
}

/* === LOGIN PAGE === */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    width: 100%;
    max-width: 380px;
}

.login-box h2 {
    text-align: center;
    margin-bottom: 24px;
    font-size: 22px;
}

.login-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--red);
    color: var(--red);
    padding: 10px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
    display: none;
}

/* === TOAST NOTIFICATIONS === */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 20px;
    font-size: 14px;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.toast.show { opacity: 1; }

/* === RESPONSIVE === */
@media (max-width: 480px) {
    .grid-3 { grid-template-columns: 1fr 1fr; }
    .grid-4 { grid-template-columns: 1fr 1fr; }
    .card-value { font-size: 22px; }
    .header h1 { font-size: 16px; }
}

/* === LOADING === */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top: 2px solid var(--blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

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

/* === TOOLTIP (? icon mit Erklaerung) === */
.tip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    margin-left: 6px;
    border-radius: 50%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    position: relative;
    vertical-align: middle;
    transition: all 0.15s ease;
}
.tip:hover, .tip.active {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
}
.tip::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    min-width: 200px;
    max-width: 260px;
    padding: 10px 12px;
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.45;
    text-align: left;
    text-transform: none;
    letter-spacing: normal;
    white-space: normal;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 1000;
}
.tip:hover::after, .tip.active::after {
    opacity: 1;
}
/* Pfeil unter dem Tooltip */
.tip::before {
    content: "";
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--border);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 1001;
}
.tip:hover::before, .tip.active::before {
    opacity: 1;
}
/* Auf kleinen Screens Tooltip linksbuendig damit er nicht abgeschnitten wird */
@media (max-width: 500px) {
    .tip::after {
        left: 0;
        transform: none;
        min-width: 180px;
        max-width: 240px;
    }
    .tip::before { left: 14px; }
}

/* In Tabellen-Headern: Tooltip nach UNTEN oeffnen, damit er nicht im
   vorherigen Card-Header oder engen Oben-Rand verschwindet. */
.data-table thead .tip::after {
    bottom: auto;
    top: calc(100% + 8px);
}
.data-table thead .tip::before {
    bottom: auto;
    top: calc(100% + 2px);
    border-top-color: transparent;
    border-bottom-color: var(--border);
}

/* Letzte 2-3 Spalten: Tooltip rechtsbuendig statt mittig, damit er nicht
   rechts aus der Karte rausragt. */
.data-table thead th:nth-last-child(-n+3) .tip::after {
    left: auto;
    right: 0;
    transform: none;
}
.data-table thead th:nth-last-child(-n+3) .tip::before {
    left: auto;
    right: 14px;
    transform: none;
}

/* === P&L PERIODS GRID === */
.pnl-periods-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 12px;
}
.pnl-period-cell {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 8px;
    text-align: center;
}
.pnl-period-cell .pnl-label {
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 4px;
}
.pnl-period-cell .pnl-usd {
    font-size: 14px;
    font-weight: 700;
    line-height: 1.2;
}
.pnl-period-cell .pnl-pct {
    font-size: 11px;
    margin-top: 2px;
}
@media (max-width: 600px) {
    .pnl-periods-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Benchmark-Cell: drei kleine Zeilen (Bot / SPY / Alpha) */
.bench-cell-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 11px;
    line-height: 1.3;
    padding: 1px 0;
}
.bench-cell-row .bench-label {
    color: var(--text-dim);
    font-weight: 500;
}
.bench-cell-row .bench-value {
    font-weight: 700;
}
.bench-cell-row.bench-alpha {
    margin-top: 3px;
    padding-top: 3px;
    border-top: 1px solid var(--border);
    font-size: 12px;
}
