/* WYSIWYG Editor Styles - Retro Terminal Theme */

.wysiwyg-wrapper {
    position: relative;
    width: 100%;
}

.wysiwyg-editor {
    width: 100%;
    min-height: 72px; /* 3 rows * 24px */
    max-height: 240px; /* 10 rows * 24px */
    padding: 8px 12px;
    background: var(--color-bg-primary);
    color: var(--color-primary);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 24px;
    overflow-y: auto;
    resize: none;
    box-sizing: border-box;
    text-align: left;
}

.wysiwyg-editor:focus {
    outline: none;
    border-color: var(--color-accent, var(--color-primary-dark));
    box-shadow: 0 0 5px var(--color-primary);
}

.wysiwyg-editor[contenteditable="true"]:empty:before {
    content: attr(data-placeholder);
    color: var(--color-primary-dim);
    pointer-events: none;
}

/* Show placeholder when editor is disabled (rate limited, capability revoked) */
.wysiwyg-editor[contenteditable="false"]:empty:before {
    content: attr(data-placeholder);
    color: var(--color-text-muted);
    pointer-events: none;
}

/* Toolbar */
.wysiwyg-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    align-items: center;
}

.wysiwyg-btn {
    padding: 0;
    background: var(--color-bg-surface);
    color: var(--color-primary);
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 12px;
    min-height: 27px;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
}

/* Hover only on devices that support it (not touch) */
@media (hover: hover) {
    .wysiwyg-btn:hover {
        background: var(--color-primary);
        color: var(--color-bg-primary);
    }
}

.wysiwyg-btn:active {
    transform: scale(0.95);
}

/* Active/toggled state for formatting buttons (B, I, U, S) */
.wysiwyg-btn.active {
    background: var(--color-primary);
    color: var(--color-bg-primary);
    box-shadow: 0 0 6px var(--color-primary);
}

.toolbar-separator {
    width: 1px;
    height: 20px;
    background: var(--color-primary);
    margin: 0 4px;
}

.toolbar-spacer {
    flex: 1;
}

/* FUCS Cost Tracker */
.fucs-cost-tracker {
    color: var(--color-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    padding: 0 8px;
    white-space: nowrap;
}

.fucs-cost-tracker strong {
    color: var(--color-warning);
}

/* Media Previews in Editor */
.wysiwyg-editor img {
    max-width: 200px;
    max-height: 200px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    margin: 4px;
    display: inline-block;
    vertical-align: middle;
}

.wysiwyg-editor video,
.wysiwyg-editor audio {
    max-width: 300px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    margin: 4px;
    display: block;
}

/* Scale media previews in chat editor with footer height (100-350px range) */
.chat-editor-wrapper .wysiwyg-editor img {
    /* Scale max size: 80px at 100px footer, ~150px at 225px, 220px at 350px */
    max-width: clamp(80px, calc(var(--footer-height, 100px) * 0.7), 220px);
    max-height: clamp(60px, calc(var(--footer-height, 100px) * 0.5), 170px);
    margin: 2px;
}

.chat-editor-wrapper .wysiwyg-editor video {
    /* Scale max size with footer */
    max-width: clamp(100px, calc(var(--footer-height, 100px) * 0.85), 280px);
    max-height: clamp(70px, calc(var(--footer-height, 100px) * 0.6), 200px);
    margin: 2px;
}

.chat-editor-wrapper .wysiwyg-editor audio {
    /* Scale width with footer */
    max-width: clamp(120px, calc(var(--footer-height, 100px) * 1.0), 320px);
    margin: 2px;
}

/* Code blocks */
.wysiwyg-editor code {
    background: var(--color-bg-secondary);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: var(--font-mono);
    color: var(--color-warning);
}

.wysiwyg-editor pre {
    background: var(--color-bg-secondary);
    padding: 12px;
    border-radius: 4px;
    border: 1px solid var(--color-border);
    overflow-x: auto;
    margin: 8px 0;
}

/* Quote blocks */
.wysiwyg-editor blockquote {
    border-left: 3px solid var(--color-border-accent);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--color-primary-dark);
    font-style: italic;
}

/* Lists */
.wysiwyg-editor ul {
    padding-left: 20px;
    margin: 8px 0;
    list-style-type: disc !important;
}

