/* -----------------------------------------------------------------------
   Bella Image Creator — editor stylesheet
   Mirrors the bella-ai-storybook image panel UI, scoped to .bella-ic-wrap
   ----------------------------------------------------------------------- */

/* ---- Root wrapper ---- */
.bella-ic-wrap {
    box-sizing: border-box;
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 20px;
    color: #111827;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, Helvetica, sans-serif;
    background: #f4f5f8;
}

.bella-ic-wrap *,
.bella-ic-wrap *::before,
.bella-ic-wrap *::after {
    box-sizing: border-box;
}

/* ---- Access notice ---- */
.bella-ic-access-notice {
    padding: 16px;
    border: 1px solid #f2d7a0;
    background: #fff8e6;
    color: #6b4a12;
    border-radius: 8px;
}

/* ---- Generation error notice ---- */
.bella-ic-gen-error-notice {
    margin-bottom: 16px;
    padding: 12px 18px;
    background: #fef2f2;
    border: 1px solid #fca5a5;
    border-radius: 6px;
    color: #991b1b;
    font-size: 0.92rem;
}

/* ---- Generated success notice ---- */
.bella-ic-generated-notice {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1e3a8a;
}

/* ---- Saved success notice ---- */
.bella-ic-saved-notice {
    margin-bottom: 16px;
    padding: 12px 18px;
    background: #ecfdf5;
    border: 1px solid #6ee7b7;
    border-radius: 6px;
    color: #065f46;
    font-size: 0.92rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.bella-ic-saved-notice a {
    color: #047857;
    text-decoration: underline;
}

.bella-ic-saved-notice__icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

/* ---- Editor grid ---- */
.bella-ic-editor-grid {
    display: grid;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.25fr) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
    max-width: 100%;
    box-sizing: border-box;
}

