/* MotherHaven Trading Dashboard - Professional Trading Terminal Styling */

/* ============================
   CSS Variables (Theming)
   ============================ */
:root {
    /* Background Colors */
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-elevated: #30363d;

    /* Text Colors */
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;

    /* Accent Colors */
    --accent-primary: #58a6ff;
    --accent-secondary: #1f6feb;
    --accent-hover: #388bfd;

    /* Terminal Noir - Gold Accent System */
    --gold: #C9A87C;
    --gold-bright: #D4B896;
    --gold-dim: #8B7355;
    --text-gold: #C9A87C;
    --gold-glow: rgba(201, 168, 124, 0.15);
    --gold-border: rgba(201, 168, 124, 0.15);
    --gold-border-hover: rgba(201, 168, 124, 0.3);
    --gold-border-active: rgba(201, 168, 124, 0.4);

    /* Terminal Noir - Surface System (unified) */
    --surface-noir: rgba(13, 17, 23, 0.95);
    --surface-noir-2: rgba(22, 27, 34, 0.9);
    --surface-noir-elevated: rgba(48, 54, 61, 0.5);
    --surface-1: rgba(13, 17, 23, 0.95);
    --surface-2: rgba(22, 27, 34, 0.9);
    --surface-3: rgba(33, 38, 45, 0.85);
    --surface-glass: rgba(48, 54, 61, 0.5);

    /* Terminal Noir - Border System (unified) */
    --border-subtle: rgba(201, 168, 124, 0.15);
    --border-accent: rgba(201, 168, 124, 0.3);
    --border-color: rgba(201, 168, 124, 0.2);

    /* Terminal Noir - Shadows */
    --shadow-noir: 0 4px 24px rgba(0, 0, 0, 0.4);
    --shadow-noir-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

    /* Status Colors */
    --status-success: #3fb950;
    --status-success-bg: rgba(63, 185, 80, 0.15);
    --status-warning: #d29922;
    --status-warning-bg: rgba(210, 153, 34, 0.15);
    --status-error: #f85149;
    --status-error-bg: rgba(248, 81, 73, 0.15);
    --status-info: #58a6ff;
    --status-info-bg: rgba(88, 166, 255, 0.15);
    --status-neutral: #8b949e;
    --status-neutral-bg: rgba(139, 148, 158, 0.15);

    /* Trading Colors */
    --long-color: #3fb950;
    --long-bg: rgba(63, 185, 80, 0.1);
    --short-color: #f85149;
    --short-bg: rgba(248, 81, 73, 0.1);

    /* Border Colors */
    --border-default: #30363d;
    --border-muted: #21262d;
    --border-focus: #58a6ff;

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.5);

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
    --font-display: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.25rem;
    --font-size-xl: 1.5rem;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s ease;

    /* Responsive Breakpoints (for reference - use in media queries) */
    /* --breakpoint-sm: 640px;   Small devices (landscape phones) */
    /* --breakpoint-md: 768px;   Medium devices (tablets) */
    /* --breakpoint-lg: 1024px;  Large devices (desktops) */

    /* Mobile-first Spacing (smaller on mobile, scales up) */
    --container-padding: var(--spacing-sm);
    --section-gap: var(--spacing-md);

    /* Responsive Font Sizes (mobile-first base) */
    --font-size-heading-xl: 1.5rem;
    --font-size-heading-lg: 1.25rem;
    --font-size-heading-md: 1.125rem;
    --font-size-body: 0.875rem;
}

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

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

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

/* ============================
   Unified Scrollbar Styles - Terminal Noir
   Applies to all scrollable elements
   ============================ */

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--gold-dim) transparent;
}

/* Webkit scrollbar (Chrome, Safari, Edge) */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--gold-dim);
    border-radius: 3px;
    transition: background 0.2s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gold);
}

/* Scrollbar corner (where h and v scrollbars meet) */
::-webkit-scrollbar-corner {
    background: transparent;
}

/* Thinner scrollbar variant for compact areas */
.scrollbar-thin::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

.scrollbar-thin::-webkit-scrollbar-thumb {
    border-radius: 2px;
}

/* Hidden scrollbar (still scrollable) */
.scrollbar-hidden::-webkit-scrollbar {
    display: none;
}

.scrollbar-hidden {
    scrollbar-width: none;
}

/* ============================
   Responsive Typography & Spacing
   Mobile-first breakpoints: 640px, 768px, 1024px
   ============================ */

/* Small devices (640px and up) */
@media (min-width: 640px) {
    :root {
        --container-padding: var(--spacing-md);
        --section-gap: var(--spacing-md);
        --font-size-heading-xl: 1.75rem;
        --font-size-heading-lg: 1.375rem;
        --font-size-heading-md: 1.25rem;
        --font-size-body: 0.9375rem;
    }
}

/* Medium devices - tablets (768px and up) */
@media (min-width: 768px) {
    :root {
        --container-padding: var(--spacing-md);
        --section-gap: var(--spacing-lg);
        --font-size-heading-xl: 2rem;
        --font-size-heading-lg: 1.5rem;
        --font-size-heading-md: 1.25rem;
        --font-size-body: 1rem;
    }
}

/* Large devices - desktops (1024px and up) */
@media (min-width: 1024px) {
    :root {
        --container-padding: var(--spacing-lg);
        --section-gap: var(--spacing-xl);
        --font-size-heading-xl: 2.25rem;
        --font-size-heading-lg: 1.75rem;
        --font-size-heading-md: 1.5rem;
        --font-size-body: 1rem;
    }
}

/* ============================
   Layout - Container
   ============================ */
.container {
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
    padding: var(--container-padding);
}

/* Container responsive width constraints */
@media (max-width: 768px) {
    .container {
        max-width: 100%;
        padding-left: var(--spacing-sm);
        padding-right: var(--spacing-sm);
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        max-width: 100%;
        padding-left: var(--spacing-md);
        padding-right: var(--spacing-md);
    }
}

/* ============================
   Sticky Header
   ============================ */
.sticky-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-default);
    padding: var(--spacing-sm) 0;
    margin-bottom: var(--spacing-md);
}

/* Sticky header responsive padding */
@media (max-width: 768px) {
    .sticky-header {
        padding: var(--spacing-xs) 0;
        margin-bottom: var(--spacing-sm);
    }
}

/* ============================
   Main Navigation Tabs
   Terminal Noir Design
   ============================ */
.main-tabs {
    display: flex;
    gap: 2px;
    padding: 6px 10px;
    background: var(--surface-noir);
    border-radius: 8px;
    border: 1px solid var(--gold-border);
    box-shadow: var(--shadow-noir);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* Main tabs responsive - keep nav container visible but adjust for mobile */
@media (max-width: 768px) {
    .main-tabs {
        /* Keep container visible for hamburger button and network selector */
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 6px 10px;
        border-radius: 6px;
    }

    /* Hide the horizontal tab links on mobile - they're in the hamburger menu */
    .main-tabs .tabs-left {
        display: none;
    }
}

/* ============================
   Mobile Navigation Menu
   Terminal Noir Design
   ============================ */

/* Mobile Menu Toggle Button (Hamburger) - Terminal Noir */
.mobile-menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    background: var(--surface-noir-2);
    border: 1px solid var(--gold-border);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    z-index: 201;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.mobile-menu-toggle:hover,
.mobile-menu-toggle:focus {
    background: var(--surface-noir-elevated);
    border-color: var(--gold-border-active);
    outline: none;
}

.mobile-menu-toggle:active {
    background: var(--gold-glow);
    transform: scale(0.95);
}

.mobile-menu-toggle:focus-visible {
    box-shadow: 0 0 0 1px var(--gold-border-hover);
}

/* Hamburger Icon Lines - Terminal Noir */
.hamburger-icon {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 18px;
    height: 12px;
    position: relative;
}

.hamburger-icon span {
    display: block;
    width: 100%;
    height: 2px;
    background: var(--text-secondary);
    border-radius: 1px;
    transition: all 0.2s ease;
    position: absolute;
    left: 0;
}

.mobile-menu-toggle:hover .hamburger-icon span {
    background: var(--gold);
}

.hamburger-icon span:nth-child(1) {
    top: 0;
}

.hamburger-icon span:nth-child(2) {
    top: 50%;
    transform: translateY(-50%);
}

.hamburger-icon span:nth-child(3) {
    bottom: 0;
}

/* Hamburger to X Animation */
.mobile-menu-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(1) {
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(2) {
    opacity: 0;
    transform: translateX(-10px);
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(3) {
    bottom: 50%;
    transform: translateY(50%) rotate(-45deg);
}

/* Show hamburger on mobile */
@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: flex;
    }
}

/* Mobile Navigation Overlay - Terminal Noir */
.mobile-nav-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 199;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

/* Only apply blur when overlay is actually visible */
.mobile-nav-overlay.active {
    display: block;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

/* Mobile Navigation Panel - Terminal Noir */
.mobile-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    max-width: 85vw;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    background: rgba(13, 17, 23, 0.98);
    border-right: 1px solid var(--gold-border);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.mobile-nav.open {
    transform: translateX(0);
}

/* Mobile Nav Header - Terminal Noir */
.mobile-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--gold-border);
    background: var(--surface-noir-2);
    min-height: 60px;
}

