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

:root {
    --bg-void: #141413;
    --bg-deep: #1c1c1b;
    --bg-surface: #232321;
    --bg-raised: #2c2c29;
    --bg-hover: #353531;
    --accent-primary: #d97757;
    --accent-primary-dim: #d9775733;
    --accent-primary-glow: #d9775718;
    --accent-secondary: #6a9bcc;
    --accent-tertiary: #788c5d;
    --text-primary: #faf9f5;
    --text-secondary: #b0aea5;
    --text-muted: #7a7870;
    --border: #2e2e2b;
    --border-bright: #3d3d38;
    --red-accent: #d97757;
    --amber-accent: #788c5d;
    --blue-accent: #6a9bcc;
    --font-display: 'Poppins', sans-serif;
    --font-mono: 'Poppins', sans-serif;
}

html { font-size: 15px; }

body {
    background: var(--bg-void);
    color: var(--text-primary);
    font-family: var(--font-display);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Noise texture overlay */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    opacity: 0.025;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    pointer-events: none;
    z-index: 9999;
}

.dashboard {
    position: relative;
    z-index: 1;
    max-width: 1320px;
    margin: 0 auto;
    padding: 2rem 2rem 4rem;
}

/* ─── Header ─── */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 2.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2.5rem;
    animation: fadeSlideDown 0.6s ease both;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-mark {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent-primary), #c4623f);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1rem;
    color: var(--bg-void);
    flex-shrink: 0;
}

.header-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text-primary);
}

.header-subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 400;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-top: 2px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.btn {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.55rem 1.1rem;
    border-radius: 8px;
    border: 1px solid var(--border-bright);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    letter-spacing: 0.02em;
}

.btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: var(--accent-primary-glow);
}

.btn-primary {
    background: var(--accent-primary);
    color: var(--bg-void);
    border-color: var(--accent-primary);
    font-weight: 600;
}

.btn-primary:hover {
    background: #c4623f;
    border-color: #c4623f;
    box-shadow: 0 0 20px var(--accent-primary-dim);
}

.btn .icon {
    font-size: 0.9rem;
    line-height: 1;
}

.btn.loading .icon {
    animation: spin 1s linear infinite;
}

/* ─── Status bar ─── */
.status-bar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 2rem;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-muted);
    animation: fadeSlideDown 0.6s ease 0.1s both;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    display: inline-block;
    margin-right: 0.4rem;
}

.status-dot.live { background: var(--accent-tertiary); box-shadow: 0 0 8px rgba(120, 140, 93, 0.4); }
.status-dot.error { background: var(--red-accent); }

/* ─── Time-Range Chips ─── */
.time-range-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    animation: fadeSlideDown 0.6s ease 0.12s both;
}

