/* ============================================================
   Bella Image Creator — Visual Editor CSS
   Adapted from bella-ai-storybook/assets/css/storybook-editor.css
   The .bella-storybook-app parent scope is removed so rules
   apply globally within the fixed-position modal overlay.
   ============================================================ */

/* Modal: hidden state */
.bella-storybook-image-editor[hidden] {
    display: none !important;
}

/* Prevent page scroll while editor is open */
body.bella-storybook-image-editor-open {
    overflow: hidden;
}

/* Full-screen fixed overlay */
.bella-storybook-image-editor {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
}

/* Dim backdrop */
.bella-storybook-image-editor__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.62);
    cursor: pointer;
}

/* Dark dialog */
.bella-storybook-image-editor__dialog {
    position: relative;
    z-index: 1;
    width: min(1440px, 98vw);
    height: min(92vh, 960px);
    max-height: 92vh;
    overflow: hidden;
    padding: 0;
    border-radius: 10px;
    background: #1a1d27;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

@media (max-width: 700px) {
    .bella-storybook-image-editor {
        padding: 10px;
    }
    .bella-storybook-image-editor__dialog {
        max-height: calc(100vh - 20px);
    }
}

/* ============================================================
   Advanced Image Editor (Fabric.js) — bella-adv-* classes
   These selectors are unchanged from the storybook source.
   ============================================================ */

/* Outer shell — fills the dialog flex container */
.bella-adv-editor {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    background: #1a1d27;
    color: #d1d5db;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    font-size: 13px;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
}

/* Top toolbar */
.bella-adv-editor__topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    height: 52px;
    min-height: 52px;
    padding: 0 16px;
    background: #13151f;
    border-bottom: 1px solid #2a2d3e;
    flex: 0 0 auto;
}

