/*
    MerchStudio version 0.01 - Core File
    Gang Sheet Builder Styles
    @author      Hezekiah Dayson
    @version     tpl/core/client/css/canvas.css - 0.03 - 10-16-2026 (MERCH_NLI1, MERCH_NLI6)
*/

/* --- Local Theme Variables (Scoped to this App) --- */
/* Default (Light) Mappings */
.gang_sheet_app {
    /* Map local ruler vars to global theme vars from theme.tpl */
    --ruler_bg: #ffffff;            /* Distinct from --bg for contrast */
    --ruler_text: var(--text);      /* Use global text color */
    --ruler_line: var(--line);      /* Use global line color */

    /* Checkerboard colors */
    --check_1: #f0f0f0;
    --check_2: transparent;

    /* Canvas bounding shadow (Dark drop-shadow for Light Mode) */
    --canvas_glow: rgba(0, 0, 0, 0.25);
}

/* Dark Theme Overrides */
/* We target the app container when the HTML tag has data-theme="dark" */
html[data-theme="dark"] .gang_sheet_app {
    --ruler_bg: var(--header_bg);   /* Use header background (#161a1a) */
    --ruler_text: var(--middle_grey);
    --ruler_line: var(--line);

    /* Dark Checkerboard */
    --check_1: #1a1b26;
    --check_2: transparent;

    /* Canvas bounding shadow (White backlight for Dark Mode) */
    --canvas_glow: rgba(255, 255, 255, 0.8);
}

/* --- App Container --- */
.gang_sheet_app {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header_height, 0px));
    background-color: var(--base);
    color: var(--text);
    overflow: hidden;
}

/* --- Header --- */
.app_header {
    height: 64px;
    background-color: var(--bg);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
}

.app_title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.header_right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.price_display {
    font-size: 1.1rem;
    font-weight: 700;
    margin-right: 10px;
    color: var(--accent);
}

.header_left {
    display: flex;
}

/* Builder Logo Link */
.builder_logo_link {
    display: flex;
    align-items: center;
    margin-right: 1.5rem;
    padding-right: 1.5rem;
    border-right: 1px solid var(--line);
    height: 100%;
    text-decoration: none;
    transition: opacity 0.2s ease;
}
.builder_logo_link:hover {
    opacity: 0.7;
}
.builder_logo_link svg,
.builder_logo_link img {
    height: 35px;
    width: auto;
    display: block;
}
.header_user_wrap {
    border-left: 1px solid var(--line);
    padding-left: 12px;
    margin-left: 4px;
    display: flex;
    align-items: center;
}

.app_title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.price_display {
    font-size: 1.1rem;
    font-weight: 700;
    margin-right: 10px;
    color: var(--accent);
}

/* --- Toolbar --- */
.app_toolbar {
    height: 56px;
    background-color: var(--bg);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 24px;
    flex-shrink: 0;
}

.tool_group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tool_group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--middle_grey);
}

.tool_group input {
    width: 100px;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 4px;
    font-size: 0.9rem;
}

.select_wrapper.small select {
    padding: 6px 30px 6px 10px;
    width: 80px;
}

/* --- Workspace Layout --- */
.app_workspace {
    flex: 1;
    display: flex;
    position: relative;
    height: 100%;
    min-width: 0;
    min-height: 0;
}

/* The wrapper containing your actual canvas element */
.canvas_container_wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
}

/* --- Sidebar --- */
.app_sidebar {
    width: 280px;
    background-color: var(--bg);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    box-sizing: border-box;
}

.sidebar_header {
    padding: 16px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 100%;
}

.sidebar_content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-sizing: border-box;
    height: 100%;
}

.empty_state {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--middle_grey);
    font-size: 0.875rem;
    border: 2px dashed var(--line);
    border-radius: 8px;
    padding: 16px;
    box-sizing: border-box;
    width: 100%;
    height: 130px;
    margin: 0;
}


/* Thumbnail Card */
.upload_thumb {
    position: relative;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
    background: var(--bg);
    cursor: pointer;
    transition: box-shadow 0.2s;
}

.canvas-count-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background-color: var(--accent_red);
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 700;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    z-index: 5;
    pointer-events: none;
}

.upload_thumb:hover {
    box-shadow: 0 4px 6px var(--shadow);
}

.upload_thumb img {
    width: 100%;
    height: 120px;
    object-fit: contain;
    background-color: var(--base);
    border-radius: 4px;
}