/* Prevent any grid child from forcing the grid wider than its container */
.bella-ic-editor-grid > * {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

/* Full-width rows */
.bella-ic-editor-grid > .bella-ic-lower-panel {
    grid-column: 1 / -1;
}

/* ---- Columns ---- */
.bella-ic-left-panel,
.bella-ic-center-panel,
.bella-ic-right-panel {
    min-width: 0;
    max-width: 100%;
}

.bella-ic-left-panel,
.bella-ic-center-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.bella-ic-right-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* ---- Cards (shared border/bg) ---- */
.bella-ic-card {
    border: 1px solid #d8e0ea;
    border-radius: 8px;
    background: #fff;
    padding: 12px 14px;
}

.bella-ic-card-title,
.bella-ic-card-label {
    margin: 0 0 6px 0;
    font-weight: 700;
    font-size: 0.92rem;
    color: #1d2327;
}

.bella-ic-card-help {
    margin: 0 0 6px 0;
    font-size: 0.8rem;
    color: #6b7280;
    line-height: 1.4;
}

.bella-ic-card-note {
    margin: 4px 0 0 0;
    font-size: 0.78rem;
    color: #6b7280;
}

/* ---- Story text card ---- */
.bella-ic-story-card .bella-ic-story-text {
    width: 100%;
    max-width: 100%;
    min-height: 100px;
    padding: 8px 10px;
    border: 1px solid #c8d0d8;
    border-radius: 4px;
    font-size: 0.88rem;
    line-height: 1.5;
    resize: vertical;
    box-sizing: border-box;
}

/* ---- Picture Idea / Required Elements 2-up grid ---- */
.bella-ic-idea-grid {
    display: grid;
    gap: 14px;
}

.bella-ic-elements-card {
    background: #f0fdf4;
    border-color: #bbf7d0;
}

.bella-ic-card-textarea {
    width: 100%;
    max-width: 100%;
    min-height: 90px;
    padding: 8px 10px;
    border: 1px solid #c8d0d8;
    border-radius: 4px;
    font-size: 0.85rem;
    line-height: 1.5;
    resize: vertical;
    box-sizing: border-box;
}

.bella-ic-elements-card .bella-ic-card-textarea {
    border-color: #a7f3d0;
    background: #ffffff;
}

/* ---- Save buttons (small secondary) ---- */
.bella-ic-save-btn {
    margin-top: 8px;
    padding: 5px 10px;
    font-size: 0.82rem;
}

/* ---- Final prompt preview (admin) ---- */
.bella-ic-prompt-preview-panel summary {
    font-size: 0.85rem;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    padding: 6px 0;
}

.bella-ic-prompt-pre {
    margin: 8px 0 0 0;
    padding: 10px;
    background: #f8f9fa;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 0.82rem;
    white-space: pre-wrap;
    word-break: break-word;
    color: #374151;
}

/* ---- Generation panel (center) ---- */
.bella-ic-generation-panel {
    border: 1px solid #d8e0ea;
    border-radius: 8px;
    background: #fff;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.bella-ic-gen-title {
    margin: 0 0 4px 0;
    font-weight: 700;
    font-size: 1rem;
    color: #1d2327;
}

.bella-ic-gen-intro {
    margin: 0 0 14px 0;
    font-size: 0.85rem;
    color: #50575e;
}

/* ---- Setting card (provider, model, background) ---- */
.bella-ic-setting-card {
    margin-bottom: 14px;
    padding: 10px 12px;
    border: 1px solid #d0dde8;
    background: #f8fafc;
    border-radius: 6px;
}

.bella-ic-setting-card--white {
    background: #ffffff;
}

.bella-ic-setting-card label,
.bella-ic-setting-label {
    display: block;
    margin: 0 0 6px 0;
    font-weight: 700;
    font-size: 0.92rem;
    color: #1d2327;
}

.bella-ic-setting-card p,
.bella-ic-setting-help {
    margin: 0 0 8px 0;
    font-size: 0.82rem;
    color: #555;
}

.bella-ic-setting-select {
    width: 100%;
    max-width: 100%;
    padding: 8px 10px;
    border: 1px solid #c8d0d8;
    border-radius: 5px;
    font-size: 0.92rem;
    background: #fff;
    box-sizing: border-box;
}

/* ---- Image title input ---- */
.bella-ic-gen-title-label {
    display: block;
    margin: 0 0 5px 0;
    font-weight: 700;
    font-size: 0.92rem;
}

.bella-ic-title-input {
    width: 100%;
    max-width: 100%;
    padding: 8px 10px;
    border: 1px solid #c8d0d8;
    border-radius: 5px;
    font-size: 0.92rem;
    margin-bottom: 4px;
    box-sizing: border-box;
}

.bella-ic-title-help {
    margin: 0 0 14px 0;
    font-size: 0.78rem;
    color: #6b7280;
}

/* ---- Generation notices ---- */
.bella-ic-gen-notices {
    margin-bottom: 14px;
}

.bella-ic-notice {
    padding: 8px 10px;
    border-radius: 5px;
    font-size: 0.82rem;
    margin-bottom: 6px;
}

.bella-ic-notice--info {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
}

.bella-ic-notice--warning {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #92400e;
}

.bella-ic-notice p {
    margin: 0;
}

/* ---- Generation action buttons ---- */
.bella-ic-gen-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

/* ---- Save Draft button ---- */
.bella-ic-btn-save {
    padding: 8px 20px;
    border: 2px solid #2271b1;
    border-radius: 4px;
    background: #ffffff;
    color: #2271b1;
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.bella-ic-btn-save:hover {
    background: #2271b1;
    color: #ffffff;
}

.bella-ic-btn-generate {
    padding: 8px 18px;
    border: 1px solid #55606d;
    border-radius: 4px;
    background: #55606d;
    color: #fff;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.bella-ic-btn-generate:hover {
    background: #3c4754;
}

.bella-ic-btn-regenerate {
    padding: 8px 18px;
    border: 1px solid #2271b1;
    border-radius: 4px;
    background: #2271b1;
    color: #fff;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.bella-ic-btn-regenerate:hover {
    background: #135e96;
}

.bella-ic-btn-generate:disabled,
.bella-ic-btn-regenerate:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ---- Image stage (center) ---- */
.bella-ic-image-stage {
    border: 1px solid #d8e0ea;
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
}

.bella-ic-image-stage__header {
    padding: 10px 14px 6px;
    border-bottom: 1px solid #f0f2f5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.bella-ic-image-stage__heading {
    margin: 0;
    font-weight: 700;
    font-size: 0.92rem;
    color: #1d2327;
}

.bella-ic-image-stage__frame {
    padding: 12px;
    text-align: center;
}

.bella-ic-image-stage__frame img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    display: block;
    margin: 0 auto;
}

.bella-ic-image-stage-placeholder {
    padding: 40px 20px;
    text-align: center;
    color: #9ca3af;
    font-size: 0.9rem;
}

.bella-ic-image-stage-placeholder svg {
    display: block;
    margin: 0 auto 10px;
    opacity: 0.35;
}

/* ---- Style cards (reuse storybook class names for JS compat) ---- */
.bella-storybook-style-cards {
    border: 1px solid #d8e0ea;
    border-radius: 8px;
    background: #fff;
    padding: 12px 14px;
    min-width: 0;
    max-width: 100%;
}

.bella-storybook-style-cards__header {
    margin-bottom: 10px;
}

.bella-storybook-style-cards__header h4 {
    margin: 0;
    font-size: 0.92rem;
    font-weight: 700;
    color: #1d2327;
}

.bella-storybook-style-card-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
}

