/*
 * XAUUSDT Scalper Dashboard — SaaS Design System
 * Glass-morphism, dark theme, responsive, animated.
 */

/* ── Custom Properties ──────────────────────────────────────── */
:root {
    /* Palette */
    --bg-deep: #070a13;
    --bg-surface: #0f1324;
    --bg-card: #121828;
    --bg-card-hover: #182034;
    --bg-sidebar: #0a0e17;
    --accent: #f0b90b;
    --accent-dim: rgba(240, 185, 11, 0.15);
    --accent-glow: rgba(240, 185, 11, 0.3);
    --profit: #00c9a7;
    --profit-dim: rgba(0, 201, 167, 0.12);
    --loss: #ff4154;
    --loss-dim: rgba(255, 65, 84, 0.12);
    --warn: #f59e0b;
    --warn-dim: rgba(245, 158, 11, 0.12);
    --text: #e8ecf1;
    --text-secondary: #8b8fa3;
    --text-muted: #555a6e;
    --border: rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.1);
    /* Radii */
    --radius-sm: 8px;
    --radius: 14px;
    --radius-lg: 20px;
    /* Shadows */
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.35);
    --shadow-glow: 0 0 20px var(--accent-glow);
    /* Transitions */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    /* Fonts */
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

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

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    background: var(--bg-deep);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    background-image:
        radial-gradient(ellipse at 20% 0%, rgba(240, 185, 11, 0.03) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 100%, rgba(0, 201, 167, 0.03) 0%, transparent 60%);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #f5c742; }

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

/* ── Layout ─────────────────────────────────────────────────── */
.dashboard-layout {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    padding: 1.5rem 2rem;
    overflow-y: auto;
    min-width: 0;
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
    width: 260px;
    flex-shrink: 0;
    padding: 1.5rem 1rem;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

/* Sidebar Brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.75rem;
    padding: 0 0.5rem;
}

.sidebar-brand .brand-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent), #f5c742);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: #0a0e17;
    font-weight: 700;
    box-shadow: 0 0 16px rgba(240, 185, 11, 0.25);
}

.sidebar-brand-text h2 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.sidebar-brand-text span {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 500;
}

/* Sidebar Status */
.sidebar-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    padding: 0.6rem 0.5rem;
    margin-bottom: 1.25rem;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.running {
    background: var(--profit);
    box-shadow: 0 0 8px rgba(0, 201, 167, 0.5);
    animation: breathe 2s ease-in-out infinite;
}

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

.status-dot.starting {
    background: var(--warn);
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes breathe {
    0%, 100% { opacity: 1; box-shadow: 0 0 4px rgba(0, 201, 167, 0.4); }
    50% { opacity: 0.5; box-shadow: 0 0 12px rgba(0, 201, 167, 0.7); }
}

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

/* Sidebar Nav */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s var(--ease);
    position: relative;
}

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

.nav-item.active {
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--accent);
    border-radius: 0 2px 2px 0;
}

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.7; }
.nav-item.active svg { opacity: 1; }

/* Sidebar Footer */
.sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.quick-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.78rem;
}

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

.quick-stat .stat-value {
    font-weight: 600;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text);
}

/* ── Cards ──────────────────────────────────────────────────── */
.card-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-card);
    transition: border-color 0.3s var(--ease), box-shadow 0.3s var(--ease);
}

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

.card header {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 1rem;
    padding-bottom: 0.65rem;
    border-bottom: 1px solid var(--border);
}

.card header svg { width: 14px; height: 14px; }

/* Position Card */
.position-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 0;
    font-size: 0.85rem;
}

.position-row .label {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.position-row .value {
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: 0.82rem;
}

.value.positive { color: var(--profit); }
.value.negative { color: var(--loss); }
.value.neutral { color: var(--text); }

#pos-status {
    color: var(--text-muted);
    font-size: 0.85rem;
}

#pos-status.active-long {
    color: var(--profit) !important;
    font-weight: 700 !important;
    font-size: 0.9rem !important;
}

/* Stats Card */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

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

.stat-value {
    font-size: 1.3rem;
    font-weight: 700;
    font-family: var(--font-mono);
    letter-spacing: -0.02em;
    transition: color 0.4s var(--ease);
}

