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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    background-color: #f0f2f5;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar Styles */
.sidebar {
    width: 280px;
    background-color: #fff;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-right {
    border-right: none;
    border-left: 1px solid #e0e0e0;
}

.sidebar-right:not(.active) {
    opacity: 0.4;
    cursor: not-allowed;
}

.sidebar-right:not(.active) * {
    pointer-events: none;
}

.sidebar-right.active {
    opacity: 1;
    pointer-events: auto;
}

/* Message overlay for disabled text controls */
.text-controls-message {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.message-content {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    text-align: center;
    max-width: 300px;
}

.message-content p {
    margin-bottom: 1rem;
    color: #333;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e0e0e0;
}

.sidebar-header h1 {
    font-size: 1.5rem;
    color: #1a1a1a;
    font-weight: 600;
}

.sidebar-section {
    padding: 1.5rem;
    border-bottom: 1px solid #e0e0e0;
}

.sidebar-section h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
}

.sidebar-footer {
    padding: 1.5rem;
    margin-top: auto;
    border-top: 1px solid #e0e0e0;
}

/* Button Styles */
.btn {
    padding: 0.75rem 1rem;
    border: 1px solid #ddd;
    background-color: #fff;
    color: #333;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn:hover {
    background-color: #f8f9fa;
    border-color: #999;
}

.btn-block {
    width: 100%;
    margin-bottom: 0.75rem;
}

.btn-primary {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}

.btn-primary:hover {
    background-color: #0056b3;
    border-color: #0056b3;
}

.btn-secondary {
    background-color: #f8f9fa;
    border-color: #ddd;
}

.btn-secondary:hover {
    background-color: #e9ecef;
}

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

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

.btn-small {
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
}

.button-group {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.5rem;
}

.button-group .btn {
    flex: 1;
}

.button-group .btn.active {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}

/* Input Styles */
.input-label {
    display: block;
    font-size: 0.875rem;
    color: #333;
    margin-bottom: 1rem;
}

.color-input {
    width: 100%;
    height: 50px;
    border: 2px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 0.5rem;
    padding: 4px;
    background: transparent;
    transition: border-color 0.2s;
}

.color-input:hover {
    border-color: #007bff;
}

.color-input:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.range-input {
    width: 100%;
    margin-top: 0.5rem;
}

#fontSizeValue {
    display: inline-block;
    margin-left: 0.5rem;
    font-weight: 600;
    color: #007bff;
}

/* Editor Container */
.editor-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    overflow: auto;
    min-width: 0; /* Prevent flex item from growing beyond its content */
}

.canvas-wrapper {
    background-color: #ddd;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.poster-canvas {
    width: 595px;
    height: 842px;
    background-color: white;
    position: relative;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    overflow: hidden;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* Poster Elements */
.poster-element {
    position: absolute;
    cursor: move;
    border: 2px solid transparent;
    user-select: none;
    transition: border-color 0.2s;
}

.poster-element:hover {
    border-color: rgba(0, 123, 255, 0.5);
}

.poster-element.selected {
    border-color: #007bff;
    box-shadow: 0 0 0 1px rgba(0, 123, 255, 0.25);
}

.poster-element.text {
    min-width: 50px;
    min-height: 30px;
    z-index: 10; /* Text always on top */
    padding: 8px;
}

.poster-element.image {
    z-index: 5; /* Images below text */
}

.poster-element.image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Resize Handles */
.resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: #007bff;
    border: 2px solid white;
    border-radius: 2px;
    display: none;
}

.poster-element.selected .resize-handle {
    display: block;
}

/* Hide resize handles when editing text */
.poster-element.editing .resize-handle {
    display: none !important;
}

.resize-handle.nw { top: -5px; left: -5px; cursor: nw-resize; }
.resize-handle.ne { top: -5px; right: -5px; cursor: ne-resize; }
.resize-handle.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.resize-handle.se { bottom: -5px; right: -5px; cursor: se-resize; }

/* Text Editor */
.text-content {
    width: 100%;
    height: 100%;
    outline: none;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Background Generation Styles */
.bg-generation-section {
    margin: 1rem 0;
    padding-top: 1rem;
    border-top: 1px solid #e0e0e0;
}

.bg-prompt-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.875rem;
    font-family: inherit;
    resize: vertical;
    margin-top: 0.5rem;
}