.bella-storybook-style-card {
    padding: 8px 10px;
    border: 2px solid #d1d5db;
    border-radius: 6px;
    background: #fafafa;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s, background 0.15s;
    display: flex;
    flex-direction: column;
    gap: 3px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: normal;
}

.bella-storybook-style-card:hover {
    border-color: #6b7280;
    background: #f3f4f6;
}

.bella-storybook-style-card.is-selected {
    border-color: #2271b1;
    background: #eff6ff;
}

.bella-storybook-style-card__label {
    display: block;
    font-size: 0.82rem;
    font-weight: 700;
    color: #1d2327;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.25;
}

.bella-storybook-style-card__helper {
    display: block;
    font-size: 0.75rem;
    color: #6b7280;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.25;
}

.bella-storybook-style-card.is-selected .bella-storybook-style-card__label {
    color: #1e40af;
}

/* ---- Advanced Picture Controls / collapsible panels ---- */
.bella-ic-collapsible {
    border: 1px solid #d8e0ea;
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
}

.bella-ic-collapsible > summary {
    padding: 10px 14px;
    font-size: 0.88rem;
    font-weight: 700;
    color: #1d2327;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}

.bella-ic-collapsible > summary::-webkit-details-marker {
    display: none;
}

.bella-ic-collapsible > summary::after {
    content: '+';
    font-size: 1rem;
    font-weight: 400;
    color: #6b7280;
    flex-shrink: 0;
}

.bella-ic-collapsible[open] > summary::after {
    content: '−';
}

.bella-ic-collapsible-body {
    padding: 12px 14px 14px;
    border-top: 1px solid #f0f2f5;
}

/* ---- Design ribbon fieldsets ---- */
.bella-ic-ribbon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    align-items: start;
    min-width: 0;
    max-width: 100%;
}

.bella-ic-ribbon-fieldset {
    margin: 0;
    padding: 10px;
    border: 1px solid #d8e0ea;
    background: #ffffff;
    border-radius: 6px;
}

.bella-ic-ribbon-fieldset legend {
    padding: 0 5px;
    font-weight: 700;
    font-size: 0.85rem;
    color: #374151;
}

.bella-ic-ribbon-fieldset .bella-ic-field-grid {
    display: grid;
    gap: 8px;
}

.bella-ic-field-row {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.bella-ic-field-row label {
    font-size: 0.82rem;
    font-weight: 700;
    color: #374151;
}

.bella-ic-field-select,
.bella-ic-field-input {
    width: 100%;
    max-width: 100%;
    min-height: 34px;
    padding: 5px 8px;
    border: 1px solid #c8d0d8;
    border-radius: 4px;
    background: #ffffff;
    font-size: 0.85rem;
    box-sizing: border-box;
}

.bella-ic-fx-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 5px 8px;
}

.bella-ic-fx-grid label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.82rem;
    line-height: 1.25;
    font-weight: 400;
}

/* ---- Lower-panel accordions (full-width) ---- */
.bella-ic-lower-panel {
    border: 1px solid #d8e0ea;
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
}