.upload_thumb .thumb_name {
    font-size: 0.8rem;
    color: var(--text);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Container adjustment to align items better */
.thumb_controls {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* --- Extracted Sidebar Thumbnail Styles --- */
.upload_thumb .thumb_meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.70rem;
    margin-top: 5px;
    padding: 0 2px;
}

.upload_thumb .thumb_dpi_badge {
    font-weight: bold;
    padding: 2px 4px;
    border-radius: 3px;
}

.upload_thumb .thumb_unit {
    color: var(--text-muted, #888888);
    font-weight: 500;
}

.upload_thumb .thumb_dims {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.upload_thumb .thumb_dim_group {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 4px;
}

.upload_thumb .thumb_label {
    font-size: 0.75rem;
    color: var(--text-muted, #888888);
    font-weight: 600;
}

.upload_thumb .thumb_dim_w,
.upload_thumb .thumb_dim_h,
.upload_thumb .thumb_qty {
    width: 100%;
    padding: 4px;
    font-size: 0.85rem;
    border: 1px solid var(--line);
    border-radius: 3px;
    background: var(--base);
    color: var(--text);
}

.upload_thumb .btn_icon.small {
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 4px;
}

.upload_thumb .btn_delete_upload {
    color: var(--accent_red, #f08080);
}

.qty_label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* The Enhanced Input Box */
.qty_input_enhanced {
    width: 110px;
    height: 28px;
    padding: 0 4px 0 8px;
    font-size: 1rem;
    font-weight: 700;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--base);
    color: var(--text);
    outline: none;
}

/* Make the increase/decrease arrows (spinners) much larger */
.qty_input_enhanced::-webkit-inner-spin-button,
.qty_input_enhanced::-webkit-outer-spin-button {
    height: 30px;      /* Increases vertical height of the arrows */
    width: 22px;       /* Widens the clickable area of the arrows */
    opacity: 1;         /* Ensures they are always visible */
    cursor: pointer;
    margin-left: 2px;
}

/* Firefox support for larger arrows */
.qty_input_enhanced {
    appearance: auto;
    -moz-appearance: number-input;
}

/* --- Stage / Canvas with Rulers (Grid Layout) --- */
.app_stage {
    flex: 1;
    background-color: var(--base);
    position: relative;
    /* Define Grid: 30px rulers, remaining space for stage */
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr);
    grid-template-rows: 30px minmax(0, 1fr);
    overflow: hidden; /* Container fixed, inner divs scroll */
}

/* The top-left empty corner */
.ruler_corner {
    grid-column: 1;
    grid-row: 1;
    background-color: var(--ruler_bg);
    border-right: 1px solid var(--ruler_line);
    border-bottom: 1px solid var(--ruler_line);
    z-index: 10;
}

/* Top Ruler (X-Axis) Container */
.ruler_x_wrapper {
    grid-column: 2;
    grid-row: 1;
    overflow: hidden; /* Hides scrollbar, synced via JS */
    background-color: var(--ruler_bg);
    border-bottom: 1px solid var(--ruler_line);
    position: relative;
}

/* Left Ruler (Y-Axis) Container */
.ruler_y_wrapper {
    grid-column: 1;
    grid-row: 2;
    overflow: hidden; /* Hides scrollbar, synced via JS */
    background-color: var(--ruler_bg);
    border-right: 1px solid var(--ruler_line);
    position: relative;
}

/* The actual scrolling area for the canvas */
.stage_scroll_area {
    grid-column: 2;
    grid-row: 2;
    overflow: auto;
    padding: 40px;
    background-color: var(--base);
    position: relative;
    min-width: 0;
    min-height: 0;
}

/* The Visual Canvas */
.canvas_visual {
    background-color: var(--bg); /* Adapts to theme base */
    box-shadow:  0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 0 9px 2px var(--canvas_glow);
    /* Flat borders look better with rulers */
    border-radius: 0;
    position: relative;
    transform-origin: 0 0;
    /* Dynamic Checkerboard */
    background-image:
        linear-gradient(45deg, var(--check_1) 25%, var(--check_2) 25%),
        linear-gradient(-45deg, var(--check_1) 25%, var(--check_2) 25%),
        linear-gradient(45deg, var(--check_2) 75%, var(--check_1) 75%),
        linear-gradient(-45deg, var(--check_2) 75%, var(--check_1) 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

/* Canvas elements inside the ruler wrappers */
canvas.ruler_canvas {
    display: block;
}

/* Zoom Controls in Toolbar */
.zoom_controls {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--base);
    border-radius: 4px;
    padding: 2px;
    border: 1px solid var(--line);
}

.zoom_controls .value_display { min-width: 45px; text-align: center; font-size: 0.8rem; font-weight: 600; }
/*
#btn_zoom_out, #btn_zoom_in {

} */

.btn_icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 4px;
    color: var(--text);
    transition: background-color 0.2s ease, color 0.2s ease;
}

.btn_icon:hover {
    background-color: var(--hover);
    color: var(--accent);
}

.btn_icon svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2;
    fill: transparent;
}

.tool_separator {
    width: 1px;
    height: 24px;
    background-color: var(--line);
    margin: 0 8px;
}

.canvas_empty_msg {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--middle_grey);
    pointer-events: none;
}

.canvas_empty_msg .msg_title { font-size: 1.125rem; margin-bottom: 8px; color: var(--text); }
.canvas_empty_msg .msg_sub { font-size: 0.875rem; }

/* Actual Ruler Canvases */
canvas.ruler_canvas { display: block; }


/* Object Properties (canvas_object_properties.tpl) */
.properties-panel {
    background: var(--bg);
    border-left: 1px solid var(--line);
    width: 280px;
    height: 100%;
    display: flex;
    flex-direction: column;
    color: var(--text);
    font-family: inherit;
}
.properties-header {
    padding: 15px;
    border-bottom: 1px solid var(--line);
    font-weight: 600;
    font-size: 1rem;
}
.properties-body {
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    flex: 1;
    overflow-y: auto;
}
.prop-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.prop-row {
    display: flex;
    gap: 10px;
}
.prop-row .prop-group {
    flex: 1;
}
.properties-panel label {
    font-size: 0.75rem;
    color: var(--middle_grey);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.properties-panel input {
    background: var(--base);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    width: 100%;
    outline: none;
}
.properties-panel input:focus {
    border-color: var(--accent);
}
.properties-panel input[readonly] {
    background: transparent;
    border: none;
    padding: 0;
    font-weight: 500;
    color: var(--middle_grey);
}
.prop-separator {
    border: 0;
    height: 1px;
    background: var(--line);
    margin: 5px 0;
}
.dpi-badge-large {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 0.85rem;
    text-align: center;
}

/* --- Bounding Box & Resize Handles --- */
.bounding-box {
    position: absolute;
    cursor: move;
    z-index: 20;
    pointer-events: auto; /* Required to catch direct drag events */
}

/* Draws a perfectly centered 2px border straddling the bounding box edge */
.bounding-box::before {
    content: '';
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    bottom: -1px;
    border: 2px solid var(--accent);
    pointer-events: none; /* Let clicks pass through to the image/box */
    box-sizing: border-box;
}

.resize-handle {
    position: absolute;
    width: 36px;
    height: 36px;
    background: rgba(0, 0, 0, 0.01); /* Invisible solid paint prevents hit-test pass-through */
    pointer-events: auto;

    /* CRITICAL FIX: Use transform instead of margins to beat global CSS resets */
    transform: translate(-50%, -50%);

    z-index: 21;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* The visual dot */
.resize-handle::after {
    content: '';
    display: block;
    width: 12px;
    height: 12px;
    background: var(--bg);
    border: 2px solid var(--accent);
    border-radius: 50%;
    box-sizing: border-box;
}

/* Handle cursor mapping */
.resize-handle.nw { cursor: nwse-resize; }
.resize-handle.n  { cursor: ns-resize; }
.resize-handle.ne { cursor: nesw-resize; }
.resize-handle.e  { cursor: ew-resize; }
.resize-handle.se { cursor: nwse-resize; }
.resize-handle.s  { cursor: ns-resize; }
.resize-handle.sw { cursor: nesw-resize; }
.resize-handle.w  { cursor: ew-resize; }

/* Rotation handle updated to match */
.rot_handle {
    position: absolute;
    width: 36px;
    height: 36px;
    background: rgba(0, 0, 0, 0.01);
    pointer-events: auto;
    left: 50%;
    top: -36px;

    /* Center horizontally via transform */
    transform: translate(-50%, 0);

    cursor: grab;
    z-index: 22;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rot_handle:active {
    cursor: grabbing;
}

/* We keep the "stick" connecting the box to the handle */
.rot_handle::before {
    content: '';
    position: absolute;
    width: 2px;
    height: 18px;
    background: var(--accent);
    top: 18px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1;
}

/* Hide the old CSS circle */
.rot_handle::after {
    display: none;
}

/* Style the new SVG Icon */
.rot_handle .rot_icon_svg {
    width: 20px;
    height: 20px;
    fill: var(--accent);
    position: relative;
    z-index: 2;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4)); /* Gives the icon a nice premium pop */
    transition: transform 0.1s ease;
}

/* Optional: Slight scaling effect when grabbed */
.rot_handle:active .rot_icon_svg {
    transform: scale(1.1);
}

/* Expand the clickable hit-area of all handles invisibly */
.resize-handle::before {
    content: '';
    position: absolute;
    top: -16px;
    left: -16px;
    right: -16px;
    bottom: -16px;
    background: rgba(0, 0, 0, 0.01);
    border-radius: 50%;
    z-index: 1;
}

/* --- Properties Panel Action Buttons --- */
.prop-actions-row {
    display: flex;
    gap: 8px;
    margin-top: 5px;
}

.properties-panel button.btn-prop-action {
    flex: 1;
    height: 36px;
    border: 1px solid var(--border-color, #2d3039);
    border-radius: 4px;
    background: transparent; /* Overrides the global white background */
    color: var(--text-primary, #ffffff);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0; /* Clears global button padding */
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

/* Force the SVG to center and scale correctly */
.properties-panel button.btn-prop-action svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

.properties-panel button.btn-prop-action:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.properties-panel button.btn-prop-action.delete-action {
    border-color: rgba(231, 76, 60, 0.3);
    background-color: rgba(231, 76, 60, 0.1);
    color: #e74c3c;
}

.properties-panel button.btn-prop-action.delete-action:hover {
    background-color: rgba(231, 76, 60, 0.2);
    border-color: rgba(231, 76, 60, 0.5);
}

/* --- Canvas Context Menu --- */
.canvas-context-menu {
    position: fixed;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    min-width: 180px;
    padding: 6px 0;
    z-index: 99999;
    font-family: inherit;
    font-size: 0.85rem;
    color: var(--text);
}

.ctx-menu-item {
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.15s;
}

.ctx-menu-item:hover {
    background-color: var(--accent);
    color: #fff;
}

.ctx-menu-item.danger:hover {
    background-color: #e74c3c;
}

.ctx-shortcut {
    color: var(--middle_grey);
    font-size: 0.75rem;
}

.ctx-menu-item:hover .ctx-shortcut {
    color: rgba(255, 255, 255, 0.8);
}

.ctx-divider {
    height: 1px;
    background-color: var(--line);
    margin: 4px 0;
}

/* --- Multi-Sheet Panel --- */
.sheets-panel {
    background: var(--bg);
    border-left: 1px solid var(--line);
    width: 280px;
    height: 100%;
    display: flex;
    flex-direction: column;
    color: var(--text);
    font-family: inherit;
}

.sheets-header {
    padding: 15px;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sheets-body {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Custom Scrollbar for Sheets Body */
.sheets-body::-webkit-scrollbar { width: 6px; }
.sheets-body::-webkit-scrollbar-track { background: transparent; }
.sheets-body::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

/* Sheet Thumbnail Card */
.sheet-thumb-card {
    background: var(--base);
    border: 2px solid var(--line);
    border-radius: 6px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.sheet-thumb-card:hover {
    border-color: var(--middle_grey);
}

.sheet-thumb-card.active {
    border-color: var(--accent);
    background: var(--info_bg);
}

.sheet-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 0.9rem;
}

.sheet-meta {
    font-size: 0.75rem;
    color: var(--middle_grey);
}

.sheet-price {
    font-size: 0.85rem;
    color: #34CB79;
    font-weight: bold;
    margin-top: 4px;
}

/* User Avatar Initials */
.user_initials_avatar {
    width: 36px;
    height: 36px;
    background-color: var(--accent);
    color: #ffffff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.2s ease;
}

.drop_trigger:hover .user_initials_avatar {
    transform: scale(1.05);
}

.gang_sheet_app .drop_panel_cont .drop_trigger {
    border: 0;
    background-color: transparent;
}

/* --- Unified Header Actions Alignment --- */
.builder_mode #btn_gs_add_cart {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 84px;
    height: 52px;
    min-width: 0;
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
    background-color: transparent;
    box-shadow: none;
    cursor: pointer;
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    line-height: 12px;
    transition: opacity 0.2s ease;
}

.builder_mode #btn_gs_add_cart:hover,
.builder_mode #btn_gs_add_cart:active {
    background: transparent;
    background-color: transparent;
    border: none;
    box-shadow: none;
    opacity: 0.7;
}

/* Vector path optimization inside header action matrices */
.builder_mode #btn_gs_add_cart svg {
    stroke: currentColor;
    fill: none;
    width: 35px;
    height: 35px;
    display: block;
}

/* Figma-style Dashed Upload Button */
.builder_mode #btn_gs_upload {
    background-color: transparent;
    color: var(--middle_grey);
    border: 2px dashed var(--line);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 10px;
    transition: all 0.2s ease;
    box-shadow: none;
    width: 100%;
    box-sizing: border-box;
    height: 110px;
    margin: 0;
}

.builder_mode #btn_gs_upload:hover {
    background-color: rgba(0,0,0,0.02);
    border-color: var(--middle_grey);
}

html[data-theme="dark"] .builder_mode #btn_gs_upload:hover {
    background-color: rgba(255,255,255,0.02);
}

/* Correctly targets filled icons like #add_icon */
.builder_mode #btn_gs_upload svg {
    fill: currentColor;
    stroke: none;
    width: 24px;
    height: 24px;
    margin-bottom: 4px;
}

