html {
    height: 100%;
    overflow-x: auto;  /* lets horizontal scroll appear when body min-width kicks in */
    overflow-y: hidden;
}
body {
    height: 100%;
    overflow: hidden;
}
body {
    font-family: 'Inter', Arial, sans-serif;
    text-align: center;
    margin: 0;
    padding: 0 0 0 26px; /* collapsed sidebar width */
    display: flex;
    flex-direction: column;
    background: #fff;
    min-width: 800px;
}

.sticky-header {
    flex-shrink: 0;
    background: #1C2333;
    z-index: 1000;
    border-bottom: 1px solid #2D3748;
    margin-left: -26px;
    width: calc(100% + 26px);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Thin top bar — account / auth only */
.header-top-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 3px 12px;
    min-height: 32px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    background: rgba(0,0,0,0.18);
}

/* Main controls row */
.header-controls-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    flex-wrap: wrap;
    gap: 8px;
}

/* ── Header button base — light ghost on dark bar ───────────────────────── */
.sticky-header button {
    height: 32px;
    padding: 0 14px;
    font-family: 'Inter', Arial, sans-serif;
    font-size: 13px;
    font-weight: 500;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.18);
    background: rgba(255,255,255,0.08);
    color: #E5E7EB;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.13s, border-color 0.13s, color 0.13s, box-shadow 0.13s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.sticky-header button:hover:not(:disabled) {
    background: rgba(255,255,255,0.16);
    border-color: rgba(255,255,255,0.35);
    color: #fff;
}
.sticky-header button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    filter: grayscale(0.25);
}
.sticky-header button:focus {
    outline: none;
}
.sticky-header button:focus-visible {
    outline: 3px solid #818CF8;
    outline-offset: 2px;
    box-shadow: 0 0 0 5px rgba(99, 102, 241, 0.25);
}

/* Primary action buttons — indigo accent */
#bgUploadBtn,
#designUploadBtn,
#exportBtn {
    background: #4F6EF7;
    color: #fff;
    border-color: #4F6EF7;
    font-weight: 600;
    box-shadow: 0 1px 4px rgba(79, 110, 247, 0.30);
}
#bgUploadBtn:hover:not(:disabled),
#designUploadBtn:hover:not(:disabled),
#exportBtn:hover:not(:disabled) {
    background: #3A56D4;
    border-color: #3A56D4;
    color: #fff;
    box-shadow: 0 2px 8px rgba(79, 110, 247, 0.40);
}

/* Filter input in the header — ghost on dark bar */
#filterByNameInput {
    height: 32px;
    padding: 0 14px;
    font-family: 'Inter', Arial, sans-serif;
    font-size: 13px;
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 999px;
    color: #E5E7EB;
    background: rgba(255,255,255,0.08);
    outline: none;
    transition: border-color 0.13s, box-shadow 0.13s, background 0.13s;
    box-sizing: border-box;
}
#filterByNameInput:focus {
    border-color: rgba(255,255,255,0.40);
    background: rgba(255,255,255,0.13);
}
#filterByNameInput:focus-visible {
    outline: 3px solid #818CF8;
    outline-offset: 2px;
    box-shadow: 0 0 0 5px rgba(99, 102, 241, 0.25);
}
#filterByNameInput::placeholder { color: rgba(255,255,255,0.40); }

/* ── Header zones ───────────────────────────────────────────────────────── */
.header-left {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}

/* Thin vertical rule between button groups */
.header-section-div {
    display: block;
    width: 1px;
    height: 22px;
    background: rgba(255,255,255,0.18);
    flex-shrink: 0;
    margin: 0 2px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}

#viewportWrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #EDEEF2;
    cursor: default;
}

/* ── Main control panel: grid + tools (floating above zoom strip) ────────── */
#vpControlPanel {
    position: fixed;
    bottom: 60px;
    right: 16px;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(0,0,0,0.13);
    border-radius: 10px;
    box-shadow: 0 3px 14px rgba(0,0,0,0.18);
    padding: 5px 6px;
    z-index: 510;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
    backdrop-filter: blur(4px);
    user-select: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
}
#vpControlPanel.vpc-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(6px);
}

/* Collapse button — badge in top-right corner above the panel */
#vpPanelCollapseBtn {
    position: absolute;
    top: -9px;
    right: -9px;
    width: 18px;
    height: 18px;
    background: #fff;
    border: 1px solid #E5E7EB;
    box-shadow: 0 1px 4px rgba(0,0,0,0.12);
    cursor: pointer;
    font-size: 11px;
    line-height: 1;
    color: #9CA3AF;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: color 0.12s, background 0.12s, border-color 0.12s;
}
#vpPanelCollapseBtn:hover { color: #374151; background: #F3F4F6; border-color: #D1D5DB; }

/* Teaser button that appears when vpControlPanel is hidden */
#vpPanelTeaser {
    position: fixed;
    bottom: 60px;
    right: 16px;
    width: 32px;
    height: 32px;
    background: rgba(255,255,255,0.97);
    border: 1px solid rgba(0,0,0,0.13);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.14);
    cursor: pointer;
    font-size: 15px;
    color: #6B7280;
    z-index: 510;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    backdrop-filter: blur(4px);
    transition: background 0.14s, color 0.14s;
}
#vpPanelTeaser:hover { background: #F3F4F6; color: #374151; }
#vpPanelTeaser[hidden] { display: none; }

/* Grid control rows: label tight against input */
.vpc-grid-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 5px;
}

.vpc-label {
    font-size: 9px;
    font-weight: 600;
    color: #666;
    white-space: nowrap;
    letter-spacing: 0.01em;
}

#numColsInput, #rowGapInput, #colGapInput {
    width: 34px;
    font-size: 11px;
    padding: 2px 3px;
    border: 1px solid #E5E7EB;
    border-radius: 4px;
    text-align: center;
}

.vpc-divider {
    height: 1px;
    background: #E5E7EB;
    margin: 1px 0;
}

/* Tool buttons — icon-sized squares in a horizontal row */
.vpc-tools {
    display: flex;
    flex-direction: row;
    gap: 3px;
    justify-content: center;
}

.vpc-tools button {
    width: 26px;
    height: 26px;
    padding: 0;
    font-size: 13px;
    font-weight: 700;
    border: 1px solid #E5E7EB;
    border-radius: 4px;
    cursor: pointer;
    background: #f0f0f0;
    color: #555;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.14s, color 0.14s;
    line-height: 1;
    flex-shrink: 0;
}
.vpc-tools button:hover { background: #ddd; color: #222; }
.vpc-tools button.tool-active {
    background: #4F6EF7;
    color: #fff;
    border-color: #3A56D4;
}

/* Reset view — action button, not a mode toggle */
#resetViewBtn {
    color: #999;
    font-size: 15px;
}
#resetViewBtn:hover { background: #ddd; color: #555; }