.bella-adv-topbar-start { display:flex; align-items:center; gap:10px; flex:0 1 220px; }
.bella-adv-title { font-size: 14px; font-weight: 600; color: #a5b4fc; letter-spacing: 0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bella-adv-topbar-center { display:flex; align-items:center; gap:5px; }
.bella-adv-topbar-end   { display:flex; align-items:center; gap:10px; }

.bella-adv-tbtn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 34px; height: 34px; padding: 0 8px;
    border: 1px solid #2e3248; border-radius: 6px;
    background: #23263a; color: #9ca3af;
    font-size: 17px; font-weight: 500; line-height: 1;
    cursor: pointer; transition: background 0.12s, color 0.12s;
}
.bella-adv-tbtn:hover { background: #2e3248; color: #e2e8f0; }
.bella-adv-tbtn-sep { width: 1px; height: 22px; background: #2a2d3e; margin: 0 5px; }

.bella-adv-zoom-label {
    min-width: 46px; text-align: center;
    font-size: 13px; font-variant-numeric: tabular-nums; color: #6b7280;
}

.bella-adv-save-btn {
    height: 36px; padding: 0 18px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff; border: none; border-radius: 7px;
    font-size: 13px; font-weight: 600; cursor: pointer;
    transition: opacity 0.12s;
}
.bella-adv-save-btn:hover { opacity: 0.88; }
.bella-adv-save-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.bella-adv-close-btn {
    width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: 1px solid #2e3248; border-radius: 6px;
    color: #6b7280; font-size: 16px; cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.bella-adv-close-btn:hover { background: #3f1818; border-color: #7f1d1d; color: #f87171; }

/* Editor body */
.bella-adv-editor__body {
    display: grid;
    grid-template-columns: 68px minmax(0,1fr) 280px;
    grid-template-rows: minmax(0,1fr);
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
}

/* Left tool strip */
.bella-adv-tools {
    display: flex; flex-direction: column; align-items: center;
    gap: 3px; padding: 12px 8px;
    background: #13151f; border-right: 1px solid #2a2d3e;
    overflow-y: auto;
}

.bella-adv-tool-group { display:flex; flex-direction:column; align-items:center; gap:3px; }
.bella-adv-tool-sep { width: 44px; height: 1px; background: #2a2d3e; margin: 6px 0; }

.bella-adv-tool {
    width: 46px; height: 46px; padding: 0;
    display: flex; align-items: center; justify-content: center;
    background: transparent; border: 1px solid transparent; border-radius: 9px;
    color: #6b7280; cursor: pointer;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.bella-adv-tool svg { width: 22px; height: 22px; }
.bella-adv-tool:hover  { background: #23263a; color: #d1d5db; border-color: #2e3248; }
.bella-adv-tool.is-active { background: #312e81; border-color: #6366f1; color: #a5b4fc; }
.bella-adv-tool--soon  { opacity: 0.45; }
.bella-adv-tool--soon:hover { background: #1e2030; color: #9ca3af; border-color: #2e3248; }

.bella-adv-color-row { display:flex; align-items:center; justify-content:center; width:100%; padding:8px 0 6px; }
.bella-adv-color-wrap { position:relative; width:42px; height:42px; border-radius:8px; overflow:hidden; cursor:pointer; border:2px solid #4b5563; }
.bella-adv-color-input { position:absolute; inset:-4px; width:calc(100%+8px); height:calc(100%+8px); opacity:0; cursor:pointer; }
.bella-adv-color-preview { position:absolute; inset:0; border-radius:6px; pointer-events:none; }

.bella-adv-size-row, .bella-adv-opacity-row {
    display:flex; flex-direction:column; align-items:center;
    width:100%; padding:3px 6px;
}
.bella-adv-range { width:50px; height:4px; appearance:none; -webkit-appearance:none; background:#2e3248; border-radius:2px; cursor:pointer; accent-color:#6366f1; }
.bella-adv-range-val { font-size:11px; color:#6b7280; margin-top:3px; font-variant-numeric:tabular-nums; }

/* Canvas area */
.bella-adv-canvas-area {
    position: relative;
    display: flex; align-items: center; justify-content: center;
    background: #0f1117;
    background-image: radial-gradient(circle, #23263a 1px, transparent 1px);
    background-size: 20px 20px;
    overflow: hidden;
}

.bella-adv-canvas-loading {
    position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
    color:#6366f1; font-size:14px; font-weight:500; background:#0f1117; z-index:5;
    transition: opacity 0.25s;
}
.bella-adv-canvas-loading.is-hidden { opacity:0; pointer-events:none; }

.bella-adv-canvas-wrap {
    position: relative;
    box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.bella-adv-canvas-wrap canvas { display: block; }

/* Right panels */
.bella-adv-panels {
    display: flex; flex-direction: column; min-height: 0;
    background: #13151f; border-left: 1px solid #2a2d3e;
    overflow: hidden;
}

.bella-adv-panel-tabs {
    display: flex; flex-shrink: 0;
    border-bottom: 1px solid #2a2d3e;
}
.bella-adv-panel-tab {
    flex: 1; height: 44px; padding: 0 2px;
    background: transparent; border: none; border-bottom: 2px solid transparent;
    color: #6b7280; font-size: 12px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.03em; cursor: pointer;
    transition: color 0.1s, border-color 0.1s;
}
.bella-adv-panel-tab:hover  { color: #d1d5db; }
.bella-adv-panel-tab.is-active { color: #a5b4fc; border-bottom-color: #6366f1; }

.bella-adv-panel {
    flex: 1 1 0; min-height: 0; overflow-y: auto;
    padding: 12px;
    display: flex; flex-direction: column; gap: 8px;
}
.bella-adv-panel[hidden] { display: none; }

/* Layers panel */
.bella-adv-panel-actions {
    display: flex; gap: 8px; padding-bottom: 10px;
    border-bottom: 1px solid #2a2d3e; flex-shrink: 0;
}
.bella-adv-panel-btn {
    width: 34px; height: 34px; padding: 0;
    display:inline-flex; align-items:center; justify-content:center;
    background: #23263a; border: 1px solid #2e3248; border-radius: 6px;
    color: #9ca3af; cursor: pointer;
    transition: background 0.1s, color 0.1s;
}
.bella-adv-panel-btn svg { width: 15px; height: 15px; }
.bella-adv-panel-btn:hover { background: #2e3248; color: #e2e8f0; }
.bella-adv-panel-btn--danger:hover { background: #3f1818; border-color: #7f1d1d; color: #f87171; }

.bella-adv-layers-list, .bella-adv-history-list {
    flex: 1 1 0; overflow-y: auto;
    display: flex; flex-direction: column; gap: 4px;
}

.bella-adv-layer-row {
    display: grid;
    grid-template-columns: 26px 1fr 64px 30px;
    align-items: center;
    gap: 6px;
    padding: 8px 8px;
    border-radius: 6px;
    background: #1e2030;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.1s;
}
.bella-adv-layer-row:hover   { background: #23263a; }
.bella-adv-layer-row.is-active { background: #1e1b4b; border-color: #6366f1; }

.bella-adv-layer-vis { background: none; border: none; padding: 0; font-size: 15px; cursor: pointer; line-height: 1; color: inherit; }
.bella-adv-layer-name { font-size: 12px; color: #d1d5db; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bella-adv-layer-opacity { width: 100%; height: 4px; accent-color: #6366f1; cursor: pointer; }
.bella-adv-layer-opacity-val { font-size: 11px; color: #6b7280; text-align:right; font-variant-numeric:tabular-nums; }

/* History panel */
.bella-adv-history-row {
    padding: 8px 10px; border-radius: 6px;
    font-size: 12px; color: #9ca3af;
    cursor: pointer; background: #1e2030;
    transition: background 0.1s;
}
.bella-adv-history-row:hover  { background: #23263a; color: #d1d5db; }
.bella-adv-history-row.is-current { background: #1e1b4b; color: #a5b4fc; font-weight: 600; }

/* Adjustments panel */
.bella-adv-panel-hint { font-size: 12px; color: #6b7280; line-height: 1.4; margin: 0 0 4px; }
.bella-adv-adj-row { display: grid; grid-template-columns: 80px 1fr 36px; align-items: center; gap: 8px; }
.bella-adv-adj-label { font-size: 12px; color: #9ca3af; }
.bella-adv-adj-slider {
    width: 100%; height: 4px; accent-color: #6366f1;
    appearance: none; -webkit-appearance: none;
    background: #2e3248; border-radius: 2px; cursor: pointer;
}
.bella-adv-adj-val { font-size: 11px; color: #6b7280; text-align:right; font-variant-numeric:tabular-nums; }
.bella-adv-adj-apply {
    margin-top: 8px; width: 100%; height: 36px;
    background: #312e81; border: 1px solid #6366f1; border-radius: 5px;
    color: #a5b4fc; font-size: 12px; font-weight: 600; cursor: pointer;
    transition: background 0.12s;
}
.bella-adv-adj-apply:hover { background: #3730a3; }
.bella-adv-adj-reset {
    width: 100%; height: 26px;
    background: transparent; border: 1px solid #2e3248; border-radius: 5px;
    color: #6b7280; font-size: 11px; cursor: pointer;
}

/* AI panel */
.bella-adv-ai-tools { display:flex; flex-direction:column; gap:8px; }
.bella-adv-ai-btn {
    display: flex; align-items: center; gap: 10px;
    height: 42px; padding: 0 14px;
    background: #1e2030; border: 1px solid #2e3248; border-radius: 8px;
    color: #9ca3af; font-size: 13px; cursor: pointer;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.bella-adv-ai-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.bella-adv-ai-btn:hover { background: #23263a; color: #e2e8f0; border-color: #6366f1; }
.bella-adv-ai-note { font-size: 11px; color: #4b5563; margin: 6px 0 0; font-style: italic; }
.bella-adv-ai-prompt-wrap { display:flex; flex-direction:column; gap:8px; }
.bella-adv-ai-prompt {
    resize: vertical; min-height: 64px;
    background: #1e2030; border: 1px solid #2e3248; border-radius: 6px;
    color: #d1d5db; font-size: 13px; padding: 8px 10px;
}
.bella-adv-ai-run {
    height: 36px; background: #312e81; border: 1px solid #6366f1; border-radius: 6px;
    color: #a5b4fc; font-size: 13px; font-weight: 600; cursor: pointer;
}

/* Status bar */
.bella-adv-editor__statusbar {
    display: flex; align-items: center; gap: 16px;
    height: 28px; min-height: 28px; padding: 0 14px;
    background: #0d0f1a; border-top: 1px solid #2a2d3e;
    font-size: 12px; color: #6b7280; flex: 0 0 auto;
}
.bella-adv-statusbar-size { color: #4b5563; margin-left: auto; }

/* Responsive: hide right panels on narrow screens */
@media (max-width: 680px) {
    .bella-adv-editor__body { grid-template-columns: 60px minmax(0,1fr); }
    .bella-adv-panels { display: none; }
}