.stat-value.positive { color: var(--profit); }
.stat-value.negative { color: var(--loss); }

/* Risk Gates Card */
.gates-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.gate-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gate-label {
    font-size: 0.83rem;
    color: var(--text-secondary);
}

/* Badge System */
.gate-badge {
    padding: 0.2rem 0.7rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-family: var(--font);
    transition: all 0.3s var(--ease);
}

.gate-badge.ok {
    background: var(--profit-dim);
    color: var(--profit);
    border: 1px solid rgba(0, 201, 167, 0.25);
}

.gate-badge.warn {
    background: var(--warn-dim);
    color: var(--warn);
    border: 1px solid rgba(245, 158, 11, 0.25);
}

.gate-badge.blocked {
    background: var(--loss-dim);
    color: var(--loss);
    border: 1px solid rgba(255, 65, 84, 0.25);
}

/* ── Charts ─────────────────────────────────────────────────── */
.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-card);
}

.chart-container h4 {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0.6rem;
    font-weight: 600;
}

.tradingview-widget-container {
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.tradingview-widget-container iframe {
    border-radius: var(--radius-sm);
}

/* ── Tables ─────────────────────────────────────────────────── */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

table.striped tbody tr:nth-child(odd) {
    background: rgba(255, 255, 255, 0.015);
}

thead th {
    text-align: left;
    padding: 0.6rem 0.75rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-surface);
    z-index: 1;
}

tbody td {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.78rem;
}

tbody tr:hover td {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text);
}

td.positive { color: var(--profit) !important; }
td.negative { color: var(--loss) !important; }

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

/* ── Trade Filters ──────────────────────────────────────────── */
.trade-filters {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.trade-filters input,
.trade-filters select {
    padding: 0.5rem 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
    max-width: 240px;
    outline: none;
    transition: border-color 0.2s var(--ease);
}

.trade-filters input:focus,
.trade-filters select:focus {
    border-color: var(--accent);
}

.trade-filters input::placeholder {
    color: var(--text-muted);
}

.trade-filters select option {
    background: var(--bg-surface);
    color: var(--text);
}

/* ── Pagination ─────────────────────────────────────────────── */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.pagination button {
    padding: 0.4rem 0.85rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s var(--ease);
}

.pagination button:hover:not(:disabled) {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

.pagination button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.pagination span {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* ── Settings ───────────────────────────────────────────────── */
.settings-section {
    margin-bottom: 1.5rem;
}

.settings-section h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.6rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.45rem;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.45rem 0.75rem;
    background: rgba(255, 255, 255, 0.015);
    border-radius: var(--radius-sm);
    font-size: 0.84rem;
}

.setting-key {
    color: var(--text-secondary);
}

.setting-value {
    font-weight: 600;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--text);
}

/* ── Toast Notifications ────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 9999;
    display: flex;
    flex-direction: column-reverse;
    gap: 0.5rem;
}

.toast {
    padding: 0.75rem 1.1rem;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 500;
    background: var(--bg-card);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--border-strong);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    max-width: 380px;
    animation: slideIn 0.35s var(--ease-spring);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toast.win { border-left: 3px solid var(--profit); }
.toast.loss { border-left: 3px solid var(--loss); }

.toast strong {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
}

.toast.win strong { background: var(--profit-dim); color: var(--profit); }
.toast.loss strong { background: var(--loss-dim); color: var(--loss); }

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

/* ── Loading Skeletons ──────────────────────────────────────── */
.skeleton {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.03) 25%,
        rgba(255, 255, 255, 0.06) 50%,
        rgba(255, 255, 255, 0.03) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-card {
    height: 180px;
    border-radius: var(--radius);
}

.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
    width: 100%;
}

.skeleton-text.short { width: 60%; }
.skeleton-text.medium { width: 80%; }

.skeleton-value {
    height: 28px;
    width: 45%;
    margin-bottom: 12px;
}

.skeleton-chart {
    height: 400px;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}

.skeleton-table {
    height: 300px;
    border-radius: var(--radius);
}

.skeleton-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