.bella-ic-lower-panel > summary {
    padding: 12px 16px;
    font-size: 0.9rem;
    font-weight: 700;
    color: #1d2327;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}

.bella-ic-lower-panel > summary::-webkit-details-marker {
    display: none;
}

.bella-ic-lower-panel > summary::after {
    content: '+';
    font-size: 1rem;
    font-weight: 400;
    color: #6b7280;
}

.bella-ic-lower-panel[open] > summary::after {
    content: '−';
}

.bella-ic-lower-body {
    padding: 14px 16px;
    border-top: 1px solid #f0f2f5;
    font-size: 0.88rem;
    color: #6b7280;
}

.bella-ic-lower-body p {
    margin: 0 0 6px 0;
}

/* ---- Responsive ---- */

/*
 * At 1200px: switch to 2 columns (left+center side by side, right panel
 * stacks below spanning full width).
 */
@media (max-width: 1200px) {
    .bella-ic-editor-grid {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
        gap: 16px;
    }
    .bella-ic-left-panel   { grid-column: 1; grid-row: 1; }
    .bella-ic-center-panel { grid-column: 2; grid-row: 1; }
    .bella-ic-right-panel  { grid-column: 1 / -1; grid-row: 2; }
    .bella-ic-editor-grid > .bella-ic-lower-panel { grid-column: 1 / -1; }

}

/* ---- Version History ---- */
.bella-ic-version-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    min-width: 0;
}

.bella-ic-version-card {
    display: flex;
    flex-direction: column;
    gap: 0;
    border: 2px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
    min-width: 0;
}

.bella-ic-version-card--selected {
    border-color: #2271b1;
    background: #eff6ff;
}

.bella-ic-version-thumb {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
    border-bottom: 1px solid #e5e7eb;
    background: #f4f5f8;
}

.bella-ic-version-meta {
    padding: 8px 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.82rem;
    color: #555;
    min-width: 0;
}

.bella-ic-version-meta p {
    margin: 0;
    overflow-wrap: anywhere;
    line-height: 1.35;
}

.bella-ic-version-meta__title {
    font-weight: 700;
    color: #1d2327;
    font-size: 0.85rem;
}

.bella-ic-version-meta__filename {
    font-size: 0.76rem;
    color: #6b7280;
    overflow-wrap: anywhere;
    word-break: break-all;
}

.bella-ic-version-badge {
    display: inline-block;
    margin-top: 6px;
    padding: 3px 8px;
    border-radius: 4px;
    background: #dcfce7;
    color: #166534;
    font-size: 0.78rem;
    font-weight: 700;
}

/* ---- Use This Image / action buttons (also used in upload) ---- */
.bella-ic-btn-use-image {
    display: inline-block;
    margin-top: 8px;
    padding: 6px 14px;
    border: none;
    border-radius: 4px;
    background: #2271b1;
    color: #fff;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.bella-ic-btn-use-image:hover {
    background: #135e96;
}

.bella-ic-btn-use-image:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ---- Upload form ---- */
.bella-ic-upload-form {
    max-width: 560px;
}

.bella-ic-upload-row {
    margin-bottom: 10px;
}

.bella-ic-upload-title-input {
    width: 100%;
    max-width: 100%;
    padding: 8px 10px;
    border: 1px solid #c8d0d8;
    border-radius: 5px;
    font-size: 0.92rem;
    box-sizing: border-box;
}

.bella-ic-upload-file-input {
    display: block;
    width: 100%;
    font-size: 0.86rem;
}

.bella-ic-upload-status {
    margin-top: 8px;
    font-size: 0.88rem;
    color: #555;
    min-height: 1.2em;
}

/* ---- Library search results ---- */
.bella-ic-library-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 14px;
    min-width: 0;
}

.bella-ic-library-card {
    display: flex;
    flex-direction: column;
    gap: 0;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    overflow: hidden;
    min-width: 0;
}

.bella-ic-library-thumb {
    width: 100%;
    height: 100px;
    object-fit: cover;
    display: block;
    background: #f4f5f8;
    border-bottom: 1px solid #e5e7eb;
}

.bella-ic-library-card__meta {
    padding: 6px 8px 8px;
    font-size: 0.78rem;
    color: #444;
    overflow-wrap: anywhere;
    word-break: break-all;
    line-height: 1.3;
}

