/* ═══════════════════════════════════════════════════════════════
   BANKNIFTY Algo Trading Dashboard — Adaptive Theme (Dark + Light)
   ═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.8);
    --bg-card-hover: rgba(31, 41, 55, 0.9);
    --bg-glass: rgba(255, 255, 255, 0.03);
    --bg-input: rgba(255, 255, 255, 0.05);
    --border: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);

    --text-primary: #f8fbff;
    --text-secondary: #d7e0ea;
    --text-muted: #a4b4c6;
    --text-dim: #475569;

    --green: #10b981;
    --green-glow: rgba(16, 185, 129, 0.15);
    --green-bright: #34d399;
    --red: #ef4444;
    --red-glow: rgba(239, 68, 68, 0.15);
    --red-bright: #f87171;
    --blue: #3b82f6;
    --blue-glow: rgba(59, 130, 246, 0.15);
    --yellow: #f59e0b;
    --yellow-glow: rgba(245, 158, 11, 0.15);
    --purple: #8b5cf6;
    --purple-glow: rgba(139, 92, 246, 0.15);
    --cyan: #06b6d4;

    --gradient-profit: linear-gradient(135deg, #10b981 0%, #34d399 100%);
    --gradient-loss: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
    --gradient-blue: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
    --gradient-purple: linear-gradient(135deg, #8b5cf6 0%, #a78bfa 100%);
    --gradient-gold: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%);
    --gradient-sidebar: linear-gradient(180deg, #0f172a 0%, #0a0e17 100%);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
    --shadow-glow-green: 0 0 20px rgba(16, 185, 129, 0.2);
    --shadow-glow-red: 0 0 20px rgba(239, 68, 68, 0.2);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --sidebar-width: 260px;
    --header-height: 64px;

    --transition: all 0.2s ease;
    --transition-slow: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --theme-transition: background 0.35s ease, color 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
}

/* ── Light Mode Variables ──────────────────────────────────── */
[data-theme="light"] {
    --bg-primary: #f0f4f8;
    --bg-secondary: #ffffff;
    --bg-card: rgba(255, 255, 255, 0.9);
    --bg-card-hover: rgba(248, 250, 252, 0.95);
    --bg-glass: rgba(0, 0, 0, 0.02);
    --bg-input: rgba(0, 0, 0, 0.04);
    --border: rgba(0, 0, 0, 0.08);
    --border-hover: rgba(0, 0, 0, 0.18);

    --text-primary: #020617;
    --text-secondary: #0f172a;
    --text-muted: #334155;
    --text-dim: #64748b;

    --green: #059669;
    --green-glow: rgba(5, 150, 105, 0.1);
    --green-bright: #10b981;
    --red: #dc2626;
    --red-glow: rgba(220, 38, 38, 0.1);
    --red-bright: #ef4444;
    --blue: #2563eb;
    --blue-glow: rgba(37, 99, 235, 0.1);
    --yellow: #d97706;
    --yellow-glow: rgba(217, 119, 6, 0.1);
    --purple: #7c3aed;
    --purple-glow: rgba(124, 58, 237, 0.1);

    --gradient-sidebar: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.12);
    --shadow-glow-green: 0 0 20px rgba(5, 150, 105, 0.15);
    --shadow-glow-red: 0 0 20px rgba(220, 38, 38, 0.15);
}

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

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

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

body.auth-loading .login-page,
body.auth-loading .app-layout {
    display: none !important;
}

.auth-splash {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    z-index: 20000;
}

body.auth-loading .auth-splash {
    display: flex;
}

.auth-splash-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 28px 34px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.auth-splash-text {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 600;
}

/* ── Theme Transition ──────────────────────────────────────── */
body, .sidebar, .top-bar, .card, .stat-card, .control-panel,
.modal, .login-container, .filter-tab, .log-terminal,
.settings-item, .indicator-item, .position-detail,
.nav-item, .form-input, .lot-input, .btn-ghost, .toast {
    transition: var(--theme-transition);
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(128, 128, 128, 0.2);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(128, 128, 128, 0.35);
}