/* ── Empty States ───────────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    text-align: center;
    color: var(--text-muted);
}

.empty-state svg {
    width: 56px;
    height: 56px;
    margin-bottom: 1rem;
    opacity: 0.4;
}

.empty-state h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
}

.empty-state p {
    font-size: 0.85rem;
    color: var(--text-muted);
    max-width: 320px;
}

/* ── Animated Entrances ─────────────────────────────────────── */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.card { animation: fadeInUp 0.5s var(--ease) both; }
.card:nth-child(1) { animation-delay: 0.05s; }
.card:nth-child(2) { animation-delay: 0.1s; }
.card:nth-child(3) { animation-delay: 0.15s; }

/* Value flash on change */
.value-flash-green {
    animation: flashGreen 0.5s var(--ease);
}
.value-flash-red {
    animation: flashRed 0.5s var(--ease);
}

@keyframes flashGreen {
    0% { color: var(--profit); text-shadow: 0 0 12px rgba(0, 201, 167, 0.5); }
    100% { color: inherit; text-shadow: none; }
}

@keyframes flashRed {
    0% { color: var(--loss); text-shadow: 0 0 12px rgba(255, 65, 84, 0.5); }
    100% { color: inherit; text-shadow: none; }
}

/* ── Utility ────────────────────────────────────────────────── */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mono { font-family: var(--font-mono); }
.hidden { display: none !important; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-xs { gap: 0.35rem; }
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 0.75rem; }

/* ── Number counter animation class ─────────────────────────── */
.animate-number {
    display: inline-block;
    transition: color 0.3s var(--ease);
}

/* ── Page headings ──────────────────────────────────────────── */
h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1rem;
    letter-spacing: -0.02em;
}

/* ── Error / Retry ──────────────────────────────────────────── */
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 2rem;
    text-align: center;
    color: var(--loss);
}

.error-state button {
    padding: 0.5rem 1rem;
    background: var(--loss-dim);
    border: 1px solid rgba(255, 65, 84, 0.3);
    border-radius: var(--radius-sm);
    color: var(--loss);
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.85rem;
    transition: all 0.2s var(--ease);
}

.error-state button:hover {
    background: rgba(255, 65, 84, 0.2);
}

/* ── Summary Cards (Trades page) ────────────────────────────── */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.summary-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
}

.summary-card header {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
    font-weight: 600;
}

.summary-card .value {
    font-size: 1.4rem;
    font-weight: 700;
    font-family: var(--font-mono);
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 1280px) {
    .card-grid { grid-template-columns: repeat(2, 1fr); }
    .card-grid .card:last-child { grid-column: span 2; }
}

@media (max-width: 1024px) {
    .card-grid { grid-template-columns: repeat(2, 1fr); }
    .card-grid .card:last-child { grid-column: span 2; }
    .main-content { padding: 1rem 1.25rem; }
    .sidebar { width: 220px; }
}

@media (max-width: 768px) {
    .dashboard-layout { flex-direction: column; }
    .sidebar {
        width: 100%;
        flex-direction: row;
        align-items: center;
        padding: 0.75rem 1rem;
        border-right: none;
        border-bottom: 1px solid var(--border);
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .sidebar-brand { margin-bottom: 0; }
    .sidebar-status { margin-bottom: 0; font-size: 0.75rem; padding: 0.3rem 0.5rem; }
    .sidebar-nav { flex-direction: row; flex: none; gap: 0.25rem; }
    .sidebar-nav .nav-item { padding: 0.4rem 0.6rem; font-size: 0.8rem; }
    .sidebar-nav .nav-item span { display: none; }
    .sidebar-footer { display: none; }
    .main-content { padding: 0.75rem; }
    .card-grid { grid-template-columns: 1fr; }
    .card-grid .card:last-child { grid-column: span 1; }
    .summary-grid { grid-template-columns: repeat(2, 1fr); }
    .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    html { font-size: 14px; }
    .sidebar-brand-text { display: none; }
    .sidebar-nav .nav-item { font-size: 0.75rem; padding: 0.35rem 0.5rem; }
    .stat-value { font-size: 1.1rem; }
    .summary-grid { grid-template-columns: 1fr; }
    .trade-filters { flex-direction: column; }
    .trade-filters input,
    .trade-filters select { max-width: 100%; }
}