.bella-ic-library-card__meta p {
    margin: 0 0 4px 0;
}

/* ---- Selected Image Asset cards ---- */
.bella-ic-asset-card {
    width: 160px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    align-items: stretch;
    padding: 8px;
    border: 1px solid #c7dfce;
    background: #fff;
    border-radius: 6px;
    min-width: 0;
}

.bella-ic-asset-thumb {
    width: 100%;
    height: 100px;
    object-fit: cover;
    border-radius: 5px;
    border: 2px solid #9cccaa;
    background: #f4f5f8;
    display: block;
}

.bella-ic-asset-filename {
    margin: 0;
    font-size: 0.78rem;
    color: #444;
    overflow-wrap: anywhere;
    word-break: break-all;
    line-height: 1.3;
}

.bella-ic-btn-remove-asset {
    padding: 5px 10px;
    font-size: 0.78rem;
    background: #fff;
    color: #7a1e1e;
    border: 1px solid #d7a9a9;
    border-radius: 4px;
    cursor: pointer;
}

.bella-ic-btn-remove-asset:hover {
    background: #fdf0f0;
}

.bella-ic-btn-save-pack {
    padding: 5px 10px;
    font-size: 0.78rem;
    background: #6b4fa3;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.bella-ic-btn-save-pack:hover {
    background: #5a4090;
}

.bella-ic-btn-save-pack:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ---- Character / Asset Pack cards ---- */
.bella-ic-pack-card {
    width: 160px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    align-items: stretch;
    padding: 8px;
    border: 1px solid #d8d0e6;
    background: #fff;
    border-radius: 6px;
    min-width: 0;
}

.bella-ic-pack-thumb {
    width: 100%;
    height: 100px;
    object-fit: cover;
    border-radius: 5px;
    border: 2px solid #c4b8e0;
    background: #f8f6ff;
    display: block;
}

.bella-ic-pack-name {
    margin: 0;
    font-size: 0.82rem;
    font-weight: 700;
    color: #1d2327;
    overflow-wrap: anywhere;
}

.bella-ic-pack-type {
    margin: 0;
    font-size: 0.76rem;
    color: #6b7280;
    text-transform: capitalize;
}

/* ================================================
   Card action rows (Save Picture Idea, Save Required Story Elements, Save Draft)
   ================================================ */

.bella-ic-card-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}

