/* Professional SaaS Rich Text Editor Styles */
:root {
    --editor-primary: #6366f1;
    --editor-border: #e2e8f0;
    --editor-bg: #fff;
    --editor-toolbar-bg: #fcfcfd;
}

.modern-editor {
    background: var(--editor-bg);
    border: 1.5px solid var(--editor-border);
    border-radius: 20px;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}

.modern-editor.fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 2147483647 !important;
    border-radius: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    background: #fff !important;
    overflow: hidden !important;
    margin: 0 !important;
}

body.editor-fullscreen-active {
    overflow: hidden !important;
    height: 100vh !important;
    height: 100dvh !important;
    position: fixed !important;
    width: 100% !important;
}

@media (max-width: 768px) {
    .editor-toolbar {
        padding: 8px 10px;
        gap: 3px;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .editor-toolbar::-webkit-scrollbar { display: none; }

    .toolbar-btn {
        width: 30px;
        height: 30px;
        min-width: 30px;
        border-radius: 8px;
    }
    .toolbar-btn svg { width: 14px; height: 14px; }

    .toolbar-divider {
        height: 18px;
        margin: 0 3px;
        min-width: 1.5px;
    }

    .modern-editor.fullscreen .editor-toolbar {
        flex-shrink: 0;
    }

    .modern-editor.fullscreen .editor-content {
        padding: 16px;
        flex: 1 1 0% !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }
}

.editor-toolbar {
    padding: 10px 16px;
    background: var(--editor-toolbar-bg);
    border-bottom: 1.5px solid var(--editor-border);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    user-select: none;
    position: relative;
    z-index: 1005;
}

.toolbar-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1.5px solid transparent;
    border-radius: 10px;
    color: #64748b;
    cursor: pointer;
    transition: all 0.2s ease;
}

.toolbar-btn:hover {
    background: #fff;
    color: var(--editor-primary);
    border-color: var(--editor-border);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.toolbar-btn.active {
    background: #eef2ff;
    color: var(--editor-primary);
    border-color: #c7d2fe;
}

.toolbar-divider {
    width: 1.5px;
    height: 24px;
    background: var(--editor-border);
    margin: 0 6px;
}

/* Editor Content Area */
.editor-content {
    min-height: 250px;
    padding: 24px;
    font-size: 1rem;
    color: #1e293b;
    outline: none;
    position: relative;
    line-height: 1.7;
}

/* Clearfix for floated images */
.editor-content::after {
    content: "";
    display: table;
    clear: both;
}

.modern-editor.fullscreen .editor-content {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    overflow-y: auto !important;
}

.editor-content[placeholder]:empty:before {
    content: attr(placeholder);
    color: #94a3b8;
    cursor: text;
}

/* Typography Inside Editor */
.editor-content h2 {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 1rem;
    color: #0f172a;
}

.editor-content h3 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: #0f172a;
}

.editor-content p {
    margin-bottom: 1rem;
}

.editor-content ul,
.editor-content ol {
    margin-bottom: 1rem;
    padding-left: 24px;
}

.editor-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--editor-border);
}

.editor-content th,
.editor-content td {
    border: 1px solid var(--editor-border);
    padding: 12px 16px;
    text-align: left;
}

.editor-content th {
    background: #f8fafc;
    font-weight: 700;
    color: #475569;
}

.editor-content blockquote {
    border-left: 4px solid var(--editor-primary);
    margin: 20px 0;
    padding: 12px 24px;
    background: #f8fafc;
    font-style: italic;
    color: #475569;
    border-radius: 8px;
}

.editor-content pre {
    background: #f1f5f9;
    border: 1px solid var(--editor-border);
    border-radius: 10px;
    padding: 16px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.9rem;
    margin: 20px 0;
    white-space: pre-wrap;
}

.editor-content img {
    max-width: 100%;
    height: auto;
    border-radius: 16px;
    margin: 15px auto;
    display: block;
    cursor: pointer;
    transition: outline 0.1s ease;
}

.editor-content img.selected {
    outline: 4px solid var(--editor-primary);
    outline-offset: 4px;
}

/* Alignment Classes */
.align-left {
    float: left;
    margin: 0 20px 20px 0;
}

.align-right {
    float: right;
    margin: 0 0 20px 20px;
}

.align-center {
    display: block;
    margin: 20px auto;
}

