/* ============================================================
   STYLE.CSS — Global Dark Modern Theme (supplements Bootstrap)
   ============================================================ */

:root {
    --bg-primary:    #0d1117;
    --bg-secondary:  #161b22;
    --bg-tertiary:   #21262d;
    --border-color:  #30363d;
    --text-primary:  #e6edf3;
    --text-secondary:#8b949e;
    --text-muted:    #6e7681;
    --accent-blue:   #58a6ff;
    --accent-green:  #3fb950;
    --accent-red:    #f85149;
    --accent-yellow: #d29922;
    --accent-purple: #a371f7;
}

/* ── Base ─────────────────────────────────────────────────── */
body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter',
                 Helvetica, Arial, sans-serif;
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    margin-bottom: 1.5rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5),
                0 0 0 1px rgba(88, 166, 255, 0.12);
}

.card-header {
    background-color: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    color: var(--text-primary);
    border-radius: 10px 10px 0 0 !important;
}

/* ── Summary / Stat Cards ─────────────────────────────────── */
.stat-card {
    border-radius: 10px;
    border: 1px solid;
    padding: 1.25rem 1.5rem;
    transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.stat-card.blue   { background: linear-gradient(135deg, #1c4a8c, #1158c7); border-color: rgba(88, 166, 255, 0.35); }
.stat-card.green  { background: linear-gradient(135deg, #1a4731, #238636); border-color: rgba(63, 185, 80, 0.35);  }
.stat-card.yellow { background: linear-gradient(135deg, #5a3e10, #9e6a03); border-color: rgba(210, 153, 34, 0.35); }
.stat-card.teal   { background: linear-gradient(135deg, #0d3a5c, #0969da); border-color: rgba(88, 166, 255, 0.35); }

.stat-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: rgba(255, 255, 255, 0.65);
    font-weight: 600;
    margin-bottom: 0.4rem;
}
.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.02em;
    line-height: 1;
}
.stat-badge {
    display: inline-block;
    margin-top: 0.5rem;
    padding: 0.25em 0.65em;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.9);
}

/* ── P&L colour helpers ───────────────────────────────────── */
.profit-positive { color: var(--accent-green); font-weight: 600; }
.profit-negative { color: var(--accent-red);   font-weight: 600; }
.text-success    { color: var(--accent-green) !important; }
.text-danger     { color: var(--accent-red)   !important; }
.text-muted      { color: var(--text-secondary) !important; }
.text-primary    { color: var(--accent-blue)  !important; }

/* ── Badges ───────────────────────────────────────────────── */
.badge-long  { background-color: #238636 !important; }
.badge-short { background-color: #9e6a03 !important; }

.action-badge  { padding: 0.35em 0.65em; font-size: 0.72rem; font-weight: 700; border-radius: 6px; }
.action-buy    { background-color: #238636; color: white; }
.action-sell   { background-color: #da3633; color: white; }
.action-short  { background-color: #9e6a03; color: white; }
.action-cover  { background-color: #0969da; color: white; }

/* ── Tables ───────────────────────────────────────────────── */
.table {
    color: var(--text-primary);
    margin-bottom: 0;
    --bs-table-bg: transparent;
    --bs-table-striped-bg: rgba(33, 38, 45, 0.5);
    --bs-table-hover-bg: rgba(88, 166, 255, 0.06);
    --bs-table-border-color: var(--border-color);
}

.table thead th {
    background-color: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    border-top: none;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.775rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    padding: 0.75rem 1rem;
    white-space: nowrap;
}

.table td {
    border-color: var(--border-color);
    vertical-align: middle;
    padding: 0.65rem 1rem;
    color: var(--text-primary);
}

.table-striped > tbody > tr:nth-of-type(odd) > * {
    background-color: rgba(33, 38, 45, 0.4);
    color: var(--text-primary);
}

.table-hover > tbody > tr:hover > * {
    background-color: rgba(88, 166, 255, 0.07);
    color: var(--text-primary);
}

.table-dark {
    --bs-table-bg: #1c2129;
    --bs-table-striped-bg: rgba(255,255,255,0.03);
    --bs-table-hover-bg: rgba(88,166,255,0.08);
}

.table-dark thead th {
    background-color: #1c2129;
    border-color: var(--border-color);
    color: var(--text-secondary);
}

/* ── Forms ────────────────────────────────────────────────── */
.form-control,
.form-select {
    background-color: var(--bg-tertiary);
    border-color: var(--border-color);
    color: var(--text-primary);
    border-radius: 6px;
}
.form-control:focus,
.form-select:focus {
    background-color: var(--bg-tertiary);
    border-color: var(--accent-blue);
    color: var(--text-primary);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.2);
}
.form-control::placeholder { color: var(--text-muted); }
.form-select option { background-color: var(--bg-secondary); }
.input-group-text {
    background-color: var(--bg-tertiary);
    border-color: var(--border-color);
    color: var(--text-secondary);
}

/* Filter active highlight */
select.form-select:not([value="all"]):not([value=""]) {
    border-color: rgba(88,166,255,0.5);
}
#position-search:not(:placeholder-shown) {
    border-color: rgba(88,166,255,0.5);
}

/* ── Navbar ───────────────────────────────────────────────── */
.navbar {
    background-color: var(--bg-secondary) !important;
    border-bottom: 1px solid var(--border-color) !important;
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.5);
}
.navbar-brand {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text-primary) !important;
}
.navbar-brand:hover { color: var(--accent-blue) !important; }
.nav-link {
    color: var(--text-secondary) !important;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 6px;
    transition: all 0.15s;
}
.nav-link:hover  { color: var(--text-primary) !important; background-color: var(--bg-tertiary); }
.nav-link.active { color: var(--accent-blue)  !important; background-color: rgba(88,166,255,0.1); }

/* ── Loading spinner ──────────────────────────────────────── */
.loading-spinner {
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--accent-blue);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 0.8s linear infinite;
    margin: 20px auto;
}
@keyframes spin {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ── Floating action button ───────────────────────────────── */
.btn-float {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    box-shadow: 0 4px 16px rgba(31, 111, 235, 0.5);
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.2s ease;
    background-color: #1f6feb;
    border-color: #1f6feb;
    color: white;
}
.btn-float:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(31, 111, 235, 0.7);
    background-color: #388bfd;
    color: white;
}

/* ── Chart container ──────────────────────────────────────── */
.chart-container {
    position: relative;
    height: 400px;
    margin-bottom: 20px;
}

/* ── bg-purple ────────────────────────────────────────────── */
.bg-purple { background-color: #6e40c9 !important; color: white; }

/* ── Scale group (metrics page) ───────────────────────────── */
.scale-group { display: flex; align-items: center; gap: 8px; }
.scale-group button { margin-right: 5px; }
.scale-group button:hover { background-color: var(--bg-tertiary) !important; }

/* ── Positions table row click ────────────────────────────── */
#positions-table tr { transition: background-color 0.15s ease; }

/* ── Modals ───────────────────────────────────────────────── */
.modal-content {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    box-shadow: 0 20px 60px rgba(0,0,0,0.8);
}
.modal-header {
    background-color: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    border-radius: 12px 12px 0 0;
}
.modal-footer {
    background-color: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
    border-radius: 0 0 12px 12px;
}
.btn-close,
.btn-close-white { filter: invert(1) grayscale(100%) brightness(200%); }

/* ── Alerts ───────────────────────────────────────────────── */
.alert-danger  { background-color: rgba(248,81,73,0.12);  border-color: rgba(248,81,73,0.4);  color: #ffa198; }
.alert-success { background-color: rgba(63,185,80,0.12);  border-color: rgba(63,185,80,0.4);  color: #7ee787; }
.alert-warning { background-color: rgba(210,153,34,0.12); border-color: rgba(210,153,34,0.4); color: #e3b341; }
.alert-info    { background-color: rgba(88,166,255,0.12); border-color: rgba(88,166,255,0.4); color: #79c0ff; }

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #484f58; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
    .btn-float { bottom: 20px; right: 20px; width: 48px; height: 48px; }
    .card-body h2 { font-size: 1.4rem; }
    .table-responsive { font-size: 0.8rem; }
}

/* ── Phones < 480px ───────────────────────────────────────── */
@media (max-width: 479.98px) {
    .navbar-brand span:last-child { font-size: 0.875rem; }
    .page-header h2               { font-size: 1.1rem; }
    .card-body                    { padding: 0.75rem; }
    .table                        { font-size: 0.75rem; }
    .btn                          { min-height: 44px; }  /* iOS HIG touch target */
    h5, .h5                       { font-size: 0.95rem; }
}

/* ── iPhone safe-area for floating button ─────────────────── */
.btn-float {
    bottom: max(20px, calc(20px + env(safe-area-inset-bottom)));
    right:  max(20px, calc(20px + env(safe-area-inset-right)));
}