.bella-ic-btn-save-field {
    padding: 6px 14px;
    border: 1px solid #1d6f42;
    border-radius: 6px;
    background: #f0faf4;
    color: #1d6f42;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.bella-ic-btn-save-field:hover { background: #1d6f42; color: #fff; }
.bella-ic-btn-save-field:disabled { opacity: 0.6; cursor: not-allowed; }

.bella-ic-field-save-status {
    font-size: 0.8rem;
    color: #1d6f42;
}

/* ================================================
   Image stage header with Rename button
   ================================================ */

/* Style-conversion hint shown near Regenerate button */
.bella-ic-regen-hint {
    margin: 8px 0 0 0;
    padding: 8px 12px;
    background: #eff6ff;
    border-left: 3px solid #3b82f6;
    border-radius: 0 5px 5px 0;
    font-size: 0.82rem;
    color: #1e40af;
    line-height: 1.5;
}

.bella-ic-stage-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.bella-ic-btn-rename-image {
    padding: 5px 12px;
    border: 1px solid #6b7280;
    border-radius: 5px;
    background: transparent;
    color: #374151;
    font-size: 0.8rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.bella-ic-btn-rename-image:hover { background: #374151; color: #fff; border-color: #374151; }
.bella-ic-btn-rename-image:disabled { opacity: 0.5; cursor: not-allowed; }

/* Download / Export buttons */
.bella-ic-btn-download {
    display: inline-block;
    padding: 5px 12px;
    border: 1px solid #1d4ed8;
    border-radius: 5px;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.bella-ic-btn-download:hover { background: #1d4ed8; color: #fff; border-color: #1d4ed8; text-decoration: none; }

.bella-ic-btn-export-zip {
    border-color: #166534;
    background: #f0fdf4;
    color: #166534;
}
.bella-ic-btn-export-zip:hover { background: #166534; color: #fff; border-color: #166534; }

.bella-ic-btn-download--sm {
    padding: 4px 10px;
    font-size: 0.78rem;
}

/* ================================================
   Image Editor — trigger button + panel
   ================================================ */

.bella-ic-edit-trigger {
    margin-top: 10px;
    text-align: right;
}

.bella-ic-btn-edit-image {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid #2563eb;
    border-radius: 6px;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.bella-ic-btn-edit-image:hover {
    background: #2563eb;
    color: #fff;
}

.bella-ic-edit-panel {
    margin-top: 16px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
    overflow: hidden;
}

/* ================================================
   Tabs
   ================================================ */

.bella-ic-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    border-bottom: 2px solid #e5e7eb;
    margin-bottom: 20px;
}

.bella-ic-tab {
    display: inline-block;
    padding: 10px 22px;
    font-size: 0.93rem;
    font-weight: 600;
    color: #374151;
    text-decoration: none;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    background: #f3f4f6;
    transition: background 0.15s, color 0.15s;
    margin-bottom: -2px;
}
.bella-ic-tab:hover { background: #e9eaf0; color: #1d2327; text-decoration: none; }
.bella-ic-tab.is-active {
    background: #fff;
    color: #1d2327;
    border-color: #e5e7eb;
    border-bottom-color: #fff;
    box-shadow: 0 -2px 0 #2563eb;
    cursor: default;
}

/* ================================================
   Image Library
   ================================================ */

.bella-ic-library {
    padding: 0;
}

.bella-ic-library__heading {
    margin: 0 0 16px;
    font-size: 1.25rem;
    font-weight: 700;
    color: #1d2327;
}

.bella-ic-library__search-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.bella-ic-library__search-input {
    flex: 1 1 280px;
    min-width: 200px;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.9rem;
}

.bella-ic-library__clear-search {
    font-size: 0.85rem;
    color: #6b7280;
    text-decoration: underline;
}

.bella-ic-library__empty {
    padding: 24px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    color: #374151;
    font-size: 0.95rem;
}

.bella-ic-library__table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.bella-ic-library__table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    background: #fff;
}

.bella-ic-library__table thead tr {
    background: #f3f4f6;
    border-bottom: 2px solid #e5e7eb;
}

.bella-ic-library__table th {
    padding: 10px 12px;
    font-weight: 700;
    color: #374151;
    text-align: left;
    white-space: nowrap;
}

.bella-ic-library__cell {
    padding: 10px 12px;
    border-bottom: 1px solid #f0f2f5;
    vertical-align: top;
}

.bella-ic-library__row:last-child .bella-ic-library__cell { border-bottom: none; }
.bella-ic-library__row--archived { opacity: 0.7; }

.bella-ic-library__thumb {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #e5e7eb;
    display: block;
}

.bella-ic-library__no-thumb {
    display: block;
    width: 60px;
    height: 60px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    line-height: 60px;
    text-align: center;
    color: #9ca3af;
    font-size: 1.1rem;
}

.bella-ic-library__story-preview {
    display: block;
    color: #6b7280;
    font-size: 0.82rem;
    margin-top: 3px;
    line-height: 1.4;
}

.bella-ic-library__cell--id { white-space: nowrap; font-weight: 700; color: #6b7280; }
.bella-ic-library__cell--date { white-space: nowrap; color: #6b7280; font-size: 0.8rem; }
.bella-ic-library__cell--provider { color: #374151; font-size: 0.82rem; }

/* Status badges */
.bella-ic-lib-badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: capitalize;
    letter-spacing: 0.02em;
}
.bella-ic-lib-badge--draft     { background: #f0f9ff; color: #0369a1; border: 1px solid #bae6fd; }
.bella-ic-lib-badge--published { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.bella-ic-lib-badge--archived  { background: #fafafa; color: #6b7280; border: 1px solid #d1d5db; }

/* Action area */
.bella-ic-lib-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: flex-start;
}

.bella-ic-lib-form {
    display: contents; /* lets the button sit inline in the flex row */
    margin: 0;
    padding: 0;
}

.bella-ic-lib-btn {
    display: inline-block;
    padding: 5px 11px;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 5px;
    border: 1px solid #d1d5db;
    background: #f9fafb;
    color: #374151;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.bella-ic-lib-btn:hover { background: #374151; color: #fff; border-color: #374151; text-decoration: none; }

.bella-ic-lib-btn--edit     { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.bella-ic-lib-btn--edit:hover { background: #1d4ed8; color: #fff; border-color: #1d4ed8; }

.bella-ic-lib-btn--publish  { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.bella-ic-lib-btn--publish:hover { background: #166534; color: #fff; border-color: #166534; }

.bella-ic-lib-btn--unpublish { background: #fff7ed; color: #9a3412; border-color: #fed7aa; }
.bella-ic-lib-btn--unpublish:hover { background: #9a3412; color: #fff; border-color: #9a3412; }

.bella-ic-lib-btn--archive  { background: #f3f4f6; color: #6b7280; border-color: #d1d5db; }
.bella-ic-lib-btn--archive:hover { background: #6b7280; color: #fff; border-color: #6b7280; }

.bella-ic-lib-btn--delete   { background: #fff0f0; color: #b91c1c; border-color: #fecaca; }
.bella-ic-lib-btn--delete:hover { background: #b91c1c; color: #fff; border-color: #b91c1c; }

@media (max-width: 600px) {
    .bella-ic-library__table th:nth-child(6),
    .bella-ic-library__cell:nth-child(6) { display: none; } /* hide Provider on small screens */
    .bella-ic-library__thumb { width: 44px; height: 44px; }
    .bella-ic-library__no-thumb { width: 44px; height: 44px; line-height: 44px; }
}

.bella-ic-edit-panel__inner {
    display: flex;
    flex-direction: column;
}

.bella-ic-edit-panel__topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: #f1f5f9;
    border-bottom: 1px solid #e2e8f0;
}

.bella-ic-edit-panel__title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #1e293b;
}

.bella-ic-edit-panel__close {
    background: none;
    border: none;
    font-size: 1.1rem;
    color: #6b7280;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1;
}

.bella-ic-edit-panel__close:hover {
    background: #e2e8f0;
    color: #111;
}

.bella-ic-edit-panel__body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    padding: 18px;
}

.bella-ic-edit-panel__image-col {
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.bella-ic-edit-panel__img {
    max-width: 100%;
    max-height: 340px;
    height: auto;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    object-fit: contain;
}

.bella-ic-edit-panel__controls-col {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bella-ic-edit-panel__label {
    font-size: 0.88rem;
    font-weight: 600;
    color: #374151;
}

.bella-ic-edit-panel__textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
    box-sizing: border-box;
    min-height: 110px;
}

.bella-ic-edit-panel__textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}

.bella-ic-edit-panel__help {
    margin: 0;
    font-size: 0.8rem;
    color: #6b7280;
    line-height: 1.4;
}

.bella-ic-edit-panel__actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.bella-ic-btn-save-edit {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    background: #2563eb;
    color: #fff;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.bella-ic-btn-save-edit:hover { background: #1d4ed8; }
.bella-ic-btn-save-edit:disabled { opacity: 0.6; cursor: not-allowed; }

.bella-ic-btn-cancel-edit {
    padding: 8px 14px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #f9fafb;
    color: #374151;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background 0.15s;
}

.bella-ic-btn-cancel-edit:hover { background: #f1f5f9; }

.bella-ic-edit-panel__status {
    font-size: 0.85rem;
    min-height: 1.4em;
    color: #374151;
}

.bella-ic-edit-panel__status.is-error { color: #dc2626; }
.bella-ic-edit-panel__status.is-success { color: #16a34a; }

@media (max-width: 640px) {
    .bella-ic-edit-panel__body {
        grid-template-columns: 1fr;
    }
}

/* At 850px: single column, everything stacked. */
@media (max-width: 850px) {
    .bella-ic-wrap {
        padding: 14px;
    }
    .bella-ic-editor-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }
    .bella-ic-left-panel,
    .bella-ic-center-panel,
    .bella-ic-right-panel  { grid-column: 1; grid-row: auto; }
    .bella-ic-editor-grid > .bella-ic-lower-panel { grid-column: 1; }
}

/* =========================================================
   iPad / iOS responsive fixes  (BELLA-IOS-01)
   Target: ≤ 1024px wide (iPad landscape + portrait)
   ========================================================= */

/* Minimum tap targets for all buttons/links */
.bella-ic-btn,
.bella-ic-btn-use-image,
.bella-ic-btn-download,
.bella-ic-btn-rename-image,
.bella-ic-btn-save-field,
.bella-ic-tab,
.bella-ic-lib-btn,
button.bella-ic-version-card__btn {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
}

/* Prevent horizontal scroll at all tablet/mobile widths */
.bella-ic-wrap,
.bella-ic-editor-grid,
.bella-ic-version-grid,
.bella-ic-right-panel,
.bella-ic-lower-panel {
    overflow-x: hidden;
    min-width: 0;
    box-sizing: border-box;
}

/* At iPad portrait width: already handled by 850px breakpoint above.
   Add additional fixes for 850–1024px (iPad landscape). */
@media (max-width: 1024px) {
    .bella-ic-wrap {
        padding: 16px 12px;
        max-width: 100%;
    }
    /* Version history: 2-col grid on tablet */
    .bella-ic-version-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
    /* Stage actions: wrap nicely on narrow screens */
    .bella-ic-stage-actions {
        flex-wrap: wrap;
        gap: 8px;
    }
    /* Library table: allow horizontal scroll within its container only */
    .bella-ic-library__table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    /* Textarea + input: larger touch area */
    .bella-ic-wrap textarea,
    .bella-ic-wrap input[type="text"],
    .bella-ic-wrap input[type="search"],
    .bella-ic-wrap select {
        font-size: 16px; /* prevents iOS auto-zoom on focus */
        min-height: 44px;
    }
}

@media (max-width: 480px) {
    /* Stage action buttons: full-width on very small phones */
    .bella-ic-stage-actions {
        flex-direction: column;
        align-items: stretch;
    }
    .bella-ic-btn-download,
    .bella-ic-btn-rename-image {
        text-align: center;
        justify-content: center;
    }
    /* Version grid: single column */
    .bella-ic-version-grid {
        grid-template-columns: 1fr;
    }
}

/* ================================================
   Credit Balances tab
   ================================================ */

.bella-credits-panel { margin-top: 4px; }
.bella-credits-help { margin: 8px 0 0; color: #6b7280; font-size: 0.9rem; }
.bella-credits-meta { margin: 12px 0 0; font-size: 0.9rem; }
.bella-credits-actions { margin: 12px 0 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.bella-credits-refresh-status { font-size: 0.85rem; color: #4b5563; }
.bella-credits-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 16px;
}
.bella-credits-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 18px 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.bella-credits-card h4 { margin: 0 0 12px; font-size: 1rem; color: #1f2937; }
.bella-credits-stats { margin: 0; display: grid; gap: 8px; }
.bella-credits-stats > div { display: flex; justify-content: space-between; gap: 12px; font-size: 0.9rem; }
.bella-credits-stats dt { margin: 0; color: #6b7280; font-weight: 600; }
.bella-credits-stats dd { margin: 0; color: #111827; font-weight: 600; text-align: right; }
.bella-credits-error {
    margin: 12px 0 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: #fff8e6;
    border: 1px solid #f2d7a0;
    color: #6b4a12;
    font-size: 0.85rem;
}
.bella-credits-image-usage {
    margin-top: 20px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 18px 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.bella-credits-image-usage h4 { margin: 0 0 8px; font-size: 1rem; color: #1f2937; }
.bella-credits-image-usage-help { margin: 0 0 14px; color: #6b7280; font-size: 0.88rem; }
.bella-credits-image-usage-table-wrap { overflow-x: auto; }
.bella-credits-image-usage-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}
.bella-credits-image-usage-table th,
.bella-credits-image-usage-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #eef0f4;
    text-align: right;
}
.bella-credits-image-usage-table th[scope="row"],
.bella-credits-image-usage-table thead th:first-child {
    text-align: left;
}
.bella-credits-image-usage-table thead th {
    color: #6b7280;
    font-weight: 600;
    background: #f9fafb;
}
.bella-credits-image-usage-table tbody th {
    color: #111827;
    font-weight: 600;
}
