/* Scoped to the builder root to avoid breaking WP theme */
#dtf-builder-root { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; 
    background: #f8f9fa; margin: 0; display: flex; 
    height: 100vh; /* Use full viewport height */
    min-height: 100dvh; /* Dynamic viewport for mobile browsers */
    width: 100%; overflow: hidden; color: #343a40; 
    position: relative; box-sizing: border-box; 
    font-size: clamp(12px, 0.85vw, 16px); /* Fluid Scaling: 12px min, 16px max, scales with width */
    user-select: none;
    -webkit-user-select: none;
}

#sidebar { 
    width: 21em; background: #fff; padding: 0.75em; border-right: 1px solid #dee2e6; 
    display: flex; flex-direction: column; gap: 0.5em; box-shadow: 0 2px 15px rgba(0,0,0,0.06); z-index: 10; 
    transition: all 0.3s ease;
}
h2 { margin: 0; font-size: 1.2em; color: #333; }

.control-group { display: flex; flex-direction: column; gap: 0.2em; }
label { font-size: 0.75em; font-weight: bold; color: #666; text-transform: uppercase; }
select, button, input { padding: 0.4em; border: 1px solid #ced4da; border-radius: 0.4em; font-size: 0.9em; transition: all 0.2s ease; }
select, input, textarea { user-select: text; -webkit-user-select: text; }
button { cursor: pointer; background: #0d6efd; color: white; border: none; font-weight: bold; }
button:hover { background: #0b5ed7; }
button:active { transform: scale(0.98); }
button.secondary { background: #6c757d; }
button.secondary:hover { background: #5c636a; }
button:disabled { background: #ccc; cursor: not-allowed; }
input:disabled { background: #e9ecef; color: #6c757d; cursor: not-allowed; }
button:focus-visible, select:focus-visible, input:focus-visible {
    outline: 2px solid #0d6efd80;
    outline-offset: 1px;
    border-color: #0d6efd;
}

#logo-container {
    text-align: center;
    padding-bottom: 0.5em;
    margin-bottom: 0.5em;
    border-bottom: 1px solid #eee;
}
/* This is a placeholder style. An <img> tag would likely replace this div. */
.logo-placeholder {
    background: transparent;
    color: #adb5bd;
    padding: 0.6em;
    border-radius: 0.5em;
    font-weight: bold;
    font-size: 1em;
    border: 2px dashed #e9ecef;
}
.back-link {
    display: block; margin-top: 0.5em; font-size: 0.8em; 
    color: #6c757d; text-decoration: none; transition: color 0.2s;
}
.back-link:hover { color: #0d6efd; text-decoration: underline; }


#file-list { 
    flex: 1; overflow-y: auto; border: 1px solid #eee; padding: 0.5em; background: #fafafa; min-height: 6em;
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5em; align-content: start;
    overflow-x: hidden;
}
.file-item { 
    background: #fff; border: 1px solid #dee2e6; padding: 0.5em; margin: 0;
    border-radius: 0.5em; font-size: 0.75em; display: flex; flex-direction: column; 
    justify-content: center; align-items: center; cursor:pointer;
    transition: all 0.2s ease; height: 8em;
    position: relative;
}
.file-item img { 
    width: 100%; height: 5em; object-fit: contain; margin-bottom: 0.3em; pointer-events: none; 
    background-color: #fff;
    background-image: linear-gradient(45deg, #eee 25%, transparent 25%), linear-gradient(-45deg, #eee 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #eee 75%), linear-gradient(-45deg, transparent 75%, #eee 75%);
    background-size: 10px 10px;
    background-position: 0 0, 0 5px, 5px -5px, -5px 0px;
}
.file-item span { width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }
.file-item:hover { background: #f0f8ff; border-color: #adb5bd; }
.file-item.selected { border-color: #0d6efd; background: #e7f1ff; box-shadow: 0 0 0 1px #0d6efd; }
.btn-remove-file {
    position: absolute; top: 4px; right: 4px;
    background: rgba(255,255,255,0.9); border-radius: 50%;
    width: 20px; height: 20px; display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: #dc3545; font-weight: bold; font-size: 14px; line-height: 1;
    border: 1px solid #dee2e6; z-index: 5;
}
.btn-remove-file:hover { background: #dc3545; color: #fff; border-color: #dc3545; }

#warning-box {
    background: #fff9e6; border: 1px solid #ffecb3; color: #664d03;
    padding: 10px; border-radius: 4px; font-size: 11px;
    max-height: 120px; overflow-y: auto; display: none;
}
#warning-box div { margin-bottom: 4px; border-bottom: 1px solid rgba(0,0,0,0.05); padding-bottom: 2px; }

#workspace { display: flex; flex-direction: column; overflow: hidden; flex: 1; width: 0; min-width: 0; height: 100%; position: relative; }
#toolbar {
    flex: 0 0 auto; width: 100%; height: auto; min-height: 52px; z-index: 100; position: relative;
    background: #ffffff; border-bottom: 1px solid #e5e7eb; padding: 10px 25px; box-sizing: border-box;
    display: flex; gap: 8px; align-items: center; font-size: 14px; 
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
    flex-wrap: wrap !important; flex-shrink: 0;
}

#toolbar button { 
    height: 32px; padding: 0 12px; font-size: 13px; line-height: 32px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; 
    background-color: transparent; color: #374151; border: 1px solid transparent; border-radius: 6px; font-weight: 500;
    transition: all 0.15s ease-in-out;
}
#toolbar button:hover { background-color: #f3f4f6; color: #111827; }
#toolbar button:active { background-color: #e5e7eb; transform: translateY(0.5px); }
#toolbar button:disabled { opacity: 0.5; cursor: not-allowed; background-color: transparent; color: #9ca3af; }

/* iOS Safari Icon Fix */
#toolbar button svg, #toolbar button i, .icon-btn svg, .icon-btn i, #align-controls button svg, #align-controls button i {
    width: 14px; height: 14px; display: inline-block; fill: currentColor; vertical-align: middle; flex-shrink: 0;
}

#toolbar input { 
    height: 32px; padding: 0 8px; font-size: 13px; width: 64px; text-align: center; 
    border: 1px solid #d1d5db; border-radius: 6px; color: #1f2937; font-weight: 500; background: #fff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#toolbar input:focus { border-color: #3b82f6; outline: none; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); }
#toolbar input:disabled { background-color: #f9fafb; color: #9ca3af; border-color: #e5e7eb; }

#toolbar #inpCopies { width: 60px !important; }
#toolbar #inpSelW, #toolbar #inpSelH { width: 80px; }

.sep { display: none !important; }

#item-controls, #align-controls { 
    display: flex !important; gap: 4px; align-items: center; 
    padding-right: 12px; margin-right: 8px; border-right: 1px solid #e5e7eb; height: 24px;
    transition: opacity 0.2s ease;
}
#item-controls:last-child, #align-controls:last-child { border-right: none; padding-right: 0; margin-right: 0; }

.icon-btn, #align-controls button { 
    width: 32px; height: 32px; padding: 0; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    background-color: transparent; color: #4b5563; border: 1px solid transparent; border-radius: 6px; 
}
.icon-btn:hover, #align-controls button:hover { background-color: #f3f4f6; color: #111827; }
.mobile-undo-btn { display: none !important; }


#canvas-wrapper {
    flex: 1;
    overflow: auto;
    display: flex;
    position: relative;
    background-color: #e9ecef;
    padding: 30px; /* Use padding to allow scrolling into the gap */
    box-sizing: border-box;
}
.ruler-grid { 
    display: inline-grid; grid-template-columns: 30px max-content; grid-template-rows: 30px max-content; 
    margin: auto; background: #fff; box-shadow: 0 5px 15px rgba(0,0,0,0.2); 
}

.ruler-corner { background: #ccc; position: sticky; top: 0; left: 0; z-index: 20; width: 30px; height: 30px; border-right: 1px solid #999; border-bottom: 1px solid #999; }
#ruler-top { background: #fff; border-bottom: 1px solid #999; position: sticky; top: 0; z-index: 10; }
#ruler-left { background: #fff; border-right: 1px solid #999; position: sticky; left: 0; z-index: 10; }
.canvas-container { position: relative; }

canvas { 
    background: white; 
    background-image: linear-gradient(45deg, #eee 25%, transparent 25%), linear-gradient(-45deg, #eee 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #eee 75%), linear-gradient(-45deg, transparent 75%, #eee 75%); 
    background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0px; 
    display: block;
}

#drop-zone { position: absolute; top:0; left:0; right:0; bottom:0; background: rgba(13,110,253,0.1); border: 4px dashed #0d6efd; display: none; pointer-events: none; justify-content: center; align-items: center; font-size: 24px; color: #0d6efd; font-weight: bold; }
#dtf-builder-root.dragging #drop-zone { display: flex; }

.info-bar { margin-top: auto; font-size: 12px; color: #6c757d; text-align: center; line-height: 1.4; }

#dpi-legend { 
    position: absolute; bottom: 15px; left: 20px; z-index: 200; 
    background: rgba(255,255,255,0.95); padding: 0; border: 1px solid #ccc; 
    border-radius: 4px; font-size: 11px; pointer-events: auto; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    display: flex; flex-direction: column; min-width: 100px;
}
.dpi-header { padding: 6px 10px; background: #f8f9fa; border-bottom: 1px solid #eee; cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-weight: bold; user-select: none; }
.dpi-content { padding: 10px; }
#dpi-legend.collapsed .dpi-content { display: none; }
#dpi-legend.collapsed .dpi-header { border-bottom: none; }
#dpi-legend.collapsed .toggle-icon { transform: rotate(180deg); display: inline-block; }
.advanced-options { display:none; border:1px solid #ddd; padding:5px; margin-top:5px; background:#f9f9f9; border-radius:4px; }
.adv-toggle { cursor:pointer; font-size:10px; color:#007bff; text-decoration:underline; margin-top:2px; display:inline-block; }

#order-sidebar {
    width: 19em;
    background: #fff;
    padding: 0.75em 0.75em 2em 0.75em;
    border-left: 1px solid #dee2e6;
    display: flex;
    flex-direction: column;
    gap: 0.75em;
    box-shadow: -2px 0 15px rgba(0,0,0,0.06);
    z-index: 10;
    transition: all 0.3s ease;
}
#order-sidebar h3 {
    margin: 0 0 0.6em 0;
    padding-bottom: 0.9em;
    border-bottom: 1px solid #eee;
    font-size: 1.2em;
}
#order-sidebar .control-group div {
    font-size: 0.9em;
    font-weight: 500;
}
#sheets-list {
    flex: 1; overflow-y: auto; width: 100%; padding-right: 0.3em;
}
.sheet-list-item {
    border: 1px solid #dee2e6;
    border-radius: 0.5em;
    padding: 0.7em;
    margin-bottom: 0.7em;
    background: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}
.sheet-list-item.active {
    border-color: #0d6efd;
    background-color: #f8f9fa;
    box-shadow: 0 0 0 1px #0d6efd;
}
.sheet-list-item:hover { border-color: #adb5bd; }
.sheet-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5em; }
.sheet-name { font-weight: bold; font-size: 0.9em; }
.sheet-price { font-weight: bold; color: #28a745; font-size: 0.9em; }
.sheet-body { display: flex; gap: 0.6em; align-items: flex-start; }
.sheet-preview-thumb {
    width: 4em; height: 4.6em;
    border: 1px solid #dee2e6;
    border-radius: 0.25em;
    background-color: #fff;
    background-image: linear-gradient(45deg, #eee 25%, transparent 25%), linear-gradient(-45deg, #eee 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #eee 75%), linear-gradient(-45deg, transparent 75%, #eee 75%);
    background-size: 10px 10px; background-position: 0 0, 0 5px, 5px -5px, -5px 0px;
    flex-shrink: 0;
}
.sheet-controls { flex: 1; display: flex; flex-direction: column; gap: 0.5em; }
.sheet-controls label { font-size: 0.7em; margin-bottom: 0.15em; }
.sheet-controls input { padding: 0.4em; font-size: 0.85em; }
.btn-delete-sheet { padding: 0.3em 0.6em; background: #dc3545; font-size: 0.75em; margin-left: auto; }

/* --- Magic Builder Modal --- */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 2000;
    display: none; justify-content: center; align-items: center;
}
.modal-content {
    background: white; padding: 1.25em; border-radius: 0.5em;
    width: 600px; max-width: 90%; max-height: 80vh;
    display: flex; flex-direction: column; gap: 1em;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid #eee; padding-bottom: 0.6em;
}
.modal-header h3 { margin: 0; }
.btn-close-modal {
    background: none; border: none; font-size: 24px; cursor: pointer; color: #666;
}
.drop-area-magic {
    border: 2px dashed #ccc; padding: 1.25em; text-align: center;
    border-radius: 0.5em; cursor: pointer; color: #666;
    transition: all 0.2s;
}
.drop-area-magic:hover { border-color: #6610f2; color: #6610f2; background: #f8f9fa; }
.modal-body {
    flex: 1; overflow-y: auto; border: 1px solid #eee; padding: 0.6em;
    border-radius: 0.25em; min-height: 12em;
}
.magic-row {
    display: flex; gap: 0.6em; align-items: center; padding: 0.5em;
    border-bottom: 1px solid #eee; background: #fff;
}
.magic-row:last-child { border-bottom: none; }
.magic-row img { width: 2.5em; height: 2.5em; object-fit: contain; border: 1px solid #dee2e6; border-radius: 0.25em; background: #f8f9fa; }
.magic-inputs { display: flex; gap: 0.6em; flex: 1; align-items: center; }
.magic-inputs div { display: flex; flex-direction: column; gap: 0.15em; }
.magic-inputs label { font-size: 0.7em; color: #888; }
.magic-inputs input { width: 4em; padding: 0.3em; font-size: 0.8em; }

/* Tablet Layout (iPad) - Compact 3-Column */
@media (min-width: 766px) and (max-width: 1366px) {
    #sidebar { width: 14em !important; padding: 0.5em 0.5em 8em 0.5em !important; }
    #order-sidebar { width: 15em !important; padding: 0.5em 0.5em 8em 0.5em !important; }
    #canvas-wrapper { padding: 15px 15px 150px 15px !important; }
    
    /* Compact Toolbar for Tablet */
    #toolbar { padding: 5px 10px !important; gap: 4px !important; }
    #toolbar button { padding: 0 6px !important; font-size: 11px !important; height: 28px !important; }
    #toolbar input { width: 45px !important; font-size: 11px !important; height: 28px !important; }
    .icon-btn { width: 28px !important; height: 28px !important; }
}

/* For Phones (Consolidated to 765px) */
@media (max-width: 765px) {
    #sidebar { padding: 1em; gap: 1em; }
    .control-group { flex-basis: 100%; }
    #toolbar { height: auto; min-height: 56px; padding: 10px 16px; gap: 8px; }
    #toolbar button { height: 36px; padding: 0 12px; font-size: 14px; border-radius: 8px; }
    #toolbar input { height: 36px; width: 60px; border-radius: 8px; font-size: 14px; }
    .icon-btn, #align-controls button { width: 36px; height: 36px; border-radius: 8px; }
    #item-controls, #align-controls { padding-right: 12px; margin-right: 8px; height: 28px; }
    .canvas-container { border: 1px solid #ccc; }
    #dpi-legend { bottom: 10px; left: 10px; }
    .info-bar { display: none; }
    button[onclick="autoLayout()"] { padding: 0.6em; }
    .mobile-undo-btn { display: flex !important; }
}

/* Small Browser Windows (Laptop/Desktop) */
@media (min-width: 766px) and (max-height: 700px) {
    #canvas-wrapper { padding: 10px 10px 60px 10px; }
}

/* --- Toast Notification --- */
#dtf-toast {
    visibility: hidden;
    min-width: 250px;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 0.5em;
    padding: 1em;
    position: fixed;
    z-index: 9999;
    left: 50%;
    transform: translateX(-50%);
    bottom: 2em;
    font-size: 0.9em;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    opacity: 0;
    transition: opacity 0.5s, bottom 0.5s;
}

#dtf-toast.show {
    visibility: visible;
    opacity: 1;
    bottom: 50px;
}

/* --- Splash Screen --- */
#dtf-splash-screen {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: #ffffff; z-index: 10000;
    display: flex; justify-content: center; align-items: center;
    transition: opacity 0.5s ease, visibility 0.5s;
}
#dtf-splash-screen.hidden {
    opacity: 0;
    visibility: hidden;
}
#dtf-splash-screen .splash-content {
    text-align: center;
}
#dtf-splash-screen img {
    max-width: 250px; height: auto;
}

/* --- User Nav --- */
#dtf-user-nav {
    position: static; /* Was absolute */
    background: transparent; padding: 0 0 0.6em 0;
    border-radius: 0; font-size: 0.8em; border: none; border-bottom: 1px solid #eee;
    box-shadow: none; text-align: right; margin-bottom: 0.6em;
}
#dtf-user-nav a { color: #0d6efd; text-decoration: none; font-weight: 600; }
#dtf-user-nav a:hover { text-decoration: underline; }

/* --- MOBILE APP INTERFACE (Max-Width 765px) --- */
@media (max-width: 765px) {
    #dtf-builder-root {
        padding-top: 60px;    /* Space for Top Header */
        padding-bottom: 140px !important; /* Space for Bottom Nav + Safe Area */
        overflow: visible;    /* Allow native scroll behavior */
        height: auto !important;
        min-height: 100vh;
    }
/* --- 1. TOP HEADER --- */
#dtf-mobile-header {
    display: flex !important;
    position: fixed; top: 0; left: 0; right: 0;
    height: 60px; background: #fff;
    border-bottom: 1px solid #ddd;
    align-items: center; justify-content: space-between;
    padding: 0 10px; z-index: 1000;
}
.mobile-qty-wrapper {
    display: flex; align-items: center; gap: 5px;
    font-weight: bold; font-size: 14px;
}
#mobile-qty-input {
    width: 50px; padding: 5px; border: 1px solid #ccc;
    border-radius: 4px; text-align: center;
}
#mobile-add-cart-btn {
    background: #28a745; /* Green or User Primary Color */
    color: white; border: none; padding: 8px 15px;
    border-radius: 5px; font-weight: bold; font-size: 14px;
}
/* --- 2. BOTTOM NAVIGATION --- */
#dtf-mobile-nav {
    display: flex !important;
    position: fixed; bottom: 0; left: 0; right: 0;
    height: auto; min-height: 65px; background: #fff;
    border-top: 1px solid #ddd;
    z-index: 2000;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
    padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
    flex: 1; background: transparent; border: none;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    color: #666; cursor: pointer; padding: 5px 0;
}
.nav-item .dashicons { font-size: 24px; width: 24px; height: 24px; margin-bottom: 4px; }
.nav-item .nav-label { font-size: 10px; font-weight: 500; }
.nav-item.active { color: #0d6efd; background: #f0f8ff; }
/* --- 3. DRAWERS (The Sidebars turned into Bottom Sheets) --- */
#sidebar, #order-sidebar {
    position: fixed;
    left: 0; right: 0;
    bottom: 65px; /* Sits exactly on top of nav */
    top: auto;
    height: 55vh; /* Occupy bottom 55% of screen */
    width: 100% !important;
    background: #fff;
    z-index: 1500;
    border-radius: 15px 15px 0 0;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.2);
    transform: translateY(120%); /* Hidden by default */
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    padding: 15px; overflow-y: auto;
    display: flex !important; flex-direction: column;
}
/* Active Drawer State */ #sidebar.drawer-open, #order-sidebar.drawer-open { transform: translateY(0); }