.time-chip {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 500;
    padding: 0.35rem 0.9rem;
    border-radius: 20px;
    border: 1px solid var(--border-bright);
    background: var(--bg-surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 0.03em;
}

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

.time-chip.active {
    background: var(--accent-primary);
    color: var(--bg-void);
    border-color: var(--accent-primary);
    font-weight: 600;
}

/* ─── Hero Stats ─── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.4rem 1.5rem;
    position: relative;
    overflow: hidden;
    transition: border-color 0.3s ease, transform 0.2s ease;
    animation: fadeSlideUp 0.5s ease both;
}

.stat-card:nth-child(1) { animation-delay: 0.15s; }
.stat-card:nth-child(2) { animation-delay: 0.2s; }
.stat-card:nth-child(3) { animation-delay: 0.25s; }
.stat-card:nth-child(4) { animation-delay: 0.3s; }

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

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-primary-dim), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

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

.stat-label {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.7rem;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 1.7rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.stat-value .unit {
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--text-secondary);
    margin-left: 0.25rem;
}

.stat-value.green { color: var(--accent-primary); }

.stat-sub {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.stat-sub .change-up { color: var(--accent-tertiary); }
.stat-sub .change-down { color: var(--red-accent); }

/* ─── Chart Panels ─── */
.panel {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    animation: fadeSlideUp 0.5s ease both;
}

.panel:nth-of-type(1) { animation-delay: 0.35s; }
.panel:nth-of-type(2) { animation-delay: 0.4s; }
.panel:nth-of-type(3) { animation-delay: 0.45s; }

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.panel-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.panel-title .accent {
    color: var(--accent-primary);
}

.panel-desc {
    font-size: 0.73rem;
    color: var(--text-muted);
    margin: -0.5rem 0 1rem;
    line-height: 1.5;
    letter-spacing: 0.01em;
}

.toggle-group {
    display: flex;
    gap: 2px;
    background: var(--bg-deep);
    border-radius: 8px;
    padding: 3px;
    border: 1px solid var(--border);
}

.toggle-btn {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 500;
    padding: 0.35rem 0.75rem;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 0.02em;
}

.toggle-btn.active {
    background: var(--bg-raised);
    color: var(--accent-primary);
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

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

.chart-wrap {
    position: relative;
    height: 320px;
}

.chart-wrap canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ─── Wallet Table ─── */
.wallet-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 0.78rem;
}

.wallet-table thead th {
    text-align: left;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.68rem;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--border);
}

.wallet-table thead th:last-child,
.wallet-table tbody td:last-child { text-align: right; }

.wallet-table tbody td {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    transition: color 0.2s;
}

.wallet-table tbody tr:hover td { color: var(--text-primary); }

.wallet-table tbody tr:last-child td { border-bottom: none; }

.wallet-name {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

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

.wallet-dot.fe { background: var(--accent-primary); }
.wallet-dot.cs { background: var(--blue-accent); }
.wallet-dot.proto { background: #788c5d; }

.mono-val {
    font-weight: 500;
    color: var(--text-primary);
}

.pct-bar-cell {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    justify-content: flex-end;
}

.pct-bar-bg {
    width: 80px;
    height: 4px;
    background: var(--bg-deep);
    border-radius: 2px;
    overflow: hidden;
}

.pct-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.6s ease;
}

.pct-bar-fill.fe { background: var(--accent-primary); }
.pct-bar-fill.cs { background: var(--blue-accent); }

/* ─── Footer ─── */
.footer {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    color: var(--text-muted);
    animation: fadeSlideUp 0.5s ease 0.5s both;
}

.footer a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s;
}

.footer a:hover { color: var(--accent-primary); }

/* ─── Loading / Error States ─── */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: var(--bg-void);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loader-ring {
    width: 44px;
    height: 44px;
    border: 2px solid var(--border);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-text {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-muted);
    letter-spacing: 0.04em;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 300;
    background: var(--bg-raised);
    border: 1px solid var(--border-bright);
    border-radius: 10px;
    padding: 0.8rem 1.2rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-secondary);
    transform: translateY(120%);
    opacity: 0;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toast.visible { transform: translateY(0); opacity: 1; }
.toast.error { border-color: var(--red-accent); color: var(--red-accent); }

/* Skeleton loading for stat values */
.skeleton {
    background: linear-gradient(90deg, var(--bg-raised) 25%, var(--bg-hover) 50%, var(--bg-raised) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
    display: inline-block;
    height: 1em;
    width: 6rem;
    vertical-align: middle;
}

/* ─── Animations ─── */
@keyframes fadeSlideDown {
    from { opacity: 0; transform: translateY(-12px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

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

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

/* ─── Responsive ─── */
@media (max-width: 900px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .chart-wrap { height: 260px; }
}

@media (max-width: 600px) {
    .dashboard { padding: 1.2rem 1rem 3rem; }
    .stats-grid { grid-template-columns: 1fr; }
    .header { flex-direction: column; align-items: flex-start; gap: 1rem; }
    .stat-value { font-size: 1.4rem; }
    .footer { flex-direction: column; gap: 0.5rem; text-align: center; }
}
