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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #832EC5 0%, #B900FF 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

#loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

.loading-content {
    text-align: center;
    color: #fff;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    margin: 0 auto 20px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: #FFC700;
    border-right-color: #FFC700;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 20px;
    color: #FFC700;
}

#loading-progress {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
}

/* Sidebar Toggle Button */
.sidebar-toggle-btn {
    position: fixed;
    top: 16px;
    left: 280px;
    width: 20px;
    height: 56px;
    border-radius: 0 10px 10px 0;
    border: none;
    background: linear-gradient(135deg, #832EC5 0%, #a855f7 100%);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 2px 8px rgba(131, 46, 197, 0.25);
    transition: all 0.25s ease, left 0.3s ease;
    z-index: 101;
    opacity: 0.7;
}

.sidebar-toggle-btn:hover {
    opacity: 1;
    width: 24px;
    box-shadow: 3px 3px 12px rgba(131, 46, 197, 0.35);
}

.sidebar-toggle-btn .toggle-icon {
    transition: transform 0.3s ease;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

.sidebar-toggle-btn.collapsed .toggle-icon {
    transform: rotate(180deg);
}

/* Sidebar */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    background: #FFFFFF;
    border-right: 1px solid #E0E0E0;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    z-index: 50;
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.1);
    transition: width 0.3s ease, padding 0.3s ease;
}

#sidebar.collapsed {
    width: 0px;
    padding: 0;
    border-right: 0;
    box-shadow: none;
    overflow: visible;
    min-width: 0;
}

#sidebar.collapsed > * {
    display: none;
}

#sidebar.collapsed .save-button {
    display: none !important;
}

/* ==================== AI PROMPT DOCK ==================== */
.ai-prompt-dock {
    position: fixed;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid #E0E0E0;
    border-radius: 16px;
    padding: 12px 14px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 120;
    min-width: 320px;
    max-width: 720px;
    width: min(80vw, 720px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.ai-prompt-dock.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%) translateY(10px);
}

.ai-prompt-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-prompt-input {
    flex: 5 1 0;
    padding: 10px 12px;
    border: 2px solid #E0E0E0;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.9rem;
    color: #333;
    background: #FAFAFA;
    transition: all 0.2s ease;
}

.ai-prompt-input:focus {
    outline: none;
    border-color: #832EC5;
    background: #FFF;
    box-shadow: 0 0 0 3px rgba(131, 46, 197, 0.1);
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.section-header {
    font-size: 0.66rem;
    font-weight: 600;
    color: #666666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* AI Inputs */
.ai-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #E0E0E0;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.85rem;
    color: #333;
    background: #FAFAFA;
    resize: none;
    transition: all 0.2s ease;
}

.ai-textarea:focus {
    outline: none;
    border-color: #832EC5;
    background: #FFF;
    box-shadow: 0 0 0 3px rgba(131, 46, 197, 0.1);
}

.ai-generate-btn {
    flex: 1 1 0;
    padding: 10px 12px;
    background: linear-gradient(135deg, #B900FF 0%, #832EC5 100%);
    border: none;
    border-radius: 10px;
    color: white;
    font-weight: 600;
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(131, 46, 197, 0.25);
}

.ai-generate-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(131, 46, 197, 0.35);
    filter: brightness(1.05);
}

.ai-generate-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
}

.ai-generate-btn.loading .btn-text {
    display: none;
}

.ai-generate-btn.loading .spinner {
    display: block;
}

.ai-error-msg {
    color: #EF4444;
    font-size: 0.75rem;
    font-weight: 500;
}

.ai-hint {
    font-size: 0.7rem;
    color: #999999;
}

.ai-prompt-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    min-height: 0;
}

.ai-error-msg:empty {
    display: none;
}

.ai-toggle-btn {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 52px;
    height: 52px;
    border-radius: 16px;
    border: none;
    background: linear-gradient(135deg, #B900FF 0%, #832EC5 100%);
    color: #fff;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 10px 22px rgba(131, 46, 197, 0.35);
    transition: all 0.2s ease;
    z-index: 130;
}

.ai-toggle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 26px rgba(131, 46, 197, 0.4);
}

.ai-toggle-btn.active {
    background: #E8E8E8;
    color: #333333;
    border: 1px solid #E0E0E0;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.15);
}

/* Tools Grid - Using shared/tools-card.css */

/* Space-builder specific tool overrides */
.tool-item[data-tool="center"] .tool-icon {
    width: 38px;
    height: 38px;
}