/* ── Zoom + fit strip — fixed to very bottom-right corner, edge-touching ──── */
#vpZoomPanel {
    position: fixed;
    bottom: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(0,0,0,0.15);
    border-bottom: none;
    border-right: none;
    border-radius: 8px 0 0 0;
    box-shadow: -2px -2px 10px rgba(0,0,0,0.12);
    padding: 4px 8px 4px 8px;
    z-index: 510;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    backdrop-filter: blur(4px);
    user-select: none;
}

/* Badge in zoom panel — small muted text */
#vpZoomPanel #windowCountBadge {
    font-size: 9px;
    font-weight: 500;
    color: #888;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    text-align: center;
    display: block !important;
    white-space: nowrap;
}
#vpZoomPanel #windowCountBadge[hidden] { visibility: hidden !important; }

/* Zoom − | 100% | + | ⛶ row */
.vpc-zoom-row {
    display: flex;
    align-items: center;
    gap: 3px;
}
.vpc-zoom-row button {
    background: #f0f0f0;
    border: 1px solid #E5E7EB;
    border-radius: 4px;
    width: 22px;
    height: 22px;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s;
    flex-shrink: 0;
    color: #374151;
}
.vpc-zoom-row button:hover { background: #ddd; }

#zoomLevelDisplay {
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    color: #444;
    user-select: none;
    cursor: pointer;
    min-width: 36px;
}
#zoomLevelDisplay:hover { color: #4F6EF7; }

/* Always show ⛶ icon — overrides any text JS sets on this button */
#centerViewBtn {
    font-size: 0 !important;
    color: transparent !important;
    overflow: hidden;
    position: relative;
    width: 22px;
    height: 22px;
}
#centerViewBtn::before {
    content: "⛶";
    font-size: 12px;
    color: #444;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}
#centerViewBtn:hover::before { color: #222; }

/* ── Background Adjustments ─────────────────────────────────────────────────── */
.bg-adj-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
.bg-adj-row label {
    width: 70px;
    font-size: 12px;
    flex-shrink: 0;
}
.bg-adj-row input[type=range] {
    flex: 1;
    min-width: 0;
}
.bg-adj-row span {
    width: 30px;
    font-size: 11px;
    text-align: right;
    flex-shrink: 0;
    color: #9CA3AF;
}

/* ── Background Crop aspect buttons ─────────────────────────────────────────── */
.bg-crop-aspect-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    margin-bottom: 8px;
}
#contextPanel .bg-aspect-btn {
    display: block;
    width: 100%;
    padding: 6px 4px;
    font-size: 12px;
    font-weight: 700;
    background: #2D3748;
    border: 2px solid #3D4F6A;
    border-radius: 8px;
    cursor: pointer;
    color: #D1D5DB;
    text-align: center;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
}
#contextPanel .bg-aspect-btn:hover {
    background: #3A4A62;
    border-color: #4F6EF7;
    color: #fff;
}
#contextPanel .bg-aspect-btn.active {
    background: #EEF2FF;
    border-color: #4F6EF7;
    color: #4F6EF7;
}