.builder_mode #btn_gs_upload span {
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.2;
    text-align: center;
}

/* Canvas Name title input */
.gs_title_input {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text, #ffffff);
    font-size: 1.1rem;
    font-weight: 600;
    padding: 4px 8px;
    outline: none;
    width: 250px;
    transition: all 0.2s ease;
}
.gs_title_input:hover, .gs_title_input:focus {
    border-color: var(--line, #333);
    background: rgba(255,255,255,0.05);
}
/* The "little bit grayed out" effect */
.gs_title_input.is_untitled {
    color: var(--text-muted, #888888);
    font-style: italic;
}


/* --- Saved Designs Gallery --- */
.design_row {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 4px;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.design_row:hover {
    background-color: rgba(255, 255, 255, 0.03); /* Subtle highlight */
    border-color: var(--middle_grey);
}

html[data-theme="light"] .design_row:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

.design_thumbnail {
    width: 80px;
    height: 80px;
    background: rgba(0, 0, 0, 0.03);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 4px;
    flex-shrink: 0;
}

html[data-theme="dark"] .design_thumbnail {
    background: rgba(255, 255, 255, 0.03);
}

.design_thumbnail img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.design_thumbnail .empty_thumb {
    font-size: 10px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.design_thumbnail .empty_thumb .merch_icon {
    width: 40px;
    height: 40px;
    opacity: 0.5;
}

.design_details {
    display: flex;
    flex-direction: column;
    flex: 1; /* Pushes the delete button to the right */
}

.design_name {
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 1rem;
    color: var(--text);
}

.design_size {
    font-size: 0.85rem;
}

.btn_delete_design {
    margin-left: auto;
    background: transparent;
    border: none;
    padding: 12px;
    cursor: pointer;
    color: var(--accent_red, #dc3545);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.btn_delete_design:hover {
    background-color: rgba(220, 53, 69, 0.1);
}

.btn_delete_design .merch_icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.no_designs_msg {
    padding: 15px;
    text-align: center;
    font-size: 0.9rem;
}


/* --- Smart Alignment Guides - START --- */
.smart-guide {
    position: absolute;
    background-color: #ff00ff; /* High-visibility magenta */
    pointer-events: none; /* Never interfere with the mouse */
    z-index: 9999;
    opacity: 0.7;
    /* Optional: Make it dashed */
    /* background-image: linear-gradient(to bottom, transparent 50%, #ff00ff 50%); background-size: 1px 4px; background-color: transparent; */
}

.smart-guide.vertical {
    width: 1px;
    top: 0;
    bottom: 0;
}

.smart-guide.horizontal {
    height: 1px;
    left: 0;
    right: 0;
}


/* --- Smart Alignment Guides - END --- */

/* Auto-Save Indicator - Start */
.gs_save_status {
    opacity: 0;
    font-size: 0.85rem;
    color: var(--text-muted, #888);
    margin-right: 12px;
    display: flex;
    align-items: center;
    transition: opacity 0.3s ease;
}

.gs_save_status.is_active {
    opacity: 1;
}

.gs_save_status.is_saving {
    animation: pulse_opacity 1.5s infinite;
}

/* Hide the mobile vertical slider when on desktop */
    .mobile-zoom-container {
        display: none;
    }

@keyframes pulse_opacity {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

/* Auto-Save Indicator - End */

/* --- Mobile Responsiveness --- */
@media (min-width: 769px) {
    .mobile_menu_toggle {
        display: none;
    }

    /* Dissolve the mobile wrapper on desktop so items become direct flex children */
    .mobile_secondary_tools {
        display: contents;
    }

    /* --- Desktop Toolbar Explicit Reordering --- */
    /* 1. Base Dimensions Configuration */
    .app_toolbar .tool_group:has(#gs_width) { order: 1; }
    .app_toolbar .tool_group:has(#gs_height) { order: 2; }
    .app_toolbar .tool_group:has(#gs_margin) { order: 3; }
    .app_toolbar .tool_group:has(#gs_unit) { order: 4; }

    /* 2. Map First Separator */
    .app_toolbar > .tool_separator { order: 5; }

    /* 3. Target History Group */
    .app_toolbar .tool_group:has(#btn_gs_undo) { order: 6; }

    /* 4. Map Second Separator */
    .app_toolbar > .tool_separator ~ .tool_separator { order: 7; }

    /* 5. Zoom Controls */
    .app_toolbar .tool_group:has(#btn_zoom_in) { order: 8; }

    /* 6. Map Third Separator */
    .app_toolbar > .tool_separator ~ .tool_separator ~ .tool_separator { order: 9; }

    /* 7. Global Canvas Actions */
    .app_toolbar .tool_group:has(#btn_canvas_nest) { order: 10; }
}

@media (max-width: 768px) {
    /* Prevents the rubber-band bounce effect and pull-to-refresh on mobile */
    body {
        overscroll-behavior-y: none;
        margin: 0;
        padding: 0;
        overflow: hidden;
    }

    .gang_sheet_app {
        --drawer_width: 280px;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100dvh; /* Dynamic Viewport Height fixes mobile browser address bar clipping */
        margin: 0;
        padding: 0;
        z-index: 9999;
    }

    .app_header {
        padding: 0 12px;
    }

    .builder_logo_link {
        margin-right: 0.5rem;
        padding-right: 0.5rem;
    }

    .gs_title_input {
        width: 130px;
        font-size: 1rem;
    }

    /* 1. Header Button Optimization: Compact Add to Cart */
    /* Reduced footprint ensures optimal avatar and login button visibility */
    .builder_mode #btn_gs_add_cart {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 0;
        margin: 0;
        width: auto;
        height: auto;
        min-width: 0;
        background: transparent;
        background-color: transparent;
        border: none;
        box-shadow: none;
        cursor: pointer;
        color: var(--text);
        font-family: inherit;
        text-align: center;
    }

    #btn_gs_add_cart span {
        display: block;
        margin-top: 5px;
        padding: 0;
        white-space: nowrap;
        font-size: 11px;
        font-weight: 800;
        line-height: 12px;
        color: var(--text);
    }

    /* Isolate and map style properties onto the raw vector node */
    .builder_mode #btn_gs_add_cart svg {
        fill: none;
        stroke: currentColor;
        width: 30px;
        height: 30px;
        display: block;
        margin: 0 auto;
    }

    /* Provide subtle feedback when tapped on mobile frames */
    #btn_gs_add_cart:active svg {
        transform: scale(0.9);
        transition: transform 0.1s ease;
    }

    .builder_mode #btn_gs_add_cart:hover,
    .builder_mode #btn_gs_add_cart:active {
        background: transparent;
        background-color: transparent;
        border: none;
        box-shadow: none;
    }

    /* Relocate save indicator directly above the active assembly stage */
    .gs_save_status {
        position: absolute;
        top: 12px;
        left: 50%;
        transform: translateX(-50%);
        margin-right: 0;
        z-index: 1010;
        background-color: var(--bg);
        border: 1px solid var(--line);
        padding: 4px 12px;
        border-radius: 20px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }

    /* Wrap the toolbar tools */
    .app_toolbar {
        height: 56px;
        min-height: 56px;
        flex-wrap: nowrap;
        padding: 0 12px;
        gap: 8px;
        position: relative;
        justify-content: flex-start;
    }

    .tool_separator { display: none; }

    /* 2. The Mobile Menu Icon */
    /* Margin adjusted to pull core tools closer to the toggle button */
    .mobile_menu_toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        background: transparent;
        border: transparent;
        color: var(--text);
        cursor: pointer;
        margin-right: 8px;
    }

    .mobile_menu_toggle svg {
        width: 30px;
        height: 30px;
        fill: currentColor;
    }

    /* 3. Off-Canvas Secondary Tools (History, Zoom, Nest, Clear) */
    .mobile_secondary_tools {
        box-sizing: border-box;
        position: absolute;
        top: 100%;
        left: 0;
        width: var(--drawer_width);
        background: var(--base);
        z-index: 1002;
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: flex-start;
        padding: 16px;
        gap: 16px;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        border-right: 1px solid var(--line);
        border-bottom: 1px solid var(--line);
    }

    .mobile_secondary_tools .tool_group:has(input),
    .mobile_secondary_tools .tool_group:has(select) {
        width: calc(50% - 8px);
        flex-direction: row;
        align-items: center;
        gap: 6px;
    }

    .mobile_secondary_tools .tool_group input,
    .mobile_secondary_tools .select_wrapper.small select {
        width: 100%;
        flex: 1;
        box-sizing: border-box;
    }

    /* Hide the traditional zoom tools completely inside the mobile drawer */
    .mobile_secondary_tools .tool_group:has(#btn_zoom_in) {
        display: none;
    }

    /* Allow the canvas actions (Nest/Clear) to sit properly without the zoom group */
    .mobile_secondary_tools .tool_group:has(#btn_canvas_nest) {
        width: 100%;
        justify-content: flex-start;
    }

    /* --- The High-Fidelity PI Tape Measure Floating Slider Container --- */
    .mobile-zoom-container {
        position: fixed;
        right: 10px;
        top: 50%;
        transform: translateY(-50%);
        z-index: 9990;
        width: 44px;
        height: 280px; /* Taller track for granular zoom control */
        background-color: transparent;
        box-shadow: -4px 0 15px rgba(0, 0, 0, 0.5), inset 0 0 10px rgba(0, 0, 0, 0.8);

        /* High-Fidelity Tick Marks mapping the image aesthetic */
        background-image:
            repeating-linear-gradient(to bottom, #777777 0px, #777777 1px, transparent 1px, transparent 5px), /* Dense minor grey ticks */
            repeating-linear-gradient(to bottom, #ffffff 0px, #ffffff 2px, transparent 2px, transparent 25px); /* Solid major white ticks */
        background-position: left center, left center;
        background-size: 10px 100%, 18px 100%;
        background-repeat: no-repeat;

        display: flex;
        justify-content: center;
        align-items: center;
    }

    /* Rotate a horizontal slider to bypass aggressive mobile OS styling overrides */
    .vertical-tape-slider {
        -webkit-appearance: none;
        appearance: none;
        width: 276px;
        height: 40px;
        background: transparent;
        margin: 0;
        padding: 0;
        transform: rotate(-90deg);
        cursor: pointer;
        outline: none;
    }

    /* Suppress the default visual track grooves */
    .vertical-tape-slider::-webkit-slider-runnable-track {
        background: transparent;
        border: none;
        height: 100%;
        width: 100%;
    }
    .vertical-tape-slider::-moz-range-track {
        background: transparent;
        border: none;
        height: 100%;
        width: 100%;
    }

    /* Create the Thick '-' Indicator (Thumb) */
    .vertical-tape-slider::-webkit-slider-thumb {
        -webkit-appearance: none;
        appearance: none;
        width: 8px;
        height: 32px;
        background-color: var(--accent);
        background-image: linear-gradient(to right, #fbd610, #d6b200);
        border: 1px solid #554400;
        border-radius: 2px;
        clip-path: none;
        transform: translateY(0px);
        cursor: pointer;
    }

    /* Firefox Support for the Thick '-' Indicator */
    .vertical-tape-slider::-moz-range-thumb {
        width: 8px;
        height: 32px;
        background-color: var(--accent);
        background-image: linear-gradient(to right, #fbd610, #d6b200);
        border: 1px solid #554400;
        border-radius: 2px;
        clip-path: none;
        transform: translateY(0px);
        cursor: pointer;
    }

    .app_toolbar #gs_price_display {
        margin-left: auto;
        margin-right: 8px;
        font-size: 1.1rem;
        display: flex;
        align-items: center;
    }

    .app_toolbar .tool_group:has(#btn_gs_undo) {
        margin-left: 0;
    }

    .app_toolbar .tool_group:has(#btn_gs_undo) label {
        display: none;
    }

    /* Strip the background and border from the shared controls wrapper */
    .app_toolbar .tool_group:has(#btn_gs_undo) .zoom_controls {
        background: transparent;
        border: none;
        padding: 0;
        gap: 6px;
    }

    /* Force the individual buttons to exactly 36x36px and ensure borders are gone */
    .app_toolbar #btn_gs_undo,
    .app_toolbar #btn_gs_redo {
        width: 36px;
        height: 36px;
        background: transparent;
        border: none;
        padding: 0;
    }

    /* Scale the SVGs proportionally inside the 36px touch target */
    .app_toolbar #btn_gs_undo svg,
    .app_toolbar #btn_gs_redo svg {
        width: 30px;
        height: 30px;
    }

    /* Trigger sliding drawer via body class */
    body.mobile_drawer_open .mobile_secondary_tools {
        transform: translateX(0);
        box-shadow: 4px 4px 15px rgba(0,0,0,0.3);
    }

    /* 4. Workspace & Sidebar (Bottom Tray Optimization) */
    .app_workspace {
        position: relative;
        flex-direction: column;
    }

    /* Break out of grid flow on mobile viewports to maximize canvas space */
    .app_stage {
        width: 100%;
        order: 1;
        flex: 1;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    /* Purge standard desktop rulers to claim maximum viewport area */
    .ruler_corner,
    .ruler_x_wrapper,
    .ruler_y_wrapper {
        display: none;
    }

    /* Let our canvas scroll area dominate the main interface section */
    .stage_scroll_area {
        width: 100%;
        flex: 1;
        min-height: 0;
        padding: 0;
        display: flex;
        flex-direction: column;
        box-sizing: border-box;
        overflow: auto;
    }

    /* Forces the inner canvas wrapper to fill the scroll area across device viewports */
    /* MERCH_GSMOB1: the sheet keeps the size the builder gives it. It sits in
       the middle when it fits (auto margins) and starts at the top left when
       zoomed past the stage, so every edge can be scrolled to. */
    .canvas_wrapper {
        margin: 0;
        display: flex;
        justify-content: flex-start;
        align-items: flex-start;
        flex: 1 0 auto;
        width: 100%;
        min-width: 100%;
        min-height: 100%;
        box-sizing: border-box;
    }

    .canvas_visual {
        margin: auto;
        min-width: 0;
        min-height: 0;
        flex-shrink: 0;
        box-sizing: border-box;
    }

    /* Clamps parent tray bounds tightly to satisfy row layout constraints */
    .app_sidebar {
        order: 2;
        width: 100%;
        height: 100px;
        flex-direction: row;
        border-right: none;
        border-top: 1px solid var(--line);
        position: relative;
        transform: none;
        z-index: 10;
        box-sizing: border-box;
    }

    .sidebar_header {
        box-sizing: border-box;
        width: 100px;
        border-bottom: none;
        border-right: 1px solid var(--line);
        padding: 6px;
        display: flex;
        align-items: stretch;
        justify-content: center;
        flex-shrink: 0;
    }

    .sidebar_header .merch_button {
        height: 45px;
        flex-direction: column;
        gap: 4px;
        padding: 6px 2px;
    }

    .sidebar_header #btn_gs_upload {
        box-sizing: border-box;
        height: 100%;
        width: 100%;
        margin: 0;
        min-width: 0;
        flex-direction: column;
        gap: 2px;
        padding: 6px;
        justify-content: center;
        align-items: center;
    }

    .sidebar_header #btn_gs_upload span {
        font-size: 0.65rem;
        line-height: 1.1;
        white-space: normal;
        text-align: center;
    }

    .sidebar_header #btn_gs_upload svg {
        width: 20px;
        height: 20px;
        margin-bottom: 0;
    }

    .sidebar_header .merch_button span {
        font-size: 0.65rem;
        line-height: 1.1;
        white-space: normal;
        text-align: center;
    }

    /* Fills remainder width completely and provisions native horizontal panning */
    .sidebar_content {
        flex: 1;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 8px 10px;
        align-items: stretch;
        gap: 10px;
        width: auto;
        box-sizing: border-box;
    }

    .sidebar_content .empty_state {
        height: 100%;
    }

    /* Harmonizes empty state bounds to match the upload button height and alignment */
    html .gang_sheet_app .app_sidebar .sidebar_content > .empty_state {
        box-sizing: border-box;
        height: 100%;
        margin: 0;
        padding: 0 16px;
        flex: 1;
        width: auto;
    }

    /* Scale down item tiles horizontally to prevent horizontal tray clipping */
    .gang_sheet_app .app_sidebar .upload_thumb {
        width: 280px;
        height: auto;
        min-height: 80px;
        flex-shrink: 0;
        display: grid;
        grid-template-columns: 60px 1fr;
        grid-template-rows: auto auto;
        gap: 4px 8px;
        padding: 6px;
        box-sizing: border-box;
    }

    .gang_sheet_app .app_sidebar .upload_thumb img {
        grid-column: 1;
        grid-row: 1 / span 2;
        width: 100%;
        height: auto;
        max-height: 60px;
        object-fit: contain;
        align-self: center;
        margin: 0;
    }

    .gang_sheet_app .app_sidebar .upload_thumb .thumb_dims,
    .gang_sheet_app .app_sidebar .upload_thumb .thumb_controls {
        display: flex;
        grid-column: 2;
        margin: 0;
        padding: 0;
        border: none;
        gap: 6px;
        align-items: center;
        justify-content: flex-start;
    }

    .gang_sheet_app .app_sidebar .upload_thumb .thumb_dims {
        grid-row: 1;
        align-self: end;
    }

    .gang_sheet_app .app_sidebar .upload_thumb .thumb_controls {
        grid-row: 2;
        align-self: start;
    }

    .gang_sheet_app .app_sidebar .upload_thumb .thumb_dims > div {
        flex: 0 0 auto;
    }

    .gang_sheet_app .app_sidebar .upload_thumb input[type="number"] {
        width: 44px;
        padding: 2px 4px;
        font-size: 0.8rem;
        height: 24px;
        box-sizing: border-box;
        margin: 0;
        background: var(--base);
        color: var(--text);
        border: 1px solid var(--line);
        border-radius: 4px;
    }

    .gang_sheet_app .app_sidebar .upload_thumb .thumb_controls .btn_icon {
        width: 24px;
        height: 24px;
        padding: 4px;
        margin: 0;
    }

    /* Keep text-only metadata fields suppressed to retain compact tracking height */
    .gang_sheet_app .app_sidebar .upload_thumb .thumb_meta,
    .gang_sheet_app .app_sidebar .upload_thumb .thumb_dpi_badge,
    .gang_sheet_app .app_sidebar .upload_thumb .thumb_name {
        display: none;
    }

    /* Floating Action Sidebar Footer Layout */
    .sidebar_footer {
        position: absolute;
        bottom: 100%;
        right: 12px;
        margin-bottom: 8px;
        z-index: 11;
        width: auto;
    }

    /* Compact button layout overrides desktop constraints */
    .sidebar_footer #btn_gs_add_all {
        min-width: 0;
        width: auto;
        height: 32px;
        padding: 0 12px;
        margin: 0;
        font-size: 0.75rem;
        border-radius: 4px;
        background-color: var(--button_bg);
        color: var(--button_text);
        border: 1px solid var(--button_border);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }

    /* 5. Sheets & Properties Off-Canvas Base */
    .sheets-panel, .properties-panel {
        box-sizing: border-box;
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: var(--drawer_width);
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        border-right: 1px solid var(--line);
    }

    .sheets-header, .properties-header {
        flex-shrink: 0;
    }

    /* Open state for panels */
    body.mobile_drawer_open .sheets-panel.is_open,
    body.mobile_drawer_open .properties-panel.is_open {
        transform: translateX(0);
        box-shadow: 4px 0 15px rgba(0,0,0,0.3);
        padding-top: 190px;
    }
}

/* MERCH_GS_V1: width, height and margin read as plain values for
   customers (founders and admins get the normal boxes). */
.tool_group input[readonly] {
    border-color: transparent;
    background: transparent;
    color: var(--dark, inherit);
    font-weight: 600;
    padding-left: 0;
    padding-right: 0;
    width: 64px;
    pointer-events: none;
    -moz-appearance: textfield;
    appearance: textfield;
}

.tool_group input[readonly]::-webkit-outer-spin-button,
.tool_group input[readonly]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

@media (max-width: 768px) {
    .mobile_secondary_tools .tool_group input[readonly] {
        width: 100%;
    }
}

/* MERCH_DSC_CHECK: light transparency checkerboard (grey on white) so
   all-black designs stay visible. A fixed pattern by design, the same in
   both themes. Display only: exports and print files never read it. */
.gang_sheet_app {
    --check_light_1: #c8c8c8;
    --check_light_bg: #ffffff;
}

html[data-theme] .gang_sheet_app.check_light {
    --check_1: var(--check_light_1);
    --check_2: transparent;
}

html[data-theme] .gang_sheet_app.check_light .canvas_visual {
    background-color: var(--check_light_bg);
}

.gs_check_btn {
    border: 1px solid var(--line);
    margin-right: 8px;
}

.gs_check_btn[aria-pressed="true"] {
    border-color: var(--highlight);
}

/* The toggle shows the light pattern it switches to */
.gs_check_swatch {
    display: block;
    width: 16px;
    height: 16px;
    border-radius: 2px;
    background-color: var(--check_light_bg);
    background-image: conic-gradient(
        var(--check_light_1) 25%, transparent 0 50%,
        var(--check_light_1) 0 75%, transparent 0
    );
    background-size: 8px 8px;
}

@media (max-width: 768px) {
    /* A finger sized target inside the tool drawer */
    .mobile_secondary_tools .gs_check_btn {
        width: 36px;
        height: 36px;
    }
}

/* MERCH_SUP8: Save To Projects and Save to user */
.gs_project_form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.gs_project_form input[type="text"],
.gs_project_form input[type="search"] {
    width: 100%;
    box-sizing: border-box;
}
.gs_user_results {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 240px;
    overflow-y: auto;
}
.gs_user_result {
    text-align: left;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: transparent;
    color: inherit;
    cursor: pointer;
    overflow-wrap: anywhere;
}
.gs_user_result span {
    opacity: 0.75;
}
.gs_user_result.is_picked {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}
.gs_user_picked {
    margin: 0;
    font-size: 0.9em;
}

/* MERCH_NLI1: image cards show transparency on the light checkerboard
   (grey on white, as the canvas light toggle), in both themes, so a
   knocked-out or transparent image is obvious at a glance. Display only. */
.gang_sheet_app .upload_thumb img {
    background-color: var(--check_light_bg, #ffffff);
    background-image:
        linear-gradient(45deg, var(--check_light_1, #c8c8c8) 25%, transparent 25%),
        linear-gradient(-45deg, var(--check_light_1, #c8c8c8) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--check_light_1, #c8c8c8) 75%),
        linear-gradient(-45deg, transparent 75%, var(--check_light_1, #c8c8c8) 75%);
    background-size: 12px 12px;
    background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
}
/* MERCH_NLI6: image cards, sidebar buttons and loading pictures, as in the
   approved mockup. Theme colours only (--bg, --text, --line, --hover,
   --accent); --gs_on_accent is set by canvas.js. */
.gang_sheet_app .upload_thumb {
    border-radius: 12px;
    padding: 10px;
    background: var(--bg);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}
.gang_sheet_app .upload_thumb .thumb_pic {
    position: relative;
}
.gang_sheet_app .upload_thumb .thumb_pic img {
    display: block;
    border-radius: 8px;
}
.gang_sheet_app .upload_thumb .thumb_ko_chip {
    position: absolute;
    left: 8px;
    bottom: 8px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px 3px 7px;
    border-radius: 999px;
    background: var(--accent);
    color: var(--gs_on_accent, #ffffff);
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1.2;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    pointer-events: auto;
}
.gang_sheet_app .upload_thumb .thumb_ko_chip .merch_icon {
    width: 13px;
    height: 13px;
    fill: currentColor;
}
.gang_sheet_app .upload_thumb .thumb_meta {
    margin-top: 10px;
    padding: 0;
}
.gang_sheet_app .upload_thumb .thumb_dpi_badge {
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.7rem;
}
.gang_sheet_app .upload_thumb .thumb_unit {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--text);
    opacity: 0.6;
}
.gang_sheet_app .upload_thumb .thumb_name {
    margin: 6px 0 0;
    font-size: 0.85rem;
    font-weight: 600;
}
.gang_sheet_app .upload_thumb .thumb_dims {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
}
.gang_sheet_app .upload_thumb .thumb_dim_group {
    display: flex;
    align-items: center;
    gap: 0;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    cursor: text;
    min-width: 0;
}
.gang_sheet_app .upload_thumb .thumb_dim_group:focus-within,
.gang_sheet_app .upload_thumb .thumb_qty_step:focus-within {
    border-color: var(--accent);
}
.gang_sheet_app .upload_thumb .thumb_label {
    flex: none;
    align-self: stretch;
    display: flex;
    align-items: center;
    padding: 0 8px;
    border-right: 1px solid var(--line);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text);
    opacity: 0.6;
}
.gang_sheet_app .upload_thumb .thumb_dim_w,
.gang_sheet_app .upload_thumb .thumb_dim_h,
.gang_sheet_app .upload_thumb .thumb_qty {
    width: 100%;
    min-width: 0;
    height: 100%;
    padding: 0 8px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text);
    font-size: 0.85rem;
    outline: none;
    box-shadow: none;
    -moz-appearance: textfield;
    appearance: textfield;
}
.gang_sheet_app .upload_thumb input[type="number"]::-webkit-inner-spin-button,
.gang_sheet_app .upload_thumb input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.gang_sheet_app .upload_thumb .thumb_controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}
.gang_sheet_app .upload_thumb .thumb_qty_step {
    display: flex;
    align-items: center;
    flex: none;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}
.gang_sheet_app .upload_thumb .thumb_qty_step .thumb_qty {
    width: 34px;
    padding: 0;
    text-align: center;
    font-weight: 600;
}
.gang_sheet_app .upload_thumb .btn_qty_step {
    width: 24px;
    height: 100%;
    padding: 0;
    margin: 0;
    border: 0;
    background: transparent;
    color: var(--text);
    opacity: 0.7;
    font: inherit;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
}
.gang_sheet_app .upload_thumb .btn_qty_step:hover {
    background: var(--hover);
    opacity: 1;
}
.gang_sheet_app .upload_thumb .thumb_actions {
    display: flex;
    margin-left: auto;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}
.gang_sheet_app .upload_thumb .thumb_actions .btn_icon.small {
    position: relative;
    width: 32px;
    height: 100%;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text);
}
.gang_sheet_app .upload_thumb .thumb_actions .btn_icon.small + .btn_icon.small {
    border-left: 1px solid var(--line);
}
.gang_sheet_app .upload_thumb .thumb_actions .btn_icon.small svg {
    width: 17px;
    height: 17px;
    fill: currentColor;
}
.gang_sheet_app .upload_thumb .thumb_actions .btn_icon.small:hover {
    background: var(--hover);
    color: var(--text);
}
.gang_sheet_app .upload_thumb .thumb_actions .btn_knockout.is_on {
    background: color-mix(in srgb, var(--accent) 22%, transparent);
    color: var(--accent);
}
.gang_sheet_app .upload_thumb .thumb_actions .btn_delete_upload {
    color: var(--text);
}
.gang_sheet_app .upload_thumb .thumb_actions .btn_delete_upload:hover {
    color: var(--accent_red, #e5484d);
}
.gang_sheet_app .upload_thumb .thumb_actions .btn_icon.small:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* Sidebar buttons: Knockout all and Auto Add All in one row */
.gang_sheet_app .sidebar_footer {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
    box-sizing: border-box;
}
.gang_sheet_app .sidebar_footer:not(:has(button:not([style*="display: none"]))) {
    display: none;
}
.gang_sheet_app .sidebar_footer #btn_gs_add_all,
.gang_sheet_app .sidebar_footer #btn_gs_ko_all {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    height: 40px;
    margin: 0;
    padding: 0 10px;
    display: inline-flex !important; /* canvas.js shows it with display: block */
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 9px;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: none;
}
.gang_sheet_app .sidebar_footer #btn_gs_add_all[style*="display: none"],
.gang_sheet_app .sidebar_footer #btn_gs_ko_all[style*="display: none"] {
    display: none !important;
}
.gang_sheet_app .sidebar_footer #btn_gs_add_all {
    background: var(--accent);
    color: var(--gs_on_accent, #ffffff);
    border: 1px solid var(--accent);
}
.gang_sheet_app .sidebar_footer #btn_gs_add_all:hover {
    filter: brightness(1.08);
}
.gang_sheet_app .sidebar_footer #btn_gs_ko_all {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--line);
}
.gang_sheet_app .sidebar_footer #btn_gs_ko_all:hover {
    background: var(--hover);
}
.gang_sheet_app .sidebar_footer .merch_icon {
    width: 17px;
    height: 17px;
    fill: currentColor;
    flex: none;
}

/* A placed picture that is still loading: a spinner in its own spot */
.gang_sheet_app .stage_item.is_loading {
    background-color: rgba(0, 0, 0, 0.28);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Ccircle cx='20' cy='20' r='16' fill='none' stroke='%23ffffff' stroke-opacity='0.25' stroke-width='4'/%3E%3Cpath d='M20 4a16 16 0 0 1 16 16' fill='none' stroke='%23ffffff' stroke-width='4' stroke-linecap='round'%3E%3CanimateTransform attributeName='transform' type='rotate' from='0 20 20' to='360 20 20' dur='0.9s' repeatCount='indefinite'/%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: min(34px, 40%) auto;
    outline: 1px dashed rgba(255, 255, 255, 0.35);
    outline-offset: -1px;
}

@media (max-width: 768px) {
    .gang_sheet_app .app_sidebar .upload_thumb {
        padding: 6px;
        border-radius: 10px;
    }
    .gang_sheet_app .app_sidebar .upload_thumb .thumb_pic {
        grid-column: 1;
        grid-row: 1 / span 2;
        align-self: center;
    }
    .gang_sheet_app .app_sidebar .upload_thumb .thumb_pic img {
        width: 100%;
        max-height: 60px;
        border-radius: 6px;
    }
    .gang_sheet_app .app_sidebar .upload_thumb .thumb_ko_chip {
        left: 2px;
        bottom: 2px;
        padding: 2px;
        gap: 0;
    }
    .gang_sheet_app .app_sidebar .upload_thumb .thumb_ko_chip span {
        display: none;
    }
    .gang_sheet_app .app_sidebar .upload_thumb .thumb_dims {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    .gang_sheet_app .app_sidebar .upload_thumb .thumb_dim_group,
    .gang_sheet_app .app_sidebar .upload_thumb .thumb_qty_step,
    .gang_sheet_app .app_sidebar .upload_thumb .thumb_actions {
        height: 28px;
        border-radius: 7px;
    }
    .gang_sheet_app .app_sidebar .upload_thumb .thumb_label {
        padding: 0 6px;
    }
    .gang_sheet_app .app_sidebar .upload_thumb input[type="number"] {
        width: 100%;
        height: 100%;
        padding: 0 6px;
        border: 0;
        border-radius: 0;
        background: transparent;
    }
    .gang_sheet_app .app_sidebar .upload_thumb .thumb_qty_step .thumb_qty {
        width: 30px;
        padding: 0;
    }
    .gang_sheet_app .app_sidebar .upload_thumb .btn_qty_step {
        width: 22px;
    }
    .gang_sheet_app .app_sidebar .upload_thumb .thumb_controls .thumb_actions .btn_icon {
        width: 26px;
        height: 100%;
        padding: 0;
    }
    .gang_sheet_app .app_sidebar .upload_thumb .thumb_actions .btn_icon.small svg {
        width: 15px;
        height: 15px;
    }
    .gang_sheet_app .sidebar_footer {
        position: absolute;
        bottom: 100%;
        right: 12px;
        margin-bottom: 8px;
        padding: 0;
        border-top: 0;
        z-index: 11;
        width: auto;
        gap: 6px;
    }
    .gang_sheet_app .sidebar_footer #btn_gs_add_all,
    .gang_sheet_app .sidebar_footer #btn_gs_ko_all {
        flex: none;
        height: 32px;
        padding: 0 12px;
        font-size: 0.75rem;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }
    .gang_sheet_app .sidebar_footer #btn_gs_ko_all {
        background: var(--bg);
    }
    .gang_sheet_app .sidebar_footer .merch_icon {
        width: 15px;
        height: 15px;
    }
}
/* MERCH_GSMOB1: phones. The header fits the screen, and fingers drive the
   stage (canvas.js handles drag, pinch and pan; the page must not scroll). */
@media (max-width: 768px) {
    .app_header {
        gap: 8px;
    }

    .header_left {
        flex: 1 1 auto;
        min-width: 0;
        overflow: hidden;
    }

    .app_logo_holder {
        min-width: 0;
    }

    .builder_logo_link {
        min-width: 0;
        margin-right: 0;
        padding-right: 0;
        border-right: none;
    }

    .builder_logo_link svg,
    .builder_logo_link img {
        height: auto;
        max-height: 30px;
        max-width: 100%;
    }

    /* No room for the sheet name on a phone; it saves with its default name. */
    .app_title_holder {
        display: none;
    }

    .header_right {
        flex: 0 0 auto;
        gap: 8px;
    }

    .header_user_wrap {
        padding-left: 8px;
        margin-left: 0;
    }

    #btn_gs_save_project,
    #btn_gs_save_user {
        min-width: 0;
        max-width: 72px;
        height: auto;
        padding: 4px 6px;
        font-size: 0.7rem;
        line-height: 1.1;
        white-space: normal;
    }

    #btn_gs_save_project span,
    #btn_gs_save_user span {
        white-space: normal;
    }

    .stage_scroll_area {
        touch-action: none;
        overscroll-behavior: contain;
    }

    .gang_sheet_app .canvas_visual img.stage_item {
        -webkit-touch-callout: none;
        -webkit-user-drag: none;
    }

    .canvas-context-menu .ctx-menu-item {
        padding-top: 10px;
        padding-bottom: 10px;
    }
}

/* MERCH_GSMOB2: phones. The zoom slider gets its own strip at the right edge
   instead of lying over the sheet, so designs at the edge can be grabbed. */
@media (max-width: 768px) {
    .stage_scroll_area {
        width: calc(100% - 30px);
        margin-right: 30px;
    }

    .mobile-zoom-container {
        right: 0;
        width: 30px;
        background-size: 8px 100%, 14px 100%;
    }

    .vertical-tape-slider {
        height: 30px;
    }

    .vertical-tape-slider::-webkit-slider-thumb {
        height: 26px;
    }

    .vertical-tape-slider::-moz-range-thumb {
        height: 26px;
    }
}

/* MERCH_GSMOB2: touch screens. A small selected design keeps its middle for
   moving: no edge handles where they would meet, corners only. */
@media (pointer: coarse) {
    .bounding-box.gs_short .resize-handle.n,
    .bounding-box.gs_short .resize-handle.s,
    .bounding-box.gs_slim .resize-handle.e,
    .bounding-box.gs_slim .resize-handle.w {
        display: none;
    }

    .bounding-box.gs_tiny .resize-handle::before {
        display: none;
    }
}