.mobile-nav-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--gold);
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.mobile-nav-title-icon {
    font-size: 1.1rem;
    opacity: 0.8;
}

/* Close Button in Mobile Nav - Terminal Noir */
.mobile-nav-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--gold-border);
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 1.25rem;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.mobile-nav-close:hover,
.mobile-nav-close:focus {
    background: var(--gold-glow);
    color: var(--gold);
    border-color: var(--gold-border-active);
}

/* Mobile Nav Body - Scrollable Menu Items */
.mobile-nav-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 0;
    -webkit-overflow-scrolling: touch;
}

/* Mobile Nav Menu List - Terminal Noir */
.mobile-nav-menu {
    list-style: none;
    margin: 0;
    padding: 0 8px;
}

/* Mobile Nav Menu Items - Touch-Friendly */
.mobile-nav-item {
    display: block;
    margin: 2px 0;
    padding: 0;
}

/* Mobile Nav Links - Terminal Noir */
.mobile-nav-link {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 44px;
    padding: 10px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.02em;
    transition: all 0.15s ease;
    border-left: 2px solid transparent;
    border-radius: 0 4px 4px 0;
    -webkit-tap-highlight-color: transparent;
}

.mobile-nav-link:hover,
.mobile-nav-link:focus {
    background: var(--surface-noir-elevated);
    color: var(--text-primary);
}

.mobile-nav-link:active {
    background: rgba(48, 54, 61, 0.7);
}

/* Active Page Highlighting - Terminal Noir */
.mobile-nav-link.active {
    background: var(--gold-glow);
    color: var(--gold);
    border-left-color: var(--gold);
}

.mobile-nav-link.active .mobile-nav-icon {
    color: var(--gold);
}

/* Mobile Nav Icon - Terminal Noir */
.mobile-nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    font-size: 1rem;
    color: var(--text-muted);
    transition: color 0.15s ease;
}

.mobile-nav-link:hover .mobile-nav-icon,
.mobile-nav-link:focus .mobile-nav-icon {
    color: var(--text-primary);
}

/* Mobile Nav Text */
.mobile-nav-text {
    flex: 1;
}

/* Mobile Nav Badge (for notifications, counts, etc.) */
.mobile-nav-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 var(--spacing-xs);
    background: var(--accent-primary);
    color: #fff;
    font-size: var(--font-size-xs);
    font-weight: 600;
    border-radius: 10px;
}

/* Mobile Nav Divider - Terminal Noir */
.mobile-nav-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold-border), transparent);
    margin: 8px 16px;
}

/* Mobile Nav Section Header - Terminal Noir */
.mobile-nav-section-header {
    padding: 8px 16px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 8px;
}

/* Mobile Nav Footer - Terminal Noir */
.mobile-nav-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--gold-border);
    background: rgba(22, 27, 34, 0.5);
}

.mobile-nav-footer-text {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    text-align: center;
}

/* Body scroll lock when mobile nav is open */
body.mobile-nav-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Swipe gesture hint (optional visual indicator) */
.mobile-nav-swipe-hint {
    display: none;
    position: absolute;
    top: 50%;
    right: -20px;
    transform: translateY(-50%);
    width: 4px;
    height: 40px;
    background: var(--text-muted);
    border-radius: 2px;
    opacity: 0.3;
}

@media (max-width: 768px) {
    .mobile-nav-swipe-hint {
        display: block;
    }
}

/* Navigation Tabs - Terminal Noir */
.tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    padding: 10px 14px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.03em;
    border-radius: 0;
    transition: all 0.2s ease;
    white-space: nowrap;
    border: none;
    background: transparent;
}

/* Underline indicator */
.tab::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 2px;
    background: var(--gold);
    transition: width 0.2s ease;
}

.tab:hover,
.tab:focus {
    color: var(--text-primary);
    background: transparent;
    outline: none;
}

.tab:hover::after {
    width: 60%;
}

.tab:active {
    background: transparent;
}

.tab:focus-visible {
    box-shadow: none;
}

.tab:focus-visible::after {
    width: 60%;
}

.tab.active {
    color: var(--gold);
    background: transparent;
    border: none;
}

.tab.active::after {
    width: 80%;
    background: var(--gold);
}

/* ============================
   Header Controls
   ============================ */
.header-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-md);
    margin-top: var(--spacing-sm);
}

/* Header controls responsive - hide on mobile (prices shown in sidebar) */
@media (max-width: 768px) {
    .header-controls {
        display: none;
    }
}

.status-indicators {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

/* Status indicators responsive */
@media (max-width: 768px) {
    .status-indicators {
        gap: var(--spacing-sm);
        flex-wrap: wrap;
    }
}

@media (max-width: 480px) {
    .status-indicators {
        width: 100%;
        justify-content: space-between;
    }
}

/* ============================
   Main Grid Layout
   ============================ */
.main-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: var(--spacing-md);
    min-height: calc(100vh - 150px);
    align-items: start;
}

/* Main grid responsive: collapse to single column below 1024px */
@media (max-width: 1024px) {
    .main-grid {
        grid-template-columns: 1fr;
        gap: var(--section-gap);
    }
}

@media (max-width: 768px) {
    .main-grid {
        gap: var(--spacing-md);
        min-height: auto;
    }
}

.content {
    background: transparent;
    border: none;
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
}

/* Content responsive padding */
@media (max-width: 768px) {
    .content {
        padding: var(--spacing-md);
        border-radius: var(--radius-md);
    }
}

@media (max-width: 480px) {
    .content {
        padding: var(--spacing-sm);
    }
}

/* ============================
   Sidebar
   ============================ */
.sidebar {
    background: transparent;
    border: none;
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    height: fit-content;
    position: sticky;
    top: 150px;
}

/* Sidebar responsive: hide on smaller screens (will be shown via mobile sidebar toggle) */
@media (max-width: 1024px) {
    .sidebar {
        display: none;
    }
}

.sidebar h3 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-muted);
}

/* ============================
   Bot List
   ============================ */
.bot-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.bot-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    text-decoration: none;
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.bot-item:hover,
.bot-item:focus {
    background: var(--bg-elevated);
    border-color: var(--accent-primary);
    outline: none;
}

.bot-item:active {
    background: var(--bg-primary);
}

.bot-item:focus-visible {
    box-shadow: 0 0 0 2px var(--accent-primary);
}