/* ── Pattern creator toggle switch ───────────────────────────────────────────── */
.cp-toggle-switch { position:relative; display:inline-flex; align-items:center; cursor:pointer; }
.cp-toggle-switch input { opacity:0; width:0; height:0; position:absolute; }
.cp-toggle-track {
    display: block;
    width: 38px; height: 22px;
    background: #4B5563;
    border-radius: 11px;
    position: relative;
    transition: background 0.2s;
}
.cp-toggle-switch input:checked + .cp-toggle-track { background: #4F6EF7; }
.cp-toggle-knob {
    position: absolute;
    width: 18px; height: 18px;
    background: #fff;
    border-radius: 50%;
    top: 2px; left: 2px;
    transition: left 0.18s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.cp-toggle-switch input:checked + .cp-toggle-track .cp-toggle-knob { left: 18px; }

/* ── Pattern type buttons ─────────────────────────────────────────────────────── */
#contextPanel .pattern-type-btn {
    display: block;
    width: 100%;
    padding: 5px 2px;
    font-size: 11px;
    font-weight: 600;
    background: #2D3748;
    border: 2px solid #3D4F6A;
    border-radius: 8px;
    cursor: pointer;
    color: #D1D5DB;
    text-align: center;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
}
#contextPanel .pattern-type-btn:hover { background: #3A4A62; border-color: #4F6EF7; color: #fff; }
#contextPanel .pattern-type-btn.active { background: #EEF2FF; border-color: #4F6EF7; color: #4F6EF7; }

/* ── Pattern number inputs ────────────────────────────────────────────────────── */
.pattern-num-input {
    width: 46px !important;
    font-size: 11px !important;
    text-align: right;
    flex-shrink: 0;
    border: 1px solid #3D4F6A;
    border-radius: 4px;
    padding: 1px 3px !important;
    color: #D1D5DB;
    background: #2D3748;
    -moz-appearance: textfield;
    box-sizing: border-box;
}
.pattern-num-input::-webkit-inner-spin-button,
.pattern-num-input::-webkit-outer-spin-button { opacity: 1; }

.pattern-reset-btn {
    font-size: 11px;
    padding: 3px 8px;
    border: 1px solid #3D4F6A;
    border-radius: 4px;
    background: #2D3748;
    color: #D1D5DB;
    cursor: pointer;
    flex-shrink: 0;
}
.pattern-reset-btn:hover { background: #3A4A62; border-color: #4F6EF7; color: #fff; }

.pattern-action-btn {
    flex: 1;
    font-size: 11px;
    padding: 4px 8px;
    border: 1px solid #3D4F6A;
    border-radius: 4px;
    background: #2D3748;
    color: #D1D5DB;
    cursor: pointer;
    font-weight: 500;
}
.pattern-action-btn:hover { background: #3A4A62; border-color: #4F6EF7; color: #fff; }
.pattern-action-btn--teal {
    background: #4F6EF7;
    color: #fff;
    border-color: #3A56D4;
}
.pattern-action-btn--teal:hover { background: #3A56D4; border-color: #2E47C0; color: #fff; }

/* ── Window count badge ─────────────────────────────────────────────────────── */
.window-count-badge {
    display: inline-block;
    font-size: 12px;
    color: #555;
    background: #eee;
    border: 1px solid #E5E7EB;
    border-radius: 10px;
    padding: 2px 9px;
    vertical-align: middle;
    white-space: nowrap;
    user-select: none;
}

/* ── Unsaved changes indicator ──────────────────────────────────────────────── */
#saveProgressBtn.has-unsaved {
    border-color: #e07000;
    box-shadow: 0 0 0 2px rgba(224,112,0,0.35);
}
#saveProgressBtn.has-unsaved::after {
    content: ' ●';
    color: #e07000;
    font-size: 9px;
    vertical-align: middle;
}

/* ── Minimap ────────────────────────────────────────────────────────────────── */
#minimap {
    position: absolute;
    bottom: 185px;
    right: 16px;
    background: rgba(18, 18, 18, 0.75);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 7px;
    overflow: hidden;
    z-index: 500;
    cursor: crosshair;
    box-shadow: 0 3px 12px rgba(0,0,0,.45);
    user-select: none;
    backdrop-filter: blur(3px);
}
#minimapCanvas { display: block; }

/* ── Export popover ─────────────────────────────────────────────────────────── */
.export-wrap {
    position: relative;
    display: inline-block;
    vertical-align: middle;
}
.export-popover {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    background: #fff;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    box-shadow: 0 4px 18px rgba(0,0,0,.14);
    padding: 12px 14px 14px;
    z-index: 2000;
    min-width: 220px;
    max-width: calc(100vw - 16px);
    box-sizing: border-box;
    text-align: left;
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
    transition: opacity 0.13s ease, transform 0.13s ease, visibility 0s linear 0s;
}
/* Keep popover in the rendering tree so transitions can fire */
.export-popover[hidden] {
    display: block !important;
    opacity: 0;
    transform: translateY(-5px);
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.13s ease, transform 0.13s ease, visibility 0s linear 0.13s;
}
.export-popover--right,
.header-right .export-popover {
    left: auto;
    right: 0;
}

/* On narrow viewports, detach from the trigger and pin to viewport edges
   so neither popover can be clipped or scroll off-screen. */
@media (max-width: 540px) {
    .export-popover {
        position: fixed;
        top: 50px;
        left: 8px;
        right: 8px;
        max-width: none;
    }
    /* Override the right-anchored variant — same fixed position */
    .export-popover--right,
    .header-right .export-popover {
        left: 8px;
        right: 8px;
    }
    /* Let button text wrap so long labels aren't clipped */
    .export-popover button:not(.seg-btn) {
        white-space: normal;
        height: auto;
        min-height: 32px;
        padding-top: 6px;
        padding-bottom: 6px;
        line-height: 1.3;
    }
}

/* ── Popover inner buttons — neutral pill, matches toolbar base ─────────── */
.export-popover button:not(.seg-btn) {
    height: 32px;
    padding: 0 14px;
    font-family: 'Inter', Arial, sans-serif;
    font-size: 13px;
    font-weight: 500;
    border-radius: 999px;
    border: 1px solid #D1D5DB;
    background: #F3F4F6;
    color: #374151;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.13s, border-color 0.13s, color 0.13s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: 100%;
    box-sizing: border-box;
}
.export-popover button:not(.seg-btn):hover {
    background: #EEF2FF;
    border-color: #818CF8;
    color: #4338CA;
}

/* Spacing between stacked file-menu buttons */
#fileMenuPopover button + button { margin-top: 6px; }

/* ── Save as New — PRO gate wrapper ───────────────────────────────────────── */
.file-menu-pro-wrap {
    position: relative;
    display: block;
    margin-top: 6px;
}
.file-menu-pro-wrap #saveNewBtn {
    margin-top: 0;
    padding-right: 52px;
}
.file-menu-pro-wrap #saveNewBtn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}
.file-menu-pro-badge {
    display: inline-block;
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 1px 5px;
    border-radius: 4px;
    pointer-events: none;
    white-space: nowrap;
    text-transform: uppercase;
}
.file-menu-pro-badge-green {
    background: linear-gradient(135deg, #10b981, #059669);
}
.file-menu-pro-tooltip {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #1f2937;
    color: #f9fafb;
    font-size: 11px;
    font-weight: 500;
    padding: 5px 10px;
    border-radius: 6px;
    white-space: nowrap;
    z-index: 3000;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.file-menu-pro-tooltip::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-bottom-color: #1f2937;
}
.file-menu-pro-wrap.is-locked:hover .file-menu-pro-tooltip {
    display: block;
}

.export-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.export-row:last-of-type { margin-bottom: 12px; }
.export-label {
    font-size: 12px;
    font-weight: 600;
    color: #6B7280;
    width: 52px;
    flex-shrink: 0;
}
.export-seg {
    display: inline-flex;
    border: 1px solid #E5E7EB;
    border-radius: 5px;
    overflow: hidden;
}
.seg-btn {
    background: #f5f5f5;
    border: none;
    border-right: 1px solid #E5E7EB;
    padding: 4px 11px;
    font-family: 'Inter', Arial, sans-serif;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background .1s;
    line-height: 1.4;
}
.seg-btn:last-child { border-right: none; }
.seg-btn:hover:not(.seg-active) { background: #e5e5e5; }
.seg-btn.seg-active { background: #4F46E5; color: #fff; }
#exportQualityRow { margin-bottom: 12px; }
#exportQualitySlider { flex: 1; cursor: pointer; accent-color: #4F46E5; }
#exportQualityVal {
    font-size: 12px;
    color: #444;
    min-width: 32px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Export go button — indigo pill, primary action */
#exportGoBtn {
    background: #4F46E5;
    color: #fff;
    border-color: #4F46E5;
    font-weight: 600;
    margin-top: 4px;
}
#exportGoBtn:hover {
    background: #3730A3;
    border-color: #3730A3;
    color: #fff;
}

/* Export Text Boxes button — extra top margin to separate from quality row */
#exportTextBtn { margin-top: 2px; }


#canvasContainer {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    display: grid;
    grid-template-columns: repeat(4, max-content);
    gap: 20px;
    width: max-content;
    padding: 20px;
    box-sizing: border-box;
    align-items: start;
}

.canvas-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    border: 2px solid transparent;
    width: 300px;
    overflow: hidden;
    vertical-align: top;
    box-sizing: border-box;
    align-items: center;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 6px rgba(0,0,0,0.09);
}
.canvas-wrapper canvas { width: 100% !important; height: auto !important; display: block; }

.filename-input {
    margin-top: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    border: none;
    border-top: 1px solid #E5E7EB;
    border-radius: 0 0 10px 10px;
    background: #F9FAFB;
    padding: 5px 10px;
    font-family: 'Inter', Arial, sans-serif;
    font-size: 12px;
    color: #6B7280;
    text-align: center;
    outline: none;
    transition: background 0.13s, color 0.13s;
}
.filename-input:focus {
    background: #fff;
    color: #111827;
}
.filename-input::placeholder { color: #D1D5DB; }

.canvas-wrapper.active          { border: 2px solid #4F6EF7 !important; box-shadow: 0 0 0 1px #4F6EF7; }
.canvas-wrapper.design-active   { border: 2px solid orange !important;  box-shadow: 0 0 0 1px orange; }
.canvas-wrapper.window-locked.active { border: 2px solid #bbb !important; box-shadow: 0 0 0 1px #bbb; }
.canvas-wrapper.window-locked::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.38);
    pointer-events: none;
    z-index: 5;
}
.window-locked .drag-handle { display: none; }
.window-locked .filename-input { opacity: 0.5; cursor: not-allowed; }

/* Crossed-eye badge for clip-layers-hidden windows */
.canvas-wrapper.clip-layers-hidden::before {
    content: '🚫';
    position: absolute;
    top: 5px;
    left: 6px;
    font-size: 13px;
    line-height: 1;
    z-index: 10;
    pointer-events: none;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35));
}
.window-locked::before {
    content: '🔒';
    position: absolute;
    top: 5px;
    right: 6px;
    font-size: 11px;
    line-height: 1;
    z-index: 10;
    pointer-events: none;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35));
}