/* ── Login Page ────────────────────────────────────────────── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: var(--bg-primary);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(59, 130, 246, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(139, 92, 246, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(16, 185, 129, 0.05) 0%, transparent 50%);
}

.login-container {
    width: 400px;
    padding: 48px 40px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow-lg);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo h1 {
    font-size: 1.75rem;
    font-weight: 800;
    background: var(--gradient-blue);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.login-logo p {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 4px;
}

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

.form-group label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: var(--transition);
    outline: none;
}

.form-input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--blue-glow);
}

.form-input::placeholder {
    color: var(--text-dim);
}

.form-input[readonly] {
    opacity: 0.92;
    cursor: default;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    outline: none;
}

.btn-primary {
    width: 100%;
    background: var(--gradient-blue);
    color: white;
    padding: 14px;
    font-size: 0.95rem;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

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

.btn-success:hover {
    box-shadow: var(--shadow-glow-green);
}

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

.btn-danger:hover {
    box-shadow: var(--shadow-glow-red);
}

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

.btn-ghost:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.btn:disabled,
.mode-switch-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.8rem;
}

.btn-xs {
    padding: 4px 10px;
    font-size: 0.75rem;
    border-radius: 6px;
}

.login-error {
    color: var(--red);
    font-size: 0.85rem;
    text-align: center;
    margin-top: 12px;
    display: none;
}

/* ── Dashboard Layout ──────────────────────────────────────── */
.app-layout {
    display: none;
    height: 100vh;
}