.bg-prompt-input:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.loading-state {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background-color: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    margin-top: 0.75rem;
    font-size: 0.875rem;
    color: #666;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e0e0e0;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* API Key Input */
.api-key-section {
    background-color: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 4px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.api-key-input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

.api-key-help {
    font-size: 0.75rem;
    color: #666;
    margin-top: 0.5rem;
}

/* New UI Components */
.section-description {
    font-size: 0.8rem;
    color: #666;
    margin-bottom: 1rem;
    line-height: 1.4;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.or-divider {
    text-align: center;
    margin: 1.5rem 0;
    position: relative;
}

.or-divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: #ddd;
}

.or-divider span {
    background: white;
    padding: 0 1rem;
    color: #999;
    font-size: 0.8rem;
}

.bg-preview-section {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
    margin: 1rem 0;
}

/* Font Selector */
.font-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.font-option {
    background: white;
    border: 2px solid #ddd;
    border-radius: 6px;
    padding: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.font-option:hover {
    border-color: #007bff;
}

.font-option.active {
    border-color: #007bff;
    background-color: rgba(0, 123, 255, 0.1);
}

.font-option span {
    font-size: 18px;
    display: block;
}

/* Text Style Options */
.text-style-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.style-option {
    background: white;
    border: 2px solid #ddd;
    border-radius: 6px;
    padding: 0.75rem 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.style-option:hover {
    border-color: #007bff;
}

.style-option.active {
    border-color: #007bff;
    background-color: rgba(0, 123, 255, 0.1);
}

.style-option span {
    font-size: 16px;
    font-weight: bold;
}

.style-option small {
    font-size: 0.7rem;
    color: #666;
    font-weight: normal;
}

/* Text Element Improvements */
.poster-element.text {
    padding: 0;
    display: block;
    overflow: visible;
    position: absolute;
    contain: layout style;
}

.text-content {
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    text-align: inherit;
    padding: 4px;
    line-height: 1.3;
    white-space: pre;
    overflow: visible;
    min-width: 20px;
    display: inline-block;
    box-sizing: border-box;
    contain: layout;
}

.text-content:not([contenteditable="true"]) {
    pointer-events: none;
}

/* Font Families */
.font-impact {
    font-family: Impact, 'Arial Black', sans-serif !important;
    font-weight: 900 !important;
}

.font-bebas {
    font-family: 'Bebas Neue', 'Arial Black', sans-serif !important;
    font-weight: 400 !important;
    letter-spacing: 2px !important;
    text-transform: uppercase !important;
}

.font-oswald {
    font-family: Oswald, 'Arial Narrow', sans-serif !important;
    font-weight: 600 !important;
}

.font-roboto {
    font-family: 'Roboto Condensed', Arial, sans-serif !important;
    font-weight: 700 !important;
}

/* Text Styles */
.text-style-outline {
    text-shadow: -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000 !important;
}

.text-style-solid .text-content {
    background-color: rgba(0, 0, 0, 0.4) !important;
    padding: 8px 12px !important;
    border-radius: 4px !important;
    display: inline !important;
    box-decoration-break: clone !important;
    -webkit-box-decoration-break: clone !important;
    line-height: 1.6 !important;
}


.text-style-shadow {
    text-shadow: 3px 3px 6px rgba(0,0,0,0.8) !important;
}

/* Color Picker Wrapper */
.color-picker-wrapper {
    position: relative;
    border: 2px solid #ddd;
    border-radius: 6px;
    background: #f8f9fa;
    padding: 0.75rem;
    margin-top: 0.5rem;
    transition: border-color 0.2s;
}

.color-picker-wrapper:hover {
    border-color: #007bff;
}

.color-picker-wrapper .color-input {
    width: 100%;
    height: 40px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin: 0;
    background: transparent;
}

.color-picker-label {
    display: block;
    text-align: center;
    font-size: 0.8rem;
    color: #666;
    margin-top: 0.5rem;
    font-weight: 500;
}

/* Responsive */
@media (max-width: 1024px) {
    .sidebar {
        width: 240px;
    }
    
    .canvas-wrapper {
        padding: 1rem;
    }
    
    .poster-canvas {
        transform: scale(0.8);
        transform-origin: center;
    }
}