/* ============================================
   MOBILE UX V2 - Swipe-from-Left Panel System
   "Star Trek console meets early 2000s open source"
   ============================================ */

/* Only apply on mobile */
@media (max-width: 1024px) {

    /* ===== DARK CONSOLE THEME (Night Mode - Default) ===== */
    :root {
        --console-bg: #1a1a1a;
        --console-panel: #242424;
        --console-card: #2d2d2d;
        --console-card-expanded: #353535;
        --console-accent: #15635E;
        --console-accent-glow: rgba(21, 99, 94, 0.4);
        --console-text: #ffffff;
        --console-text-secondary: #888888;
        --console-success: #4ade80;
        --console-border: #3a3a3a;
    }

    /* ===== LIGHT THEME (Day Mode) ===== */
    body.day-mode {
        --console-bg: #f5f5f5;
        --console-panel: #ffffff;
        --console-card: #ffffff;
        --console-card-expanded: #f8f9fa;
        --console-accent: #15635E;
        --console-accent-glow: rgba(21, 99, 94, 0.2);
        --console-text: #1f2937;
        --console-text-secondary: #6b7280;
        --console-success: #22c55e;
        --console-border: #e5e7eb;
    }

    /* ===== DAY/NIGHT MODE TOGGLE ===== */
    #theme-toggle-btn {
        position: fixed;
        top: 70px;
        right: 12px;
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background: var(--console-panel);
        border: 2px solid var(--console-border);
        color: var(--console-text);
        font-size: 1.3rem;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        z-index: 4999;
        transition: all 0.3s ease;
        box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    }

    #theme-toggle-btn:active {
        transform: scale(0.9);
    }

    body.day-mode #theme-toggle-btn {
        background: #ffffff;
        border-color: #d1d5db;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }

    /* Day mode - Cart panel light styling */
    body.day-mode #build-summary {
        background: #ffffff !important;
    }

    body.day-mode #build-summary > div:not(.drawer-header) {
        background: #f8f9fa !important;
    }

    body.day-mode #build-summary #selected-modules-list > div {
        background: #ffffff !important;
        border-color: #e5e7eb !important;
    }

    body.day-mode #build-summary #selected-modules-list > div span:first-child {
        color: #1f2937 !important;
    }

    /* Day mode - Modules panel light styling */
    body.day-mode #module-library {
        background: #ffffff !important;
    }

    body.day-mode #module-library #modules-container {
        background: #f5f5f5 !important;
    }

    body.day-mode #module-library #category-tabs {
        background: #f8f9fa !important;
        border-color: #e5e7eb !important;
    }

    body.day-mode #module-library .category-tab {
        background: #ffffff !important;
        border-color: #e5e7eb !important;
        color: #6b7280 !important;
    }

    body.day-mode #module-library .category-tab.active {
        background: var(--console-accent) !important;
        border-color: var(--console-accent) !important;
        color: white !important;
    }

    body.day-mode #module-library .module-item-card {
        background: #ffffff !important;
        border-color: #e5e7eb !important;
    }

    body.day-mode #module-library .module-item-card > div:first-child {
        background: #f5f5f5 !important;
        border-color: #e5e7eb !important;
    }

    body.day-mode #module-library .module-item-card > div:nth-child(2) > div:first-child {
        color: #1f2937 !important;
    }

    body.day-mode .module-card-icon {
        background: #f5f5f5 !important;
        border-color: #e5e7eb !important;
    }

    body.day-mode .module-card-name {
        color: #1f2937 !important;
    }

    body.day-mode .module-card-toggle {
        background: #f5f5f5 !important;
        border-color: #e5e7eb !important;
        color: #6b7280 !important;
    }

    body.day-mode .material-btn {
        background: #f5f5f5 !important;
        border-color: #e5e7eb !important;
        color: #6b7280 !important;
    }

    body.day-mode .material-btn.active {
        background: var(--console-accent) !important;
        border-color: var(--console-accent) !important;
        color: white !important;
    }

    body.day-mode .module-edit-label {
        color: #6b7280 !important;
    }

    body.day-mode .opacity-slider {
        background: #e5e7eb !important;
    }

    body.day-mode .opacity-value {
        color: #1f2937 !important;
    }

    body.day-mode .color-input-wrapper {
        border-color: #e5e7eb !important;
    }

    body.day-mode #module-library #module-search {
        background: #ffffff !important;
        border-color: #e5e7eb !important;
        color: #1f2937 !important;
    }

    body.day-mode #module-library #foundation-section {
        background: #f8f9fa !important;
        border-color: var(--console-accent) !important;
    }

    body.day-mode #module-library #foundation-section button {
        background: #ffffff !important;
        border-color: #e5e7eb !important;
        color: #6b7280 !important;
    }

    /* ===== LEFT EDGE PEEK STRIP - HIDDEN (using bottom nav instead) ===== */
    #mobile-peek-strip {
        display: none !important;
    }

    /* ===== MODULES PANEL - Slides up from bottom ===== */
    #module-library {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        top: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        height: 95vh !important;
        background: var(--console-panel) !important;
        border-radius: 20px 20px 0 0 !important;
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.4) !important;
        transform: translateY(100%) !important;
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1) !important;
        z-index: 10001 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        /* Override the old bottom sheet display:none */
        visibility: visible !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        /* Remove desktop padding that creates gaps */
        padding: 0 !important;
    }

    /* Hide the default grab handle - using minimal X close button instead */
    #module-library::before {
        display: none !important;
    }

    #module-library.open {
        transform: translateY(0) !important;
    }

    /* Ensure content inside panel is visible */
    #module-library #modules-container {
        display: block !important;
        visibility: visible !important;
        flex: 1 !important;
        overflow-y: auto !important;
    }

    #module-library #category-tabs {
        display: flex !important;
        visibility: visible !important;
    }

    #module-library #module-grid {
        display: flex !important;
        flex-direction: column !important;
        visibility: visible !important;
        gap: 8px !important;
    }

    /* Force single column layout for module cards */
    #module-library .module-item-card {
        width: 100% !important;
        min-width: 100% !important;
        height: auto !important;
        min-height: 70px !important;
        background: var(--console-card) !important;
        border: 1px solid var(--console-border) !important;
        border-radius: 12px !important;
        padding: 14px 16px !important;
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 14px !important;
        text-align: left !important;
        cursor: pointer !important;
    }

    #module-library .module-item-card:active {
        background: var(--console-card-expanded) !important;
        transform: scale(0.98) !important;
    }

    /* Card inner content - override inline styles */
    #module-library .module-item-card > div:first-child {
        width: 48px !important;
        height: 48px !important;
        min-width: 48px !important;
        background: var(--console-bg) !important;
        border-radius: 10px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 1.5rem !important;
        margin: 0 !important;
    }

    /* Module name and price */
    #module-library .module-item-card > div:nth-child(2) {
        flex: 1 !important;
        min-width: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 4px !important;
    }

    #module-library .module-item-card > div:nth-child(2) > div:first-child {
        font-size: 0.95rem !important;
        font-weight: 600 !important;
        color: var(--console-text) !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    #module-library .module-item-card > div:nth-child(2) > div:last-child {
        font-size: 0.85rem !important;
        color: var(--console-accent) !important;
        font-weight: 600 !important;
    }

    /* Add button */
    #module-library .module-item-card .module-quick-add,
    #module-library .module-item-card > button {
        width: 44px !important;
        height: 44px !important;
        min-width: 44px !important;
        border-radius: 50% !important;
        background: var(--console-accent) !important;
        color: white !important;
        border: none !important;
        font-size: 1.3rem !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* Panel glow edge when open */
    #module-library.open::after {
        content: '';
        position: absolute;
        right: -2px;
        top: 0;
        bottom: 0;
        width: 2px;
        background: var(--console-accent);
        box-shadow: 0 0 12px var(--console-accent-glow);
    }

    /* ===== PANEL HEADER - Console Style ===== */
    #module-library .drawer-header {
        background: #15635E !important;
        border-bottom: none !important;
        padding: 16px 20px !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        margin-bottom: 0 !important;
        flex-shrink: 0 !important;
    }

    /* Eliminate any gap between header and content */
    #module-library .drawer-header + #modules-container,
    #module-library > #modules-container {
        margin-top: 0 !important;
        padding-top: 12px !important;
        border-top: none !important;
    }

    #module-library .drawer-header h2 {
        color: white !important;
        font-size: 1rem !important;
        font-weight: 700 !important;
        text-transform: uppercase !important;
        letter-spacing: 1px !important;
        margin: 0 !important;
    }

    #module-library .drawer-close-btn {
        color: white !important;
        opacity: 0.8 !important;
    }

    /* ===== MODULE CARDS - Accordion Style ===== */
    #module-library .module-item-card {
        background: var(--console-card) !important;
        border: 1px solid var(--console-border) !important;
        border-radius: 12px !important;
        margin-bottom: 8px !important;
        overflow: hidden !important;
        transition: all 0.2s ease !important;
    }

    #module-library .module-item-card:active {
        transform: scale(0.98) !important;
    }

    #module-library .module-item-card.expanded {
        background: var(--console-card-expanded) !important;
        border-color: var(--console-accent) !important;
    }

    /* Card header (always visible) */
    .module-card-header {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 14px 16px;
        cursor: pointer;
    }

    .module-card-icon {
        width: 44px;
        height: 44px;
        background: var(--console-bg);
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.3rem;
        flex-shrink: 0;
        border: 1px solid var(--console-border);
    }

    .module-card-info {
        flex: 1;
        min-width: 0;
    }

    .module-card-name {
        font-size: 0.95rem;
        font-weight: 600;
        color: var(--console-text);
        margin-bottom: 2px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .module-card-price {
        font-size: 0.85rem;
        color: var(--console-accent);
        font-weight: 600;
    }

    .module-card-toggle {
        width: 36px;
        height: 36px;
        background: var(--console-bg);
        border: 1px solid var(--console-border);
        border-radius: 8px;
        color: var(--console-text-secondary);
        font-size: 1.2rem;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;
        flex-shrink: 0;
    }

    .module-item-card.expanded .module-card-toggle {
        background: var(--console-accent);
        border-color: var(--console-accent);
        color: white;
        transform: rotate(45deg);
    }

    /* Card body (expandable) */
    .module-card-body {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease, padding 0.3s ease;
        padding: 0 16px;
    }

    .module-item-card.expanded .module-card-body {
        max-height: 300px;
        padding: 0 16px 16px;
    }

    /* ===== INLINE EDIT CONTROLS ===== */
    .module-edit-section {
        margin-bottom: 16px;
    }

    .module-edit-label {
        font-size: 0.7rem;
        font-weight: 600;
        color: var(--console-text-secondary);
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin-bottom: 8px;
        display: block;
    }

    /* Material selector - pill buttons */
    .material-selector {
        display: flex;
        gap: 8px;
    }

    .material-btn {
        flex: 1;
        padding: 10px 8px;
        background: var(--console-bg);
        border: 2px solid var(--console-border);
        border-radius: 8px;
        color: var(--console-text-secondary);
        font-size: 0.8rem;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s ease;
        text-align: center;
    }

    .material-btn.active {
        background: var(--console-accent);
        border-color: var(--console-accent);
        color: white;
    }

    .material-btn:active {
        transform: scale(0.95);
    }

    /* Color picker */
    .color-picker-row {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .color-input-wrapper {
        width: 44px;
        height: 44px;
        border-radius: 10px;
        overflow: hidden;
        border: 2px solid var(--console-border);
        flex-shrink: 0;
    }

    .color-input-wrapper input[type="color"] {
        width: 60px;
        height: 60px;
        margin: -8px;
        cursor: pointer;
        border: none;
    }

    .color-presets {
        display: flex;
        gap: 6px;
        flex-wrap: wrap;
        flex: 1;
    }

    .color-preset {
        width: 32px;
        height: 32px;
        border-radius: 6px;
        border: 2px solid transparent;
        cursor: pointer;
        transition: all 0.15s ease;
    }

    .color-preset:active {
        transform: scale(0.9);
    }

    .color-preset.active {
        border-color: white;
        box-shadow: 0 0 0 2px var(--console-accent);
    }

    /* Opacity slider */
    .opacity-slider-wrapper {
        display: flex;
        align-items: center;
        gap: 12px;
    }

    .opacity-slider {
        flex: 1;
        -webkit-appearance: none;
        appearance: none;
        height: 6px;
        background: var(--console-bg);
        border-radius: 3px;
        outline: none;
    }

    .opacity-slider::-webkit-slider-thumb {
        -webkit-appearance: none;
        appearance: none;
        width: 20px;
        height: 20px;
        background: var(--console-accent);
        border-radius: 50%;
        cursor: pointer;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    }

    .opacity-value {
        width: 40px;
        font-size: 0.85rem;
        color: var(--console-text);
        font-weight: 600;
        text-align: right;
    }

    /* Remove button */
    .module-remove-btn {
        width: 100%;
        padding: 10px;
        background: transparent;
        border: 1px solid #ef4444;
        border-radius: 8px;
        color: #ef4444;
        font-size: 0.85rem;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s ease;
        margin-top: 8px;
    }

    .module-remove-btn:active {
        background: #ef4444;
        color: white;
    }

    /* ===== SIMPLIFIED BOTTOM NAV ===== */
    #mobile-nav.simplified {
        justify-content: space-around !important;
    }

    #mobile-nav.simplified .mobile-nav-item {
        flex: 1;
    }

    /* Hide modules tab - panel handles it */
    #mobile-nav.simplified #nav-btn-modules {
        display: none !important;
    }

    /* ===== CATEGORY TABS - Horizontal Scroll ===== */
    #module-library #category-tabs {
        background: var(--console-bg) !important;
        border-bottom: none !important;
        padding: 12px !important;
        gap: 8px !important;
    }

    #module-library .category-tab {
        background: var(--console-card) !important;
        border: 1px solid var(--console-border) !important;
        color: var(--console-text-secondary) !important;
        padding: 8px 14px !important;
        font-size: 0.8rem !important;
    }

    #module-library .category-tab.active {
        background: var(--console-accent) !important;
        border-color: var(--console-accent) !important;
        color: white !important;
    }

    /* ===== MODULES CONTAINER ===== */
    #module-library #modules-container {
        background: var(--console-bg) !important;
        padding: 12px !important;
        margin-top: 0 !important;
        border-top: none !important;
    }

    /* Search container - remove any gaps */
    #module-library #modules-container > div:first-child {
        background: var(--console-bg) !important;
        padding-top: 0 !important;
        margin-top: 0 !important;
    }

    /* Search input */
    #module-library #module-search {
        background: var(--console-card) !important;
        border-color: var(--console-border) !important;
        color: var(--console-text) !important;
    }

    #module-library #module-search::placeholder {
        color: var(--console-text-secondary) !important;
    }

    /* ===== SHARE & TOOLS DROPDOWN - Dark Mode Support ===== */
    #share-dropdown,
    #more-tools-dropdown {
        background: var(--console-panel) !important;
        border: 1px solid var(--console-border) !important;
    }

    #share-dropdown .tool-item,
    #more-tools-dropdown .tool-item {
        color: var(--console-text) !important;
    }

    #share-dropdown .tool-item:active,
    #more-tools-dropdown .tool-item:active {
        background: var(--console-card) !important;
    }

    /* Divider line in dropdowns */
    #share-dropdown > div[style*="height: 1px"],
    #more-tools-dropdown > div[style*="height: 1px"] {
        background: var(--console-border) !important;
    }

    /* ===== SHARE SECTION - Always Ready ===== */
    .share-ready-section {
        background: linear-gradient(135deg, var(--console-accent) 0%, #1a7a73 100%);
        border-radius: 12px;
        padding: 16px;
        margin: 12px;
        text-align: center;
    }

    .share-ready-text {
        color: rgba(255, 255, 255, 0.9);
        font-size: 0.85rem;
        margin-bottom: 12px;
    }

    .share-ready-buttons {
        display: flex;
        gap: 10px;
    }

    .share-btn {
        flex: 1;
        padding: 12px;
        border-radius: 8px;
        font-size: 0.9rem;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s ease;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
    }

    .share-btn.primary {
        background: white;
        color: var(--console-accent);
        border: none;
    }

    .share-btn.secondary {
        background: rgba(255, 255, 255, 0.15);
        color: white;
        border: 1px solid rgba(255, 255, 255, 0.3);
    }

    .share-btn:active {
        transform: scale(0.95);
    }

    /* ===== OVERLAY WHEN PANEL OPEN ===== */
    #panel-overlay {
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        bottom: 75px;
        background: rgba(0, 0, 0, 0.5);
        z-index: 4998;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.35s ease;
    }

    #panel-overlay.visible {
        opacity: 1;
        pointer-events: auto;
    }

    /* ===== OVERRIDE OLD BOTTOM SHEET STYLES ===== */
    /* The old system uses .active class and display:none - we override that */
    #module-library,
    #module-library.active {
        /* Both states handled by transform, not display */
        display: flex !important;
    }

    /* When active, slide the panel up into view */
    #module-library.active {
        transform: translateY(0) !important;
    }

    /* When active, slide the cart panel up into view */
    #build-summary.active {
        transform: translateY(0) !important;
    }

    /* ===== FOUNDATION SECTION IN DARK THEME ===== */
    #module-library #foundation-section {
        background: var(--console-card) !important;
        border-color: var(--console-accent) !important;
    }

    #module-library #foundation-section button {
        background: var(--console-bg) !important;
        border-color: var(--console-border) !important;
        color: var(--console-text-secondary) !important;
    }

    #module-library #foundation-section button[style*="background: #15635E"],
    #module-library #foundation-section button[style*="background: rgb(21, 99, 94)"] {
        background: var(--console-accent) !important;
        border-color: var(--console-accent) !important;
        color: white !important;
    }

    /* ===== CART/SUMMARY PANEL - Slides up from bottom ===== */
    #build-summary {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        top: auto !important;
        width: 100% !important;
        height: 95vh !important;
        max-height: 95vh !important;
        border-radius: 20px 20px 0 0 !important;
        z-index: 10001 !important;
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.4) !important;
        background: var(--console-panel) !important;
        display: flex !important;
        flex-direction: column !important;
        transform: translateY(100%) !important;
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1) !important;
        overflow: hidden !important;
    }

    /* Hide the default grab handle - header has close X */
    #build-summary::before {
        display: none !important;
    }

    #build-summary.active {
        transform: translateY(0) !important;
    }

    /* Cart header - styled like modules panel */
    #build-summary .drawer-header {
        background: #15635E !important;
        border-bottom: none !important;
        padding: 16px 20px !important;
        flex-shrink: 0 !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
    }

    #build-summary .drawer-header h2 {
        color: white !important;
        font-size: 1rem !important;
        font-weight: 700 !important;
        text-transform: uppercase !important;
        letter-spacing: 1px !important;
        margin: 0 !important;
    }

    /* Add visible close button to cart */
    #build-summary .drawer-header::after {
        content: '✕';
        font-size: 1.3rem;
        color: white;
        opacity: 0.8;
        cursor: pointer;
        padding: 8px;
    }

    /* Cart content area - takes remaining space */
    #build-summary > div:not(.drawer-header) {
        flex: 1 !important;
        overflow-y: auto !important;
        padding: 16px !important;
        background: var(--console-panel) !important;
    }

    /* Cart items list - more space for items */
    #build-summary #selected-modules-list {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        padding-bottom: 100px !important; /* Space for sticky CTA */
    }

    /* Each cart item - cleaner styling */
    #build-summary #selected-modules-list > div,
    #build-summary .selected-module,
    #selected-modules .selected-module {
        background: var(--console-card) !important;
        border-radius: 12px !important;
        padding: 14px 16px !important;
        border: 1px solid var(--console-border) !important;
        display: flex !important;
        align-items: center !important;
        gap: 12px !important;
    }

    /* Cart item module name */
    #build-summary #selected-modules-list > div span:first-child,
    #build-summary .selected-module .selected-module-name,
    #selected-modules .selected-module .selected-module-name {
        flex: 1 !important;
        font-weight: 600 !important;
        color: var(--console-text) !important;
    }

    /* Cart item secondary text (qty, price breakdown) */
    #build-summary .selected-module .selected-module-qty,
    #selected-modules .selected-module .selected-module-qty {
        color: var(--console-text-secondary) !important;
    }

    /* Cart item price */
    #build-summary #selected-modules-list > div span:last-of-type {
        color: var(--console-success) !important;
        font-weight: 600 !important;
    }

    /* Remove button in cart items */
    #build-summary #selected-modules-list > div button {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        border-radius: 50% !important;
        background: #fee2e2 !important;
        color: #dc2626 !important;
        border: none !important;
        font-size: 1rem !important;
        cursor: pointer !important;
    }

    /* Cart total section - sticky at bottom */
    #build-summary .total-section,
    #build-summary > div:last-child {
        position: sticky !important;
        bottom: 0 !important;
        background: var(--console-panel) !important;
        padding: 16px 20px !important;
        border-top: 1px solid var(--console-border) !important;
        box-shadow: 0 -4px 12px rgba(0,0,0,0.15) !important;
    }

    /* CTA button in cart */
    #build-summary button[style*="background: #15635E"],
    #build-summary .checkout-btn,
    #build-summary .cta-btn {
        width: 100% !important;
        padding: 16px !important;
        font-size: 1.1rem !important;
        font-weight: 700 !important;
        border-radius: 12px !important;
    }

    /* ===== EDIT PANEL - Full Screen Action Sheet ===== */
    #module-edit-panel {
        /* Override inline styles - make it nearly full screen */
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        top: 60px !important; /* Just below any header */
        transform: none !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
        height: auto !important;
        max-height: none !important;
        border-radius: 20px 20px 0 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        background: var(--console-panel) !important;
        box-shadow: 0 -8px 32px rgba(0,0,0,0.3) !important;
        z-index: 6000 !important;
        overflow-y: auto !important;
        animation: slideUpSheet 0.3s ease !important;
        display: flex !important;
        flex-direction: column !important;
    }

    @keyframes slideUpSheet {
        from {
            transform: translateY(100%);
            opacity: 0.8;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    /* Backdrop for edit panel */
    body:has(#module-edit-panel)::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 5999;
        pointer-events: none;
    }

    /* Edit panel header - clean look with accent color */
    #module-edit-panel .tool-window-header,
    #module-edit-panel > div:first-child {
        background: #15635E !important;
        border-bottom: none !important;
        border-radius: 20px 20px 0 0 !important;
        padding: 20px 20px !important;
        margin: 0 !important;
        cursor: default !important;
        flex-shrink: 0 !important;
    }

    #module-edit-panel .tool-window-header span[style*="font-weight: 700"],
    #module-edit-panel .tool-window-header span:last-of-type {
        color: white !important;
        font-size: 1.2rem !important;
        font-weight: 700 !important;
    }

    /* Close button - bigger touch target */
    #module-edit-panel #edit-close-btn,
    #module-edit-panel .tool-window-close {
        font-size: 1.8rem !important;
        width: 48px !important;
        height: 48px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        color: white !important;
        opacity: 0.9 !important;
    }

    /* Pin button hidden on mobile */
    #module-edit-panel #edit-pin-btn {
        display: none !important;
    }

    /* Content area - scrollable and fills space */
    #module-edit-panel > div:not(:first-child) {
        padding: 24px 20px !important;
        flex: 1 !important;
        overflow-y: auto !important;
        background: #f8f9fa !important;
    }

    /* Section labels - higher contrast */
    #module-edit-panel div[style*="font-size: 0.85rem"][style*="color: #666"] {
        color: #374151 !important;
        font-size: 0.9rem !important;
        font-weight: 600 !important;
        margin-bottom: 12px !important;
    }

    /* Material buttons - larger, clearer */
    #module-edit-panel .edit-mat-btn {
        padding: 16px !important;
        font-size: 1rem !important;
        min-height: 80px !important;
        background: var(--console-card) !important;
        border-color: var(--console-border) !important;
        color: var(--console-text) !important;
    }

    #module-edit-panel .edit-mat-btn[style*="border-color: rgb(21, 99, 94)"],
    #module-edit-panel .edit-mat-btn[style*="border-color: #15635E"] {
        background: var(--console-accent-glow) !important;
        border-color: var(--console-accent) !important;
        border-width: 3px !important;
    }

    /* Color presets - bigger touch targets */
    #module-edit-panel .color-preset {
        width: 40px !important;
        height: 40px !important;
        border-radius: 50% !important;
        border-width: 3px !important;
    }

    /* Custom color picker */
    #module-edit-panel input[type="color"] {
        width: 50px !important;
        height: 50px !important;
        border-radius: 12px !important;
    }

    /* Opacity slider - bigger thumb */
    #module-edit-panel input[type="range"] {
        height: 8px !important;
    }

    #module-edit-panel input[type="range"]::-webkit-slider-thumb {
        width: 28px !important;
        height: 28px !important;
    }

    /* Action buttons - full width stack */
    #module-edit-panel > div:last-child {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        padding: 16px 20px 24px !important;
        margin-top: auto !important;
        border-top: 1px solid var(--console-border) !important;
        background: var(--console-bg) !important;
    }

    #module-edit-panel #edit-done-btn {
        order: 1 !important;
        width: 100% !important;
        padding: 16px !important;
        font-size: 1.1rem !important;
        font-weight: 700 !important;
        border-radius: 12px !important;
        background: #15635E !important;
    }

    #module-edit-panel #edit-remove-btn {
        order: 2 !important;
        width: 100% !important;
        padding: 14px !important;
        font-size: 1rem !important;
        border-radius: 12px !important;
        background: var(--console-card) !important;
        color: #ef4444 !important;
        border-color: #ef4444 !important;
    }

    /* Dim background when edit panel is open */
    body:has(#module-edit-panel)::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 5999;
        pointer-events: none;
    }

    /* When edit panel is open, auto-close the slide panel */
    body:has(#module-edit-panel) #module-library {
        transform: translateY(100%) !important;
    }

    body:has(#module-edit-panel) #panel-overlay {
        opacity: 0 !important;
        pointer-events: none !important;
    }

    body:has(#module-edit-panel) #mobile-peek-strip {
        opacity: 0 !important;
        pointer-events: none !important;
    }

    /* ===== INITIAL CHOICE - Bottom Sheet Style on Mobile ===== */
    /* Note: Don't force display on #loading - JS controls visibility */
    #loading[style*="flex"] {
        /* Center loading widget in the middle of the screen */
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
        padding: 0 !important;
    }

    /* Override ALL inline styles and position at bottom */
    #initial-choice-inline[style] {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        margin: 0 !important;
        margin-top: 0 !important;
        transform: none !important;
        background: var(--console-panel) !important;
        padding: 24px 20px 40px 20px !important;
        border-radius: 24px 24px 0 0 !important;
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.4) !important;
        z-index: 10000 !important;
        animation: slideUpChoice 0.4s ease !important;
    }

    /* Backup selector without [style] */
    #initial-choice-inline {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        margin: 0 !important;
        transform: none !important;
        background: var(--console-panel) !important;
        padding: 24px 20px 40px 20px !important;
        border-radius: 24px 24px 0 0 !important;
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.4) !important;
        z-index: 10000 !important;
        animation: slideUpChoice 0.4s ease !important;
    }

    @keyframes slideUpChoice {
        from {
            transform: translateY(100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    #initial-choice-inline p,
    #initial-choice-inline p[style] {
        text-align: center !important;
        font-size: 1.1rem !important;
        margin: 0 0 16px 0 !important;
        color: var(--console-text) !important;
    }

    #initial-choice-inline > div,
    #initial-choice-inline > div[style] {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        justify-content: stretch !important;
    }

    #initial-choice-inline button,
    #initial-choice-inline button[style] {
        width: 100% !important;
        padding: 18px 24px !important;
        font-size: 1.1rem !important;
        border-radius: 14px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 10px !important;
    }

    /* Kit button - primary action */
    #choice-kit-inline,
    #choice-kit-inline[style] {
        background: var(--console-accent) !important;
        border-color: var(--console-accent) !important;
        color: white !important;
        order: -1 !important; /* Show first since it's the recommended action */
    }

    /* Custom button - secondary */
    #choice-custom-inline,
    #choice-custom-inline[style] {
        background: var(--console-card) !important;
        border: 2px solid var(--console-border) !important;
        color: var(--console-text) !important;
    }

    /* ===== KIT SELECTION MODAL - Bottom Sheet Style ===== */
    #kit-selection-modal {
        align-items: flex-end !important;
        z-index: 6000 !important;
    }

    #kit-selection-modal .modal-content {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: 95vh !important;
        max-height: 95vh !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 24px 24px 0 0 !important;
        padding: 0 !important;
        animation: slideUpChoice 0.35s ease !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        background: var(--console-panel) !important;
    }

    #kit-selection-modal .modal-content > div:first-child {
        /* Header section */
        background: #15635E !important;
        padding: 20px !important;
        border-radius: 24px 24px 0 0 !important;
    }

    #kit-selection-modal .modal-content > div:first-child h2 {
        color: white !important;
        margin: 0 !important;
    }

    #kit-selection-modal .modal-content > div:first-child p {
        color: rgba(255,255,255,0.8) !important;
        margin: 8px 0 0 0 !important;
    }

    /* Kit grid */
    #kit-grid {
        padding: 16px !important;
        flex: 1 !important;
        overflow-y: auto !important;
        background: var(--console-bg) !important;
    }

    /* Kit loading text */
    #kit-loading p {
        color: var(--console-text-secondary) !important;
    }

    /* Individual kit cards */
    #kit-grid > div:not(#kit-loading) {
        padding: 16px !important;
        border-radius: 12px !important;
        background: var(--console-card) !important;
        border: 1px solid var(--console-border) !important;
    }

    /* Kit card text */
    #kit-grid > div h3,
    #kit-grid > div h4 {
        color: var(--console-text) !important;
    }

    #kit-grid > div p {
        color: var(--console-text-secondary) !important;
    }

    /* Close button styling */
    #kit-selection-modal .modal-content button[onclick*="closeKitModal"] {
        position: absolute !important;
        top: 16px !important;
        right: 16px !important;
        background: rgba(255,255,255,0.2) !important;
        color: white !important;
        border: none !important;
        width: 40px !important;
        height: 40px !important;
        border-radius: 50% !important;
        font-size: 1.2rem !important;
    }

    /* ===== FAB - Below panels when open ===== */
    #mobile-share-fab {
        z-index: 4999 !important; /* Below panels (5000+) */
    }

    /* Hide FAB when panels are open */
    #module-library.open ~ #mobile-share-fab,
    #build-summary.open ~ #mobile-share-fab,
    body:has(#module-library.open) #mobile-share-fab,
    body:has(#build-summary.open) #mobile-share-fab {
        opacity: 0 !important;
        pointer-events: none !important;
        transform: scale(0.8) !important;
    }

}

/* ===== DESKTOP UNCHANGED ===== */
@media (min-width: 1025px) {
    #mobile-peek-strip,
    #panel-overlay {
        display: none !important;
    }
}
