/* Source: tpl/core/client/css/canvas.css */
/*
    MerchStudio version 0.01 - Core File
    Gang Sheet Builder Styles
    @author      Hezekiah Dayson
    @version     tpl/core/client/css/canvas.css - 0.01 - 02-17-2026
*/

/* --- 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;
    overflow: hidden;
    display: flex;
    height: 100%;
}

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

.sidebar_header {
    padding: 16px;
    border-bottom: 1px solid var(--line);
}

.sidebar_content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.empty_state {
    text-align: center;
    color: var(--middle_grey);
    margin-top: 30px;
    font-size: 0.875rem;
}

/* 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.75rem;
    color: var(--text);
    margin-top: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- 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 1fr;
    grid-template-rows: 30px 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;
}

/* 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;

    /* CRITICAL FIX: 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;
}

.builder_mode #btn_gs_upload,
.builder_mode #btn_gs_add_cart {
    background-color: #ffffff !important;
    color: #000000 !important;
    border: 1px solid #cccccc !important;
}

.builder_mode #btn_gs_upload:hover,
.builder_mode #btn_gs_add_cart:hover {
    background-color: #f0f0f0 !important;
    border-color: #999999 !important;
}

/* Force the SVGs inside these specific buttons to be black */
.builder_mode #btn_gs_upload svg,
.builder_mode #btn_gs_add_cart svg {
    stroke: #000000 !important;
}

/* 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; /* Reduced from 25px so it doesn't break row heights */
    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;
}

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

/* Auto-Save Indicator - End */

