/* =============================================================================
   UNIFIED COLOR SYSTEM - Variables Visualizer
   ============================================================================= */

:root {
  /* Background Colors */
  --bg-primary: #000000;
  --bg-secondary: #161b22;
  --bg-interactive: #21262d;
  --bg-elevated: #30363d;
  --bg-canvas: #070708;
  
  /* Text Colors */
  --text-primary: #f0f6fc;
  --text-secondary: #e3e4e8;
  --text-tertiary: #b0b2b8;
  --text-muted: #8b949e;
  
  /* Accent Colors */
  --accent-primary: #58a6ff;
  --accent-primary-hover: #79b8ff;
  --accent-primary-bright: #79c0ff;
  --accent-primary-alt: #60a5fa;
  --accent-button: #1f6feb;
  --accent-button-hover: #388bfd;
  --accent-button-dark: #236586;
  --accent-button-dark-border: #3888af;
  --accent-button-dark-hover: #3992be;
  --accent-error: #f85149;
  --accent-error-alt: #da3633;
  --accent-error-secondary: #dc3545;
  --accent-warning: #fb8500;
  --accent-warning-alt: #ffc107;
  --accent-success: #16a34a;
  --accent-success-alt: #28a745;
  --accent-success-bright: #3fb950;
  
  /* Border Colors */
  --border-subtle: #21262d;
  --border-default: #30363d;
  --border-interactive: #444c56;
  --border-accent: #58a6ff;
  
  /* Style Type Indicators */
  --indicator-text: #2563eb;
  --indicator-text-alt: #1d4ed8;
  --indicator-fill: #16a34a;
  --indicator-effect: #7c3aed;
  --indicator-stroke: #dc2626;
  --indicator-grid: #ea580c;
  --indicator-default: #6b7280;
  --indicator-muted: #4b5563;
  
  /* Specialized Colors */
  --color-collection: #a5a5ff;
  --color-orange: #ffa657;
  
  /* Opacity Variations */
  --overlay-dark: rgba(0, 0, 0, 0.7);
  --accent-primary-03: rgba(88, 166, 255, 0.03);
  --accent-primary-05: rgba(88, 166, 255, 0.05);
  --accent-primary-08: rgba(88, 166, 255, 0.08);
  --accent-primary-10: rgba(88, 166, 255, 0.1);
  --accent-primary-20: rgba(88, 166, 255, 0.2);
  --accent-primary-30: rgba(88, 166, 255, 0.3);
  --accent-error-10: rgba(248, 81, 73, 0.1);
  --accent-error-20: rgba(248, 81, 73, 0.2);
  --accent-success-10: rgba(22, 163, 74, 0.1);
  --accent-success-20: rgba(22, 163, 74, 0.2);
  --accent-warning-10: rgba(255, 166, 87, 0.1);
  --accent-warning-15: rgba(255, 166, 87, 0.15);
  --color-collection-10: rgba(165, 165, 255, 0.1);
  --color-collection-15: rgba(165, 165, 255, 0.15);
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 16px;
    letter-spacing: 0.01em;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Main Layout */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 500px;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.sidebar-header {
    font-size: 16px;
    color: var(--text-tertiary);
    font-weight: 600;
    padding: 24px 16px 16px 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

/* TokenFlow Header Specific Styling */
.sidebar-header-content h3 {
    margin: 0;
    padding: 0;
    font-size: 24px;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}

/* Individual word styling for TokenFlow */
.sidebar-header-content h3 .token-light {
    font-weight: 300; /* Light weight for "Token" */
}

.sidebar-header-content h3 .flow-heavy {
    font-weight: 900; /* Heavy weight for "Flow" */
}

/* View Mode Toggle Styles */
.view-mode-toggle {
    display: flex;
    align-items: center;
}

.toggle-switch {
    position: relative;
    display: flex;
    background: #00000000;
    border: 1px solid var(--border-default);
    border-radius: 20px;
    padding: 2px;
    width: 140px;
    height: 32px;
}

.toggle-switch input[type="radio"] {
    display: none;
}

.toggle-option {
    flex: 1;
    text-align: center;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 18px;
    transition: all 0.3s ease;
    z-index: 2;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 0.02em;
}

.toggle-switch input[type="radio"]:checked + .toggle-option {
    color: var(--text-primary);
}

.toggle-slider {
    position: absolute;
    top: 2px;
    left: 2px;
    width: calc(50% - 2px);
    height: calc(100% - 4px);
    background: linear-gradient(135deg, #1e1e1e, #2f2f2f);
    border-radius: 18px;
    transition: transform 0.3s ease;
    z-index: 1;
    transform: translateX(100%); /* Default position for Variables mode */
}

/* When style mode is selected, move slider to the left */
.toggle-switch input[id="styleMode"]:checked ~ .toggle-slider {
    transform: translateX(0%);
}

/* When variables mode is selected, move slider to the right */
.toggle-switch input[id="variablesMode"]:checked ~ .toggle-slider {
    transform: translateX(100%);
}

.toggle-option:hover {
    color: var(--text-primary);
}

.sidebar-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.collapse-all-btn,
.sidebar-close-btn {
    background: transparent;
    border: 1px solid var(--border-default);
    color: var(--text-muted);
    padding: 4px 8px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.collapse-all-btn:hover,
.sidebar-close-btn:hover {
    background: var(--bg-interactive);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.sidebar-content {
    font-size: 16px;
    flex: 1;
    overflow-y: auto;
    padding-top: 0px;
}

.search-box {
    font-size: 16px;
    padding: 12px 16px;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
    width: 100%;
}

.search-box:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-primary-30);
}

/* Search in Sidebar */
.sidebar-search {
    margin-top: 8px;
    position: relative;
}

/* New container for search box and reset button */
.search-box-container {
    position: relative;
    display: flex;
    align-items: center;
}

.sidebar-search .search-box {
    width: 100%;
    height: 40px;
    font-size: 14.4px;
    padding: 8px 30px 8px 12px;
    border: 1px solid var(--border-default);
    border-radius: 8px;
    background: transparent !important;
    color: var(--text-secondary);
    font-family: 'Space Grotesk', Roboto, sans-serif;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
}

.sidebar-search .search-box:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 1px var(--accent-primary);
    background: transparent !important;
}

.search-reset-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 4px;
    line-height: 1;
}

.search-reset-btn:hover {
    color: var(--accent-primary);
}

/* Mode selector styling moved to unified-dropdowns.css for consistency */

/* Sidebar positioning and transitions */
.sidebar.tree {
    position: relative;
    left: 0;
    top: 0;
    height: auto;
    z-index: 100;
    transition: width 0.3s ease, transform 0.3s ease;
    padding: 0;
    overflow-y: auto;
}

/* Sidebar Toggle Button */
.sidebar-toggle-btn {
    position: absolute;
    top: 16px;
    right: -40px;
    width: 32px;
    height: 32px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    display: none; /* Hide by default on desktop */
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s ease;
    z-index: 101;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    user-select: none;
}

.sidebar-toggle-btn:hover {
    background: var(--bg-interactive);
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    transform: scale(1.05);
}

.sidebar-toggle-btn:active {
    transform: scale(0.95);
}

.sidebar-toggle-btn .toggle-icon {
    transition: transform 0.2s ease;
    display: inline-block;
}

/* Sidebar collapsed state - REMOVE for desktop */
.sidebar.tree.collapsed {
    width: 500px; /* Keep normal width on desktop */
    min-width: 500px;
    border-right: 1px solid var(--border-subtle);
    overflow: visible; /* Don't hide on desktop */
}

.sidebar.tree.collapsed .sidebar-toggle-btn {
    right: -40px; /* Keep normal position */
}

/* Canvas expands when sidebar is collapsed - REMOVE for desktop */
.main-container:has(.sidebar.collapsed) .canvas-container {
    margin-left: 0; /* This will be overridden by media query */
}

/* Add subtle visual feedback for collapsed state - REMOVE */
/* .sidebar.tree.collapsed::after - removed */

/* Smooth content transitions - REMOVE for desktop */
.sidebar-content {
    transition: none; /* No transition on desktop */
    opacity: 1; /* Always visible on desktop */
}

.sidebar.tree.collapsed .sidebar-content {
    opacity: 1; /* Always visible on desktop */
}

/* Mobile-specific behavior */
@media (max-width: 768px) {
    /* Show toggle button only on mobile/tablet - floating center-left, match canvas-btn style */
    .sidebar-toggle-btn {
        display: flex !important; /* Show on mobile with !important */
        position: fixed !important;
        top: 50% !important;
        left: 16px !important;
        right: auto !important;
        transform: translateY(-50%) !important; /* Center vertically */
        z-index: 1001;
        background: #000000 !important; /* Match canvas-btn */
        color: #e3e4e8 !important; /* Match canvas-btn */
        border: 1px solid #232427 !important; /* Match canvas-btn */
        box-shadow: none !important; /* Match canvas-btn */
        width: 36px !important; /* Match canvas-btn size */
        height: 36px !important; /* Match canvas-btn size */
        border-radius: 8px !important; /* Match canvas-btn */
        font-size: 16px;
        transition: all 0.2s;
    }
    
    .sidebar-toggle-btn:hover {
        background: #30363d !important;
        border-color: var(--accent-primary) !important;
    }
    
    .sidebar.tree {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 85vw; /* Use viewport width for better mobile experience */
        max-width: 400px;
        transform: translateX(-100%); /* Start collapsed on mobile */
        z-index: 1000;
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
        transition: transform 0.3s ease; /* Only animate transform */
    }
    
    .sidebar.tree.collapsed {
        width: 85vw; /* Keep responsive width on mobile for proper animation */
        max-width: 400px;
        transform: translateX(-100%);
        border-right: none;
        overflow: hidden;
    }
    
    .sidebar.tree.open {
        transform: translateX(0) !important; /* Override collapsed state */
    }
    
    .sidebar.tree.open + .sidebar-toggle-btn,
    .sidebar.tree.open ~ .sidebar-toggle-btn {
        left: calc(85vw + 16px) !important; /* Adjust position when sidebar is open */
    }
    
    /* Mobile backdrop */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.6);
        z-index: 999;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    
    .sidebar.tree.open ~ .sidebar-backdrop {
        display: block;
        opacity: 1;
    }
    
    /* Hide version control bar when mobile sidebar is open */
    .sidebar.tree.open ~ * .file-info-container {
        display: none !important;
    }
    
    /* Alternative - hide version control when body has mobile-sidebar-open class */
    body.mobile-sidebar-open .file-info-container {
        display: none !important;
    }
    
    /* Prevent body scroll when mobile sidebar is open */
    body.mobile-sidebar-open {
        overflow: hidden;
    }
    
    /* Mobile-friendly search and controls */
    .sidebar-search .search-box {
        height: 44px; /* Touch-friendly height */
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    /* Larger touch targets for mobile */
    .collapse-all-btn,
    .turn-all-off-btn {
        
        padding: 4px 4px;
        font-size: 12px;
    }
    
    /* Adjust sidebar content padding for mobile */
    .sidebar-content {
        padding-right: 12px;
        transition: none; /* No transitions on mobile */
        opacity: 1; /* Always visible when sidebar is shown */
    }
    
    /* Make tree items more touch-friendly */
    .tree-node-header {
        min-height: 40px;
        padding: 10px 12px;
    }
    
    .variable-item {
        min-height: 36px;
        padding: 8px 12px;
    }
}

/* Tablet-specific adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar.tree {
        width: 400px; /* Slightly smaller on tablets */
    }
}

