/* =============================================================================
 * imageMaskEditor.css
 *
 * Styling for the in-chat "Edit with mask" feature. Class taxonomy:
 *
 *   Hover affordances on chat images
 *     .image-mask-edit-host           positioned wrapper around <img>
 *     .image-mask-edit-overlay        primary "Edit with mask" pill
 *     .image-refine-overlay           secondary "Refine" pill
 *
 *   Modal chrome
 *     .image-mask-modal-backdrop      full-screen scrim
 *     .image-mask-modal-panel         centred dialog
 *     .image-mask-modal-header        title + close
 *     .image-mask-modal-body          scrollable body
 *     .image-mask-modal-footer        action row
 *
 *   Canvas + tool previews
 *     .image-mask-canvas-area         flex container
 *     .image-mask-canvas-stack        positioned canvas viewport
 *     .image-mask-display-canvas      the single composited canvas
 *     .image-mask-cursor-preview      brush size indicator (CSS-only circle)
 *     .image-mask-zoom-readout        zoom % chip
 *     .image-mask-onboarding          one-time hint
 *
 *   Toolbar
 *     .image-mask-toolbar             flex row
 *     .image-mask-tool-group          logical grouping (drawing/brush/view/...)
 *     .image-mask-tool-btn            primary tool toggle (B/R/L/E)
 *     .image-mask-icon-btn            secondary icon button (zoom/undo/help)
 *
 *   Prompt + chips + banner
 *     .image-mask-prompt-area         textarea + suggestion strip
 *     .image-mask-suggestions         chip strip
 *     .image-mask-chip                clickable verb chip
 *     .image-mask-banner              status / error / success banner
 *
 *   Help overlay
 *     .image-mask-help-overlay        inline modal layered on top of body
 *
 * !important is applied liberally on color/background declarations because
 * main.css emits high-specificity dark-mode overrides that would otherwise
 * win against page-specific styles.
 * ========================================================================= */

/* ---------------------------------------------------------------------------
 * Hover affordances on chat images. Unchanged from prior — only kept stable
 * to avoid affecting the existing Refine flow's behaviour and selectors.
 * ------------------------------------------------------------------------- */
.image-mask-edit-host {
    position: relative;
    display: inline-block;
    line-height: 0;
}

.image-mask-edit-host > img {
    display: block;
    max-width: 100%;
    height: auto;
}