/* Color Picker */
#color-selector {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

#hue-ring-container {
    position: relative;
    width: 110px;
    height: 110px;
}

#hue-ring {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red);
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

#hue-ring-inner {
    position: absolute;
    top: 18px;
    left: 18px;
    width: 74px;
    height: 74px;
    border-radius: 50%;
    background: #FFFFFF;
    box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.1);
}

#hue-marker {
    position: absolute;
    width: 14px;
    height: 14px;
    background: #fff;
    border: 2px solid #333;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

#shade-square {
    width: 110px;
    height: 110px;
    position: relative;
    border-radius: 8px;
    cursor: crosshair;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

#shade-marker {
    position: absolute;
    width: 14px;
    height: 14px;
    background: transparent;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #333, 0 1px 4px rgba(0, 0, 0, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

/* Zoom Control */
.zoom-control {
    position: fixed;
    bottom: 5px;
    right: 10px;
    display: flex;
    align-items: center;
    background: white;
    border: 2px solid #E0E0E0;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
    height: 32px;
    width: 180px;
    overflow: hidden;
}

.zoom-control-inner {
    display: flex;
    align-items: center;
    background: #FAFAFA;
    height: 100%;
    width: 100%;
    border-radius: 6px;
}

.zoom-control-section {
    display: flex;
    align-items: center;
    height: 100%;
}

.zoom-info-section {
    padding: 0 5px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.zoom-control .zoom-icon {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    color: #000;
}

.zoom-control .zoom-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.zoom-percentage {
    font-size: 12px;
    font-weight: 500;
    color: #000;
    min-width: 34px;
    text-align: left;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.zoom-divider {
    width: 2px;
    height: 100%;
    background: #E0E0E0;
}

.zoom-button-wrapper {
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.zoom-button-wrapper:hover:not(.disabled) {
    background: rgba(0, 0, 0, 0.05);
}

.zoom-button-wrapper.disabled {
    cursor: default;
}

.zoom-control button {
    width: 18px;
    height: 18px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 18px;
    font-weight: 500;
    color: #3379FF;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.2s ease;
    pointer-events: none;
}

.zoom-button-wrapper.disabled button {
    color: #E0E0E0;
}

.zoom-slider-container {
    position: relative;
    flex: 1;
    height: 100%;
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 0 8px;
}

.zoom-slider-track {
    position: absolute;
    left: 8px;
    right: 8px;
    height: 1px;
    background: #E0E0E0;
    border-radius: 0.5px;
}

.zoom-slider-dot {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #000;
    border-radius: 50%;
    z-index: 1;
    transition: all 0.1s ease;
    left: 50%;
    transform: translateX(-50%);
    cursor: grab;
}

.zoom-slider-dot:active {
    cursor: grabbing;
    transform: translateX(-50%) scale(1.1);
}

/* Cursor styles for tools */
.cursor-add { cursor: crosshair; }
.cursor-hammer { cursor: pointer; }

.cursor-dropper { cursor: copy; }
.cursor-rotate { cursor: grab; }
.cursor-rotate:active { cursor: grabbing; }

/* Controls List */
.controls-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: #F5F5F5;
    border-radius: 6px;
}

.control-keys {
    display: flex;
    gap: 4px;
    align-items: center;
}

.control-desc {
    font-size: 0.75rem;
    color: #666666;
    font-weight: 500;
}

kbd {
    display: inline-block;
    padding: 4px 8px;
    background: linear-gradient(180deg, #832EC5 0%, #6b24a0 100%);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    box-shadow: 0 2px 0 #4a1a70;
    min-width: 24px;
    text-align: center;
}

.control-keys kbd {
    padding: 3px 6px;
    font-size: 10px;
    min-width: 20px;
}

/* Builder Container - Space Theme */
#builder-container {
    position: fixed;
    top: 0;
    left: 280px;
    width: calc(100vw - 280px);
    height: 100vh;
    background: transparent;
    z-index: 5;
    transition: left 0.3s ease, width 0.3s ease;
}


#builder-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Floating cube particles */
@keyframes floatUp {
    0% { transform: translateY(100vh) rotate(0deg) scale(0.5); opacity: 0; }
    10% { opacity: 0.6; }
    90% { opacity: 0.6; }
    100% { transform: translateY(-100px) rotate(360deg) scale(0.8); opacity: 0; }
}

.floating-cube {
    position: fixed;
    pointer-events: none;
    z-index: 1;
    animation: floatUp linear infinite;
}

.floating-cube svg {
    filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.5));
}

