/* ===========================
   Design System — Crypto Dashboard
   Shared tokens, themes, and components
   =========================== */

/* --- CSS Custom Properties (Light Theme — Default) --- */
:root {
    /* Primary palette */
    --color-green: #4CAF50;
    --color-green-dark: #388E3C;
    --color-green-light: #81C784;
    --color-blue: #2196F3;
    --color-blue-dark: #1565C0;
    --color-blue-light: #64B5F6;

    /* Semantic colors */
    --color-positive: #2E7D32;
    --color-positive-bg: rgba(76, 175, 80, 0.12);
    --color-negative: #C62828;
    --color-negative-bg: rgba(198, 40, 40, 0.10);
    --color-warning: #E65100;
    --color-warning-bg: rgba(230, 81, 0, 0.10);
    --color-protected-bg: rgba(33, 150, 243, 0.15);

    /* Surface colors */
    --bg: #f0f4f8;
    --bg-card: #ffffff;
    --bg-card-hover: #f8fafc;
    --bg-header: #e8edf2;
    --bg-input: #ffffff;

    /* Text */
    --text-primary: #1a2332;
    --text-secondary: #5a6a7a;
    --text-muted: #8a96a3;
    --text-inverse: #ffffff;

    /* Borders & shadows */
    --border-color: #dde3ea;
    --border-radius: 10px;
    --border-radius-sm: 6px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.10);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-size-xs: 11px;
    --font-size-sm: 13px;
    --font-size-base: 15px;
    --font-size-lg: 18px;
    --font-size-xl: 22px;
    --font-size-2xl: 28px;
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    /* Row highlights */
    --row-protected: rgba(33, 150, 243, 0.13);
    --row-profit: rgba(76, 175, 80, 0.13);

    /* Transition */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* --- Dark Theme --- */
[data-theme="dark"] {
    --bg: #0f1419;
    --bg-card: #1a2332;
    --bg-card-hover: #1f2b3d;
    --bg-header: #15202b;
    --bg-input: #253341;

    --text-primary: #e7e9ea;
    --text-secondary: #8899a6;
    --text-muted: #5c6d7e;

    --border-color: #2f3e50;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);

    --color-positive-bg: rgba(76, 175, 80, 0.18);
    --color-negative-bg: rgba(198, 40, 40, 0.18);
    --color-warning-bg: rgba(230, 81, 0, 0.18);
    --color-protected-bg: rgba(33, 150, 243, 0.2);

    --row-protected: rgba(33, 150, 243, 0.2);
    --row-profit: rgba(76, 175, 80, 0.18);
}

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

html {
    font-size: var(--font-size-base);
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    transition: background var(--transition-normal), color var(--transition-normal);
}

a {
    color: var(--color-blue);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* --- Card Component --- */
.card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: all var(--transition-normal);
    overflow: hidden;
}

.card:hover {
    border-color: var(--color-blue);
    box-shadow: var(--shadow-sm);
    /* Keep small shadow, don't grow to md */
}

.card-header {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
    font-weight: var(--font-weight-semibold);
}

.card-body {
    padding: var(--space-md);
}

/* Card tint variants */
.card-protected {
    background: var(--row-protected);
}

.card-profit {
    background: var(--row-profit);
}

/* --- Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    line-height: 1.4;
}

.badge-buy {
    background: var(--color-positive-bg);
    color: var(--color-positive);
}

.badge-sell {
    background: var(--color-negative-bg);
    color: var(--color-negative);
}

.badge-protected {
    background: var(--color-protected-bg);
    color: var(--color-blue);
    font-size: 9px;
    margin-left: var(--space-xs);
}

.badge-orders {
    background: var(--color-negative);
    color: var(--text-inverse);
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: var(--space-xs);
}

/* --- Stat Value --- */
.stat-value {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.stat-sub {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

/* --- Value coloring --- */
.val-positive {
    color: var(--color-positive);
}

.val-negative {
    color: var(--color-negative);
}

.val-warning {
    color: var(--color-warning);
}

.val-muted {
    color: var(--text-muted);
}

/* --- Toggle Switch (dark/light) --- */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
    user-select: none;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.theme-toggle-track {
    position: relative;
    width: 36px;
    height: 20px;
    background: var(--border-color);
    border-radius: 10px;
    transition: background var(--transition-normal);
}

[data-theme="dark"] .theme-toggle-track {
    background: var(--color-blue);
}

.theme-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform var(--transition-normal);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .theme-toggle-thumb {
    transform: translateX(16px);
}

/* --- Events (expand/collapse) --- */
.events-pre {
    font-size: var(--font-size-xs);
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.3;
    color: var(--text-secondary);
    font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
}

.events-collapsed {
    overflow: hidden;
}

.events-toggle {
    display: inline-block;
    margin-top: var(--space-xs);
    font-size: var(--font-size-xs);
    color: var(--color-blue);
    cursor: pointer;
    user-select: none;
    font-weight: var(--font-weight-medium);
}

.events-toggle:hover {
    text-decoration: underline;
}

/* --- Footer --- */
.footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-md);
    padding: var(--space-lg) var(--space-md);
    margin-top: var(--space-lg);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

.footer-links {
    display: flex;
    gap: var(--space-lg);
    align-items: center;
}

/* WebSocket connection status */
.ws-status {
    font-size: var(--font-size-xs);
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

.ws-connected {
    color: var(--color-green);
}

.ws-reconnecting {
    color: var(--color-warning);
}

.ws-disconnected {
    color: var(--text-muted);
}

/* Bybit price links */
.bybit-link {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dotted var(--text-muted);
    transition: border-color var(--transition-fast), color var(--transition-fast);
}

.bybit-link:hover {
    color: var(--color-blue);
    border-bottom-color: var(--color-blue);
    text-decoration: none;
}

/* --- Utility classes --- */
.text-right {
    text-align: right;
}

.text-center {
    text-align: center;
}

.text-sm {
    font-size: var(--font-size-sm);
}

.text-xs {
    font-size: var(--font-size-xs);
}

.text-muted {
    color: var(--text-muted);
}

.font-mono {
    font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
}

.mb-xs {
    margin-bottom: var(--space-xs);
}

.mb-sm {
    margin-bottom: var(--space-sm);
}

.mb-md {
    margin-bottom: var(--space-md);
}

.mb-lg {
    margin-bottom: var(--space-lg);
}

.desktop-only {
    display: initial;
}

.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: initial !important;
    }
}

/* Smooth number transitions */
.smooth-value {
    transition: color var(--transition-fast);
}