/* Gray out lock-sensitive panel controls when every selected window is locked */
#contextPanelBody.all-locked .lock-sensitive {
    opacity: 0.38;
    pointer-events: none;
    user-select: none;
}

.color-tool-btn {
    padding: 2px 7px;
    font-size: 11px;
    border: 1px solid #3D4F6A;
    background: #2D3748;
    border-radius: 3px;
    cursor: pointer;
}
/* Needs higher specificity than #contextPanel button to override background */
#contextPanel .color-tool-btn         { background: #2D3748; color: #D1D5DB; border: 1px solid #3D4F6A; width: auto; display: inline-block; padding: 2px 7px; font-size: 11px; }
#contextPanel .color-tool-btn.active  { background: #4F6EF7; color: #fff; border-color: #3A56D4; }
#contextPanel .color-tool-btn:hover   { background: #3A4A62; }
#contextPanel .color-tool-btn.active:hover { background: #3A56D4; }

/* Hide system cursor over the whole wrapper in color-layer mode */
.canvas-wrapper.color-layer-mode,
.canvas-wrapper.color-layer-mode .upper-canvas { cursor: none !important; }

/* ── Drag-to-reorder ─────────────────────────────────────────────────────── */
.drag-handle {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    padding: 1px 8px;
    background: rgba(255,255,255,0.93);
    border: 1px solid #E5E7EB;
    border-radius: 4px;
    font-size: 12px;
    color: #888;
    cursor: grab;
    opacity: 0;
    transition: opacity 0.15s;
    user-select: none;
    z-index: 15;
    white-space: nowrap;
    line-height: 1.6;
}
.window-cell:hover .drag-handle { opacity: 1; }
.canvas-wrapper.drag-source { opacity: 0.35; }

#brushCursorRing {
    position: fixed;
    pointer-events: none;
    border-radius: 50%;
    border: 1.5px solid rgba(255,255,255,0.85);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.7);
    display: none;
    transform: translate(-50%, -50%);
    z-index: 9999;
}
#designEraserCursor {
    position: fixed;
    pointer-events: none;
    box-sizing: border-box;
    border-radius: 50%;
    border: 1.5px solid rgba(255,255,255,0.9);
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.75);
    transform: translate(-50%, -50%);
    z-index: 99999;
}
#designEraserInner {
    position: absolute;
    border-radius: 50%;
    border: 1px dashed rgba(255,255,255,0.65);
    box-sizing: border-box;
    display: none;
}

.upload-count {
    display: inline-block;
    font-size: 12px;
    font-weight: 500;
    color: #6B7280;
    background: #F3F4F6;
    border: 1px solid #E5E7EB;
    border-radius: 10px;
    padding: 1px 8px;
    margin-right: 4px;
    vertical-align: middle;
    white-space: nowrap;
}
.upload-count:empty { display: none; }

#dropZone {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    inset: 20px;
    border: 3px dashed #D1D5DB;
    border-radius: 14px;
    cursor: default;
    transition: background 0.15s, border-color 0.15s;
    box-sizing: border-box;
    z-index: 20;
    background: #EDEEF2;
}
#dropZone.dz-hover { background: #EEF2FF; border-color: #4F6EF7; }

#dropZoneInner { text-align: center; pointer-events: none; user-select: none; }
.dz-icon { font-size: 52px; color: #D1D5DB; line-height: 1; margin-bottom: 14px; }
.dz-title { font-size: 22px; font-weight: 600; color: #9CA3AF; margin: 0 0 8px; }
.dz-sub   { font-size: 13px; color: #D1D5DB; margin: 0; }

#designPrompt {
    display: none;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 10px 20px;
    background: #fffbee;
    border-bottom: 1px solid #ffe99e;
    font-size: 14px;
    color: #666;
    text-align: center;
    box-sizing: border-box;
    z-index: 20;
}
#designPrompt.dz-hover { background: #fff8d0; border-color: #f5c400; }
#designPromptBtn {
    background: none;
    border: none;
    color: #4F6EF7;
    cursor: pointer;
    font-size: 14px;
    text-decoration: underline;
    padding: 0;
    font-family: inherit;
}

#canvasContainer.dz-designs-hover::before {
    content: 'Drop designs here';
    position: fixed;
    inset: 0;
    background: rgba(79, 110, 247, 0.08);
    border: 3px dashed #4F6EF7;
    border-radius: 14px;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 600;
    color: #4F6EF7;
    pointer-events: none;
}

/* ── Context Panel — left side, always present ──────────────────────────── */
#appLogoBar {
    flex-shrink: 0;
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0.3px;
    color: #fff;
    background: #242D40;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    white-space: nowrap;
    user-select: none;
}

#contextPanel {
    position: fixed;
    left: 0;
    top: 0;
    width: 26px; /* collapsed by default */
    height: 100vh;
    padding-top: 84px;
    background: #fff;
    border-right: 1px solid #E5E7EB;
    z-index: 999;
    display: flex;
    flex-direction: column;
    font-family: 'Inter', Arial, sans-serif;
    color: #374151;
    transition: width 0.22s ease;
    overflow: hidden;
}
body.sidebar-expanded #contextPanel { width: 220px; }

/* ── Sidebar resize handle ─────────────────────────────────────────────────── */
#sidebarResizeHandle {
    position: absolute;
    right: 0;
    top: 0;
    width: 5px;
    height: 100%;
    cursor: col-resize;
    z-index: 1002;
    transition: background 0.15s;
}
body:not(.sidebar-expanded) #sidebarResizeHandle { display: none; }
#sidebarResizeHandle:hover,
body.sidebar-resizing #sidebarResizeHandle { background: rgba(79,110,247,0.18); }
body.sidebar-resizing,
body.sidebar-resizing * { cursor: col-resize !important; user-select: none !important; }

/* Hide idle message when sidebar is collapsed */
body:not(.sidebar-expanded) .cp-idle-msg { display: none !important; }

