/* ========================================
   AI Image Editor - Modern Dark Theme
   ======================================== */

:root {
    --bg-primary: #0f0f14;
    --bg-secondary: #16161d;
    --bg-tertiary: #1c1c26;
    --bg-elevated: #22222e;
    --bg-hover: #2a2a38;
    
    --border-color: #2d2d3a;
    --border-light: #3d3d4a;
    
    --accent: #8b5cf6;
    --accent-hover: #a78bfa;
    --accent-glow: rgba(139, 92, 246, 0.3);
    
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    
    --text-primary: #f1f1f4;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    
    --mask-color: rgba(0, 255, 100, 0.35);  /* Зелёный полупрозрачный */
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    
    --sidebar-width: 240px;
    --toolbar-height: 52px;
    --prompt-height: 100px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    font-size: 14px;
}

/* ========== Layout ========== */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ========== Sidebars ========== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-color: var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-left {
    border-right: 1px solid var(--border-color);
}

.sidebar-right {
    width: 280px;
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-icon-text {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon-text:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

/* Sessions List */
.sessions-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.session-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 4px;
}

.session-item:hover {
    background: var(--bg-hover);
}

.session-item.active {
    background: var(--accent-glow);
    border: 1px solid var(--accent);
}

.session-thumb {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    background: var(--bg-tertiary);
}

.session-info {
    flex: 1;
    min-width: 0;
}

.session-title {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-date {
    font-size: 11px;
    color: var(--text-muted);
}

/* ========== Main Area ========== */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-primary);
}

/* ========== Toolbar ========== */
.toolbar {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    height: var(--toolbar-height);
    gap: 8px;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.toolbar-divider {
    width: 1px;
    height: 28px;
    background: var(--border-color);
    margin: 0 8px;
}

.toolbar-spacer {
    flex: 1;
}

.btn-tool {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 36px;
    height: 36px;
    padding: 0 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-tool:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-light);
}

.btn-tool.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.btn-tool:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-tool i {
    font-size: 14px;
}

.toolbar-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: 8px;
}

.slider-mini {
    width: 80px;
    height: 4px;
    -webkit-appearance: none;
    background: var(--bg-tertiary);
    border-radius: 2px;
    cursor: pointer;
}

.slider-mini::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.15s;
}

.slider-mini::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.slider-value {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 30px;
}

/* ========== Canvas Wrapper ========== */
.canvas-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow: hidden;
    position: relative;
    background: 
        repeating-conic-gradient(var(--bg-tertiary) 0% 25%, var(--bg-secondary) 0% 50%) 
        50% / 20px 20px;
}

/* Drop Zone */
.drop-zone {
    width: 100%;
    max-width: 500px;
    aspect-ratio: 4/3;
    border: 2px dashed var(--border-light);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    background: rgba(0, 0, 0, 0.2);
}

.drop-zone.drag-over {
    border-color: var(--accent);
    background: var(--accent-glow);
    transform: scale(1.02);
}

.drop-zone-inner {
    text-align: center;
    color: var(--text-secondary);
}

.drop-zone-inner i {
    font-size: 56px;
    color: var(--accent);
    margin-bottom: 16px;
}

.drop-zone-inner h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.drop-zone-inner p {
    font-size: 14px;
    margin-bottom: 12px;
}

.drop-zone-inner .formats {
    font-size: 12px;
    color: var(--text-muted);
}

/* Canvas Container */
.canvas-container {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.canvas-container canvas {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - var(--toolbar-height) - var(--prompt-height) - 80px);
}

#mainCanvas {
    position: relative;
    z-index: 1;
}

#maskCanvas {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    cursor: crosshair;
    /* Прозрачность управляется через JS */
    opacity: 0.25;
}

/* Brush Cursor */
.brush-cursor {
    position: fixed;
    border: 2px solid rgba(255, 50, 50, 0.8);
    border-radius: 50%;
    pointer-events: none;
    z-index: 1000;
    display: none;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px rgba(255, 50, 50, 0.3);
}

.canvas-container:hover .brush-cursor {
    display: block;
}

/* ========== Prompt Bar ========== */
.prompt-bar {
    padding: 12px 20px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.prompt-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.prompt-wrapper textarea {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    transition: border-color 0.2s;
    min-height: 44px;
    max-height: 100px;
}

.prompt-wrapper textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.prompt-wrapper textarea::placeholder {
    color: var(--text-muted);
}

.btn-generate {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-generate:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--accent-glow);
}

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

.prompt-hints {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.hint-chip {
    padding: 5px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}

.hint-chip:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

/* ========== Right Panel Sections ========== */
.panel-section {
    border-bottom: 1px solid var(--border-color);
}

.section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s;
}

.section-header:hover {
    background: var(--bg-hover);
}

.section-header i {
    color: var(--accent);
    width: 16px;
}

.ref-count {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
}

.section-content {
    padding: 0 16px 16px;
}

.form-group {
    margin-bottom: 14px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.select-styled {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: border-color 0.15s;
}

.select-styled:focus {
    outline: none;
    border-color: var(--accent);
}

.select-styled option {
    background: var(--bg-secondary);
}

/* References Grid */
.references-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.ref-slot {
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
    position: relative;
    background: var(--bg-tertiary);
}

.ref-slot img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ref-slot .remove-ref {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 10px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ref-slot:hover .remove-ref {
    opacity: 1;
}

.add-ref {
    border: 2px dashed var(--border-light);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
    color: var(--text-muted);
}

.add-ref:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.hint-text {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 10px;
}

/* Results Grid */
.results-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.result-item {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.15s;
}

.result-item:hover {
    transform: scale(1.03);
}

.result-item.selected {
    border-color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}

.result-item img {
    width: 100%;
    display: block;
}

.section-actions {
    padding: 12px 16px;
    display: flex;
    gap: 8px;
}

.btn-action {
    flex: 1;
    padding: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-action:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-action:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-action.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.btn-action.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

/* ========== Modal ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(8px);
}

.modal-loading {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 40px 50px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto 20px;
    animation: spin 1s linear infinite;
}

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

.modal-loading p {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 8px;
}

.loading-hint {
    font-size: 13px;
    color: var(--text-muted);
}

/* ========== Toast ========== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 12px 18px;
    border-radius: var(--radius-md);
    color: white;
    font-size: 13px;
    font-weight: 500;
    animation: slideIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
.toast.info { background: var(--accent); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ========== Responsive ========== */
@media (max-width: 1200px) {
    .sidebar-left {
        width: 200px;
    }
    .sidebar-right {
        width: 260px;
    }
}

@media (max-width: 900px) {
    .sidebar-left {
        display: none;
    }
    .sidebar-right {
        width: 240px;
    }
}