.bot-item-info {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.bot-name {
    font-weight: 500;
    font-size: var(--font-size-sm);
}

.bot-mode {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

/* ============================
   Status Badges
   ============================ */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: var(--font-size-xs);
    font-weight: 500;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: var(--spacing-xs);
}

.status-badge.online,
.status-badge.running,
.status-badge.success {
    color: var(--status-success);
    background: var(--status-success-bg);
}

.status-badge.online::before,
.status-badge.running::before,
.status-badge.success::before {
    background: var(--status-success);
    box-shadow: 0 0 6px var(--status-success);
}

.status-badge.paused,
.status-badge.warning {
    color: var(--status-warning);
    background: var(--status-warning-bg);
}

.status-badge.paused::before,
.status-badge.warning::before {
    background: var(--status-warning);
    box-shadow: 0 0 6px var(--status-warning);
}

.status-badge.stopped,
.status-badge.error,
.status-badge.offline {
    color: var(--status-error);
    background: var(--status-error-bg);
}

.status-badge.stopped::before,
.status-badge.error::before,
.status-badge.offline::before {
    background: var(--status-error);
    box-shadow: 0 0 6px var(--status-error);
}

.status-badge.idle {
    color: var(--status-neutral);
    background: var(--status-neutral-bg);
}

.status-badge.idle::before {
    background: var(--status-neutral);
    box-shadow: 0 0 6px var(--status-neutral);
}

.status-badge.observing,
.status-badge.info {
    color: var(--status-info);
    background: var(--status-info-bg);
}

.status-badge.observing::before,
.status-badge.info::before {
    background: var(--status-info);
    box-shadow: 0 0 6px var(--status-info);
}

.status-badge.loading,
.status-badge.neutral {
    color: var(--status-neutral);
    background: var(--status-neutral-bg);
}

.status-badge.loading::before,
.status-badge.neutral::before {
    background: var(--status-neutral);
    animation: pulse 1.5s infinite;
}

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

/* ============================
   Loading States
   ============================ */
.loading-text {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    padding: var(--spacing-md);
    text-align: center;
}

.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-default);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================
   Skeleton Loading States
   Loading placeholders for async content on mobile
   ============================ */

/* Shimmer animation for skeleton elements */
@keyframes skeleton-shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Base skeleton styles */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 25%,
        var(--bg-elevated) 50%,
        var(--bg-tertiary) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

/* Skeleton card - for card-shaped loading placeholders */
.skeleton-card {
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 25%,
        var(--bg-elevated) 50%,
        var(--bg-tertiary) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-muted);
    min-height: 100px;
    width: 100%;
}

/* Skeleton card size variants */
.skeleton-card.skeleton-sm {
    min-height: 60px;
}

.skeleton-card.skeleton-lg {
    min-height: 150px;
}

/* Skeleton text - for text line loading placeholders */
.skeleton-text {
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 25%,
        var(--bg-elevated) 50%,
        var(--bg-tertiary) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
    height: 1em;
    width: 100%;
    display: block;
}

/* Skeleton text width variants */
.skeleton-text.skeleton-w-25 {
    width: 25%;
}

.skeleton-text.skeleton-w-50 {
    width: 50%;
}

.skeleton-text.skeleton-w-75 {
    width: 75%;
}

.skeleton-text.skeleton-w-full {
    width: 100%;
}

/* Skeleton text size variants */
.skeleton-text.skeleton-title {
    height: 1.5em;
    margin-bottom: var(--spacing-sm);
}

.skeleton-text.skeleton-subtitle {
    height: 1.25em;
    margin-bottom: var(--spacing-xs);
}

.skeleton-text.skeleton-body {
    height: 1em;
    margin-bottom: var(--spacing-xs);
}

/* Skeleton container for grouping multiple skeleton elements */
.skeleton-container {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

/* Skeleton row for horizontal layouts */
.skeleton-row {
    display: flex;
    gap: var(--spacing-sm);
    align-items: center;
}

/* Skeleton avatar - circular placeholder for profile images */
.skeleton-avatar {
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 25%,
        var(--bg-elevated) 50%,
        var(--bg-tertiary) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

/* Skeleton button - placeholder for buttons */
.skeleton-button {
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 25%,
        var(--bg-elevated) 50%,
        var(--bg-tertiary) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
    height: 44px;
    width: 100px;
}

/* Mobile-specific skeleton optimizations */
@media (max-width: 768px) {
    .skeleton-card {
        min-height: 80px;
        border-radius: var(--radius-md);
    }

    .skeleton-card.skeleton-lg {
        min-height: 120px;
    }

    .skeleton-text.skeleton-title {
        height: 1.25em;
    }

    /* Reduce motion for users who prefer it */
    @media (prefers-reduced-motion: reduce) {
        .skeleton,
        .skeleton-card,
        .skeleton-text,
        .skeleton-avatar,
        .skeleton-button {
            animation: none;
            background: var(--bg-tertiary);
        }
    }
}

/* Skeleton grid layout for dashboard widgets */
.skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--spacing-sm);
}

@media (max-width: 480px) {
    .skeleton-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* ============================
   Buttons
   ============================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}

.btn-primary:hover:not(:disabled),
.btn-primary:focus:not(:disabled) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    outline: none;
}

.btn-primary:active:not(:disabled) {
    background: var(--accent-secondary);
    border-color: var(--accent-secondary);
}

.btn-primary:focus-visible:not(:disabled) {
    box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--accent-primary);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-default);
}

.btn-secondary:hover:not(:disabled),
.btn-secondary:focus:not(:disabled) {
    background: var(--bg-elevated);
    border-color: var(--border-focus);
    outline: none;
}

.btn-secondary:active:not(:disabled) {
    background: var(--bg-tertiary);
}

.btn-secondary:focus-visible:not(:disabled) {
    box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--accent-primary);
}

.btn-danger {
    background: var(--status-error-bg);
    color: var(--status-error);
    border-color: var(--status-error);
}

.btn-danger:hover:not(:disabled),
.btn-danger:focus:not(:disabled) {
    background: var(--status-error);
    color: #fff;
    outline: none;
}

.btn-danger:active:not(:disabled) {
    filter: brightness(0.9);
}

.btn-danger:focus-visible:not(:disabled) {
    box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--status-error);
}

.btn-success {
    background: var(--status-success-bg);
    color: var(--status-success);
    border-color: var(--status-success);
}

.btn-success:hover:not(:disabled),
.btn-success:focus:not(:disabled) {
    background: var(--status-success);
    color: #fff;
    outline: none;
}

.btn-success:active:not(:disabled) {
    filter: brightness(0.9);
}

.btn-success:focus-visible:not(:disabled) {
    box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--status-success);
}

/* Button Touch-Friendly Sizing */
/* 44px minimum touch target per WCAG 2.1 guidelines */
.btn {
    min-height: 44px;
    min-width: 44px;
}

/* Larger touch targets on mobile for better accessibility */
@media (max-width: 768px) {
    .btn {
        padding: var(--spacing-sm) var(--spacing-lg);
    }
}

/* Small button variant - maintains touch target on mobile */
.btn-sm {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: var(--font-size-xs);
    min-height: 32px;
    min-width: 32px;
}

@media (max-width: 768px) {
    .btn-sm {
        min-height: 44px;
        min-width: 44px;
        padding: var(--spacing-xs) var(--spacing-md);
    }
}

/* Large button variant */
.btn-lg {
    padding: var(--spacing-md) var(--spacing-xl);
    font-size: var(--font-size-md);
    min-height: 52px;
}

/* Full-width button for mobile */
.btn-block {
    width: 100%;
    display: flex;
    justify-content: center;
}

/* ============================
   Tap Target Utilities
   ============================ */
/* Minimum 44x44px touch target wrapper */
.tap-target {
    position: relative;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Expand clickable area for small interactive elements */
.tap-target-expand {
    position: relative;
}

.tap-target-expand::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: 44px;
    min-width: 100%;
    min-height: 100%;
}