/* Sidebar toggle tab — fixed so it escapes the panel's overflow:hidden */
#sidebarToggleBtn {
    position: fixed;
    left: 26px; /* right edge of collapsed panel */
    top: 50%;
    transform: translateY(-50%);
    width: 18px !important;
    display: flex !important;
    height: 52px;
    background: #fff;
    border: 1px solid #E5E7EB;
    border-left: none;
    border-radius: 0 8px 8px 0;
    box-shadow: 3px 0 8px rgba(0,0,0,0.09);
    cursor: pointer;
    font-size: 9px;
    color: #9CA3AF;
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    transition: left 0.22s ease, background 0.15s, color 0.15s, box-shadow 0.15s;
    flex-shrink: 0;
}
#sidebarToggleBtn:hover {
    background: #F3F4F6;
    color: #4F6EF7;
    box-shadow: 3px 0 10px rgba(0,0,0,0.14);
}
body.sidebar-expanded #sidebarToggleBtn { left: 220px; }



/* Sidebar body hidden when collapsed */
#contextPanelBody {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.18s ease, visibility 0s linear 0.18s;
}
body.sidebar-expanded #contextPanelBody {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 0.18s ease 0.05s, visibility 0s linear 0s;
}

#contextPanelBody {
    flex: 1;
    overflow-y: auto;
    padding: 4px 10px 20px;
    display: flex;
    flex-direction: column;
}

/* Hide all sections + feedback link when nothing is selected */
#contextPanel:not(.active) .cp-section,
#contextPanel:not(.active) .cp-feedback {
    display: none;
}

/* Idle hint — fills the panel body when nothing is selected */
.cp-idle-msg {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 24px 16px;
    text-align: center;
    color: #9CA3AF;
    font-size: 12px;
    line-height: 1.7;
    pointer-events: none;
    gap: 6px;
}
#contextPanel:not(.active) .cp-idle-msg { display: flex; }

.cp-idle-icon {
    font-size: 24px;
    opacity: 0.3;
    transform: rotate(90deg);
    display: block;
    margin-bottom: 4px;
}

.cp-section {
    padding: 8px 0;
    border-bottom: 1px solid #E5E7EB;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.cp-section:last-of-type { border-bottom: none; }

.cp-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #9CA3AF;
    padding-bottom: 1px;
}

.cp-section label {
    font-size: 12px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    color: #374151;
    text-align: left;
}
.cp-section input[type="range"] { width: 100%; padding: 0; margin: 0; cursor: pointer; accent-color: #4F6EF7; }
.cp-section input[type="number"],
.cp-section select {
    width: 100%;
    padding: 4px 6px;
    font-size: 13px;
    border: 1px solid #E5E7EB;
    border-radius: 4px;
    box-sizing: border-box;
    background: #F9FAFB;
    color: #374151;
}

#contextPanel button {
    display: block;
    width: 100%;
    padding: 6px 10px;
    font-size: 12px;
    text-align: left;
    background: #F3F4F6;
    border: 1px solid #E5E7EB;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
    box-sizing: border-box;
    font-family: 'Inter', Arial, sans-serif;
    color: #374151;
}
#contextPanel button:hover { background: #EEF2FF; border-color: #C7D2FE; }
#contextPanel button:disabled { opacity: 0.4; cursor: not-allowed; }
#contextPanel button:disabled:hover { background: #F3F4F6; border-color: #E5E7EB; }

/* ── Framing (bgCrop) custom dimension row ───────────────────────────────── */
.bgcrop-dim-row {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
}

.bgcrop-dim-input {
    width: 44px !important;
    padding: 3px 5px !important;
    font-size: 12px !important;
    text-align: center !important;
}

.bgcrop-apply-btn {
    flex: 1;
    padding: 3px 6px;
    font-size: 12px;
    text-align: center;
    display: block;
    width: auto;
}

/* Clipping sub-buttons — indented secondary actions */
#contextPanel .clip-sub-btn {
    margin-left: 12px;
    width: calc(100% - 12px);
    font-size: 11px;
    color: #6B7280;
    background: #F9FAFB;
    border-color: #E5E7EB;
    padding: 4px 8px;
}
#contextPanel .clip-sub-btn::before {
    content: '↳ ';
    opacity: 0.4;
    font-size: 10px;
}
#contextPanel .clip-sub-btn:hover { background: #EEF2FF; border-color: #C7D2FE; color: #374151; }
#contextPanel .clip-sub-btn--danger { color: #EF4444; }
#contextPanel .clip-sub-btn--danger:hover { background: #FEF2F2; border-color: #FECACA; }

.cp-btn-row {
    display: flex;
    gap: 6px;
}
.cp-btn-row button {
    flex: 1;
    text-align: center;
}

.cp-feedback {
    font-size: 10px;
    color: #9CA3AF;
    text-decoration: underline;
    text-align: center;
    padding-top: 10px;
    display: block;
}
.cp-feedback:hover { color: #6B7280; }

/* ── Canvas text layer ─────────────────────────────────────────────────── */
#textLayer {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    transform-origin: 0 0;
    pointer-events: none;
    z-index: 15;
}

