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

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

/* --- 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, #007bff);
    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.1), 0 0 9px 2px rgb(255 255 255);
    /* 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: 3px;
    color: var(--middle_grey) !important;
}

.btn_icon:hover { background-color: rgba(128,128,128,0.1); }
.btn_icon svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 2; }

.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-secondary, #1a1c23);
    border-left: 1px solid var(--border-color, #2d3039);
    width: 280px;
    height: 100%;
    display: flex;
    flex-direction: column;
    color: var(--text-primary, #ffffff);
    font-family: inherit;
}
.properties-header {
    padding: 15px;
    border-bottom: 1px solid var(--border-color, #2d3039);
    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(--text-muted, #888);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.properties-panel input {
    background: var(--bg-input, #0d0e12);
    border: 1px solid var(--border-color, #2d3039);
    color: #fff;
    padding: 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    width: 100%;
    outline: none;
}
.properties-panel input:focus {
    border-color: var(--accent, #007bff);
}
.properties-panel input[readonly] {
    background: transparent;
    border: none;
    padding: 0;
    font-weight: 500;
    color: #ccc;
}
.prop-separator {
    border: 0;
    height: 1px;
    background: var(--border-color, #2d3039);
    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;
    border: 2px solid var(--accent, #007bff);
    pointer-events: none; /* Let drag clicks pass through to the image */
    z-index: 20;
}

.resize-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #ffffff;
    border: 2px solid var(--accent, #007bff);
    border-radius: 50%;
    pointer-events: auto; /* Catch clicks specifically on the handles */
    transform: translate(-50%, -50%); /* Perfectly center them on the edges */
    z-index: 21;
}

/* Position and map the correct cursor for each handle */
.resize-handle.nw { left: 0; top: 0; cursor: nwse-resize; }
.resize-handle.n { left: 50%; top: 0; cursor: ns-resize; }
.resize-handle.ne { left: 100%; top: 0; cursor: nesw-resize; }
.resize-handle.e { left: 100%; top: 50%; cursor: ew-resize; }
.resize-handle.se { left: 100%; top: 100%; cursor: nwse-resize; }
.resize-handle.s { left: 50%; top: 100%; cursor: ns-resize; }
.resize-handle.sw { left: 0; top: 100%; cursor: nesw-resize; }
.resize-handle.w { left: 0; top: 50%; cursor: ew-resize; }


/* --- Properties Panel Action Buttons --- */
.prop-actions-row {
    display: flex;
    gap: 8px; /* Slightly tighter gap to ensure all 3 fit beautifully */
    margin-top: 5px;
}

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

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

.btn-prop-action:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
}

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

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

/* --- Canvas Context Menu --- */
.canvas-context-menu {
    position: fixed; /* Fixed to window coordinates for mouse tracking */
    background: var(--bg-secondary, #1a1c23);
    border: 1px solid var(--border-color, #2d3039);
    border-radius: 6px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
    min-width: 180px;
    padding: 6px 0;
    z-index: 99999;
    font-family: inherit;
    font-size: 0.85rem;
    color: var(--text-primary, #ffffff);
}

.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, #007bff);
    color: #fff;
}

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

.ctx-shortcut {
    color: var(--text-muted, #888);
    font-size: 0.75rem;
}

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

.ctx-divider {
    height: 1px;
    background-color: var(--border-color, #2d3039);
    margin: 4px 0;
}

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

.sheets-header {
    padding: 15px;
    border-bottom: 1px solid var(--border-color, #2d3039);
    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(--border-color, #2d3039); border-radius: 4px; }

/* Sheet Thumbnail Card */
.sheet-thumb-card {
    background: var(--bg-input, #0d0e12);
    border: 2px solid var(--border-color, #2d3039);
    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: rgba(255, 255, 255, 0.2);
}

.sheet-thumb-card.active {
    border-color: var(--accent, #007bff);
    background: rgba(0, 123, 255, 0.05);
}

.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(--text-muted, #888);
}

.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);
}

.drop_trigger {
    border: 0px !important;
    background-color: transparent !important;
}