.wysiwyg-editor li {
    margin: 4px 0;
    display: list-item !important;
    list-style-position: outside;
    list-style-type: disc !important;
}

/* Chat-specific wrapper - scales with --footer-height */
.chat-editor-wrapper {
    position: relative;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Allow flex shrinking */
}

/* wysiwyg-wrapper must also be flex to pass height to editor */
.chat-editor-wrapper .wysiwyg-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Make chat editor fill remaining space after toolbar */
.chat-editor-wrapper .wysiwyg-editor {
    flex: 1;
    min-height: 20px !important; /* Override inline style, allow smaller at small footer */
    max-height: none; /* Override default max-height, let container control it */
}

/* Scale toolbar with footer height (100-350px range) */
/* Uses clamp to cap scaling at reasonable min/max values */
.chat-editor-wrapper .wysiwyg-toolbar {
    /* Scale padding: 4px at 100px footer, ~8px at 225px, 12px at 350px */
    padding: clamp(4px, calc(var(--footer-height, 100px) * 0.035), 12px);
    gap: clamp(2px, calc(var(--footer-height, 100px) * 0.02), 6px);
    flex-shrink: 0; /* Don't shrink toolbar */
}

/* Scale toolbar buttons - including emoji icons */
.chat-editor-wrapper .wysiwyg-btn {
    /* Scale font: 14px at 100px footer, ~18px at 225px, 24px at 350px */
    font-size: clamp(14px, calc(var(--footer-height, 100px) * 0.08), 24px);
    /* Scale height: 32px at 100px footer, ~38px at 225px, 48px at 350px */
    min-height: clamp(32px, calc(var(--footer-height, 100px) * 0.17), 48px);
    /* Scale width to match height for square buttons */
    min-width: clamp(32px, calc(var(--footer-height, 100px) * 0.17), 48px);
    /* Scale padding */
    padding: clamp(4px, calc(var(--footer-height, 100px) * 0.025), 8px);
    /* Center emoji/text */
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* Scale color swatch inside button */
.chat-editor-wrapper .wysiwyg-btn .color-swatch {
    width: clamp(16px, calc(var(--footer-height, 100px) * 0.09), 28px) !important;
    height: clamp(16px, calc(var(--footer-height, 100px) * 0.09), 28px) !important;
}

/* Scale toolbar separator */
.chat-editor-wrapper .toolbar-separator {
    height: clamp(20px, calc(var(--footer-height, 100px) * 0.12), 36px);
    margin: 0 clamp(2px, calc(var(--footer-height, 100px) * 0.015), 5px);
}

/* Scale FUCS cost tracker */
.chat-editor-wrapper .fucs-cost-tracker {
    font-size: clamp(10px, calc(var(--footer-height, 100px) * 0.06), 16px);
    padding: 0 clamp(4px, calc(var(--footer-height, 100px) * 0.03), 10px);
}

/* Chat input container - scales with footer height (100-350px range) */
.chat-input-container {
    display: flex;
    gap: clamp(4px, calc(var(--footer-height, 100px) * 0.035), 12px);
    align-items: stretch;
    width: 100%;
    flex: 1;
    min-height: 0;
}

/* Button group - contains send and clear buttons */
.chat-button-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
    /* Scale width with footer height (100-350px range) */
    width: clamp(60px, calc(var(--footer-height, 100px) * 0.4), 120px);
}

