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

body {
    font-family: 'Outfit', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 20px;
    gap: 20px;
}

/* ===== APP BANNER (hero branding) ===== */
.app-banner {
    width: 100%;
    max-width: 1400px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
    line-height: 0;
}

.banner-img {
    width: 100%;
    height: auto;
    max-height: 190px;
    object-fit: cover;
    object-position: center;
    display: block;
}

.container {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 20px;
    width: 100%;
    max-width: 1400px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
    background: linear-gradient(180deg, #f5f7fa 0%, #e9ecef 100%);
    border-right: 1px solid #dee2e6;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    max-height: 90vh;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 2px solid #dee2e6;
    background: white;
}

.sidebar-header h2 {
    font-size: 1.5rem;
    color: #333;
}

/* Search bar */
.search-wrap {
    position: relative;
    margin-top: 12px;
}

.element-search {
    width: 100%;
    padding: 9px 32px 9px 12px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    color: #333;
    transition: border-color 0.2s ease;
}

.element-search:focus {
    outline: none;
    border-color: #667eea;
}

.search-clear {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: #dee2e6;
    color: #555;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    padding: 0;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-clear:hover {
    background: #adb5bd;
    color: white;
}

.search-clear.hidden {
    display: none;
}

.gallery-empty {
    grid-column: 1 / -1;
    padding: 20px;
    text-align: center;
    color: #999;
    font-size: 0.88rem;
}

.categories {
    padding: 12px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    overflow-y: auto;
}

/* 2-column compact grid when 7+ categories exist */
.categories.compact {
    grid-template-columns: 1fr 1fr;
    gap: 5px;
}

.category-btn {
    padding: 10px 10px;
    background: white;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 500;
    color: #333;
    display: flex;
    align-items: center;
    gap: 7px;
    transition: all 0.2s ease;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* In compact 2-col mode, center icon + label and allow wrap */
.categories.compact .category-btn {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 0.75rem;
    padding: 10px 6px;
    text-align: center;
    white-space: normal;
}

.category-btn:hover {
    background: #e9ecef;
    border-color: #667eea;
    transform: translateX(3px);
}

.categories.compact .category-btn:hover {
    transform: scale(1.04);
}

.category-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.category-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.categories.compact .category-icon {
    font-size: 1.5rem;
}

/* Gallery */
.gallery {
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}

.gallery.hidden {
    display: none;
}

.gallery-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.back-btn {
    padding: 6px 12px;
    background: #dee2e6;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    color: #333;
    transition: background 0.2s ease;
}

.back-btn:hover {
    background: #adb5bd;
}

#gallery-title {
    font-size: 1.1rem;
    color: #333;
    flex: 1;
}

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

.gallery-item {
    aspect-ratio: 1;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    padding: 8px;
    background: white;
    cursor: grab;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-item:hover {
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
    transform: scale(1.05);
}

.gallery-item img,
.gallery-item svg {
    max-width: 90%;
    max-height: 90%;
    width: auto;
    height: auto;
    pointer-events: none;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 20px;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: #f5f7fa;
    border-radius: 8px;
    gap: 20px;
}

.canvas-controls,
.action-controls {
    display: flex;
    gap: 10px;
}

button {
    padding: 10px 16px;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    background: white;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    color: #333;
    transition: all 0.2s ease;
}

button:hover {
    border-color: #667eea;
    color: #667eea;
}

.orientation-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

#clear-canvas-btn {
    background: #dc3545;
    color: white;
    border-color: #dc3545;
}

#clear-canvas-btn:hover {
    background: #c82333;
    border-color: #c82333;
}

#save-btn,
#print-btn {
    background: #28a745;
    color: white;
    border-color: #28a745;
}

#save-btn:hover,
#print-btn:hover {
    background: #218838;
    border-color: #218838;
}

/* Canvas Area */
.canvas-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f9fafb;
    border-radius: 8px;
    min-height: 500px;
    padding: 20px;
    position: relative;
}

.canvas {
    background: white;
    position: relative;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    cursor: default;
}

.canvas.portrait {
    width: 8.5in;
    height: 11in;
    aspect-ratio: 8.5 / 11;
}

.canvas.landscape {
    width: 11in;
    height: 8.5in;
    aspect-ratio: 11 / 8.5;
}

/* Draggable Elements */
.canvas-element {
    position: absolute;
    cursor: grab;
    user-select: none;
}

.canvas-element.dragging {
    z-index: 1000;
    opacity: 0.9;
}

.canvas-element.selected {
    border: 2px dashed #667eea;
    outline: 2px solid rgba(102, 126, 234, 0.2);
    outline-offset: 4px;
}