/* Small mobile phones */
@media (max-width: 480px) {
    .sidebar.tree {
        width: 90vw;
    }
    
    .sidebar.tree.open + .sidebar-toggle-btn {
        left: calc(90vw + 8px);
    }
    
    .sidebar-toggle-btn {
        left: 8px;
        top: 8px;
    }
}

.sidebar.tree.open {
    left: 0;
}

body.sidebar-open .main-container {
    margin-left: 0;
}

/* =============================================================================
   GLOBAL SCROLLBAR STYLING
   ============================================================================= */

/* Global scrollbar styling for consistent appearance across all components */
.global-scrollbar::-webkit-scrollbar {
    width: 8px;
    height: 8px; /* For horizontal scrollbars */
}

.global-scrollbar::-webkit-scrollbar-track {
    background: #00000000;
    border-radius: 4px;
}

.global-scrollbar::-webkit-scrollbar-thumb {
    background: #30363d;
    border-radius: 4px;
    border: 1px solid #00000000;
}

.global-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #484f58;
}

.global-scrollbar::-webkit-scrollbar-corner {
    background: #00000000;
}

/* Firefox scrollbar styling */
.global-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: #30363d #00000000;
}

/* =============================================================================
   UI STATUS INDICATOR
   ============================================================================= */

.ui-status-indicator {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--accent-success);
    color: var(--bg-primary);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 1000;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(22, 163, 74, 0.2);
}

.ui-status-indicator.show {
    opacity: 1;
    transform: translateY(0);
}

.ui-status-indicator .ui-status-icon {
    font-size: 14px;
    animation: sparkle 2s ease-in-out infinite;
}

@keyframes sparkle {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

.ui-status-indicator .ui-status-text {
    white-space: nowrap;
}

/* Hide after 3 seconds */
.ui-status-indicator.auto-hide {
    animation: statusFadeOut 0.5s ease-out 3s forwards;
}

@keyframes statusFadeOut {
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}
