:root {
    --bg-color: #121212;
    --surface-color: #1e1e1e;
    --surface-hover: #2d2d2d;
    --primary-color: #8a63f5;
    --primary-hover-color: #a081f7;
    --text-color: #e0e0e0;
    --text-secondary-color: #a0a0a0;
    --border-color: #333333;
    --input-bg: #252525;
    --error-color: #ff5252;
    --success-color: #4caf50;
    
    --header-height: 50px;
    --footer-height: 60px;
    --border-radius: 12px;
    --gap-size: 1.5rem;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    width: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    font-size: 16px;
    line-height: 1.5;
    overflow: hidden; /* Prevent body scroll, use containers */
}

body.no-scroll {
    overflow: hidden !important;
}

.hidden { display: none !important; }
.hidden-field { display: none !important; }

/* --- Layout --- */
.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
}

/* --- Header --- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1.5rem;
    height: var(--header-height);
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
    margin: 0;
}

.logout-link {
    color: var(--text-secondary-color);
    text-decoration: none;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.logout-link:hover {
    color: var(--text-color);
    background-color: var(--border-color);
}

/* --- Main Content --- */
.main-content {
    flex-grow: 1;
    display: grid;
    grid-template-columns: 550px 1fr; /* Fixed sidebar width */
    gap: var(--gap-size);
    padding: var(--gap-size);
    overflow: hidden; /* Contains scrolling parts */
}

/* Panels */
.controls-panel, .result-panel {
    background-color: var(--surface-color);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden; 
}

.controls-panel {
    padding: 1.25rem;
}

.result-panel {
    padding: 0;
    background-color: #000;
    position: relative;
}

h2 {
    font-size: 1.1rem;
    margin: 0 0 1rem 0;
    color: var(--text-color);
    font-weight: 600;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

/* --- Form --- */
#generation-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    overflow-y: auto;
    height: 100%;
    padding-right: 5px; /* space for scrollbar */
    
    /* Scrollbar styling */
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

#generation-form::-webkit-scrollbar { width: 6px; }
#generation-form::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 3px; }

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary-color);
}

/* Inputs & Selects */
input[type="text"], 
input[type="number"], 
input[type="password"], 
textarea, 
select {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(138, 99, 245, 0.25);
}

textarea {
    resize: vertical;
    min-height: 100px;
    line-height: 1.4;
}

/* Custom Resolution Fields */
.res-inputs {
    display: flex;
    gap: 10px;
}

.res-single-input {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.res-single-input span {
    font-size: 0.75rem;
    color: var(--text-secondary-color);
}

/* Checkbox Style */
.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 5px;
    cursor: pointer;
    user-select: none;
    padding: 8px 12px;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: background-color 0.2s;
}

.checkbox-wrapper:hover {
    background-color: var(--surface-hover);
}

.checkbox-wrapper input[type="checkbox"] {
    appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--text-secondary-color);
    border-radius: 4px;
    background-color: transparent;
    cursor: pointer;
    position: relative;
    margin: 0;
}

.checkbox-wrapper input[type="checkbox"]:checked {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.checkbox-wrapper input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    color: white;
    font-size: 12px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: bold;
}

.checkbox-label {
    font-size: 0.9rem;
    color: var(--text-color);
}

/* --- Drop Zone --- */
.drop-zone-wrapper {
    display: block;
    cursor: pointer;
}

.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    position: relative;
    min-height: 130px;
    background-color: var(--input-bg);
    transition: all 0.2s;
}

.drop-zone:hover, .drop-zone.dragging-over {
    border-color: var(--primary-color);
    background-color: rgba(138, 99, 245, 0.05);
}

.drop-zone-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-secondary-color);
    position: absolute;
    inset: 0;
}

.drop-zone.has-files .drop-zone-prompt { opacity: 0; pointer-events: none; }

#preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 8px;
    position: relative;
    z-index: 2;
}

.preview-thumbnail {
    position: relative;
    aspect-ratio: 1;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.preview-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(0,0,0,0.7);
    color: white;
    border: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}

.preview-thumbnail:hover .remove-btn { opacity: 1; }

/* --- Prompt Actions --- */
.prompt-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.secondary-button {
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-secondary-color);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.secondary-button:hover:not(:disabled) {
    background-color: var(--surface-hover);
    color: var(--text-color);
    border-color: var(--text-secondary-color);
}

.secondary-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --- Result Area --- */
.image-display-area {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #000;
    position: relative;
    overflow: hidden;
}

#result-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    cursor: zoom-in;
}

.placeholder-text {
    color: var(--text-secondary-color);
    font-size: 0.9rem;
}

.result-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.95) 20%, rgba(0,0,0,0.6) 80%, transparent);
    padding: 1.5rem 1.5rem 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    z-index: 10;
}

.result-actions-group {
    display: flex;
    gap: 12px;
    align-items: center;
}

.result-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-family: monospace;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.8);
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.download-button {
    background-color: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 12px; /* Чуть более квадратные кнопки */
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    backdrop-filter: blur(6px);
    cursor: pointer;
    padding: 0;
}

.download-button:hover {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(138, 99, 245, 0.4);
}

.download-button svg {
    fill: white;
    width: 24px; 
    height: 24px;
}

/* --- Footer Actions --- */
.action-bar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.5rem;
    height: var(--footer-height);
    background-color: var(--surface-color);
    border-top: 1px solid var(--border-color);
}

.clear-all-button {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background-color: var(--input-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.clear-all-button svg { fill: var(--text-secondary-color); }

.clear-all-button:hover {
    background-color: var(--error-color);
    border-color: var(--error-color);
}
.clear-all-button:hover svg { fill: white; }

.submit-button {
    flex-grow: 1;
    height: 42px;
    padding: 0 2rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.submit-button:hover:not(:disabled) { background-color: var(--primary-hover-color); }
.submit-button:disabled { background-color: #444; color: #888; cursor: not-allowed; }

/* --- Spinner --- */
.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Lightbox --- */
.lightbox {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}
.lightbox-content {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
}
.close-lightbox {
    position: absolute;
    top: 20px;
    right: 30px;
    color: #fff;
    font-size: 40px;
    cursor: pointer;
    z-index: 2001;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 900px) {
    .main-content {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        padding: 0.35rem;
    }
    
    .controls-panel {
        order: 2;
        flex: 1;
        max-height: none;
    }
    
    .result-panel {
        order: 1;
        height: 40vh; /* Fixed height for image area on mobile */
        flex: none;
        border-radius: var(--border-radius);
    }

    .res-inputs {
        flex-direction: row; /* Keep inputs side-by-side even on mobile */
    }

    .controls-panel {
        padding: 0.75rem 0.25rem 0.75rem 0.75rem;
    }
    #generation-form {
        padding-right: 0.5rem;
    };
    
    #orientation-lock { display: none; }
    
    @media (orientation: landscape) {
        #orientation-lock {
            display: flex;
            position: fixed;
            inset: 0;
            background-color: var(--bg-color);
            color: var(--text-color);
            align-items: center;
            justify-content: center;
            text-align: center;
            z-index: 3000;
            padding: 20px;
        }
        .container { display: none; }
    }
}

/* Toast */
#toast-container {
    position: fixed;
    bottom: 80px;
    right: 20px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 12px 16px;
    border-radius: 8px;
    color: #fff;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background-color: var(--error-color); }
.toast.success { background-color: var(--success-color); }