/* Adjust Canvas */
#workspace {
        width: 100% !important; height: auto !important;
        position: fixed; top: 50px; left: 0;
        bottom: calc(75px + env(safe-area-inset-bottom)); /* Ensure gap above nav */
        z-index: 1;
    }
    #canvas-wrapper {
        padding: 10px 10px 180px 10px !important; /* Extra bottom padding for mobile scrolling */
    }
/* Special adjustments for content inside drawers */ #file-list { grid-template-columns: repeat(3, 1fr) !important; } .file-item { height: 90px; }


}
/* Hide on Desktop */ @media (min-width: 766px) { #dtf-mobile-nav, #dtf-mobile-header { display: none !important; } }

/* --- Mobile Navigation Bar --- */
#mobile-navbar { display: none; }

@media (max-width: 765px) {
#mobile-navbar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: auto;
    min-height: 65px;
    background: #ffffff !important; /* Force White */
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    z-index: 2147483647; /* Max Z-Index to stay on top */
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid #ccc;
    padding-bottom: env(safe-area-inset-bottom);
}
/* Adjust Legend Position */
#dpi-legend { bottom: 10px !important; left: 10px !important; font-size: 10px !important; padding: 0 !important; z-index: 200; }

.mobile-nav-item {
    background: transparent !important;
    border: none !important;
    color: #444444 !important; /* Force Dark Grey Text */
    font-size: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    gap: 2px;
}
.mobile-nav-item .icon { font-size: 20px; margin-bottom: 2px; }
.mobile-nav-item .label { font-weight: 600; text-transform: uppercase; }
/* Upload Button Highlight */ .mobile-nav-item.action-btn { color: #0d6efd !important; } .mobile-nav-item.action-btn .icon { font-weight: bold; font-size: 24px; }

/* Active State */
.mobile-nav-item:active { background-color: #f2f2f2 !important; }
/* Fix Sidebar Scrolling */
#sidebar, #order-sidebar {
    position: fixed;
    top: 60px; /* Below header */
    left: 0;
    width: 100%;
    height: calc(100% - 125px) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
    overscroll-behavior: contain;
    touch-action: pan-y !important;
    padding-bottom: 20px;
    z-index: 9998;
    background: #fff;
    display: none; /* Hidden by default */
}
/* Ensure File List Scrolls */ #file-list { max-height: none !important; overflow-y: visible !important; }
/* Show when active */
#sidebar.drawer-open, #order-sidebar.drawer-open { display: flex !important; flex-direction: column; }

#dtf-builder-root { padding-bottom: 70px; }

/* --- Mobile Header Styling --- */
#dtf-mobile-header {
    display: flex !important;
    position: fixed; top: 0; left: 0; right: 0;
    background: #fff; z-index: 1000;
    border-bottom: 1px solid #ddd;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    height: 50px;
}
.mobile-header-left { display: flex; align-items: center; gap: 8px; }
.mobile-logo-placeholder { display: flex; align-items: center; }
.mobile-logo-placeholder img { max-height: 25px; width: auto; object-fit: contain; }
.mobile-back-link { 
    font-size: 11px; color: #666; text-decoration: none; display: flex; align-items: center; 
    background: #f0f0f0; padding: 4px 8px; border-radius: 4px; white-space: nowrap;
}
#mobile-user-nav { 
    font-size: 11px; display: flex; align-items: center; 
    border: none !important; margin: 0 !important; padding: 0 !important;
}
#mobile-user-nav a { color: #0d6efd; font-weight: 600; }