.canvas-element.locked {
    cursor: not-allowed;
}

.canvas-element img,
.canvas-element svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

/* Resize Handle */
.resize-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #667eea;
    border: 2px solid white;
    border-radius: 50%;
    bottom: -6px;
    right: -6px;
    cursor: se-resize;
    display: none;
}

/* Resize handle only on a single (primary) selection — hidden in multi-select */
.canvas-element.primary .resize-handle {
    display: block;
}

/* Marquee selection box */
.marquee {
    position: absolute;
    border: 1.5px dashed #667eea;
    background: rgba(102, 126, 234, 0.12);
    z-index: 99999;
    pointer-events: none;
}

/* Properties Panel — floating, draggable, collapsible */
.properties-panel {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: white;
    border: 2px solid #667eea;
    border-radius: 10px;
    width: 260px;
    box-shadow: 0 8px 28px rgba(102, 126, 234, 0.3);
    z-index: 9000;
    overflow: hidden;
}

.properties-panel.hidden {
    display: none;
}

/* Draggable header (grab here to move) */
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: #667eea;
    cursor: move;
    user-select: none;
}

.panel-header h4 {
    color: white;
    font-size: 0.95rem;
    margin: 0;
}

.panel-collapse {
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.25);
    color: white;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}

.panel-collapse:hover {
    background: rgba(255, 255, 255, 0.45);
    color: white;
}

.panel-body {
    padding: 15px;
}

/* Collapsed: hide the body, keep just the header bar */
.properties-panel.collapsed .panel-body {
    display: none;
}

.properties-panel.collapsed {
    width: 200px;
}

.property-group {
    margin-bottom: 12px;
}

.property-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 0.9rem;
    color: #555;
}

.property-group input[type="range"] {
    width: 100%;
    height: 4px;
    cursor: pointer;
}

.property-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Layer controls */
.layer-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    margin-top: 4px;
}

.layer-controls button {
    padding: 7px 6px;
    font-size: 0.78rem;
    font-weight: 600;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    background: #f8f9fa;
    color: #555;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.layer-controls button:hover {
    border-color: #667eea;
    background: #667eea;
    color: white;
}

.delete-btn {
    width: 100%;
    background: #dc3545;
    color: white;
    border-color: #dc3545;
    margin-top: 10px;
}

.delete-btn:hover {
    background: #c82333;
    border-color: #c82333;
}

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

    .sidebar {
        grid-column: 1;
        max-height: 300px;
        border-right: none;
        border-bottom: 1px solid #dee2e6;
    }

    .categories {
        flex-direction: row;
        overflow-x: auto;
    }

    .category-btn {
        flex-shrink: 0;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        gap: 10px;
    }

    .canvas-wrapper {
        min-height: 350px;
    }

    .canvas.portrait {
        width: 6in;
        height: 8in;
    }

    .canvas.landscape {
        width: 8in;
        height: 6in;
    }
}

/* ===== HELP BUTTON ===== */
#help-btn {
    font-size: 1.1rem;
    padding: 10px 14px;
}

/* ===== SHORTCUTS OVERLAY ===== */
.shortcuts-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
}

.shortcuts-overlay.hidden {
    display: none;
}

.shortcuts-modal {
    position: relative;
    background: white;
    border-radius: 14px;
    padding: 30px 34px;
    max-width: 460px;
    width: 90%;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.4);
    animation: pop 0.18s ease;
}

@keyframes pop {
    from { transform: scale(0.94); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.shortcuts-modal h2 {
    font-size: 1.35rem;
    color: #333;
    margin-bottom: 18px;
}

.shortcuts-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: #f0f0f4;
    color: #555;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0;
}

.shortcuts-close:hover {
    background: #dc3545;
    color: white;
}

.shortcuts-table {
    width: 100%;
    border-collapse: collapse;
}

.shortcuts-table td {
    padding: 8px 6px;
    border-bottom: 1px solid #f0f0f4;
    font-size: 0.9rem;
    color: #444;
    vertical-align: middle;
}

.shortcuts-table td:first-child {
    white-space: nowrap;
    width: 45%;
}

kbd {
    display: inline-block;
    background: #f5f7fa;
    border: 1px solid #cdd3da;
    border-bottom-width: 2px;
    border-radius: 5px;
    padding: 2px 7px;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    color: #333;
    line-height: 1.4;
}

.shortcuts-hint {
    margin-top: 18px;
    text-align: center;
    font-size: 0.82rem;
    color: #999;
}