/* Large tap target (48px - recommended for primary actions) */
.tap-target-lg {
    min-width: 48px;
    min-height: 48px;
}

/* Mobile-only tap target expansion */
@media (max-width: 768px) {
    .tap-target-mobile {
        position: relative;
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .tap-target-mobile::before {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 44px;
        height: 44px;
        min-width: 100%;
        min-height: 100%;
    }
}

/* Touch-action optimization for interactive elements */
.touch-action-manipulation {
    touch-action: manipulation;
}

/* Prevent text selection on touch elements */
.touch-no-select {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* ============================
   Cards
   ============================ */
.card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
}

/* Card responsive padding */
@media (max-width: 768px) {
    .card {
        padding: var(--spacing-md);
        border-radius: var(--radius-md);
    }
}

@media (max-width: 480px) {
    .card {
        padding: var(--spacing-sm);
    }
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-muted);
}

/* Card header responsive - stack on mobile */
@media (max-width: 480px) {
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-sm);
    }
}

.card-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
}

/* Card title responsive */
@media (max-width: 768px) {
    .card-title {
        font-size: var(--font-size-md);
    }
}

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

/* ============================
   Forms
   ============================ */
.form-group {
    margin-bottom: var(--spacing-md);
}

.form-label {
    display: block;
    margin-bottom: var(--spacing-xs);
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-secondary);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    transition: border-color var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

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

.form-textarea {
    resize: vertical;
    min-height: 100px;
    font-family: var(--font-mono);
}

.form-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b949e' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--spacing-sm) center;
    padding-right: var(--spacing-xl);
}

/* iOS Zoom Prevention - Minimum 16px font-size on form inputs
   iOS Safari zooms the page when tapping on inputs with font-size < 16px
   Using !important to override any inline styles on specific pages */
@media (max-width: 768px) {
    .form-input,
    .form-select,
    .form-textarea,
    .config-input,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    input[type="search"],
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"],
    select,
    textarea {
        font-size: 16px !important; /* Prevents iOS zoom on focus */
        padding: var(--spacing-sm) var(--spacing-md);
        line-height: 1.5;
    }

    /* Ensure proper padding for readability on touch devices */
    .form-input,
    .form-select,
    .config-input {
        min-height: 44px; /* Touch-friendly height */
    }
}

/* Ensure settings page inputs also have proper sizing */
@media (max-width: 768px) {
    .config-value input,
    .config-value select,
    .user-input-textarea {
        font-size: 16px !important;
    }
}

/* ============================
   Tables
   ============================ */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Table container responsive - allow horizontal scroll on mobile */
@media (max-width: 768px) {
    .table-container {
        margin-left: calc(-1 * var(--spacing-sm));
        margin-right: calc(-1 * var(--spacing-sm));
        padding-left: var(--spacing-sm);
        padding-right: var(--spacing-sm);
    }
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}

/* Table responsive - smaller text and padding on mobile */
@media (max-width: 768px) {
    .table {
        font-size: var(--font-size-xs);
        min-width: 500px;
    }
}

.table th,
.table td {
    padding: var(--spacing-sm) var(--spacing-md);
    text-align: left;
    border-bottom: 1px solid var(--border-muted);
}

/* Table cells responsive padding */
@media (max-width: 768px) {
    .table th,
    .table td {
        padding: var(--spacing-xs) var(--spacing-sm);
    }
}

.table th {
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    white-space: nowrap;
}

.table tbody tr:hover,
.table tbody tr:focus-within {
    background: var(--bg-tertiary);
}

.table tbody tr:active {
    background: var(--bg-elevated);
}

/* ============================
   Alert Messages
   ============================ */
.alert {
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    margin-bottom: var(--spacing-md);
    font-size: var(--font-size-sm);
}

.alert-success {
    background: var(--status-success-bg);
    border: 1px solid var(--status-success);
    color: var(--status-success);
}

.alert-warning {
    background: var(--status-warning-bg);
    border: 1px solid var(--status-warning);
    color: var(--status-warning);
}

.alert-error {
    background: var(--status-error-bg);
    border: 1px solid var(--status-error);
    color: var(--status-error);
}

.alert-info {
    background: var(--status-info-bg);
    border: 1px solid var(--status-info);
    color: var(--status-info);
}

/* ============================
   Empty States
   ============================ */
.empty-state {
    text-align: center;
    padding: var(--spacing-xl);
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: var(--spacing-md);
    opacity: 0.5;
}

.empty-state-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
    color: var(--text-secondary);
}

.empty-state-text {
    margin-bottom: var(--spacing-lg);
}

/* ============================
   Trading Mode Labels
   ============================ */
.mode-badge {
    display: inline-flex;
    align-items: center;
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: var(--font-size-xs);
    font-weight: 500;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
}

.mode-observation {
    background: var(--status-info-bg);
    color: var(--status-info);
    border: 1px solid var(--status-info);
}

.mode-entry {
    background: var(--long-bg);
    color: var(--long-color);
    border: 1px solid var(--long-color);
}

.mode-exit {
    background: var(--short-bg);
    color: var(--short-color);
    border: 1px solid var(--short-color);
}

.mode-hedge {
    background: var(--status-warning-bg);
    color: var(--status-warning);
    border: 1px solid var(--status-warning);
}

.mode-coop {
    background: var(--status-neutral-bg);
    color: var(--text-secondary);
    border: 1px solid var(--status-neutral);
}

/* Trading Indicator (shows if mode allows trading) */
.trading-indicator {
    display: inline-flex;
    align-items: center;
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 10px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.trading-indicator.trading-enabled {
    background: var(--status-warning-bg);
    color: var(--status-warning);
    border: 1px solid var(--status-warning);
}

.trading-indicator.trading-disabled {
    background: var(--status-info-bg);
    color: var(--status-info);
    border: 1px solid var(--status-info);
}

/* ============================
   Dashboard Widgets
   ============================ */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

/* Dashboard grid responsive: smaller minmax for mobile */
@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: var(--spacing-sm);
    }
}

@media (max-width: 480px) {
    .dashboard-grid {
        grid-template-columns: 1fr 1fr;
        gap: var(--spacing-sm);
    }
}

.widget {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
}

/* Widget responsive adjustments */
@media (max-width: 768px) {
    .widget {
        padding: var(--spacing-sm);
        border-radius: var(--radius-md);
    }
}

.widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-sm);
}

.widget-title {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Widget title responsive */
@media (max-width: 480px) {
    .widget-title {
        font-size: var(--font-size-xs);
        letter-spacing: 0.02em;
    }
}

.widget-value {
    font-size: var(--font-size-xl);
    font-weight: 700;
    font-family: var(--font-mono);
}

/* Widget value responsive - smaller on mobile */
@media (max-width: 768px) {
    .widget-value {
        font-size: var(--font-size-lg);
    }
}

@media (max-width: 480px) {
    .widget-value {
        font-size: var(--font-size-md);
    }
}

.widget-change {
    font-size: var(--font-size-xs);
    margin-top: var(--spacing-xs);
}

.widget-change.positive {
    color: var(--status-success);
}

.widget-change.negative {
    color: var(--status-error);
}

/* ============================
   Tabs (for Strategy Page)
   ============================ */
.tabs {
    display: flex;
    gap: var(--spacing-xs);
    margin-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--border-muted);
    padding-bottom: var(--spacing-sm);
}