/* Wrapper — transparent by default; border/bg appear on hover or edit */
.canvas-text-box {
    position: absolute;
    min-width: 120px;
    background: transparent;
    border: 1.5px solid transparent;
    border-radius: 6px;
    box-shadow: none;
    pointer-events: auto;
    box-sizing: border-box;
    cursor: grab;
    user-select: none;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.canvas-text-box:hover {
    background: rgba(255,255,255,0.92);
    border-color: #4F6EF7;
    box-shadow: 0 0 0 2px rgba(79,110,247,0.12), 0 2px 8px rgba(0,0,0,0.08);
}
.canvas-text-box.tb-focused {
    background: rgba(255,255,255,0.97);
    border-color: #4F6EF7;
    box-shadow: 0 0 0 2px rgba(79,110,247,0.18), 0 2px 8px rgba(0,0,0,0.10);
}

/* Thin grab bar at top */
.tb-drag-bar {
    height: 13px;
    cursor: grab;
    border-radius: 5px 5px 0 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tb-drag-bar::after {
    content: '• • •';
    font-size: 7px;
    color: #bbb;
    letter-spacing: 2px;
    line-height: 1;
    pointer-events: none;
}
.tb-drag-bar:active { cursor: grabbing; }

/* Inner contenteditable — text area */
.tb-text {
    display: block;
    min-width: 80px;
    min-height: 1.6em;
    padding: 2px 10px 8px;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Arial, sans-serif;
    line-height: 1.55;
    color: #222;
    outline: none;
    word-break: break-word;
    white-space: pre-wrap;
    box-sizing: border-box;
    user-select: text;
    cursor: text;
    border-radius: 0 0 5px 5px;
}
.tb-text:empty::before {
    content: 'Type here…';
    color: #bbb;
    pointer-events: none;
}
/* Click-created (no drag): grow horizontally, no wrapping */
.canvas-text-box.tb-auto-width .tb-text {
    white-space: nowrap;
    word-break: normal;
}

/* Resize handles */
.tb-resize-r {
    position: absolute;
    top: 6px; right: -6px; bottom: 6px;
    width: 12px;
    cursor: ew-resize;
    z-index: 3;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tb-resize-r::after {
    content: '';
    width: 3px; height: 20px;
    background: #4F6EF7;
    border-radius: 2px;
    opacity: 0.7;
}
.tb-resize-b {
    position: absolute;
    left: 6px; right: 6px; bottom: -6px;
    height: 12px;
    cursor: ns-resize;
    z-index: 3;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tb-resize-b::after {
    content: '';
    height: 3px; width: 20px;
    background: #4F6EF7;
    border-radius: 2px;
    opacity: 0.7;
}
.canvas-text-box:hover .tb-resize-r,
.canvas-text-box:hover .tb-resize-b,
.canvas-text-box.tb-focused .tb-resize-r,
.canvas-text-box.tb-focused .tb-resize-b { opacity: 1; }

/* Delete button */
.tb-delete {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 17px;
    height: 17px;
    background: #e74c3c;
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 11px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    z-index: 1;
    line-height: 1;
}
.canvas-text-box:hover .tb-delete { opacity: 1; }

/* Floating font-size toolbar */
.tb-font-toolbar {
    position: fixed;
    background: #2c3e50;
    color: #fff;
    border-radius: 6px;
    padding: 4px 8px;
    display: none;
    align-items: center;
    gap: 4px;
    z-index: 10000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.28);
    pointer-events: auto;
    font-size: 12px;
    white-space: nowrap;
}
.tb-font-toolbar.visible { display: flex; }
.tb-font-toolbar label { color: #ccc; font-size: 11px; margin-right: 2px; }
.tb-font-toolbar select {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    color: #fff;
    border-radius: 3px;
    padding: 2px 5px;
    font-size: 12px;
    cursor: pointer;
    outline: none;
}
.tb-font-toolbar select option { background: #2c3e50; color: #fff; }



/* ── Mobile overlay ─────────────────────────────────────────────────────────── */
#mobileOverlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 99999;
    background: #0f1117;
    align-items: center;
    justify-content: center;
    text-align: center;
    box-sizing: border-box;
    padding: 24px;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
}
#mobileOverlayContent {
    width: 100%;
    max-width: 300px;
    box-sizing: border-box;
}
#mobileOverlayIcon {
    font-size: 40px;
    margin-bottom: 16px;
    line-height: 1;
}
#mobileOverlay h1 {
    font-size: 18px;
    font-weight: 600;
    color: #ffffff;
    margin: 0 0 10px;
    line-height: 1.3;
}
#mobileOverlay p {
    font-size: 14px;
    color: #9ca3af;
    margin: 0 0 20px;
    line-height: 1.5;
}
#mobileOverlayUrl {
    display: inline-block;
    font-size: 13px;
    color: #6366f1;
    text-decoration: none;
    border: 1px solid #6366f1;
    border-radius: 8px;
    padding: 9px 18px;
    word-break: break-all;
}

/* ── Plan / Watermark System ─────────────────────────────────────────────── */

/* Top upgrade-prompt bar */
.upgrade-prompt {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: linear-gradient(90deg, #4f46e5 0%, #7c3aed 100%);
    color: #fff;
    font-size: 13px;
    padding: 8px 16px;
    width: 100%;
    box-sizing: border-box;
    z-index: 200;
    flex-shrink: 0;
}
.upgrade-prompt a {
    color: #fde68a;
    font-weight: 600;
    text-decoration: underline;
}
.upgrade-prompt-close {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 2px 6px;
    flex-shrink: 0;
}
.upgrade-prompt-close:hover { color: #fff; }

/* ⭐ PRO badge on sidebar section titles */
.pro-badge {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.03em;
    padding: 1px 5px;
    border-radius: 4px;
    vertical-align: middle;
    margin-left: 4px;
    white-space: nowrap;
    text-transform: uppercase;
}
.pro-badge--green {
    background: linear-gradient(135deg, #10b981, #059669);
}

/* Outer cell that wraps each canvas-wrapper, providing a positioned
   overflow-visible context so the PRO badge can sit above the window */
.window-cell {
    position: relative;
}

/* ⭐ PRO pill badge — floats above the canvas window, not over the image */
.pro-star-badge {
    position: absolute;
    bottom: calc(100% + 4px);
    right: 0;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.03em;
    color: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
    text-transform: uppercase;
    pointer-events: none;
    z-index: 10;
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
.pro-star-yellow { background: linear-gradient(135deg, #f59e0b, #d97706); }
.pro-star-green  { background: linear-gradient(135deg, #10b981, #059669); }

/* ── Clerk auth UI ──────────────────────────────────────────────────────── */
#clerkSignInBtn {
    background: #4F6EF7;
    color: #fff;
    border-color: #4F6EF7;
    font-weight: 600;
    box-shadow: 0 1px 4px rgba(79, 110, 247, 0.30);
}
#clerkSignInBtn:hover {
    background: #3A56D4;
    border-color: #3A56D4;
    color: #fff;
    box-shadow: 0 2px 8px rgba(79, 110, 247, 0.40);
}

.ms-user-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.ms-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.25);
    transition: border-color 0.15s, box-shadow 0.15s;
    display: block;
}
.ms-avatar:hover {
    border-color: rgba(255,255,255,0.55);
    box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.35);
}

.ms-avatar-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 200px;
    background: #1C2333;
    border: 1px solid #2D3748;
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0,0,0,0.45);
    padding: 10px;
    z-index: 2000;
    flex-direction: column;
    gap: 6px;
}
.ms-avatar-dropdown.open {
    display: flex;
}

.ms-avatar-email {
    font-size: 12px;
    color: #9CA3AF;
    word-break: break-all;
    padding: 2px 4px;
}

.ms-avatar-plan {
    font-size: 12px;
    color: #D1D5DB;
    padding: 2px 4px;
}
.ms-avatar-plan strong {
    color: #818CF8;
}
.ms-avatar-cancels {
    font-size: 11px;
    color: #F87171;
    padding: 1px 4px 3px;
}
.ms-avatar-settings-btn {
    margin-top: 4px;
    width: 100%;
    height: 30px;
    padding: 0 10px;
    font-family: 'Inter', Arial, sans-serif;
    font-size: 12px;
    background: transparent;
    color: #D1D5DB;
    border: 1px solid #374151;
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
}
.ms-avatar-settings-btn:hover {
    background: #1F2937;
    color: #fff;
}

#clerkSignOutBtn {
    margin-top: 6px;
    width: 100%;
    height: 30px;
    padding: 0 10px;
    font-family: 'Inter', Arial, sans-serif;
    font-size: 12px;
    font-weight: 500;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(255,255,255,0.07);
    color: #E5E7EB;
    cursor: pointer;
    transition: background 0.13s, border-color 0.13s;
}
#clerkSignOutBtn:hover {
    background: rgba(255,255,255,0.14);
    border-color: rgba(255,255,255,0.30);
    color: #fff;
}