/* Send button - takes 75% of button group height */
.chat-button-group .send-button {
    flex: 3;
    background: var(--color-primary);
    color: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: 4px 4px 0 0;
    cursor: pointer;
    font-family: var(--font-mono);
    font-weight: bold;
    white-space: nowrap;
    transition: all 0.2s;
    /* Scale font with footer height (100-350px range) */
    font-size: clamp(10px, calc(var(--footer-height, 100px) * 0.06), 18px);
    padding: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-button-group .send-button:hover {
    background: var(--color-accent, var(--color-primary-dark));
    box-shadow: 0 0 10px var(--color-primary);
}

.chat-button-group .send-button:active {
    transform: scale(0.98);
}

/* Clear button - takes 25% of button group height */
.chat-button-group .clear-button {
    flex: 1;
    background: var(--color-bg-tertiary);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
    border-radius: 0 0 4px 4px;
    cursor: pointer;
    font-family: var(--font-mono);
    font-weight: bold;
    white-space: nowrap;
    transition: all 0.2s;
    /* Scale font with footer height (100-350px range) */
    font-size: clamp(8px, calc(var(--footer-height, 100px) * 0.05), 16px);
    padding: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 20px;
}

.chat-button-group .clear-button:hover {
    background: var(--color-error, #ff4444);
    color: var(--color-bg-primary);
    border-color: var(--color-error, #ff4444);
}

.chat-button-group .clear-button:active {
    transform: scale(0.98);
}

/* Send button - fills container height, doesn't shrink */
.chat-input-container > .send-button {
    background: var(--color-primary);
    color: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-mono);
    font-weight: bold;
    white-space: nowrap;
    transition: all 0.2s;
    /* Scale font with footer height (100-350px range) */
    font-size: clamp(12px, calc(var(--footer-height, 100px) * 0.06), 20px);
    /* Scale padding */
    padding: clamp(6px, calc(var(--footer-height, 100px) * 0.035), 14px) clamp(12px, calc(var(--footer-height, 100px) * 0.07), 28px);
    /* Scale width with footer height */
    min-width: clamp(60px, calc(var(--footer-height, 100px) * 0.35), 120px);
    /* Don't shrink, stretch to fill container height */
    flex-shrink: 0;
    align-self: stretch;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-input-container > .send-button:hover {
    background: var(--color-accent, var(--color-primary-dark));
    box-shadow: 0 0 10px var(--color-primary);
}

.chat-input-container > .send-button:active {
    transform: scale(0.98);
}

/* Make chat editor in container have clearer focus */
.chat-editor-wrapper .wysiwyg-editor {
    background: #0a0a0a;
    border: 1px solid #444;
}

.chat-editor-wrapper .wysiwyg-editor:focus {
    background: var(--color-bg-primary);
    border-color: #666;
    box-shadow: 0 0 5px rgba(255, 255, 255, 0.1);
}

.chat-editor-wrapper .wysiwyg-toolbar {
    border: 1px solid #444;
    border-bottom: none;
}

/* Upload progress indicator */
.chat-upload-progress {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-primary);
    border-radius: 4px;
    padding: 8px 12px;
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--color-primary);
    z-index: 100;
    font-family: var(--font-mono);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

@keyframes upload-pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.upload-progress-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.upload-progress-bar-container {
    width: 100%;
    height: 6px;
    background: var(--color-bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}

.upload-progress-bar {
    height: 100%;
    background: var(--color-primary);
    transition: width 0.3s ease;
    border-radius: 3px;
}

.upload-progress-text {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.upload-progress-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-cancel-btn {
    background: transparent;
    border: 1px solid var(--color-danger);
    color: var(--color-danger);
    padding: 2px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    margin-left: 10px;
    transition: all 0.2s ease;
}

.upload-cancel-btn:hover {
    background: var(--color-danger);
    color: var(--color-bg);
}

/* Mobile adjustments */
@media (max-width: 768px) {
    /* Mobile toolbar - fixed compact size, doesn't scale with footer height */
    .wysiwyg-toolbar {
        padding: 4px !important;
        gap: 3px !important;
        flex-shrink: 0;
    }

    /* Mobile toolbar buttons - larger touch targets */
    .wysiwyg-btn {
        padding: 4px !important;
        font-size: 14px !important;
        min-height: 32px !important;
        min-width: 32px !important;
    }

    /* Override chat-editor-wrapper toolbar button scaling on mobile */
    .chat-editor-wrapper .wysiwyg-btn {
        font-size: 14px !important;
        min-height: 32px !important;
        min-width: 32px !important;
        padding: 4px !important;
    }

    /* Mobile toolbar separator */
    .chat-editor-wrapper .toolbar-separator {
        height: 20px !important;
        margin: 0 2px !important;
    }

    /* Mobile FUCS tracker - compact */
    .chat-editor-wrapper .fucs-cost-tracker {
        font-size: 10px !important;
        padding: 0 4px !important;
    }

    .wysiwyg-editor {
        font-size: 13px;
        line-height: 20px;
        min-height: 30px; /* Allow smaller on mobile */
    }

    .fucs-cost-tracker {
        font-size: 10px;
    }

    /* Mobile: ensure footer input fills space */
    .footer-input {
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

    /* Mobile: ensure send button stays visible */
    .chat-input-container {
        width: 100%;
        max-width: 100%;
        flex-wrap: nowrap;
        flex: 1;
        min-height: 0;
    }

    .chat-input-container .send-button {
        flex-shrink: 0;
        min-width: 60px;
        padding: 8px 12px;
    }

    .chat-editor-wrapper {
        min-width: 0; /* Allow shrinking */
        min-height: 0; /* Allow vertical shrinking too */
    }
}

/* Scrollbar styling for editor */
.wysiwyg-editor::-webkit-scrollbar {
    width: 8px;
}

.wysiwyg-editor::-webkit-scrollbar-track {
    background: var(--color-bg-primary);
}

.wysiwyg-editor::-webkit-scrollbar-thumb {
    background: var(--color-primary);
    border-radius: 4px;
}

.wysiwyg-editor::-webkit-scrollbar-thumb:hover {
    background: var(--color-accent, var(--color-primary-dark));
}

/* ===== Responsive Toolbar ===== */

/* Buttons container - holds priority and overflow */
.toolbar-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
    overflow: hidden;
}

/* Priority and overflow button containers */
.toolbar-priority,
.toolbar-overflow {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* More button (···) - hidden by default, shown in compact mode */
.wysiwyg-more-btn {
    display: none;
    font-weight: bold;
    letter-spacing: 2px;
    flex-shrink: 0;
}

/* Collapse button («) - hidden by default, shown in expanded mode */
.wysiwyg-collapse-btn {
    display: none;
    font-weight: bold;
    font-size: 16px;
    flex-shrink: 0;
}

/* Compact mode (narrow screens) */
.wysiwyg-toolbar.compact {
    position: relative;
}

.wysiwyg-toolbar.compact .toolbar-overflow {
    display: none;
}

.wysiwyg-toolbar.compact .wysiwyg-more-btn {
    display: flex;
}

/* Expanded mode (horizontal scroll) */
.wysiwyg-toolbar.expanded .toolbar-buttons {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--color-primary) transparent;
}

.wysiwyg-toolbar.expanded .toolbar-buttons::-webkit-scrollbar {
    height: 4px;
}

.wysiwyg-toolbar.expanded .toolbar-buttons::-webkit-scrollbar-track {
    background: transparent;
}

.wysiwyg-toolbar.expanded .toolbar-buttons::-webkit-scrollbar-thumb {
    background: var(--color-primary);
    border-radius: 2px;
}

.wysiwyg-toolbar.expanded .toolbar-overflow {
    display: flex;
}

.wysiwyg-toolbar.expanded .wysiwyg-more-btn {
    display: none;
}

.wysiwyg-toolbar.expanded .wysiwyg-collapse-btn {
    display: flex;
}

/* FUCS cost tracker states */
.fucs-cost-tracker.high-cost strong {
    color: var(--color-warning, #ffcc00);
}

.fucs-cost-tracker.insufficient {
    color: var(--color-error, #ff4444) !important;
}

.fucs-cost-tracker.insufficient strong {
    color: var(--color-error, #ff4444) !important;
}

/* ===== Modal Editor (Phase 3) ===== */

/* Modal backdrop */
.wysiwyg-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    animation: fadeIn 0.15s ease-out;
}

/* Modal container */
.wysiwyg-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 75vw;
    height: 75vh;
    max-width: 1200px;
    max-height: 800px;
    background: var(--color-bg-primary);
    border: 2px solid var(--color-primary);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    z-index: 10000;
    box-shadow: 0 0 30px rgba(0, 255, 0, 0.2);
    animation: modalSlideIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translate(-50%, -48%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

/* Modal header - simplified with CANCEL | FUCS | SUBMIT */
.wysiwyg-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
    border-radius: 6px 6px 0 0;
    gap: 8px;
}

.wysiwyg-modal-header .modal-cancel-btn {
    background: transparent;
    color: var(--color-error, #ff4444);
    border: 1px solid var(--color-error, #ff4444);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: bold;
    transition: all 0.15s;
    flex-shrink: 0;
}

.wysiwyg-modal-header .modal-cancel-btn:hover {
    background: var(--color-error, #ff4444);
    color: var(--color-bg-primary);
}

.wysiwyg-modal-header .modal-submit-btn {
    background: var(--color-primary);
    color: var(--color-bg-primary);
    border: 1px solid var(--color-primary);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: bold;
    transition: all 0.15s;
    flex-shrink: 0;
}

.wysiwyg-modal-header .modal-submit-btn:hover {
    box-shadow: 0 0 10px var(--color-primary);
}

.wysiwyg-modal-header .modal-submit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

/* Modal FUCS info bar - inside header */
.wysiwyg-modal-fucs-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    flex: 1;
    font-family: var(--font-mono);
    font-size: 11px;
    min-width: 0;
    overflow: hidden;
}

.wysiwyg-modal-fucs-bar.insufficient {
    color: var(--color-error, #ff4444);
}

.modal-balance {
    color: var(--color-primary);
    white-space: nowrap;
}

.modal-cost {
    color: var(--color-warning);
    white-space: nowrap;
}

.modal-cost.insufficient {
    color: var(--color-error, #ff4444);
}

/* Modal toolbar */
.wysiwyg-modal .wysiwyg-toolbar {
    border-radius: 0;
    border-left: none;
    border-right: none;
}

/* Modal content area */
.wysiwyg-modal-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 16px;
    gap: 16px;
}

/* Preview area for media */
.wysiwyg-modal-preview {
    flex: 1;
    overflow-y: auto;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 16px;
    min-height: 150px;
}

.wysiwyg-modal-preview img,
.wysiwyg-modal-preview video {
    max-width: 100%;
    max-height: 300px;
    border-radius: 4px;
    margin: 8px;
}

/* Modal editor */
.wysiwyg-modal .wysiwyg-editor {
    min-height: 100px;
    max-height: 200px;
}

/* Attachment indicator in minimized editor */
.attachment-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: var(--color-bg-tertiary);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    font-size: 11px;
    color: var(--color-primary);
    margin-left: 8px;
}

.expand-btn {
    background: var(--color-primary);
    color: var(--color-bg-primary);
    border: none;
    padding: 2px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
    margin-left: 4px;
}

/* Mobile modal - 90% */
@media (max-width: 768px) {
    .wysiwyg-modal {
        width: 90vw;
        height: auto;
        max-height: 80vh;
        max-height: 80dvh; /* Dynamic viewport height - accounts for virtual keyboard */
    }

    /* Ensure content area scrolls, not the whole modal */
    .wysiwyg-modal-content {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }

    /* Keep header fixed/compact */
    .wysiwyg-modal-header {
        flex-shrink: 0;
    }

    /* Smaller preview area on mobile */
    .wysiwyg-modal-preview {
        min-height: 100px;
        max-height: 40vh;
        max-height: 40dvh;
    }
}

/* Very small screens - almost full but with room for keyboard */
@media (max-width: 480px) {
    .wysiwyg-modal {
        width: 100vw;
        height: auto;
        max-height: 85vh;
        max-height: 85dvh; /* Dynamic viewport - adjusts when keyboard opens */
        top: 10px;
        transform: translateX(-50%);
        border-radius: 8px 8px 0 0;
        border: none;
        border-top: 2px solid var(--color-primary);
    }

    .wysiwyg-modal-header {
        border-radius: 6px 6px 0 0;
        padding: 6px 8px;
        gap: 6px;
    }

    .wysiwyg-modal-header .modal-cancel-btn,
    .wysiwyg-modal-header .modal-submit-btn {
        padding: 5px 10px;
        font-size: 10px;
    }

    /* Compact FUCS bar in header */
    .wysiwyg-modal-fucs-bar {
        font-size: 9px;
        gap: 8px;
    }

    /* Scrollable content */
    .wysiwyg-modal-content {
        padding: 8px;
        gap: 8px;
        overflow-y: auto;
        flex: 1;
        min-height: 0;
    }

    .wysiwyg-modal-preview {
        min-height: 80px;
        padding: 8px;
    }

    /* Force compact mode on small screens (but allow expanded mode to override) */
    .wysiwyg-toolbar.compact .toolbar-overflow {
        display: none;
    }

    .wysiwyg-toolbar.compact .wysiwyg-more-btn {
        display: flex;
    }

    /* Allow expanded mode on small screens */
    .wysiwyg-toolbar.expanded .toolbar-overflow {
        display: flex;
    }

    .wysiwyg-toolbar.expanded .wysiwyg-more-btn {
        display: none;
    }

    .wysiwyg-toolbar.expanded .wysiwyg-collapse-btn {
        display: flex;
    }
}

/* ===== Code Block Modal ===== */

/* Code modal backdrop */
.wysiwyg-code-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    animation: fadeIn 0.15s ease-out;
}

/* Code modal container */
.wysiwyg-code-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 70vw;
    max-width: 800px;
    max-height: 80vh;
    background: var(--color-bg-primary);
    border: 2px solid var(--color-warning, #ffcc00);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    z-index: 10000;
    box-shadow: 0 0 30px rgba(255, 204, 0, 0.2);
    animation: modalSlideIn 0.2s ease-out;
}

/* Code modal header */
.code-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
    border-radius: 6px 6px 0 0;
}

.code-modal-title {
    color: var(--color-warning, #ffcc00);
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: bold;
}

.code-modal-close {
    background: transparent;
    color: var(--color-text-secondary);
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 0 8px;
    line-height: 1;
    transition: color 0.15s;
}

.code-modal-close:hover {
    color: var(--color-error, #ff4444);
}

/* Code modal body */
.code-modal-body {
    flex: 1;
    padding: 16px;
    display: flex;
    flex-direction: column;
    min-height: 200px;
    max-height: 50vh;
}

/* Code textarea */
.code-modal-textarea {
    flex: 1;
    width: 100%;
    min-height: 150px;
    padding: 12px;
    background: #0a0a0a;
    color: var(--color-warning, #ffcc00);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
    resize: vertical;
    tab-size: 4;
}

.code-modal-textarea:focus {
    outline: none;
    border-color: var(--color-warning, #ffcc00);
    box-shadow: 0 0 8px rgba(255, 204, 0, 0.3);
}

.code-modal-textarea::placeholder {
    color: var(--color-text-muted);
}

/* Code modal footer */
.code-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
    border-radius: 0 0 6px 6px;
}

.code-modal-cancel,
.code-modal-insert {
    padding: 8px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: bold;
    transition: all 0.15s;
}

.code-modal-cancel {
    background: transparent;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

.code-modal-cancel:hover {
    background: var(--color-bg-tertiary);
    color: var(--color-primary);
}

.code-modal-insert {
    background: var(--color-warning, #ffcc00);
    color: #000;
    border: 1px solid var(--color-warning, #ffcc00);
}

.code-modal-insert:hover {
    box-shadow: 0 0 12px rgba(255, 204, 0, 0.5);
}

/* Code modal mobile */
@media (max-width: 768px) {
    .wysiwyg-code-modal {
        width: 90vw;
        max-width: none;
        max-height: 80vh;
        max-height: 80dvh;
    }

    .code-modal-textarea {
        min-height: 120px;
    }

    .code-modal-body {
        overflow-y: auto;
        flex: 1;
        min-height: 0;
    }
}

@media (max-width: 480px) {
    .wysiwyg-code-modal {
        width: 100vw;
        height: auto;
        max-height: 85vh;
        max-height: 85dvh;
        top: 10px;
        transform: translateX(-50%);
        border-radius: 8px 8px 0 0;
        border: none;
        border-top: 2px solid var(--color-warning, #ffcc00);
    }

    .code-modal-header {
        border-radius: 6px 6px 0 0;
        padding: 8px 12px;
        flex-shrink: 0;
    }

    .code-modal-footer {
        border-radius: 0;
        padding: 8px 12px;
        flex-shrink: 0;
    }

    .code-modal-body {
        flex: 1;
        min-height: 0;
        max-height: none;
        overflow-y: auto;
        padding: 8px;
    }

    .code-modal-textarea {
        min-height: 100px;
    }
}
