* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #f7f4ef 0%, #eef3f6 100%);
    color: #24313d;
    height: 100vh;
    overflow: hidden;
}

.container {
    display: grid;
    grid-template-columns: 280px 1fr 240px;
    gap: 12px;
    padding: 16px;
    height: 100vh;
    background: transparent;
}

/* Gallery Section */
.gallery-section {
    background: rgba(255,255,255,0.92);
    border: 1px solid rgba(36,49,61,0.08);
    border-radius: 16px;
    padding: 16px;
    overflow-y: auto;
    box-shadow: 0 16px 40px rgba(35, 48, 60, 0.08);
    backdrop-filter: blur(14px);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.panel-kicker {
    font-size: 11px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #6f7a86;
    margin-bottom: 2px;
}

.panel-pill {
    padding: 6px 10px;
    border-radius: 999px;
    background: #eef5ee;
    color: #3e6d44;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.gallery-section h2,
.canvas-section h2,
.layer-panel h3 {
    font-size: 18px;
    color: #24313d;
}

.category {
    margin-bottom: 20px;
}

.category-title {
    font-weight: 600;
    font-size: 14px;
    color: #33414d;
    margin-bottom: 10px;
    padding: 9px 10px;
    background: linear-gradient(135deg, #f8fafc 0%, #eef3f7 100%);
    border: 1px solid rgba(36,49,61,0.06);
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.category-title:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 18px rgba(35,48,60,0.08);
}

.category-title.collapsed::after {
    content: '▶';
}

.category-title.expanded::after {
    content: '▼';
}

.gallery-items {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.gallery-item {
    width: 100%;
    aspect-ratio: 1;
    background: linear-gradient(145deg, #ffffff 0%, #f7f9fb 100%);
    border: 1px solid rgba(36,49,61,0.08);
    border-radius: 12px;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px rgba(36,49,61,0.06);
}

.gallery-item:hover {
    border-color: #4CAF50;
    box-shadow: 0 12px 24px rgba(36,49,61,0.12);
    transform: translateY(-2px) scale(1.01);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 4px;
}

.gallery-item-name {
    font-size: 11px;
    text-align: center;
    color: #888;
    word-break: break-word;
}

/* Canvas Section */
.canvas-section {
    background: rgba(255,255,255,0.94);
    border: 1px solid rgba(36,49,61,0.08);
    border-radius: 18px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 50px rgba(35,48,60,0.08);
}

.canvas-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.canvas-hint {
    font-size: 12px;
    color: #6f7a86;
    margin-bottom: 12px;
}

.canvas-section h2 {
    font-size: 18px;
    margin-bottom: 0;
    color: #333;
}

.background-control {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    color: #444;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

.background-control select {
    height: 34px;
    min-width: 170px;
    border: 1px solid #d8d8d8;
    border-radius: 999px;
    background: white;
    color: #333;
    font: inherit;
    padding: 0 34px 0 12px;
    cursor: pointer;
}

.controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.btn,
.toggle-control,
.background-control select {
    box-shadow: 0 6px 16px rgba(35,48,60,0.06);
}

.btn {
    padding: 8px 12px;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-primary {
    background: #4CAF50;
    color: white;
}

.btn-primary:hover {
    background: #45a049;
}

.btn-danger {
    background: #f44336;
    color: white;
}

.btn-danger:hover {
    background: #da190b;
}

.toggle-control {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 10px;
    border: 1px solid #d8d8d8;
    border-radius: 999px;
    background: white;
    color: #444;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

.toggle-control input {
    width: 14px;
    height: 14px;
    accent-color: #4CAF50;
    cursor: pointer;
}

.range-control {
    display: inline-grid;
    grid-template-columns: 1fr;
    gap: 4px;
    min-width: 92px;
    color: #444;
    font-size: 11px;
    font-weight: 500;
    line-height: 1;
}

.range-control span {
    display: flex;
    justify-content: space-between;
    gap: 6px;
}

.range-control output {
    min-width: 20px;
    text-align: right;
    color: #666;
}

.range-control input {
    width: 100%;
    accent-color: #4CAF50;
    cursor: pointer;
}

.range-control input:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

#canvas {
    flex: 1;
    background-color: #ffffff;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    border: 1px solid rgba(36,49,61,0.12);
    border-radius: 16px;
    position: relative;
    overflow: hidden;
    cursor: crosshair;
}

/* Canvas Items */
.canvas-item {
    position: absolute;
    cursor: move;
    border: 2px solid transparent;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s ease;
}

.canvas-item:hover {
    transform: translateY(-1px);
}

.canvas-product-image {
    position: absolute;
    object-fit: contain;
    pointer-events: none;
    filter: drop-shadow(2px 2px 5px rgba(0,0,0,0.22));
    transform-origin: center;
}

.canvas-item.selected {
    filter: none;
    box-shadow: none;
}

.canvas-label {
    --keyline-length: 18px;
    position: absolute;
    z-index: 5;
    display: flex;
    align-items: center;
    padding: 0 6px;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    color: #ffffff;
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
    overflow: visible;
    pointer-events: none;
    text-shadow: 0 1px 2px rgba(0,0,0,0.45);
}

.canvas-label span {
    display: block;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.canvas-label::before {
    content: none;
}

.labels-hidden .canvas-label {
    display: none;
}

/* Layer Panel */
.layer-panel {
    background: rgba(255,255,255,0.92);
    border: 1px solid rgba(36,49,61,0.08);
    border-radius: 16px;
    padding: 16px;
    overflow-y: auto;
    box-shadow: 0 16px 40px rgba(35,48,60,0.08);
}

.layer-panel h3 {
    font-size: 16px;
    margin-bottom: 12px;
    color: #24313d;
}

.layers-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.layer-item {
    padding: 10px;
    background: linear-gradient(135deg, #f8fafc 0%, #eef3f7 100%);
    border: 1px solid rgba(36,49,61,0.08);
    border-radius: 12px;
    cursor: grab;
    font-size: 12px;
    color: #44515d;
    transition: all 0.2s ease;
    user-select: none;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

.layer-item:hover {
    background: #f2f7fb;
    border-color: #4CAF50;
    transform: translateY(-1px);
}

.layer-item.active {
    background: linear-gradient(135deg, #4CAF50 0%, #3b8f43 100%);
    color: white;
    border-color: #3b8f43;
}

.layer-item.drag-over {
    border-color: #4CAF50;
    box-shadow: inset 0 0 0 1px rgba(76,175,80,0.22);
}

.layer-handle {
    font-size: 13px;
    color: #8a95a1;
    margin-right: 6px;
}

.layer-item.active .layer-handle {
    color: rgba(255,255,255,0.86);
}

.layer-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.layer-item-title {
    display: flex;
    align-items: center;
    min-width: 0;
}

.layer-item-name {
    flex: 1;
    word-break: break-word;
    min-width: 0;
}

.layer-order-controls {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.layer-order-btn,
.layer-delete-btn {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 14px;
    padding: 0 3px;
    transition: color 0.2s;
    flex-shrink: 0;
}

.layer-order-btn:hover {
    color: #4CAF50;
}

.layer-delete-btn:hover {
    color: #f44336;
}

.layer-item.active .layer-order-btn,
.layer-item.active .layer-delete-btn {
    color: white;
}

.layer-item.active .layer-order-btn:hover {
    color: #e8f5e9;
}

.layer-item.active .layer-delete-btn:hover {
    color: #ffcdd2;
}

.layer-size-controls,
.layer-rotate-controls {
    display: grid;
    grid-template-columns: 24px 1fr 24px;
    align-items: center;
    gap: 6px;
}

.layer-size-btn,
.layer-rotate-btn {
    width: 24px;
    height: 24px;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    background: white;
    color: #555;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
}

.layer-rotate-controls {
    display: flex;
    justify-content: flex-start;
}

.layer-rotate-btn {
    width: 28px;
    font-size: 18px;
}

.layer-size-btn:hover,
.layer-rotate-btn:hover {
    border-color: #4CAF50;
    color: #4CAF50;
}

.layer-size-range {
    width: 100%;
    min-width: 0;
    accent-color: #4CAF50;
    cursor: pointer;
}

.layer-item.active .layer-size-btn,
.layer-item.active .layer-rotate-btn {
    background: rgba(255,255,255,0.16);
    border-color: rgba(255,255,255,0.55);
    color: white;
}

.layer-item.active .layer-size-btn:hover,
.layer-item.active .layer-rotate-btn:hover {
    background: rgba(255,255,255,0.26);
    border-color: white;
    color: white;
}

.layer-item.active .layer-size-range {
    accent-color: white;
}

/* Context Menu */
.context-menu {
    position: fixed;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 10000;
    display: none;
    flex-direction: column;
    min-width: 150px;
}

.context-menu.active {
    display: flex;
}

.context-btn {
    padding: 10px 16px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    text-align: left;
    transition: background 0.2s;
}

.context-btn:first-child {
    border-radius: 4px 4px 0 0;
}

.context-btn:last-child {
    border-radius: 0 0 4px 4px;
}

.context-btn:hover {
    background: #f5f5f5;
}

.context-btn[data-action="delete"]:hover {
    background: #ffebee;
    color: #f44336;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .container {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
    }

    .gallery-section,
    .canvas-section,
    .layer-panel {
        border-radius: 8px;
    }

    .layer-panel {
        display: none;
    }
}
