/* ===================================================================
   ID Card Template Builder — 3-Column Designer Workspace
   =================================================================== */

.designer-workspace {
    display: flex;
    height: calc(100vh - var(--header-h) - 52px);
    overflow-x: auto;
    overflow-y: hidden;
    background: #eef2f7;
}

/* Common Sidebar Styles */
.designer-sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 10;
    transition: all .2s ease;
}

.designer-sidebar__head {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
}
.designer-sidebar__title {
    font-size: 14px;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}

.designer-sidebar__body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

/* Left Sidebar - Toolbox */
.designer-sidebar-left {
    width: 290px;
    flex-shrink: 0;
}

.toolbox-search {
    position: relative;
    margin-bottom: 16px;
}
.toolbox-search i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-3);
}
.toolbox-search input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 12.5px;
    background: var(--bg);
}

.toolbox-group-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--brand);
    margin: 14px 0 8px;
}
.toolbox-group-title:first-child { margin-top: 0; }

.toolbox-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: 10px;
    margin-bottom: 8px;
    cursor: grab;
    transition: .15s ease;
    user-select: none;
}
.toolbox-item:hover {
    border-color: var(--brand);
    background: var(--brand-soft);
    transform: translateX(2px);
}
.toolbox-ico {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--bg);
    color: var(--brand);
    display: grid;
    place-items: center;
    font-size: 15px;
    flex-shrink: 0;
}
.toolbox-item:hover .toolbox-ico {
    background: var(--brand);
    color: #fff;
}
.toolbox-label {
    font-weight: 600;
    font-size: 12.5px;
    color: var(--text);
    display: flex;
    flex-direction: column;
}
.toolbox-label small {
    font-size: 10.5px;
    font-weight: 500;
    color: var(--brand);
}

/* Center Panel - Canvas Area */
.designer-canvas-area {
    flex: 1;
    /* Both sidebars are flex-shrink:0, so on a narrow window this column is
       what gives way. Without a floor it collapses to 0 and the canvas
       disappears entirely — the workspace scrolls sideways instead. */
    min-width: 360px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background: #e2e8f0;
}

.canvas-toolbar {
    height: 48px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 5;
}
.canvas-toolbar__group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.canvas-btn {
    width: 32px;
    height: 32px;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    display: grid;
    place-items: center;
    font-size: 14px;
    cursor: pointer;
    transition: .15s;
}
.canvas-btn:hover {
    background: var(--bg);
    color: var(--brand);
    border-color: var(--brand);
}
.canvas-btn.active {
    background: var(--brand-soft);
    color: var(--brand);
    border-color: var(--brand);
}

.zoom-badge {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-2);
    padding: 4px 8px;
    min-width: 48px;
    text-align: center;
}

/* Canvas Viewport */
.canvas-viewport {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    position: relative;
}

.canvas-viewport.has-grid {
    background-image: radial-gradient(rgba(0, 0, 0, 0.12) 1px, transparent 1px);
    background-size: 16px 16px;
}

/* CR80 Standard ID Card Container */
.id-card-frame {
    width: 538px;
    height: 338px;
    /* The card is a flex item in .canvas-viewport; without this it shrinks
       with the container and every element's position stops matching print. */
    flex-shrink: 0;
    background: #ffffff;
    /* Own stacking context, so a "behind background" element parked at
       z-index -1 stays inside the card instead of vanishing underneath it. */
    isolation: isolate;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0,0,0,0.05);
    position: relative;
    overflow: hidden;
    transition: transform .2s ease;
    user-select: none;
}

.id-card-frame.portrait {
    width: 338px;
    height: 538px;
}

/* Background Image Layer (Locked at z-index 0) */
.canvas-bg-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: 100% 100%;
    z-index: 0;
    pointer-events: none;
    user-select: none;
}

/* Photo clipping lives on an inner wrapper, never on .card-element itself —
   the resize handles sit outside the box (bottom/right: -5px) and would be
   clipped away, leaving nothing to grab. */
.card-element .photo-clip {
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: inherit;
    pointer-events: none;
}

/* Marks an element sitting below the background image (z-index < 0). The
   inline z-index is the single source of truth; this class only drives the
   outline colour, so the two can never disagree. */

/* "Outlines" mode: fade the background and outline every element, so
   behind-background elements can still be found, selected and moved. */
.id-card-frame.show-outlines .canvas-bg-layer {
    opacity: .28;
}
.id-card-frame.show-outlines .card-element {
    outline: 1px dashed rgba(164, 38, 44, .65);
    outline-offset: 1px;
}
.id-card-frame.show-outlines .card-element.is-behind-bg {
    outline: 1px dashed #2563eb;
}

/* Interactive Card Elements */
.card-element {
    position: absolute;
    cursor: move;
    border: 1.5px dashed transparent;
    padding: 2px;
    border-radius: 4px;
    transition: border-color .15s ease;
    z-index: 1;
}
.card-element:hover {
    border-color: rgba(37, 99, 235, 0.5);
}
.card-element.selected {
    border-color: var(--brand);
    box-shadow: 0 0 0 1px var(--brand);
}

/* Locked Element State */
.card-element.is-locked {
    cursor: not-allowed !important;
    border-color: #ef4444 !important;
}
.card-element.is-locked::before {
    content: "\F458";
    font-family: "bootstrap-icons";
    position: absolute;
    top: -10px;
    right: -10px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: grid;
    place-items: center;
}

/* Resize & Rotation Handles */
.resize-handle {
    position: absolute;
    width: 9px;
    height: 9px;
    background: var(--brand);
    border: 1.5px solid #fff;
    border-radius: 50%;
    display: none;
}
.card-element.selected .resize-handle {
    display: block;
}
.resize-handle.se { bottom: -5px; right: -5px; cursor: se-resize; }
.resize-handle.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.resize-handle.ne { top: -5px; right: -5px; cursor: ne-resize; }
.resize-handle.nw { top: -5px; left: -5px; cursor: nw-resize; }

.rotate-handle {
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 16px;
    background: #a4262c;
    color: #fff;
    border-radius: 50%;
    font-size: 10px;
    display: none;
    place-items: center;
    cursor: grab;
}
.card-element.selected .rotate-handle {
    display: grid;
}

/* Right Sidebar - Properties Panel */
.designer-sidebar-right {
    width: 320px;
    flex-shrink: 0;
    border-right: none;
    border-left: 1px solid var(--border);
}

.prop-section {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-2);
}
.prop-section:last-child {
    border-bottom: none;
}
.prop-section__title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--brand);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.prop-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.prop-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.prop-group.full {
    grid-column: span 2;
}
.prop-group label {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-2);
    margin: 0;
}
.prop-group .form-control,
.prop-group .form-select {
    padding: 6px 10px;
    font-size: 12.5px;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: var(--bg);
}

.color-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}
.color-input-wrapper input[type="color"] {
    width: 32px;
    height: 32px;
    padding: 2px;
    border-radius: 6px;
    border: 1px solid var(--border);
    cursor: pointer;
}

.style-toggle-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    border-radius: 6px;
    display: grid;
    place-items: center;
    font-size: 13px;
    cursor: pointer;
    transition: .15s;
}
.style-toggle-btn:hover { background: var(--bg); color: var(--brand); }
.style-toggle-btn.active { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); font-weight: bold; }