.ms-upgrade-toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    background: #4F46E5;
    color: #fff;
    font-family: 'Inter', Arial, sans-serif;
    font-size: 14px;
    font-weight: 500;
    padding: 12px 24px;
    border-radius: 10px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.35);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    z-index: 99999;
    white-space: nowrap;
}
.ms-upgrade-toast--visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.ms-upgrade-toast--pending {
    background: #92400E;
    max-width: 380px;
    white-space: normal;
    text-align: center;
    line-height: 1.45;
}

/* ── Activating banner (shown while plan upgrade is being confirmed) ─────── */
.ms-activating-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: #312e81;
    color: #e0e7ff;
    font-family: 'Inter', Arial, sans-serif;
    font-size: 13px;
    font-weight: 500;
    padding: 8px 16px;
    opacity: 0;
    transform: translateY(-100%);
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 99998;
    pointer-events: none;
}
.ms-activating-banner--visible {
    opacity: 1;
    transform: translateY(0);
}
.ms-activating-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(224, 231, 255, 0.35);
    border-top-color: #e0e7ff;
    border-radius: 50%;
    animation: ms-spin 0.75s linear infinite;
    flex-shrink: 0;
}
@keyframes ms-spin {
    to { transform: rotate(360deg); }
}

/* ── Plans modal ────────────────────────────────────────────────────────────── */
.ms-plans-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,15,35,0.55);
    backdrop-filter: blur(3px);
    z-index: 9000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.ms-plans-overlay--open {
    display: flex;
}
.ms-plans-dialog {
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 24px 80px rgba(0,0,0,0.18);
    width: 100%;
    max-width: 880px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 48px 44px 36px;
    position: relative;
    box-sizing: border-box;
}
.ms-plans-close {
    position: absolute;
    top: 18px;
    right: 20px;
    background: #f3f4f6;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.ms-plans-close:hover { background: #e5e7eb; color: #111; }

.ms-plans-header {
    text-align: center;
    margin-bottom: 32px;
}
.ms-plans-header h2 {
    font-size: 28px;
    font-weight: 800;
    color: #0f0f23;
    margin: 0 0 6px;
    letter-spacing: -0.02em;
}
.ms-plans-subtitle {
    font-size: 14px;
    color: #6b7280;
    margin: 0 0 24px;
}

/* Billing tabs */
.ms-billing-tabs {
    display: inline-flex;
    background: #f3f4f6;
    border-radius: 50px;
    padding: 4px;
    gap: 2px;
}
.ms-billing-tab {
    background: transparent;
    border: none;
    border-radius: 50px;
    padding: 8px 20px;
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.18s;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.ms-billing-tab.active {
    background: #fff;
    color: #4f46e5;
    box-shadow: 0 1px 4px rgba(0,0,0,0.10);
}
.ms-billing-tab:hover:not(.active) { color: #374151; }
.ms-billing-save {
    background: #dcfce7;
    color: #16a34a;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 50px;
}

/* Plan grid */
.ms-plans-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    align-items: start;
}
.ms-plan-card {
    border: 1.5px solid #e5e7eb;
    border-radius: 16px;
    padding: 28px 24px 24px;
    position: relative;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 0;
    transition: box-shadow 0.18s;
}
.ms-plan-card:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.07); }
.ms-plan-card--featured {
    border-color: #4f46e5;
    border-width: 2px;
    box-shadow: 0 8px 32px rgba(79,70,229,0.12);
}
.ms-plan-card--featured:hover { box-shadow: 0 12px 40px rgba(79,70,229,0.18); }

.ms-plan-popular {
    position: absolute;
    top: -14px;
    left: 50%;
    transform: translateX(-50%);
    background: #4f46e5;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 4px 14px;
    border-radius: 50px;
    white-space: nowrap;
}
.ms-plan-tier {
    font-size: 18px;
    font-weight: 800;
    color: #0f0f23;
    margin-bottom: 4px;
}
.ms-plan-tagline {
    font-size: 12px;
    color: #9ca3af;
    margin-bottom: 18px;
}
.ms-plan-pricing {
    display: flex;
    align-items: baseline;
    gap: 2px;
    margin-bottom: 4px;
}
.ms-plan-amount {
    font-size: 36px;
    font-weight: 800;
    color: #0f0f23;
    letter-spacing: -0.02em;
}
.ms-plan-period {
    font-size: 14px;
    color: #9ca3af;
    font-weight: 500;
}
.ms-plan-billing-note {
    font-size: 11px;
    color: #9ca3af;
    min-height: 16px;
    margin-bottom: 20px;
}
.ms-plan-features {
    list-style: none;
    padding: 0;
    margin: 0 0 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}
.ms-plan-features li {
    font-size: 13px;
    color: #374151;
    display: flex;
    align-items: center;
    gap: 8px;
}
.ms-plan-features li::before {
    content: '✓';
    font-weight: 700;
    color: #4f46e5;
    font-size: 13px;
    flex-shrink: 0;
}
.ms-plan-features li.ms-feature-no {
    color: #d1d5db;
    text-decoration: line-through;
}
.ms-plan-features li.ms-feature-no::before {
    content: '✕';
    color: #d1d5db;
    font-weight: 400;
}