/* Drop Marker */
.drop-marker {
    position: absolute;
    height: 4px;
    background: var(--editor-primary);
    border-radius: 2px;
    z-index: 10001;
    pointer-events: none;
    display: none;
}

/* Editor Footer */
.editor-footer {
    padding: 12px 24px;
    background: #fff;
    border-top: 1.5px solid var(--editor-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    clear: both;
}

.editor-status {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #94a3b8;
}

.status-divider {
    width: 4px;
    height: 4px;
    background: #cbd5e1;
    border-radius: 50%;
}

.limit-exceeded {
    color: #ef4444;
}

/* Overlays (Resizers, Toolbars) */
.editor-overlay-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1000;
}

.img-resizer-handle,
.img-align-toolbar {
    pointer-events: auto;
}

.img-resizer-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    background: var(--editor-primary);
    border: 2.5px solid #fff;
    border-radius: 50%;
    cursor: nwse-resize;
    display: none;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.img-resizer-handle.active {
    display: block;
}

@media (pointer: coarse) {
    .img-resizer-handle {
        width: 24px;
        height: 24px;
        border-width: 3px;
    }
}

.img-align-toolbar {
    position: absolute;
    background: #fff;
    border: 1px solid var(--editor-border);
    border-radius: 12px;
    padding: 6px;
    display: none;
    gap: 6px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
}

.img-align-toolbar.active {
    display: flex;
}

.align-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
}

.align-btn:hover {
    background: #eef2ff;
    border-color: var(--editor-primary);
    color: var(--editor-primary);
}

.align-icon-left,
.align-icon-center,
.align-icon-right {
    width: 16px;
    height: 12px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='21' y1='6' x2='3' y2='6'%3E%3C/line%3E%3Cline x1='15' y1='12' x2='3' y2='12'%3E%3C/line%3E%3Cline x1='17' y1='18' x2='3' y2='18'%3E%3C/line%3E%3C/svg%3E");
    background-repeat: no-repeat;
}

.align-icon-center {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='18' y1='6' x2='6' y2='6'%3E%3C/line%3E%3Cline x1='21' y1='12' x2='3' y2='12'%3E%3C/line%3E%3Cline x1='18' y1='18' x2='6' y2='18'%3E%3C/line%3E%3C/svg%3E");
}

.align-icon-right {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='21' y1='6' x2='3' y2='6'%3E%3C/line%3E%3Cline x1='21' y1='12' x2='9' y2='12'%3E%3C/line%3E%3Cline x1='21' y1='18' x2='7' y2='18'%3E%3C/line%3E%3C/svg%3E");
}

/* Pickers & Dropdowns */
.style-picker,
.list-picker,
.emoji-picker,
.color-picker {
    position: relative;
}

.style-dropdown,
.list-dropdown,
.emoji-dropdown,
.color-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    background: #fff;
    border: 1px solid var(--editor-border);
    border-radius: 14px;
    box-shadow: 0 15px 30px -5px rgba(0, 0, 0, 0.1);
    z-index: 5000;
    display: none;
    padding: 8px;
    min-width: 180px;
    animation: dropdownFade 0.2s ease;
}

.style-picker.active .style-dropdown,
.list-picker.active .list-dropdown,
.emoji-picker.active .emoji-dropdown,
.color-picker.active .color-dropdown {
    display: block;
}