.image-mask-edit-overlay {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 5;
    padding: 6px 10px;
    border: 1px solid rgba(255, 255, 255, 0.55) !important;
    border-radius: 6px;
    background: rgba(20, 20, 20, 0.78) !important;
    color: #fff !important;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.2px;
    line-height: 1.2;
    cursor: pointer;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.15s ease, transform 0.15s ease, background 0.15s ease;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.image-mask-edit-host:hover .image-mask-edit-overlay,
.image-mask-edit-host:focus-within .image-mask-edit-overlay,
.image-mask-edit-overlay:focus {
    opacity: 1;
    transform: translateY(0);
}

.image-mask-edit-overlay:hover {
    background: rgba(40, 40, 40, 0.92) !important;
}

.image-refine-overlay {
    position: absolute;
    top: 8px;
    right: 132px;
    z-index: 5;
    padding: 6px 10px;
    border: 1px solid rgba(255, 255, 255, 0.55) !important;
    border-radius: 6px;
    background: rgba(60, 60, 60, 0.78) !important;
    color: #fff !important;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.2px;
    line-height: 1.2;
    cursor: pointer;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.15s ease, transform 0.15s ease, background 0.15s ease;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.image-mask-edit-host:hover .image-refine-overlay,
.image-mask-edit-host:focus-within .image-refine-overlay,
.image-refine-overlay:focus {
    opacity: 1;
    transform: translateY(0);
}

.image-refine-overlay:hover {
    background: rgba(80, 80, 80, 0.92) !important;
}

/* ---------------------------------------------------------------------------
 * Modal chrome. More breathing room and a softer drop shadow than v1.
 * ------------------------------------------------------------------------- */
.image-mask-modal-backdrop {
    position: fixed !important;
    inset: 0;
    background: rgba(8, 12, 20, 0.62) !important;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow-y: auto;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.image-mask-modal-panel {
    background: #ffffff !important;
    color: #1f1f1f !important;
    border-radius: 14px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.32), 0 4px 12px rgba(0, 0, 0, 0.12);
    width: min(1100px, 100%);
    max-width: 100%;
    max-height: 95vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(0, 0, 0, 0.06) !important;
}

.image-mask-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid #ececec !important;
    background: #fafafa !important;
}

.image-mask-modal-title {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.1px;
    color: #1f1f1f !important;
}

.image-mask-modal-close {
    border: none;
    background: transparent !important;
    color: #555 !important;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 10px;
    border-radius: 6px;
    transition: background 0.12s ease, color 0.12s ease;
}

.image-mask-modal-close:hover {
    background: rgba(0, 0, 0, 0.06) !important;
    color: #000 !important;
}

.image-mask-modal-body {
    padding: 22px 24px 8px 24px;
    overflow-y: auto;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* ---------------------------------------------------------------------------
 * Canvas area. The .image-mask-canvas-stack is the actual viewport — sized
 * by its container, with a max-height to keep the modal usable on short
 * displays. JS reads its dimensions on init.
 * ------------------------------------------------------------------------- */
.image-mask-canvas-area {
    display: flex;
    justify-content: center;
}

.image-mask-canvas-stack {
    position: relative;
    width: 100%;
    height: clamp(360px, 60vh, 640px);
    background: transparent !important; /* checkerboard drawn in JS */
    border: 1px solid #ddd !important;
    border-radius: 10px;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none; /* prevent native scroll/zoom while painting */
    outline: none;
}

.image-mask-canvas-stack:focus-visible {
    border-color: #d63a6f !important;
    box-shadow: 0 0 0 3px rgba(214, 58, 111, 0.2);
}

.image-mask-display-canvas {
    display: block;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

/* Cursor variants per active tool. */
.image-mask-canvas-stack.cursor-brush  .image-mask-display-canvas,
.image-mask-canvas-stack.cursor-eraser .image-mask-display-canvas { cursor: none; }
.image-mask-canvas-stack.cursor-rect   .image-mask-display-canvas { cursor: crosshair; }
.image-mask-canvas-stack.cursor-lasso  .image-mask-display-canvas { cursor: crosshair; }

.image-mask-display-canvas.is-pan-ready { cursor: grab; }
.image-mask-display-canvas.is-panning   { cursor: grabbing; }

/* Brush cursor preview — a CSS-only circle following the pointer. */
.image-mask-cursor-preview {
    position: absolute;
    pointer-events: none;
    z-index: 4;
    border: 1.5px dashed rgba(220, 30, 90, 0.95);
    background: rgba(220, 30, 90, 0.08);
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.6);
    opacity: 0;
    transition: opacity 0.12s ease;
    will-change: transform, left, top;
}
.image-mask-cursor-preview.is-visible { opacity: 1; }
.image-mask-cursor-preview.is-eraser {
    border-color: rgba(80, 90, 110, 0.95);
    background: rgba(255, 255, 255, 0.10);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

/* Zoom readout — small chip top-right. */
.image-mask-zoom-readout {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 6;
    padding: 4px 9px;
    background: rgba(20, 20, 20, 0.78) !important;
    color: #fff !important;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
    border-radius: 12px;
    pointer-events: none;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

/* Onboarding hint — bottom-left, dismissible, animated in. */
.image-mask-onboarding {
    position: absolute;
    bottom: 12px;
    left: 12px;
    right: 12px;
    z-index: 6;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px 10px 14px;
    background: rgba(20, 20, 20, 0.86) !important;
    color: #fff !important;
    border-radius: 10px;
    border-left: 3px solid #ec407a !important;
    font-size: 13px;
    line-height: 1.4;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    animation: imageMaskHintIn 0.35s ease;
}
.image-mask-onboarding.is-hidden { display: none; }
.image-mask-onboarding-text { flex: 1; }
.image-mask-onboarding-dismiss {
    flex: 0 0 auto;
    background: transparent !important;
    border: none !important;
    color: rgba(255, 255, 255, 0.85) !important;
    font-size: 18px;
    line-height: 1;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
}
.image-mask-onboarding-dismiss:hover {
    background: rgba(255, 255, 255, 0.12) !important;
    color: #fff !important;
}
@keyframes imageMaskHintIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------------------------------------------------------------------------
 * Toolbar. Flex row with logical groups separated by 20px, items within a
 * group separated by 8px. Groups are sticky-ish but allowed to wrap on
 * narrow viewports.
 * ------------------------------------------------------------------------- */
.image-mask-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 20px;
    padding: 10px 12px;
    background: #f7f8fa !important;
    border: 1px solid #e6e7eb !important;
    border-radius: 10px;
}

.image-mask-tool-group {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.image-mask-tool-label {
    font-size: 12px;
    font-weight: 600;
    color: #555 !important;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

/* Brush size slider with a visible handle and pink accent. */
.image-mask-brush-size {
    width: 140px;
    accent-color: #ec407a;
    cursor: pointer;
}

.image-mask-brush-value {
    min-width: 50px;
    text-align: right;
    font-size: 12px;
    color: #555 !important;
    font-variant-numeric: tabular-nums;
}

/* Drawing tool toggle buttons — square icon buttons with active state. */
.image-mask-tool-btn {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #d6d8dd !important;
    border-radius: 8px;
    background: #fff !important;
    color: #2c2f36 !important;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease, transform 0.12s ease;
}
.image-mask-tool-btn:hover {
    background: #f0f1f4 !important;
    border-color: #bfc2c8 !important;
}
.image-mask-tool-btn:active {
    transform: scale(0.97);
}
.image-mask-tool-btn.is-active {
    background: #ec407a !important;
    color: #fff !important;
    border-color: #d63a6f !important;
    box-shadow: 0 2px 6px rgba(236, 64, 122, 0.35);
}
.image-mask-tool-btn.is-active svg { color: #fff; }
.image-mask-tool-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Secondary icon buttons (zoom / undo / clear / help). */
.image-mask-icon-btn {
    height: 32px;
    min-width: 36px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid #d6d8dd !important;
    border-radius: 7px;
    background: #fff !important;
    color: #2c2f36 !important;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease;
}
.image-mask-icon-btn:hover {
    background: #f0f1f4 !important;
    border-color: #bfc2c8 !important;
}
.image-mask-icon-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
.image-mask-icon-btn.is-off {
    background: #2c2f36 !important;
    color: #fff !important;
    border-color: #2c2f36 !important;
}

/* ---------------------------------------------------------------------------
 * Prompt + suggestion chips + banner.
 * ------------------------------------------------------------------------- */
.image-mask-prompt-area {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Side-by-side row: reference dropzone (left) + prompt textarea (right). */
.image-mask-prompt-row {
    display: flex;
    align-items: stretch;
    gap: 12px;
}

/* ---------------------------------------------------------------------------
 * Reference image dropzone (optional). Compact 120x120 well that swaps between
 * an empty "drop here" affordance and a thumbnail + clear-button preview when
 * a file has been picked. Drag/drop highlight matches the prompt focus accent.
 * ------------------------------------------------------------------------- */
.image-mask-reference {
    flex: 0 0 120px;
    width: 120px;
    height: 120px;
    position: relative;
    border-radius: 10px;
    box-sizing: border-box;
}

.image-mask-reference.is-drag-over {
    outline: 2px dashed #ec407a !important;
    outline-offset: 2px;
}

.image-mask-reference-empty {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 6px;
    box-sizing: border-box;
    border: 2px dashed #cfcfcf !important;
    background: #fafafa !important;
    color: #6b6f76 !important;
    border-radius: 10px;
    cursor: pointer;
    font-size: 11px;
    line-height: 1.3;
    text-align: center;
    transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.image-mask-reference-empty:hover {
    border-color: #ec407a !important;
    background: #fff5f8 !important;
    color: #b9285c !important;
}
.image-mask-reference-empty:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.image-mask-reference-plus {
    font-size: 22px;
    font-weight: 600;
    line-height: 1;
}

.image-mask-reference-text {
    display: block;
    font-weight: 500;
}
.image-mask-reference-text small {
    display: block;
    font-weight: 400;
    opacity: 0.7;
}

.image-mask-reference-loaded {
    width: 100%;
    height: 100%;
    position: relative;
    border: 1px solid #d6d8dd !important;
    border-radius: 10px;
    overflow: hidden;
    background: #fff !important;
}

.image-mask-reference-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.image-mask-reference-clear {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none !important;
    background: rgba(0, 0, 0, 0.7) !important;
    color: #fff !important;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.12s ease;
}
.image-mask-reference-clear:hover {
    background: rgba(220, 38, 38, 0.92) !important;
}
.image-mask-reference-clear:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Distinct accent on the auto-injected "Replace with this image" chip so users
 * can see at a glance that it's the reference-driven shortcut. */
.image-mask-chip.image-mask-chip-reference {
    border-color: #ec407a !important;
    background: #fff0f5 !important;
    color: #b9285c !important;
}

.image-mask-prompt {
    flex: 1 1 auto;
    min-width: 0;
    box-sizing: border-box;
    padding: 12px 14px;
    border: 1px solid #cfcfcf !important;
    border-radius: 10px;
    background: #fff !important;
    color: #1f1f1f !important;
    font-size: 14px;
    line-height: 1.5;
    resize: vertical;
    min-height: 72px;
    font-family: inherit;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.image-mask-prompt:focus {
    outline: none;
    border-color: #ec407a !important;
    box-shadow: 0 0 0 3px rgba(236, 64, 122, 0.18);
}

.image-mask-prompt:disabled {
    background: #f6f6f6 !important;
    color: #888 !important;
}

.image-mask-suggestions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 8px;
    padding: 4px 0;
    position: relative;
}
.image-mask-suggestions.is-hidden { display: none; }

.image-mask-suggestions-label {
    font-size: 11px;
    font-weight: 600;
    color: #777 !important;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-right: 4px;
}

.image-mask-suggestions-chips {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
    flex: 1 1 auto;
}

.image-mask-chip {
    border: 1px solid #d6d8dd !important;
    background: #fff !important;
    color: #2c2f36 !important;
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.image-mask-chip:hover {
    background: #fff0f5 !important;
    border-color: #ec407a !important;
    color: #b9285c !important;
}
.image-mask-chip:active { transform: scale(0.98); }
.image-mask-chip:disabled { opacity: 0.55; cursor: not-allowed; }

.image-mask-suggestions-dismiss {
    flex: 0 0 auto;
    margin-left: auto;
    background: transparent !important;
    border: none !important;
    color: #888 !important;
    font-size: 16px;
    line-height: 1;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
}
.image-mask-suggestions-dismiss:hover {
    background: #ececec !important;
    color: #333 !important;
}

/* Banner — proper toast-styled status notice rather than a single text line. */
.image-mask-banner {
    min-height: 0;
    padding: 0;
    margin: 0;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.4;
    overflow: hidden;
    transition: padding 0.15s ease;
}
.image-mask-banner.is-visible {
    padding: 10px 14px;
    border: 1px solid transparent !important;
}
.image-mask-banner.is-info {
    background: #eef4ff !important;
    color: #1d4ed8 !important;
    border-color: #bfd4fb !important;
}
.image-mask-banner.is-success {
    background: #ecfdf5 !important;
    color: #047857 !important;
    border-color: #a7f3d0 !important;
}
.image-mask-banner.is-error {
    background: #fef2f2 !important;
    color: #b91c1c !important;
    border-color: #fecaca !important;
}

/* ---------------------------------------------------------------------------
 * Footer / primary actions.
 * ------------------------------------------------------------------------- */
.image-mask-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 24px;
    border-top: 1px solid #ececec !important;
    background: #fafafa !important;
}

.image-mask-btn {
    border: 1px solid #d0d0d0 !important;
    border-radius: 8px;
    background: #fff !important;
    color: #1f1f1f !important;
    padding: 9px 18px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease, transform 0.12s ease;
}
.image-mask-btn:hover {
    background: #f3f3f3 !important;
    border-color: #b8b8b8 !important;
}
.image-mask-btn:active { transform: scale(0.98); }
.image-mask-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}
.image-mask-btn.image-mask-primary {
    background: #ec407a !important;
    color: #fff !important;
    border-color: #d63a6f !important;
    padding: 9px 28px;
    box-shadow: 0 2px 6px rgba(236, 64, 122, 0.30);
}
.image-mask-btn.image-mask-primary:hover {
    background: #d63a6f !important;
    border-color: #c33365 !important;
}
.image-mask-btn.image-mask-primary:disabled {
    background: #efb8cc !important;
    border-color: #efb8cc !important;
    color: #fff !important;
    box-shadow: none;
}

/* Spinner inside primary action while submitting. */
.image-mask-btn.is-loading::before {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 8px;
    vertical-align: -2px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-top-color: #fff;
    border-radius: 50%;
    animation: imageMaskSpin 0.7s linear infinite;
}

@keyframes imageMaskSpin {
    to { transform: rotate(360deg); }
}

/* ---------------------------------------------------------------------------
 * Toast (success notice).
 * ------------------------------------------------------------------------- */
.image-mask-toast {
    position: fixed !important;
    right: 24px;
    bottom: 24px;
    padding: 10px 16px;
    border-radius: 8px;
    background: #2e7d32 !important;
    color: #fff !important;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    z-index: 10010;
    opacity: 1;
    transition: opacity 0.35s ease;
}
.image-mask-toast-fade { opacity: 0; }

/* ---------------------------------------------------------------------------
 * Help overlay — keyboard shortcut reference. Sits inside the modal panel,
 * absolutely positioned and z-index'd above everything else within the panel.
 * Toggled via .is-open.
 * ------------------------------------------------------------------------- */
.image-mask-help-overlay {
    position: absolute;
    inset: 0;
    z-index: 7;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.image-mask-help-overlay.is-open { display: flex; }
.image-mask-help-overlay-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.image-mask-help-overlay-card {
    position: relative;
    z-index: 1;
    width: min(440px, 100%);
    max-height: 80%;
    overflow-y: auto;
    background: #fff !important;
    color: #1f1f1f !important;
    border-radius: 12px;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.32);
    padding: 18px 22px;
}
.image-mask-help-overlay-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.image-mask-help-overlay-head h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}
.image-mask-help-close {
    border: none;
    background: transparent !important;
    color: #555 !important;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 8px;
    border-radius: 4px;
}
.image-mask-help-close:hover {
    background: rgba(0, 0, 0, 0.06) !important;
    color: #000 !important;
}
.image-mask-help-overlay-list {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 13px;
}
.image-mask-help-overlay-list li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid #f1f1f1 !important;
}
.image-mask-help-overlay-list li:last-child { border-bottom: none !important; }
.image-mask-help-overlay-list span {
    color: #555 !important;
    flex: 1;
}
.image-mask-help-overlay-list kbd {
    display: inline-block;
    padding: 2px 8px;
    border: 1px solid #d6d8dd !important;
    border-bottom-width: 2px !important;
    border-radius: 5px;
    background: #f7f8fa !important;
    color: #2c2f36 !important;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.2;
    min-width: 20px;
    text-align: center;
}

/* ---------------------------------------------------------------------------
 * Refine modal — narrower than the mask editor.
 * ------------------------------------------------------------------------- */
.image-refine-modal-panel {
    width: min(560px, 100%);
}

.image-refine-body {
    padding-bottom: 12px;
}

.image-refine-thumb-wrap {
    display: flex;
    justify-content: center;
    margin: 0 auto 14px auto;
    max-width: 100%;
    background: #f4f4f4 !important;
    border: 1px solid #ddd !important;
    border-radius: 8px;
    padding: 10px;
    overflow: hidden;
}

.image-refine-thumb {
    display: block;
    max-width: 100%;
    max-height: 280px;
    width: auto;
    height: auto;
    border-radius: 4px;
    background: transparent !important;
}

.image-refine-prompt { min-height: 80px; }

.image-mask-help {
    margin: 0 0 14px 0;
    color: #555 !important;
    font-size: 13px;
    line-height: 1.45;
}

/* ---------------------------------------------------------------------------
 * Touch target sizing — make sliders and chips comfortably tappable.
 * ------------------------------------------------------------------------- */
@media (hover: none) and (pointer: coarse) {
    .image-mask-brush-size {
        width: 180px;
        height: 28px;
    }
    .image-mask-tool-btn {
        width: 44px;
        height: 44px;
    }
    .image-mask-icon-btn {
        height: 40px;
        min-width: 44px;
    }
    .image-mask-chip {
        padding: 8px 14px;
        font-size: 13px;
    }
}

/* ---------------------------------------------------------------------------
 * Narrow viewport: stack toolbar groups vertically.
 * ------------------------------------------------------------------------- */
@media (max-width: 720px) {
    .image-mask-toolbar { gap: 12px; }
    .image-mask-tool-group { flex-wrap: wrap; }
    .image-mask-modal-body { padding: 16px 14px 6px 14px; }
    .image-mask-modal-header { padding: 14px 16px; }
    .image-mask-modal-footer { padding: 12px 16px; }
    /* On narrow viewports stack the reference dropzone above the textarea so
       neither has to fight for horizontal space. */
    .image-mask-prompt-row {
        flex-direction: column;
        align-items: stretch;
    }
    .image-mask-reference {
        width: 100%;
        height: 96px;
        flex: 0 0 96px;
    }
    .image-mask-reference-empty {
        flex-direction: row;
        gap: 10px;
    }
    .image-mask-reference-text br { display: none; }
}

/* =============================================================================
 * Dark mode overrides. main.css applies dark mode globally with !important on
 * many declarations, so we mirror that pattern. Both the `body.dark-mode` and
 * the `[data-theme="dark"]` selectors are supported because the project has
 * used both patterns.
 * ========================================================================= */

body.dark-mode .image-mask-modal-panel,
[data-theme="dark"] .image-mask-modal-panel {
    background: #1c1d22 !important;
    color: #e8e8e8 !important;
    border-color: rgba(255, 255, 255, 0.08) !important;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55), 0 4px 12px rgba(0, 0, 0, 0.3);
}

body.dark-mode .image-mask-modal-header,
[data-theme="dark"] .image-mask-modal-header {
    background: #232429 !important;
    border-bottom-color: rgba(255, 255, 255, 0.08) !important;
}

body.dark-mode .image-mask-modal-title,
[data-theme="dark"] .image-mask-modal-title {
    color: #f0f0f0 !important;
}

body.dark-mode .image-mask-modal-close,
[data-theme="dark"] .image-mask-modal-close {
    color: #ccc !important;
}

body.dark-mode .image-mask-modal-close:hover,
[data-theme="dark"] .image-mask-modal-close:hover {
    background: rgba(255, 255, 255, 0.08) !important;
    color: #fff !important;
}

body.dark-mode .image-mask-help,
[data-theme="dark"] .image-mask-help {
    color: #aaa !important;
}

body.dark-mode .image-mask-canvas-stack,
[data-theme="dark"] .image-mask-canvas-stack {
    border-color: rgba(255, 255, 255, 0.1) !important;
}

body.dark-mode .image-mask-toolbar,
[data-theme="dark"] .image-mask-toolbar {
    background: #232429 !important;
    border-color: rgba(255, 255, 255, 0.08) !important;
}

body.dark-mode .image-mask-tool-label,
body.dark-mode .image-mask-brush-value,
body.dark-mode .image-mask-suggestions-label,
[data-theme="dark"] .image-mask-tool-label,
[data-theme="dark"] .image-mask-brush-value,
[data-theme="dark"] .image-mask-suggestions-label {
    color: #b8b8b8 !important;
}

body.dark-mode .image-mask-tool-btn,
[data-theme="dark"] .image-mask-tool-btn {
    background: #2c2d33 !important;
    color: #e8e8e8 !important;
    border-color: rgba(255, 255, 255, 0.12) !important;
}
body.dark-mode .image-mask-tool-btn:hover,
[data-theme="dark"] .image-mask-tool-btn:hover {
    background: #383a42 !important;
    border-color: rgba(255, 255, 255, 0.22) !important;
}
body.dark-mode .image-mask-tool-btn.is-active,
[data-theme="dark"] .image-mask-tool-btn.is-active {
    background: #ec407a !important;
    color: #fff !important;
    border-color: #d63a6f !important;
}

body.dark-mode .image-mask-icon-btn,
[data-theme="dark"] .image-mask-icon-btn {
    background: #2c2d33 !important;
    color: #e8e8e8 !important;
    border-color: rgba(255, 255, 255, 0.12) !important;
}
body.dark-mode .image-mask-icon-btn:hover,
[data-theme="dark"] .image-mask-icon-btn:hover {
    background: #383a42 !important;
    border-color: rgba(255, 255, 255, 0.22) !important;
}
body.dark-mode .image-mask-icon-btn.is-off,
[data-theme="dark"] .image-mask-icon-btn.is-off {
    background: #ec407a !important;
    color: #fff !important;
    border-color: #d63a6f !important;
}

body.dark-mode .image-mask-prompt,
[data-theme="dark"] .image-mask-prompt {
    background: #262629 !important;
    color: #f0f0f0 !important;
    border-color: rgba(255, 255, 255, 0.16) !important;
}

body.dark-mode .image-mask-prompt:disabled,
[data-theme="dark"] .image-mask-prompt:disabled {
    background: #1f1f23 !important;
    color: #888 !important;
}

body.dark-mode .image-mask-reference-empty,
[data-theme="dark"] .image-mask-reference-empty {
    background: #1f1f23 !important;
    color: #b8b8b8 !important;
    border-color: rgba(255, 255, 255, 0.18) !important;
}
body.dark-mode .image-mask-reference-empty:hover,
[data-theme="dark"] .image-mask-reference-empty:hover {
    background: #3a2530 !important;
    border-color: #ec407a !important;
    color: #ffb1cb !important;
}
body.dark-mode .image-mask-reference-loaded,
[data-theme="dark"] .image-mask-reference-loaded {
    background: #1c1d22 !important;
    border-color: rgba(255, 255, 255, 0.16) !important;
}
body.dark-mode .image-mask-chip.image-mask-chip-reference,
[data-theme="dark"] .image-mask-chip.image-mask-chip-reference {
    background: #3a2530 !important;
    border-color: #ec407a !important;
    color: #ffb1cb !important;
}

body.dark-mode .image-mask-chip,
[data-theme="dark"] .image-mask-chip {
    background: #2c2d33 !important;
    color: #e8e8e8 !important;
    border-color: rgba(255, 255, 255, 0.16) !important;
}
body.dark-mode .image-mask-chip:hover,
[data-theme="dark"] .image-mask-chip:hover {
    background: #3a2530 !important;
    border-color: #ec407a !important;
    color: #ffb1cb !important;
}

body.dark-mode .image-mask-suggestions-dismiss,
[data-theme="dark"] .image-mask-suggestions-dismiss {
    color: #aaa !important;
}
body.dark-mode .image-mask-suggestions-dismiss:hover,
[data-theme="dark"] .image-mask-suggestions-dismiss:hover {
    background: rgba(255, 255, 255, 0.08) !important;
    color: #fff !important;
}

body.dark-mode .image-mask-banner.is-info,
[data-theme="dark"] .image-mask-banner.is-info {
    background: rgba(59, 130, 246, 0.16) !important;
    color: #93c5fd !important;
    border-color: rgba(59, 130, 246, 0.4) !important;
}
body.dark-mode .image-mask-banner.is-success,
[data-theme="dark"] .image-mask-banner.is-success {
    background: rgba(16, 185, 129, 0.18) !important;
    color: #6ee7b7 !important;
    border-color: rgba(16, 185, 129, 0.42) !important;
}
body.dark-mode .image-mask-banner.is-error,
[data-theme="dark"] .image-mask-banner.is-error {
    background: rgba(239, 68, 68, 0.18) !important;
    color: #fca5a5 !important;
    border-color: rgba(239, 68, 68, 0.42) !important;
}

body.dark-mode .image-mask-modal-footer,
[data-theme="dark"] .image-mask-modal-footer {
    background: #232429 !important;
    border-top-color: rgba(255, 255, 255, 0.08) !important;
}

body.dark-mode .image-mask-btn,
[data-theme="dark"] .image-mask-btn {
    background: #2c2d33 !important;
    color: #e8e8e8 !important;
    border-color: rgba(255, 255, 255, 0.16) !important;
}
body.dark-mode .image-mask-btn:hover,
[data-theme="dark"] .image-mask-btn:hover {
    background: #383a42 !important;
    border-color: rgba(255, 255, 255, 0.22) !important;
}
body.dark-mode .image-mask-btn.image-mask-primary,
[data-theme="dark"] .image-mask-btn.image-mask-primary {
    background: #ec407a !important;
    color: #fff !important;
    border-color: #d63a6f !important;
}
body.dark-mode .image-mask-btn.image-mask-primary:hover,
[data-theme="dark"] .image-mask-btn.image-mask-primary:hover {
    background: #d63a6f !important;
}
body.dark-mode .image-mask-btn.image-mask-primary:disabled,
[data-theme="dark"] .image-mask-btn.image-mask-primary:disabled {
    background: #5e2c44 !important;
    color: #d8b6c5 !important;
    border-color: #5e2c44 !important;
}

body.dark-mode .image-mask-help-overlay-card,
[data-theme="dark"] .image-mask-help-overlay-card {
    background: #1c1d22 !important;
    color: #e8e8e8 !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}
body.dark-mode .image-mask-help-overlay-list li,
[data-theme="dark"] .image-mask-help-overlay-list li {
    border-bottom-color: rgba(255, 255, 255, 0.07) !important;
}
body.dark-mode .image-mask-help-overlay-list span,
[data-theme="dark"] .image-mask-help-overlay-list span {
    color: #c0c0c0 !important;
}
body.dark-mode .image-mask-help-overlay-list kbd,
[data-theme="dark"] .image-mask-help-overlay-list kbd {
    background: #2c2d33 !important;
    color: #e8e8e8 !important;
    border-color: rgba(255, 255, 255, 0.16) !important;
}
body.dark-mode .image-mask-help-close,
[data-theme="dark"] .image-mask-help-close {
    color: #ccc !important;
}
body.dark-mode .image-mask-help-close:hover,
[data-theme="dark"] .image-mask-help-close:hover {
    background: rgba(255, 255, 255, 0.08) !important;
    color: #fff !important;
}

body.dark-mode .image-refine-thumb-wrap,
[data-theme="dark"] .image-refine-thumb-wrap {
    background: #2a2a2a !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}