/* Active State for Nav Items */
.mobile-nav-item.active { color: #0d6efd !important; background: #f9f9f9 !important; }
.mobile-nav-item.active .icon { transform: scale(1.1); transition: transform 0.2s; }
}
/* --- MOBILE FILES DRAWER FIXES --- */
@media (max-width: 765px) {
    /* 1. Thicker, Grabbable Scrollbars */
    #sidebar::-webkit-scrollbar,
    #order-sidebar::-webkit-scrollbar,
    #file-list::-webkit-scrollbar,
    #canvas-wrapper::-webkit-scrollbar {
        width: 25px !important; /* Increased size for easier touch dragging */
        height: 25px !important; /* Ensure horizontal scrollbars are also big */
        background: #f0f0f0;
        -webkit-appearance: none;
    }
    #sidebar::-webkit-scrollbar-thumb,
    #order-sidebar::-webkit-scrollbar-thumb,
    #file-list::-webkit-scrollbar-thumb,
    #canvas-wrapper::-webkit-scrollbar-thumb {
        background: #555; /* Darker thumb for better visibility */
        border: 4px solid #f0f0f0; /* Inset effect */
        border-radius: 20px;
    }

    /* Force Sidebar to Column Layout for Files */
    #sidebar {
        flex-direction: column !important;
        flex-wrap: nowrap !important;
        touch-action: pan-y !important; /* Explicitly allow vertical scroll */
    }

    /* 2. Hide Non-File Controls in Sidebar */
    /* Hide Logo, Sheet Size, Snap/Undo controls on Mobile Files Tab */
    #sidebar #logo-container,
    #sidebar .group-size,
    #sidebar .group-snap,
    #sidebar .info-bar,
    #sidebar #warning-box,
    .btn-magic, .btn-auto {
        display: none !important;
    }

    /* 3. Full Width Upload Button at Top */
    #sidebar .group-upload {
        display: block !important;
        width: 100%;
        flex: 0 0 auto;
        position: sticky;
        top: 0;
        background: #fff;
        z-index: 20;
        padding: 10px 0;
        border-bottom: 1px solid #eee;
        margin: 0 !important;
    }
    #sidebar .group-upload label { display: none; /* Hide 'Upload Images' text label to save space */ }

    /* Style the button to be full width */
    #sidebar .group-upload button {
        width: 100%;
        display: block;
        font-size: 14px !important;
        padding: 12px !important;
        margin: 0 !important;
    }
    /* Force File List to fill the rest */ 
    #file-list { 
        width: 100%;
        height: auto !important; 
        flex: 1; 
        overflow-y: visible !important; /* Let parent handle scroll */ 
        min-height: 50vh; 
        padding-bottom: 80px; 
        margin-top: 0 !important;
    }

    /* 4. Increase File Item Hit Area (easier tap) */ 
    .file-item { min-height: 120px; /* Taller */ }

    /* 5. Visual Scroll Hint (Gradient Mask) for File List */
    /* This indicates more content is available below */
    #file-list {
        /* Ensure container is positioned for pseudo-element */
        position: relative;
        /* Add padding at bottom so last item isn't covered by gradient if we used an overlay, 
           but here we just ensure space. */
        padding-bottom: 80px; 
        /* Optional: A subtle shadow at the bottom of the sticky header to show depth */
        box-shadow: inset 0 10px 10px -10px rgba(0,0,0,0.1);
    }

    /* 5. Visual Scroll Hint (Gradient Mask) for File List */
    /* This indicates more content is available below */
    #file-list {
        /* Ensure container is positioned for pseudo-element */
        position: relative;
        /* Add padding at bottom so last item isn't covered by gradient if we used an overlay, 
           but here we just ensure space. */
        padding-bottom: 80px; 
        /* Optional: A subtle shadow at the bottom of the sticky header to show depth */
        box-shadow: inset 0 10px 10px -10px rgba(0,0,0,0.1);
    }
}

/* Magic Builder Responsive Fixes */
.magic-file-info { flex: 1; min-width: 0; overflow: hidden; }
.magic-file-info span { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

@media (max-width: 765px) {
    .magic-row { align-items: flex-start; }
    .magic-inputs { flex-wrap: wrap; }
    .magic-file-info { flex-basis: 100%; width: 100%; margin-bottom: 5px; }
    .magic-inputs input { width: 100%; }
    .magic-inputs div:not(.magic-file-info) { flex: 1; }
}