@keyframes dropdownFade {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.style-option,
.list-option {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #475569;
    cursor: pointer;
    transition: all 0.2s;
}

.style-option:hover,
.list-option:hover {
    background: #f1f5f9;
    color: var(--editor-primary);
}

/* Modals */
.editor-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(8px);
    z-index: 2147483647 !important;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.editor-modal.active {
    display: flex !important;
}

.modal-card {
    background: #fff;
    width: 100%;
    max-width: 440px;
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    animation: modalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-tabs {
    display: flex;
    background: #f8fafc;
    padding: 6px;
    margin: 24px 32px 0;
    border-radius: 14px;
    gap: 6px;
}

.modal-tab-btn {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #64748b;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-tab-btn.active {
    background: #fff;
    color: var(--editor-primary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.file-drop-area {
    border: 2px dashed var(--editor-border);
    border-radius: 16px;
    padding: 30px;
    text-align: center;
    transition: all 0.2s;
    cursor: pointer;
}

.file-drop-area:hover {
    border-color: var(--editor-primary);
    background: #f5f3ff;
}

.file-drop-trigger {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: #64748b;
}

.file-drop-trigger svg {
    color: var(--editor-primary);
}

.file-drop-trigger span {
    font-weight: 600;
    font-size: 0.9rem;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-head {
    padding: 24px 32px;
    border-bottom: 1px solid var(--editor-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 24px 32px;
}

.modal-group {
    margin-bottom: 20px;
}

.modal-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    color: #64748b;
    margin-bottom: 8px;
}

.form-control {
    width: 100%;
    height: 48px;
    padding: 0 16px;
    background: #fff;
    border: 1.5px solid var(--editor-border);
    border-radius: 12px;
    font-size: 0.95rem;
    color: #1e293b;
    outline: none;
    transition: all 0.2s;
}

.form-control:focus {
    border-color: var(--editor-primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.modal-foot {
    padding: 20px 32px;
    background: #fcfcfd;
    border-top: 1px solid var(--editor-border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.btn-modal-cancel,
.btn-modal-confirm {
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-modal-cancel {
    background: transparent;
    border: 1px solid var(--editor-border);
    color: #64748b;
}

.btn-modal-confirm {
    background: var(--editor-primary);
    border: 1px solid var(--editor-primary);
    color: #fff;
}

.btn-modal-confirm:hover {
    background: #4f46e5;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.btn-close-modal {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: #94a3b8;
    cursor: pointer;
    line-height: 1;
}

.btn-close-modal:hover {
    color: #ef4444;
}

/* Color & Emoji Grids */
.color-grid,
.emoji-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid rgba(0, 0, 0, 0.05);
    transition: transform 0.2s;
}

.color-swatch:hover {
    transform: scale(1.15);
}

.emoji-item {
    font-size: 1.4rem;
    padding: 8px;
    cursor: pointer;
    border-radius: 10px;
    transition: background 0.2s, transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Custom Confirm Modal Styles */
.custom-confirm-modal {
    background: rgba(15, 23, 42, 0.5);
    /* Soft dark overlay */
    backdrop-filter: blur(4px);
}

.confirm-card {
    background: #ffffff;
    width: 100%;
    max-width: 420px;
    border-radius: 16px;
    padding: 28px;
    color: #1e293b;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.05);
    animation: confirmBounce 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes confirmBounce {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.confirm-head {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: #0f172a;
}

.confirm-body {
    font-size: 0.95rem;
    color: #64748b;
    margin-bottom: 28px;
    line-height: 1.6;
}

.confirm-foot {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.btn-confirm-yes,
.btn-confirm-no {
    padding: 10px 20px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.btn-confirm-yes {
    background: #6366f1;
    color: #fff;
}

.btn-confirm-yes:hover {
    background: #4f46e5;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-confirm-no {
    background: #f1f5f9;
    color: #475569;
}

.btn-confirm-no:hover {
    background: #e2e8f0;
    color: #1e293b;
}

/* Canned Response Autocomplete Dropdown Styles */
.canned-autocomplete-dropdown {
    position: absolute;
    z-index: 10000;
    width: 320px;
    max-height: 240px;
    overflow-y: auto;
    background: #ffffff;
    border: 1px solid var(--editor-border);
    border-radius: 14px;
    box-shadow: 0 12px 30px -4px rgba(15, 23, 42, 0.12), 0 4px 12px -2px rgba(15, 23, 42, 0.05);
    display: none;
    flex-direction: column;
    padding: 6px;
    font-family: inherit;
    gap: 4px;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.canned-autocomplete-item {
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-align: left;
    background: transparent;
    border: none;
    width: 100%;
    transition: all 0.15s ease;
}

.canned-autocomplete-item.active,
.canned-autocomplete-item:hover {
    background: #f1f5f9;
}

.canned-autocomplete-item .item-title {
    font-size: 0.86rem;
    font-weight: 750;
    color: #0f172a;
}

.canned-autocomplete-item.active .item-title,
.canned-autocomplete-item:hover .item-title {
    color: var(--editor-primary);
}

.canned-autocomplete-item .item-shortcut {
    font-size: 0.72rem;
    color: var(--editor-primary);
    font-weight: 800;
    background: #eef2ff;
    padding: 2px 6px;
    border-radius: 6px;
}

.canned-autocomplete-item .item-preview {
    font-size: 0.76rem;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}