/* Embedded mode - hide sidebar when loaded in iframe */
body.embedded #sidebar {
    display: none;
}

body.embedded #ai-prompt-dock,
body.embedded #ai-toggle-btn {
    display: none;
}

body.embedded #builder-container {
    left: 0;
    width: 100vw;
}

body.embedded #stats-display {
    left: 50%;
    transform: translateX(-50%);
}

/* Stats Display */
#stats-display {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: row;
    gap: 12px;
    z-index: 100;
    pointer-events: none;
}

.stat-item {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    border-radius: 8px;
    padding: 8px 20px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(131, 46, 197, 0.15);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    min-width: auto;
}

.stat-label {
    font-size: 10px;
    font-weight: 600;
    color: #832EC5;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.stat-value {
    font-size: 18px;
    font-weight: 700;
    color: #333333;
    line-height: 1;
}

.stat-unit {
    font-size: 10px;
    font-weight: 500;
    color: #888888;
}

/* ================================
   SAVE FEATURE STYLES
   ================================ */

/* Saves Section */
.saves-section {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Sessions List */
.sessions-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
}

/* Save Button */
.save-button {
    width: 100%;
    padding: 12px 16px;
    background: linear-gradient(135deg, #B900FF 0%, #832EC5 100%);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(131, 46, 197, 0.4);
    flex-shrink: 0;
}

.save-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(185, 0, 255, 0.5);
}

.save-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(131, 46, 197, 0.4);
}

.save-button svg {
    width: 18px;
    height: 18px;
}

.sessions-list::-webkit-scrollbar {
    width: 6px;
}

.sessions-list::-webkit-scrollbar-track {
    background: #F5F5F5;
    border-radius: 3px;
}

.sessions-list::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #832EC5 0%, #B900FF 100%);
    border-radius: 3px;
}

/* Session Tile */
.session-tile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: all 0.2s ease;
}

.session-tile:hover {
    background: rgba(34, 197, 94, 0.12);
    border-color: rgba(34, 197, 94, 0.35);
}

.session-tile.active {
    background: rgba(34, 197, 94, 0.1);
    border-color: rgba(34, 197, 94, 0.5);
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.1);
}

.session-tile.modified {
    border-color: #F59E0B;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2), 0 2px 8px rgba(245, 158, 11, 0.15);
}

.session-tile.pending-delete {
    border-color: #EF4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2), 0 2px 8px rgba(239, 68, 68, 0.15);
}

/* Session Thumbnail */
.session-thumbnail {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    background: #fff;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #eee;
}

.session-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.session-thumbnail svg {
    width: 24px;
    height: 24px;
    opacity: 0.6;
    color: #999;
}

/* Session Info */
.session-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.session-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: #333333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.session-meta {
    font-size: 0.75rem;
    color: rgba(51, 51, 51, 0.5);
    display: flex;
    gap: 8px;
}

.session-time {
    font-size: 0.75rem;
    color: rgba(51, 51, 51, 0.5);
}

.session-cubes {
    font-size: 10px;
    font-weight: 600;
    color: rgba(51, 51, 51, 0.55);
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 10px;
}

/* Session Actions */
.session-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
    flex-shrink: 0;
    position: relative;
}

.session-tile:hover .session-actions {
    opacity: 1;
}

.session-action-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: rgba(51, 51, 51, 0.7);
}

.session-action-btn:hover {
    background: rgba(0, 0, 0, 0.2);
    color: #000;
}

.session-action-btn.update-btn:hover {
    background: rgba(131, 46, 197, 0.15);
    color: #832EC5;
}

.session-action-btn.delete-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.session-menu-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.06);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: rgba(51, 51, 51, 0.6);
}

.session-menu-btn:hover {
    background: rgba(0, 0, 0, 0.14);
    color: #111111;
}

.session-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    display: none;
    flex-direction: column;
    gap: 2px;
    min-width: 150px;
    padding: 6px;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
    z-index: 5;
}

.session-menu.open {
    display: flex;
}

.session-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 8px;
    background: transparent;
    border: none;
    border-radius: 8px;
    font-size: 0.75rem;
    color: #333333;
    cursor: pointer;
    text-align: left;
    transition: background 0.2s ease, color 0.2s ease;
}

.session-menu-item:hover {
    background: rgba(0, 0, 0, 0.06);
}

.session-menu-item.remove {
    color: #ef4444;
}