.tab-button {
    padding: var(--spacing-sm) var(--spacing-md);
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.tab-button:hover,
.tab-button:focus {
    color: var(--text-primary);
    background: var(--bg-tertiary);
    outline: none;
}

.tab-button:active {
    background: var(--bg-elevated);
}

.tab-button:focus-visible {
    box-shadow: 0 0 0 2px var(--accent-primary);
}

.tab-button.active {
    color: var(--accent-primary);
    border-bottom: 2px solid var(--accent-primary);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ============================
   Presets List
   ============================ */
.preset-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.preset-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md);
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.preset-item:hover,
.preset-item:focus-within {
    border-color: var(--accent-primary);
}

.preset-item:active {
    background: var(--bg-tertiary);
}

.preset-item.default {
    border-color: var(--status-success);
    background: var(--status-success-bg);
}

.preset-info {
    flex: 1;
}

.preset-name {
    font-weight: 600;
    margin-bottom: var(--spacing-xs);
}

.preset-description {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.preset-actions {
    display: flex;
    gap: var(--spacing-sm);
}

/* ============================
   Config Form
   ============================ */
.config-section {
    margin-bottom: var(--spacing-lg);
}

.config-section-title {
    font-size: var(--font-size-md);
    font-weight: 600;
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-muted);
}

.config-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: var(--spacing-sm) 0;
    border-bottom: 1px solid var(--border-muted);
}

.config-item:last-child {
    border-bottom: none;
}

.config-label {
    flex: 1;
}

.config-key {
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
}

.config-description {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin-top: var(--spacing-xs);
}

.config-value {
    width: 200px;
    text-align: right;
}

/* ============================
   Modal Dialogs
   ============================ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    padding: var(--spacing-lg);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    transform: scale(0.9);
    transition: transform var(--transition-normal);
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-muted);
}

.modal-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.modal-close:hover,
.modal-close:focus {
    color: var(--text-primary);
    outline: none;
}

.modal-close:active {
    transform: scale(0.95);
}

.modal-close:focus-visible {
    box-shadow: 0 0 0 2px var(--accent-primary);
    border-radius: var(--radius-sm);
}

.modal-body {
    margin-bottom: var(--spacing-lg);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-sm);
}

/* ============================
   Tooltip
   Touch-friendly: Shows on hover for desktop, focus for touch/keyboard
   ============================ */
.tooltip {
    position: relative;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: var(--font-size-xs);
    border-radius: var(--radius-sm);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    pointer-events: none;
    z-index: 10;
}

/* Show tooltip on hover (desktop) or focus (touch/keyboard) */
.tooltip:hover::after,
.tooltip:focus::after,
.tooltip:focus-within::after {
    opacity: 1;
    visibility: visible;
}

/* Touch-specific: tap to show tooltip on mobile */
@media (hover: none) and (pointer: coarse) {
    .tooltip:active::after {
        opacity: 1;
        visibility: visible;
    }
}

/* ============================
   Utility Classes
   ============================ */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--status-success); }
.text-warning { color: var(--status-warning); }
.text-error { color: var(--status-error); }
.text-mono { font-family: var(--font-mono); }

.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }
.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }

.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--spacing-sm); }
.gap-md { gap: var(--spacing-md); }

.hidden { display: none !important; }
.visible { display: block !important; }

/* ============================
   Mobile-Specific Utility Classes
   ============================ */

/* Show only on mobile devices (below 768px) */
.mobile-only {
    display: none !important;
}

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

    /* Inline variant for flex/inline contexts */
    .mobile-only.inline {
        display: inline !important;
    }

    .mobile-only.inline-block {
        display: inline-block !important;
    }

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

    .mobile-only.inline-flex {
        display: inline-flex !important;
    }
}

/* Show only on desktop devices (768px and above) */
.desktop-only {
    display: block;
}

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

/* Inline variants for desktop-only */
.desktop-only.inline {
    display: inline;
}

.desktop-only.inline-block {
    display: inline-block;
}

.desktop-only.flex {
    display: flex;
}

.desktop-only.inline-flex {
    display: inline-flex;
}

/* Touch target - ensures minimum 44x44px touch area per WCAG 2.1 guidelines */
.touch-target {
    position: relative;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Expanded touch target variant - for smaller elements that need larger hit area */
.touch-target-area {
    position: relative;
}

.touch-target-area::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: 44px;
    min-width: 100%;
    min-height: 100%;
}

/* Touch target that only expands on touch devices */
@media (hover: none) and (pointer: coarse) {
    .touch-target-auto {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Prevent scrolling on mobile - useful for modals, overlays, and locked states */
.no-scroll-mobile {
    overflow: auto;
}

@media (max-width: 768px) {
    .no-scroll-mobile {
        overflow: hidden !important;
        position: fixed;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
    }

    /* Body-level scroll lock for mobile */
    body.no-scroll-mobile {
        overflow: hidden !important;
        position: fixed;
        width: 100%;
        height: 100%;
    }
}

/* Alternative: just hide overflow without position fixed */
.no-overflow-mobile {
    overflow: auto;
}

@media (max-width: 768px) {
    .no-overflow-mobile {
        overflow: hidden !important;
    }
}

/* ============================
   Responsive Grid Utilities
   ============================ */

/* General responsive grid - auto-fit with minimum column width */
.responsive-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(var(--grid-min-width, 280px), 1fr));
    gap: var(--section-gap);
}

/* Two-column grid that collapses to single column on mobile */
.grid-2-col {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--section-gap);
}

@media (max-width: 768px) {
    .grid-2-col {
        grid-template-columns: 1fr;
    }
}

/* Three-column grid with responsive collapse */
.grid-3-col {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--section-gap);
}

@media (max-width: 1024px) {
    .grid-3-col {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .grid-3-col {
        grid-template-columns: 1fr;
    }
}

/* Four-column grid with responsive collapse */
.grid-4-col {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--section-gap);
}

@media (max-width: 1024px) {
    .grid-4-col {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .grid-4-col {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .grid-4-col {
        grid-template-columns: 1fr;
    }
}

/* Responsive gap utilities */
.gap-responsive {
    gap: var(--section-gap);
}

/* Stack layout - always single column, useful for mobile-first layouts */
.grid-stack {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--section-gap);
}

/* ============================
   User Input Component
   ============================ */
.mode-toggle {
    display: flex;
    gap: var(--spacing-xs);
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-xs);
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-muted);
}

.mode-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-lg);
    background: transparent;
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-secondary);
    flex: 1;
}

.mode-btn:hover:not(.active):not(:disabled),
.mode-btn:focus:not(.active):not(:disabled) {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.mode-btn:active:not(:disabled) {
    background: var(--bg-elevated);
}

.mode-btn:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-primary);
}

.mode-btn.active {
    background: var(--status-info-bg);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    box-shadow: 0 0 8px rgba(88, 166, 255, 0.2);
}

.mode-btn.active .mode-icon {
    transform: scale(1.1);
}

.mode-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.mode-icon {
    font-size: var(--font-size-lg);
    transition: transform var(--transition-fast);
}

.mode-label {
    font-weight: 600;
    letter-spacing: 0.02em;
}

.mode-description {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--accent-primary);
    margin-bottom: var(--spacing-md);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    line-height: 1.5;
}

/* User Input Form */
.user-input-form {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.user-input-textarea {
    width: 100%;
    padding: var(--spacing-md);
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    line-height: 1.5;
    resize: vertical;
    min-height: 80px;
    max-height: 200px;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.user-input-textarea:hover:not(:focus):not(:disabled) {
    border-color: var(--border-focus);
}

.user-input-textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

.user-input-textarea:disabled {
    background: var(--bg-tertiary);
    color: var(--text-muted);
    cursor: not-allowed;
}

.user-input-textarea::placeholder {
    color: var(--text-muted);
    font-style: italic;
}

/* Input Actions Row */
.input-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--spacing-md);
}

.char-count {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-family: var(--font-mono);
    transition: color var(--transition-fast);
}

.char-count.warning {
    color: var(--status-warning);
}

.char-count.over-limit {
    color: var(--status-error);
    font-weight: 600;
}

/* Submit Button States */
#submit-input-btn {
    min-width: 140px;
    position: relative;
}