.app-layout.active {
    display: flex;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    background: var(--gradient-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow-y: auto;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-brand-icon {
    width: 40px;
    height: 40px;
    background: var(--gradient-blue);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.sidebar-brand-text h2 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.sidebar-brand-text span {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 12px;
}

.nav-section-title {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1.2px;
    padding: 16px 12px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 2px;
    text-decoration: none;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.07);
    color: var(--text-primary);
}

/* keep sidebar nav always dark regardless of app theme */
.sidebar .nav-item { color: #94a3b8; }
.sidebar .nav-item:hover { background: rgba(255,255,255,0.07); color: #f1f5f9; }
.sidebar .nav-item.active { background: rgba(59,130,246,0.18); color: #60a5fa; }
.sidebar .nav-section-title { color: #475569; }
.sidebar .sidebar-brand-text h2 { color: #f1f5f9; }
.sidebar .sidebar-brand-text span { color: #64748b; }
.sidebar .sidebar-status { color: #64748b; }
.sidebar .sidebar-footer { border-color: rgba(255,255,255,0.06); }
.sidebar .sidebar-header { border-color: rgba(255,255,255,0.06); }

.nav-item.active {
    background: var(--blue-glow);
    color: var(--blue);
    font-weight: 600;
}

.nav-item .nav-icon {
    font-size: 1.1rem;
    width: 22px;
    text-align: center;
}

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

.sidebar-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

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

.status-dot.running {
    background: var(--green);
    box-shadow: 0 0 8px var(--green);
    animation: pulse-dot 2s infinite;
}

.status-dot.stopped {
    background: var(--red);
}

.status-dot.connected {
    background: var(--green);
}

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

/* ── Main Content ──────────────────────────────────────────── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.top-bar {
    height: var(--header-height);
    min-height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.top-bar-left h1 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mode-badge {
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.mode-badge.paper {
    background: var(--yellow-glow);
    color: var(--yellow);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.mode-badge.live {
    background: var(--green-glow);
    color: var(--green);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.page-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px 28px;
}

/* ── Pages ─────────────────────────────────────────────────── */
.page {
    display: none;
}

.page.active {
    display: block;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    backdrop-filter: blur(10px);
    transition: var(--transition);
}

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

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

.card-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

/* ── Stat Cards Grid ───────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: var(--transition);
}

.stat-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.stat-card.profit::before { background: var(--gradient-profit); }
.stat-card.loss::before { background: var(--gradient-loss); }
.stat-card.info::before { background: var(--gradient-blue); }
.stat-card.warn::before { background: var(--gradient-gold); }
.stat-card.purple::before { background: var(--gradient-purple); }

.stat-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.stat-value.profit { color: var(--green); }
.stat-value.loss { color: var(--red); }

.stat-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── Grid Layouts ──────────────────────────────────────────── */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.grid-2-1 {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.grid-1-2 {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 20px;
    margin-bottom: 24px;
}

/* ── Control Panel ─────────────────────────────────────────── */
.control-panel {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
    padding: 16px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
}

.lot-input {
    width: 60px;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    text-align: center;
    outline: none;
}

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

.control-divider {
    width: 1px;
    height: 32px;
    background: var(--border);
}

/* ── Live Position Card ────────────────────────────────────── */
.position-card {
    padding: 20px;
}

.position-empty {
    text-align: center;
    padding: 32px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

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

.position-direction {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
}

.position-direction.buy {
    background: var(--green-glow);
    color: var(--green);
}

.position-direction.sell {
    background: var(--red-glow);
    color: var(--red);
}

.position-details {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.position-detail {
    padding: 12px;
    background: var(--bg-glass);
    border-radius: var(--radius-sm);
}

.position-detail-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.position-detail-value {
    font-size: 1rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
}

/* ── Indicator Panel ───────────────────────────────────────── */
.indicator-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.indicator-item {
    padding: 14px;
    background: var(--bg-glass);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.indicator-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 4px;
}

.indicator-value {
    font-size: 1.05rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-primary);
}

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

/* ── Tables ────────────────────────────────────────────────── */
.table-container {
    overflow-x: auto;
}

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

thead th {
    text-align: left;
    padding: 10px 14px;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 10px 14px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

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

.badge {
    display: inline-flex;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-buy {
    background: var(--green-glow);
    color: var(--green);
}

.badge-sell {
    background: var(--red-glow);
    color: var(--red);
}

.badge-open {
    background: var(--blue-glow);
    color: var(--blue);
}

.badge-closed {
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-muted);
}

.badge-traded {
    background: var(--green-glow);
    color: var(--green);
}

.badge-skipped {
    background: var(--yellow-glow);
    color: var(--yellow);
}

.badge-expired {
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-muted);
}

.badge-waiting {
    background: var(--blue-glow);
    color: var(--blue);
}

.badge-cancelled {
    background: var(--red-glow);
    color: var(--red);
}

.pnl-positive {
    color: var(--green);
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}

.pnl-negative {
    color: var(--red);
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}

/* ── Chart Container ───────────────────────────────────────── */
.chart-container {
    position: relative;
    height: 280px;
    margin-top: 12px;
}

.chart-container.tall {
    height: 360px;
}

/* ── Log Terminal ──────────────────────────────────────────── */
.log-terminal {
    background: #0d1117;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    height: 500px;
    overflow-y: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    line-height: 1.8;
}

.log-entry {
    padding: 2px 0;
}

.log-time {
    color: var(--text-dim);
    margin-right: 8px;
}

.log-level {
    display: inline-block;
    width: 56px;
    font-weight: 600;
    margin-right: 8px;
}

.log-level.INFO { color: var(--blue); }
.log-level.SUCCESS { color: var(--green); }
.log-level.WARN { color: var(--yellow); }
.log-level.ERROR { color: var(--red); }

.log-category {
    color: var(--purple);
    margin-right: 8px;
}

.log-message {
    color: var(--text-secondary);
}

/* ── Filter Bar ────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filter-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg-glass);
    border-radius: var(--radius-sm);
    padding: 4px;
    border: 1px solid var(--border);
}

.filter-tab {
    padding: 6px 14px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
}

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

.filter-tab.active {
    background: var(--blue);
    color: white;
}

/* ── Settings Form ─────────────────────────────────────────── */
.settings-section {
    margin-bottom: 32px;
}

.settings-section h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

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

.settings-item {
    padding: 16px;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.settings-item-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.settings-item-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
}

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

.toast {
    padding: 14px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow-lg);
    color: var(--text-primary);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease;
    min-width: 300px;
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.warning { border-left: 3px solid var(--yellow); }
.toast.info { border-left: 3px solid var(--blue); }

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

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    max-width: 420px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}

.modal h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.modal p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* ── Theme Toggle Switch ───────────────────────────────────── */
.theme-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    cursor: pointer;
    transition: var(--transition);
}

.theme-toggle-row:hover {
    border-color: var(--border-hover);
    background: var(--bg-card-hover);
}

.theme-toggle-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

.theme-toggle-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.theme-toggle-text strong {
    display: block;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.theme-toggle-text small {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* The pill switch */
.toggle-switch {
    position: relative;
    width: 52px;
    height: 28px;
    flex-shrink: 0;
}

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

.toggle-track {
    position: absolute;
    inset: 0;
    border-radius: 28px;
    background: rgba(100, 116, 139, 0.3);
    border: 1px solid var(--border);
    transition: background 0.3s ease, border-color 0.3s ease;
    cursor: pointer;
}

.toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s ease;
    pointer-events: none;
}

.toggle-switch input:checked ~ .toggle-track {
    background: var(--blue);
    border-color: var(--blue);
}

.toggle-switch input:checked ~ .toggle-track .toggle-thumb {
    transform: translateX(24px);
    background: #ffffff;
}

/* Theme preview chips in the toggle row */
.theme-preview-chips {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.theme-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-muted);
    background: var(--bg-glass);
}

.theme-chip.active {
    background: var(--blue-glow);
    color: var(--blue);
    border-color: var(--blue);
}

.theme-chip:hover:not(.active) {
    border-color: var(--border-hover);
    color: var(--text-secondary);
}

/* Theme toggle in top bar */
.theme-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.theme-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

/* Light mode specific terminal */
[data-theme="light"] .log-terminal {
    background: #f8fafc;
    border-color: var(--border);
    color: #334155;
}

[data-theme="light"] .log-message {
    color: #475569;
}

[data-theme="light"] .log-time {
    color: #94a3b8;
}

[data-theme="light"] .log-category {
    color: #7c3aed;
}

/* Light mode login page */
[data-theme="light"] .login-page {
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(37, 99, 235, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(124, 58, 237, 0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(5, 150, 105, 0.04) 0%, transparent 50%);
}

/* ── Login Logo Icon ───────────────────────────────────────── */
.login-logo-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    background: var(--gradient-blue);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    box-shadow: 0 8px 32px rgba(59, 130, 246, 0.3);
}

.login-bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    background: var(--bg-primary);
}

/* ── Glow Button ──────────────────────────────────────────── */
.btn-glow {
    position: relative;
}

.btn-glow::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: inherit;
    background: inherit;
    filter: blur(12px);
    opacity: 0.4;
    z-index: -1;
    transition: opacity 0.3s ease;
}

.btn-glow:hover::after {
    opacity: 0.6;
}

/* ── State Badge ──────────────────────────────────────────── */
.state-badge {
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.state-badge.running {
    background: var(--green-glow);
    color: var(--green);
    border-color: rgba(16, 185, 129, 0.3);
    animation: pulse-badge 2s infinite;
}

.state-badge.ready {
    background: var(--blue-glow);
    color: var(--blue);
    border-color: rgba(59, 130, 246, 0.3);
}

.state-badge.error {
    background: var(--red-glow);
    color: var(--red);
    border-color: rgba(239, 68, 68, 0.3);
}

.state-badge.authenticated, .state-badge.initialized {
    background: var(--yellow-glow);
    color: var(--yellow);
    border-color: rgba(245, 158, 11, 0.3);
}

@keyframes pulse-badge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ── Readiness Panel ──────────────────────────────────────── */
.readiness-panel {
    margin-bottom: 24px;
    padding: 20px 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    backdrop-filter: blur(10px);
}

.readiness-title {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 16px;
}

.readiness-items {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.readiness-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    border: 1px solid var(--border);
    background: var(--bg-glass);
    color: var(--text-muted);
    transition: var(--transition);
}

.readiness-item.ready {
    background: var(--green-glow);
    color: var(--green);
    border-color: rgba(16, 185, 129, 0.2);
}

.readiness-item.pending {
    background: rgba(100, 116, 139, 0.08);
    color: var(--text-dim);
}

.readiness-icon {
    font-size: 1rem;
}

/* ── Stat Card Glow ───────────────────────────────────────── */
.stat-card-glow {
    position: absolute;
    top: -50%;
    right: -30%;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.stat-card:hover .stat-card-glow {
    opacity: 1;
}

.stat-card.profit .stat-card-glow { background: radial-gradient(circle, rgba(16,185,129,0.08) 0%, transparent 70%); }
.stat-card.info .stat-card-glow { background: radial-gradient(circle, rgba(59,130,246,0.08) 0%, transparent 70%); }
.stat-card.purple .stat-card-glow { background: radial-gradient(circle, rgba(139,92,246,0.08) 0%, transparent 70%); }
.stat-card.warn .stat-card-glow { background: radial-gradient(circle, rgba(245,158,11,0.08) 0%, transparent 70%); }

/* ── Pulse LTP ────────────────────────────────────────────── */
.pulse {
    animation: ltp-pulse 1.5s ease-in-out infinite;
}

@keyframes ltp-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ── Mode Switch ──────────────────────────────────────────── */
.mode-switch-container {
    display: flex;
    gap: 8px;
    padding: 6px;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.mode-switch-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
}

.mode-switch-btn.active {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.mode-switch-btn:hover:not(.active) {
    color: var(--text-secondary);
}

/* ── Backtest ─────────────────────────────────────────────── */
.backtest-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.bt-progress {
    padding: 12px;
    background: var(--bg-glass);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.bt-progress-bar {
    height: 6px;
    background: rgba(100, 116, 139, 0.2);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.bt-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--gradient-blue);
    border-radius: 3px;
    transition: width 0.5s ease;
}

.bt-progress-text {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ── Token Status ─────────────────────────────────────────── */
.token-status.success { color: var(--green); }
.token-status.error { color: var(--red); }
.token-status.loading { color: var(--blue); }

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

@media (max-width: 768px) {
    .sidebar {
        display: none;
    }
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .grid-2, .grid-3, .grid-2-1, .grid-1-2 {
        grid-template-columns: 1fr;
    }
}