.session-menu-item.remove:hover {
    background: rgba(239, 68, 68, 0.12);
}

.session-tile.is-hidden {
    opacity: 0.5;
}

.session-tile.is-hidden .session-thumbnail {
    filter: grayscale(0.4);
}

.session-action-btn svg {
    width: 16px;
    height: 16px;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 24px 16px;
    gap: 8px;
}

.empty-state svg {
    width: 40px;
    height: 40px;
    color: #CCCCCC;
    opacity: 0.5;
}

.empty-state span {
    font-size: 13px;
    color: #999999;
    text-align: center;
}

/* ================================
   MODAL STYLES
   ================================ */

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

/* Modal Dialog */
.modal-dialog {
    width: 90%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.1);
    transform: scale(0.9) translateY(20px);
    transition: transform 0.2s ease;
    overflow: hidden;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-overlay.visible .modal-dialog {
    transform: scale(1) translateY(0);
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    color: #333333;
    margin: 0;
}

.modal-input {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid #E0E0E0;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    color: #333333;
    background: #FFFFFF;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.modal-input:focus {
    outline: none;
    border-color: #832EC5;
    box-shadow: 0 0 0 3px rgba(131, 46, 197, 0.15);
}

.modal-input::placeholder {
    color: #999999;
}

.modal-message {
    font-size: 14px;
    color: #666666;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 4px;
}

/* Modal Buttons */
.modal-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.modal-btn-cancel {
    background: #F5F5F5;
    color: #666666;
}

.modal-btn-cancel:hover {
    background: #E8E8E8;
}

.modal-btn-confirm {
    background: linear-gradient(135deg, #B900FF 0%, #832EC5 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(131, 46, 197, 0.3);
}

.modal-btn-confirm:hover {
    box-shadow: 0 4px 12px rgba(185, 0, 255, 0.4);
    transform: translateY(-1px);
}

.modal-btn-danger {
    background: linear-gradient(135deg, #EF4444 0%, #DC2626 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.modal-btn-danger:hover {
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
    transform: translateY(-1px);
}

/* ================================
   TEMPLATE POPUP STYLES
   ================================ */

.template-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.template-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.template-popup {
    width: 90%;
    max-width: 520px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px);
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
    transform: scale(0.9) translateY(20px);
    transition: transform 0.2s ease;
    overflow: hidden;
}

.template-overlay.visible .template-popup {
    transform: scale(1) translateY(0);
}

.template-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #E0E0E0;
}

.template-popup-title {
    font-size: 18px;
    font-weight: 600;
    color: #333333;
    margin: 0;
}

.template-popup-close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: #F5F5F5;
    color: #666666;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.template-popup-close:hover {
    background: #E8E8E8;
    color: #333333;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    padding: 16px 20px 20px;
    max-height: 400px;
    overflow-y: auto;
}

.template-card {
    background: #FFFFFF;
    border: 1px solid #E8E8E8;
    border-radius: 10px;
    padding: 16px 12px 14px;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s ease;
}

.template-card:hover {
    border-color: #D0D0D0;
    background: #FAFAFA;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.template-card-icon {
    font-size: 32px;
    line-height: 1;
    margin-bottom: 8px;
}

.template-card-name {
    font-size: 13px;
    font-weight: 600;
    color: #333333;
    margin-bottom: 2px;
}

.template-card-desc {
    font-size: 11px;
    color: #888888;
}

.template-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    gap: 12px;
}

.template-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(131, 46, 197, 0.2);
    border-top-color: #832EC5;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.template-loading-text {
    font-size: 14px;
    color: #666666;
}

/* Section Header Row */
.section-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.section-header-row .section-header {
    margin-bottom: 0;
    flex: 1;
}

/* Load Template Button */
.load-template-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 8px;
    background: none;
    border: 1px solid rgba(131, 46, 197, 0.3);
    border-radius: 5px;
    color: #832EC5;
    font-family: inherit;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.load-template-btn:hover {
    background: rgba(131, 46, 197, 0.08);
    border-color: rgba(131, 46, 197, 0.5);
}

.load-template-btn svg {
    width: 12px;
    height: 12px;
}

/* Template Placement Mode */
.template-ghost {
    opacity: 0.6;
    pointer-events: none;
}

.placement-hint {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(131, 46, 197, 0.95);
    color: white;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 20px rgba(131, 46, 197, 0.4);
    z-index: 200;
    display: none;
}

.placement-hint.visible {
    display: block;
}