#submit-input-btn:disabled {
    background: var(--bg-tertiary);
    border-color: var(--border-muted);
    color: var(--text-muted);
    cursor: not-allowed;
}

#submit-input-btn.submitting {
    color: transparent;
}

#submit-input-btn.submitting::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-top: -8px;
    margin-left: -8px;
    border: 2px solid var(--text-muted);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Submission Status Feedback */
.submission-status {
    margin-top: var(--spacing-md);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    animation: slideIn 0.2s ease-out;
}

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

.submission-status.success {
    background: var(--status-success-bg);
    border: 1px solid var(--status-success);
    color: var(--status-success);
}

.submission-status.success::before {
    content: "\2713";
    font-weight: bold;
}

.submission-status.error {
    background: var(--status-error-bg);
    border: 1px solid var(--status-error);
    color: var(--status-error);
}

.submission-status.error::before {
    content: "\2717";
    font-weight: bold;
}

.submission-status.loading {
    background: var(--status-neutral-bg);
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
}

.submission-status.loading::before {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--text-muted);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.status-message {
    flex: 1;
}

/* Responsive Adjustments for User Input */
@media (max-width: 768px) {
    .mode-toggle {
        flex-direction: column;
        gap: var(--spacing-sm);
    }

    .mode-btn {
        padding: var(--spacing-md);
        justify-content: center;
    }

    .input-actions {
        flex-direction: column-reverse;
        align-items: stretch;
        gap: var(--spacing-sm);
    }

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

    #submit-input-btn {
        width: 100%;
    }

    .user-input-textarea {
        min-height: 100px;
    }
}

@media (max-width: 480px) {
    .mode-description {
        font-size: var(--font-size-xs);
        padding: var(--spacing-sm);
    }

    .mode-icon {
        font-size: var(--font-size-md);
    }

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

/* ============================
   Optimistic UI & Loading States
   ============================ */

/* Card updating state */
.bot-card.updating,
[data-bot-id].updating {
    opacity: 0.85;
    pointer-events: none;
    position: relative;
    overflow: hidden;
}

.bot-card.updating::after,
[data-bot-id].updating::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(88, 166, 255, 0.1), transparent);
    animation: shimmer 1s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Button spinner */
.btn-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: btn-spin 0.6s linear infinite;
}

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

.status-btn:disabled {
    opacity: 0.7;
    cursor: wait;
}

/* Toast Notifications */
/* Stacking container so multiple toasts queue instead of overlapping. */
#mh-toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 3000;
    display: flex;
    flex-direction: column-reverse; /* newest at the bottom, older stack upward */
    align-items: flex-end;
    gap: 8px;
    pointer-events: none;
    max-width: 360px;
}

.toast {
    /* Opaque terminal-noir card (matches tooltips) so the network monitor and
       page content never bleed through. */
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, rgba(13, 17, 23, 0.98), rgba(22, 27, 34, 0.98));
    border: 1px solid rgba(201, 168, 124, 0.3);
    border-left-width: 3px;
    color: rgba(255, 255, 255, 0.9);
    font-size: var(--font-size-sm);
    line-height: 1.45;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(201, 168, 124, 0.06);
    z-index: 3000;
    transform: translateY(12px);
    opacity: 0;
    transition: opacity 0.22s ease, transform 0.22s ease;
    max-width: 350px;
}

/* Inside the container, toasts flow normally (the container is positioned). */
#mh-toast-container .toast {
    position: relative;
    bottom: auto;
    right: auto;
    pointer-events: auto;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

/* Type accents — colored left border + heading tint, opaque body stays readable. */
.toast-error   { border-left-color: var(--status-error); }
.toast-success { border-left-color: var(--status-success); }
.toast-info    { border-left-color: var(--accent-primary); }

/* ============================
   Version Footer
   ============================ */
.version-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-muted);
    border-right: 1px solid var(--border-muted);
    border-top-right-radius: var(--radius-md);
    z-index: 50;
}

.version-text {
    font-size: var(--font-size-xs);
    font-family: var(--font-mono);
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

.tick-debug {
    margin-left: var(--spacing-sm);
    padding-left: var(--spacing-sm);
    border-left: 1px solid var(--border-muted);
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
}

.tick-debug .tick-item {
    margin-right: 6px;
    padding: 1px 4px;
    border-radius: 3px;
    background: var(--bg-tertiary);
}

.tick-debug .tick-item.active {
    color: var(--status-success);
    background: var(--status-success-bg);
}

.tick-debug {
    cursor: pointer;
}

/* Network Monitor Panel */
.network-monitor {
    position: fixed;
    bottom: 30px;
    right: 0;
    width: 600px;
    max-height: 0;
    overflow: hidden;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-right: none;
    border-bottom: none;
    border-top-left-radius: var(--radius-lg);
    z-index: 100;
    transition: max-height 0.3s ease;
    font-family: var(--font-mono);
    font-size: 12px;
    box-shadow: -4px -4px 20px rgba(0, 0, 0, 0.3);
}

.network-monitor.expanded {
    max-height: 450px;
}

.network-monitor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-muted);
}

.network-monitor-header .net-title {
    font-weight: 700;
    font-size: 13px;
    color: var(--text-primary);
}

.network-monitor-header .net-rps-badge {
    background: var(--status-success-bg);
    color: var(--status-success);
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 11px;
}

.network-monitor-header .net-rps-badge.medium {
    background: var(--status-warning-bg);
    color: var(--status-warning);
}

.network-monitor-header .net-rps-badge.high {
    background: var(--status-error-bg);
    color: var(--status-error);
}

.network-monitor-header button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 0 6px;
    line-height: 1;
}

.network-monitor-header button:hover {
    color: var(--text-primary);
}

.network-monitor-stats {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-muted);
}