/* CTA buttons */
.ms-plan-cta {
    width: 100%;
    padding: 11px 0;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    transition: all 0.18s;
    margin-top: auto;
}
.ms-plan-cta--current {
    background: #f3f4f6;
    color: #9ca3af;
    cursor: default;
}
.ms-plan-cta--upgrade {
    background: #f0f0ff;
    color: #4f46e5;
    border: 1.5px solid #c7d2fe;
}
.ms-plan-cta--upgrade:hover { background: #e0e7ff; }
.ms-plan-cta--pro {
    background: #4f46e5;
    color: #fff;
}
.ms-plan-cta--pro:hover { background: #4338ca; }
.ms-plan-cta--loading {
    background: #f3f4f6;
    color: #9ca3af;
    cursor: default;
    opacity: 0.7;
}

.ms-plans-notice {
    background: #fef9c3;
    border: 1px solid #fde047;
    border-radius: 8px;
    padding: 10px 14px;
    margin: 0 0 20px;
    font-size: 13px;
    color: #713f12;
    line-height: 1.45;
}
.ms-plans-notice p { margin: 0 0 8px; }
.ms-plans-notice p:last-child { margin-bottom: 0; }
.ms-plans-skip-btn {
    display: inline-block;
    margin-top: 4px;
    padding: 6px 14px;
    border: 1.5px solid #ca8a04;
    background: #fff;
    color: #92400e;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.ms-plans-skip-btn:hover { background: #fef3c7; color: #713f12; }

.ms-plans-footer {
    text-align: center;
    font-size: 12px;
    color: #9ca3af;
    margin: 24px 0 0;
}

/* Upgrade button in avatar dropdown */
.ms-avatar-upgrade-btn {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 7px 0;
    background: #4f46e5;
    color: #fff;
    border: none;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: background 0.15s;
}
.ms-avatar-upgrade-btn:hover { background: #4338ca; }

.ms-avatar-billing-btn {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 7px 0;
    background: transparent;
    color: #9ca3af;
    border: 1px solid #374151;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    transition: color 0.15s, border-color 0.15s;
}
.ms-avatar-billing-btn:hover { color: #f9fafb; border-color: #6b7280; }
.ms-avatar-billing-btn:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 680px) {
    .ms-plans-dialog { padding: 36px 18px 24px; }
    .ms-plans-grid { grid-template-columns: 1fr; }
    .ms-plans-header h2 { font-size: 22px; }
}

/* ── My Projects panel (avatar dropdown) ─────────────────────────────────── */
.ms-avatar-dropdown {
    min-width: 240px;
}

.ms-projects-section {
    border-top: 1px solid #2D3748;
    border-bottom: 1px solid #2D3748;
    margin: 8px 0;
    padding: 8px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ms-projects-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #6B7280;
    padding: 0 4px 2px;
}

.ms-projects-limit {
    font-size: 11px;
    color: #4B5563;
    padding: 0 4px 4px;
}

.ms-save-toast-action {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    pointer-events: auto;
}

.ms-save-toast-btn {
    flex-shrink: 0;
    background: #fff;
    color: #1a1a1a;
    border: none;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.ms-save-toast-btn:hover {
    background: #e5e7eb;
}

.ms-save-toast-close {
    flex-shrink: 0;
    margin-left: auto;
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 14px;
    cursor: pointer;
    padding: 2px 4px;
    line-height: 1;
}
.ms-save-toast-close:hover {
    color: #fff;
}

.ms-projects-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 200px;
    overflow-y: auto;
}

.ms-projects-loading,
.ms-projects-empty {
    font-size: 12px;
    color: #6B7280;
    padding: 4px;
    font-style: italic;
}

.ms-project-row {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 4px;
    border-radius: 5px;
}
.ms-project-row:hover {
    background: rgba(255,255,255,0.04);
}

.ms-project-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.ms-project-name {
    font-size: 12px;
    color: #E5E7EB;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ms-project-name--editable {
    cursor: pointer;
}
.ms-project-name--editable:hover {
    color: #A5B4FC;
    text-decoration: underline;
    text-decoration-color: rgba(165,180,252,0.4);
}

.ms-project-date {
    font-size: 10px;
    color: #6B7280;
}

.ms-project-rename-input {
    width: 100%;
    background: #111827;
    border: 1px solid #4B5563;
    border-radius: 3px;
    color: #E5E7EB;
    font-size: 12px;
    font-family: 'Inter', Arial, sans-serif;
    padding: 1px 5px;
    outline: none;
    box-sizing: border-box;
}
.ms-project-rename-input:focus { border-color: #6366F1; }

.ms-project-open-btn {
    flex-shrink: 0;
    height: 22px;
    padding: 0 8px;
    font-size: 11px;
    font-weight: 500;
    font-family: 'Inter', Arial, sans-serif;
    background: #3730A3;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}
.ms-project-open-btn:hover { background: #4338ca; }

.ms-project-icon-btn {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: #6B7280;
    cursor: pointer;
    border-radius: 4px;
    padding: 0;
    font-size: 14px;
    line-height: 1;
    transition: background 0.15s;
}
.ms-project-icon-btn:hover {
    background: rgba(255,255,255,0.08);
}
.ms-project-delete-btn:hover {
    background: rgba(239,68,68,0.12);
}

.ms-open-uuid-row {
    display: flex;
    gap: 4px;
    margin-top: 4px;
}

.ms-open-uuid-input {
    flex: 1;
    min-width: 0;
    height: 28px;
    padding: 0 8px;
    font-size: 11px;
    font-family: 'Inter', Arial, sans-serif;
    background: #0F172A;
    color: #E2E8F0;
    border: 1px solid #374151;
    border-radius: 5px;
    outline: none;
}
.ms-open-uuid-input:focus { border-color: #6366F1; }
.ms-open-uuid-input::placeholder { color: #4B5563; }

.ms-open-uuid-btn {
    flex-shrink: 0;
    height: 28px;
    padding: 0 10px;
    font-size: 11px;
    font-weight: 500;
    font-family: 'Inter', Arial, sans-serif;
    background: #374151;
    color: #E2E8F0;
    border: 1px solid #4B5563;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.15s;
}
.ms-open-uuid-btn:hover { background: #4B5563; }

/* ── File menu — Open from cloud UUID row ────────────────────────────────── */
.file-menu-uuid-row {
    display: flex;
    gap: 4px;
    margin-top: 6px;
}

.file-menu-uuid-input {
    flex: 1;
    min-width: 0;
    height: 28px;
    padding: 0 8px;
    font-size: 11px;
    font-family: 'Inter', Arial, sans-serif;
    background: #F8FAFF;
    color: #1e293b;
    border: 1px solid #C7D2FE;
    border-radius: 5px;
    outline: none;
    box-sizing: border-box;
}
.file-menu-uuid-input:focus { border-color: #6366F1; }
.file-menu-uuid-input::placeholder { color: #94A3B8; }

.file-menu-uuid-go {
    flex-shrink: 0;
    height: 28px;
    padding: 0 10px;
    font-size: 11px;
    font-weight: 600;
    font-family: 'Inter', Arial, sans-serif;
    background: #4F46E5;
    color: #fff;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.15s;
}
.file-menu-uuid-go:hover { background: #4338ca; }

/* ── Project name prompt modal ───────────────────────────────────────────── */
.ms-name-prompt-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ms-name-prompt-box {
    background: #1E2336;
    border: 1px solid #2D3748;
    border-radius: 12px;
    padding: 24px;
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.ms-name-prompt-title {
    font-size: 15px;
    font-weight: 600;
    color: #E5E7EB;
    font-family: 'Inter', Arial, sans-serif;
}

.ms-name-prompt-input {
    background: #111827;
    border: 1px solid #374151;
    border-radius: 8px;
    color: #E5E7EB;
    font-size: 14px;
    font-family: 'Inter', Arial, sans-serif;
    padding: 10px 12px;
    outline: none;
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.15s;
}
.ms-name-prompt-input:focus { border-color: #6366F1; }
.ms-name-prompt-input::placeholder { color: #4B5563; }

.ms-name-prompt-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.ms-name-prompt-cancel {
    background: transparent;
    border: 1px solid #374151;
    color: #9CA3AF;
    border-radius: 8px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 13px;
    font-family: 'Inter', Arial, sans-serif;
    transition: background 0.15s;
}
.ms-name-prompt-cancel:hover { background: #1F2937; color: #E5E7EB; }

.ms-name-prompt-save {
    background: #6366F1;
    border: none;
    color: #fff;
    border-radius: 8px;
    padding: 8px 18px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    font-family: 'Inter', Arial, sans-serif;
    transition: background 0.15s;
}
.ms-name-prompt-save:hover { background: #4F46E5; }