.network-monitor-stats .stat-group {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.network-monitor-stats .stat-group.endpoint-breakdown {
    padding-top: 8px;
    border-top: 1px solid var(--border-muted);
}

.network-monitor-stats .stat-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.network-monitor-stats .stat-item.small {
    min-width: 60px;
}

.network-monitor-stats .stat-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.network-monitor-stats .stat-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.network-monitor-stats .stat-item.small .stat-value {
    font-size: 14px;
}

.network-monitor-stats .stat-value.stat-error {
    color: var(--status-error);
}

.network-monitor-stats .stat-value.stat-warning {
    color: var(--status-warning);
}

/* Log header row */
.network-monitor-log-header {
    display: flex;
    padding: 6px 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-weight: 600;
}

.network-monitor-log-header .col-time { width: 70px; }
.network-monitor-log-header .col-method { width: 50px; }
.network-monitor-log-header .col-url { flex: 1; }
.network-monitor-log-header .col-status { width: 50px; text-align: center; }
.network-monitor-log-header .col-latency { width: 70px; text-align: right; }

.network-monitor-log {
    max-height: 260px;
    overflow-y: auto;
}

.network-monitor-log .req-entry {
    display: flex;
    align-items: center;
    padding: 5px 16px;
    border-bottom: 1px solid var(--border-muted);
    transition: background 0.1s;
}

.network-monitor-log .req-entry:hover {
    background: var(--bg-tertiary);
}

/* Category color coding - left border */
.network-monitor-log .req-entry.prices { border-left: 3px solid var(--accent-primary); }
.network-monitor-log .req-entry.positions { border-left: 3px solid var(--status-success); }
.network-monitor-log .req-entry.bots { border-left: 3px solid var(--status-warning); }
.network-monitor-log .req-entry.status { border-left: 3px solid var(--text-muted); }
.network-monitor-log .req-entry.other { border-left: 3px solid var(--border-color); }

.network-monitor-log .col-time {
    width: 70px;
    color: var(--text-muted);
    font-size: 11px;
}

.network-monitor-log .col-method {
    width: 50px;
    font-weight: 600;
    font-size: 10px;
}

.network-monitor-log .col-method.get { color: var(--status-success); }
.network-monitor-log .col-method.post { color: var(--status-warning); }
.network-monitor-log .col-method.put { color: var(--accent-primary); }
.network-monitor-log .col-method.delete { color: var(--status-error); }

.network-monitor-log .col-url {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
    padding-right: 10px;
}

.network-monitor-log .col-status {
    width: 50px;
    text-align: center;
    font-weight: 600;
}

.network-monitor-log .col-status.ok { color: var(--status-success); }
.network-monitor-log .col-status.warn { color: var(--status-warning); }
.network-monitor-log .col-status.err { color: var(--status-error); }

.network-monitor-log .col-latency {
    width: 70px;
    text-align: right;
    font-size: 11px;
}

.network-monitor-log .col-latency.fast { color: var(--status-success); }
.network-monitor-log .col-latency.medium { color: var(--status-warning); }
.network-monitor-log .col-latency.slow { color: var(--status-error); }

/* Error row highlighting */
.network-monitor-log .req-entry.has-error {
    background: rgba(255, 77, 77, 0.1);
    border-left: 3px solid var(--status-error) !important;
}

.network-monitor-log .error-msg {
    color: var(--status-error);
    font-size: 10px;
    margin-left: 8px;
    opacity: 0.9;
}

/* Debug toggle switch in network monitor */
.network-monitor-stats .toggle-item {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.debug-toggle {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

.debug-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.debug-toggle .toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    transition: 0.2s;
}

.debug-toggle .toggle-slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: var(--text-muted);
    border-radius: 50%;
    transition: 0.2s;
}

.debug-toggle input:checked + .toggle-slider {
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
}

.debug-toggle input:checked + .toggle-slider:before {
    transform: translateX(16px);
    background-color: white;
}

/* Same-value flash indicator (blue) */
.price-same {
    color: #4da6ff !important;
    animation: flash-same 0.5s ease-out;
}

.position-ticker.flash-same {
    color: #4da6ff !important;
    animation: flash-same 0.5s ease-out;
}

/* Table cell flash for positions page */
td.flash-same {
    animation: flash-same-cell 0.6s ease-out;
}

@keyframes flash-same {
    0% { background-color: rgba(77, 166, 255, 0.4); }
    100% { background-color: transparent; }
}

@keyframes flash-same-cell {
    0% { background-color: rgba(77, 166, 255, 0.3); color: #4da6ff; }
    100% { background-color: transparent; }
}

/* ============================
   Touch Optimization & Accessibility
   Ensures all interactive elements work on touch devices
   ============================ */

/* Global touch optimization for interactive elements */
button,
[role="button"],
a,
input[type="button"],
input[type="submit"],
input[type="reset"],
.clickable {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Ensure all focusable elements have visible focus states */
:focus:not(:focus-visible) {
    outline: none;
}

:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Touch device optimizations - detected via media query */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover delays on touch devices */
    * {
        -webkit-tap-highlight-color: transparent;
    }

    /* Slightly larger touch targets on pure touch devices */
    button:not(.btn-sm),
    [role="button"],
    a.btn {
        min-height: 44px;
    }

    /* Active states for immediate touch feedback */
    button:active,
    [role="button"]:active,
    a:active,
    .btn:active {
        opacity: 0.9;
    }
}

/* ============================
   Landscape Orientation Optimizations
   Mobile landscape: limited vertical space (375px-428px height)
   Target viewports: 667x375 (iPhone SE), 926x428 (iPhone Pro Max)
   ============================ */

/* Mobile landscape - limited height viewport with ample width */
@media (max-width: 926px) and (max-height: 500px) and (orientation: landscape) {
    /* Reduce root spacing for tighter layout */
    :root {
        --container-padding: var(--spacing-xs);
        --section-gap: var(--spacing-sm);
    }

    /* Compact sticky header for more content space */
    .sticky-header {
        padding: var(--spacing-xs) 0;
        margin-bottom: var(--spacing-xs);
    }

    /* Reduce main content padding */
    .content {
        padding: var(--spacing-sm);
    }

    /* Container uses smaller padding */
    .container {
        padding: var(--spacing-xs);
    }

    /* Main grid - minimal gap */
    .main-grid {
        gap: var(--spacing-sm);
        min-height: auto;
    }

    /* Cards with tighter padding */
    .card {
        padding: var(--spacing-sm);
    }

    .card-header {
        margin-bottom: var(--spacing-sm);
        padding-bottom: var(--spacing-xs);
    }

    /* Dashboard grid - side by side layout leveraging width */
    .dashboard-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        gap: var(--spacing-xs);
        margin-bottom: var(--spacing-sm);
    }

    /* Widgets with compact sizing */
    .widget {
        padding: var(--spacing-xs);
    }

    .widget-value {
        font-size: var(--font-size-md);
    }

    .widget-title {
        font-size: 10px;
    }

    /* Reduce chart heights for landscape viewing */
    .chart-section,
    .chart-container,
    .chart-placeholder {
        min-height: 150px;
        max-height: 200px;
    }

    /* FAB repositioned for landscape - left side to avoid chart overlap */
    .mobile-sidebar-fab {
        bottom: 12px;
        right: 12px;
        width: 48px;
        height: 48px;
    }

    .mobile-sidebar-fab .fab-icon svg {
        width: 22px;
        height: 22px;
    }

    /* Mobile navigation panel - shorter in landscape */
    .mobile-nav {
        width: 50vw;
        max-width: 320px;
    }

    .mobile-nav-header {
        min-height: 44px;
        padding: var(--spacing-sm);
    }

    .mobile-nav-link {
        min-height: 40px;
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: var(--font-size-sm);
    }

    /* Mobile sidebar panel - landscape optimized width */
    .mobile-sidebar-panel {
        width: 50vw;
        max-width: 320px;
    }

    .mobile-sidebar-header {
        padding: var(--spacing-sm);
    }

    .mobile-sidebar-body {
        padding: var(--spacing-sm);
    }

    /* Bot list items - compact */
    .bot-item {
        padding: var(--spacing-xs) var(--spacing-sm);
    }

    /* Status badges - smaller */
    .status-badge {
        padding: 2px var(--spacing-xs);
        font-size: 10px;
    }

    /* Buttons maintain 44px touch target but reduce visual padding */
    .btn {
        padding: var(--spacing-xs) var(--spacing-sm);
    }

    /* Form groups tighter */
    .form-group {
        margin-bottom: var(--spacing-sm);
    }

    /* Metrics grid - horizontal layout in landscape */
    .metrics-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: var(--spacing-xs);
    }

    /* Alert messages - compact */
    .alert {
        padding: var(--spacing-sm);
        margin-bottom: var(--spacing-sm);
    }

    /* Version footer - more compact */
    .version-footer {
        padding: 2px var(--spacing-xs);
    }

    .version-text {
        font-size: 10px;
    }

    /* User input components - landscape friendly */
    .mode-toggle {
        flex-direction: row;
        gap: var(--spacing-xs);
        margin-bottom: var(--spacing-sm);
        padding: var(--spacing-xs);
    }

    .mode-btn {
        padding: var(--spacing-xs) var(--spacing-sm);
        flex: 1;
    }

    .mode-description {
        padding: var(--spacing-xs) var(--spacing-sm);
        margin-bottom: var(--spacing-sm);
        font-size: 11px;
    }

    .user-input-textarea {
        min-height: 60px;
        max-height: 100px;
    }

    /* Reduce modal padding in landscape */
    .modal {
        max-height: 85vh;
        padding: var(--spacing-sm);
    }

    .modal-header {
        margin-bottom: var(--spacing-sm);
        padding-bottom: var(--spacing-xs);
    }

    .modal-body {
        margin-bottom: var(--spacing-sm);
    }

    /* Toast notifications - positioned at top in landscape for visibility */
    #mh-toast-container {
        bottom: auto;
        top: 12px;
        right: 12px;
        left: 12px;
        max-width: none;
        align-items: stretch;
        flex-direction: column; /* newest on top when anchored to the top edge */
    }

    .toast {
        bottom: auto;
        top: 12px;
        right: 12px;
        max-width: 280px;
    }

    /* Config sections - compact */
    .config-section {
        margin-bottom: var(--spacing-sm);
    }

    .config-item {
        padding: var(--spacing-xs) 0;
    }

    /* Presets - compact */
    .preset-item {
        padding: var(--spacing-sm);
    }

    /* Empty states - compact */
    .empty-state {
        padding: var(--spacing-md);
    }

    .empty-state-icon {
        font-size: 2rem;
        margin-bottom: var(--spacing-sm);
    }
}

/* Very small mobile landscape (iPhone SE size: 667x375) */
@media (max-width: 700px) and (max-height: 400px) and (orientation: landscape) {
    /* Even more compact for very limited height */
    .sticky-header {
        padding: 2px 0;
        margin-bottom: 2px;
    }

    .container {
        padding: 4px;
    }

    .content {
        padding: var(--spacing-xs);
    }

    /* Side-by-side dashboard layout */
    .dashboard-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    /* Chart section - minimal height */
    .chart-section,
    .chart-container,
    .chart-placeholder {
        min-height: 120px;
        max-height: 150px;
    }

    /* Hide less critical UI elements */
    .version-footer {
        display: none;
    }

    /* Mobile nav - narrower */
    .mobile-nav {
        width: 240px;
    }

    .mobile-sidebar-panel {
        width: 240px;
    }

    /* Reduce widget text further */
    .widget-value {
        font-size: var(--font-size-sm);
    }

    .widget-title {
        font-size: 9px;
    }

    /* Skeleton elements - smaller in landscape */
    .skeleton-card {
        min-height: 50px;
    }

    .skeleton-card.skeleton-lg {
        min-height: 80px;
    }
}

/* ============================
   Mobile Touch-Friendly Overrides
   Ensures 44px minimum touch targets and better mobile UX
   ============================ */

/* Global touch target enforcement on mobile */
@media (max-width: 768px) {
    /* Buttons - ensure 44px minimum touch target */
    button,
    .btn,
    [role="button"],
    input[type="button"],
    input[type="submit"] {
        min-height: 44px;
        min-width: 44px;
    }

    /* Small buttons that need visual compactness but touch-friendly hit area */
    .btn-sm,
    .action-btn,
    .bot-action-btn {
        min-height: 44px;
        padding: 10px 16px;
        font-size: var(--font-size-sm);
    }

    /* Table containers - ensure horizontal scroll with visual indicator */
    .table-container,
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 calc(-1 * var(--spacing-sm));
        padding: 0 var(--spacing-sm);
        /* Fade effect to indicate scrollable content */
        background:
            linear-gradient(to right, var(--bg-secondary), var(--bg-secondary)),
            linear-gradient(to right, var(--bg-secondary), var(--bg-secondary)),
            linear-gradient(to right, rgba(0,0,0,0.15), transparent),
            linear-gradient(to left, rgba(0,0,0,0.15), transparent);
        background-position: left center, right center, left center, right center;
        background-repeat: no-repeat;
        background-size: 20px 100%, 20px 100%, 10px 100%, 10px 100%;
        background-attachment: local, local, scroll, scroll;
    }

    /* Tables - prevent text wrapping in cells */
    table {
        min-width: 600px;
    }

    table th,
    table td {
        white-space: nowrap;
        padding: var(--spacing-sm);
    }

    /* Form inputs - touch-friendly */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    select,
    textarea {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS zoom on focus */
        padding: var(--spacing-sm) var(--spacing-md);
    }

    /* Links in lists - touch-friendly spacing */
    .nav-link,
    .mobile-nav-link,
    .list-item a {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Remove min-width constraints that break mobile */
    .metrics-value,
    .metric-value,
    .stat-value {
        min-width: auto !important;
    }

    /* Ensure modals don't overflow */
    .modal,
    .modal-content {
        max-width: calc(100vw - 32px);
        max-height: calc(100vh - 32px);
        margin: 16px;
    }

    /* Stack grids earlier */
    .metrics-grid,
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-sm);
    }
}

/* Extra small phones (320px - 480px) */
@media (max-width: 480px) {
    /* Single column for all grids */
    .metrics-grid,
    .stats-grid,
    .config-grid,
    .form-grid {
        grid-template-columns: 1fr;
    }

    /* Compact padding */
    .content {
        padding: var(--spacing-sm);
    }

    /* Smaller table min-width to fit screen */
    table {
        min-width: 480px;
    }

    /* Stack action buttons */
    .action-buttons,
    .button-group {
        flex-direction: column;
        gap: var(--spacing-xs);
    }

    .action-buttons .btn,
    .button-group .btn {
        width: 100%;
    }

    /* Readable text sizes */
    body {
        font-size: 14px;
    }

    /* Ensure modal takes full width on tiny screens */
    .modal {
        width: calc(100vw - 16px);
        max-width: none;
        margin: 8px;
    }
}

/* ============================
   Global Modal Styles - Terminal Noir
   ============================ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--surface-2);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-md);
    max-width: 480px;
    width: 90%;
    max-height: 90vh;
    overflow: auto;
    z-index: 1;
    box-shadow: 0 0 40px var(--gold-glow), 0 25px 50px rgba(0, 0, 0, 0.5);
}

.modal-content.modal-large {
    max-width: 1200px;
    width: 95%;
    height: 85vh;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* TA Snapshot Viewer - Full width modal */
.modal-content.modal-large.ta-viewer {
    max-width: 95vw;
    width: 95vw;
    height: 90vh;
    max-height: 90vh;
}

@media (max-width: 1100px) {
    .modal-content.modal-large.ta-viewer {
        max-width: 98vw;
        width: 98vw;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border-subtle);
    background: var(--surface-1);
    flex-shrink: 0;
}

.modal-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gold);
    letter-spacing: 0.05em;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--gold-dim);
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s ease;
}

.modal-close:hover {
    color: var(--gold);
}

.modal-body {
    padding: var(--spacing-md);
    flex: 1;
    overflow: auto;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    border-top: 1px solid var(--border-subtle);
    background: var(--surface-1);
    flex-shrink: 0;
}

/* Modal animations */
.modal-content {
    animation: modalSlideIn 0.2s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Dynamic tooltips (mh-tooltip) */
[data-tip] {
    cursor: help;
}

/* subtle hover affordance on stat labels that carry a tip */
.alltime-cell[data-tip] .alltime-cell-label,
.metric-card[data-tip] .metric-label,
.momentum-cell[data-tip] .momentum-label,
.alltime-hero[data-tip] .alltime-hero-label {
    border-bottom: 1px dotted var(--gold-dim);
    display: inline-block;
    padding-bottom: 1px;
}

.mh-tooltip {
    position: fixed;
    z-index: 2000;
    max-width: 300px;
    padding: 10px 12px;
    background: linear-gradient(135deg, rgba(13, 17, 23, 0.98), rgba(22, 27, 34, 0.98));
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(201, 168, 124, 0.08);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    line-height: 1.5;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.12s ease, transform 0.12s ease;
    pointer-events: none;
}

.mh-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

.mh-tooltip::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.mh-tooltip-title {
    display: block;
    font-family: var(--font-display);
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-gold);
    margin-bottom: 4px;
}

.mh-tooltip-body { color: rgba(255, 255, 255, 0.82); white-space: pre-line; }

.mh-tooltip-readout {
    display: block;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-subtle);
    color: var(--gold-bright);
    font-size: 0.7rem;
}

.mh-tooltip-readout.positive { color: var(--status-success); }
.mh-tooltip-readout.negative { color: var(--status-error); }
