/**
 * EduBridge Modern Tabler-Integrated Rich Text Editor Stylesheet
 */

:root {
    --rich-border: var(--tblr-border-color, #dce1e7);
    --rich-bg: var(--tblr-bg-surface, #ffffff);
    --rich-bg-subtle: var(--tblr-bg-surface-secondary, #f8fafc);
    --rich-text: var(--tblr-body-color, #1e293b);
    --rich-muted: var(--tblr-secondary, #64748b);
    --rich-primary: #206bc4;
    --rich-radius: var(--tblr-border-radius, 6px);
}

.rich-editor-container {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--rich-border);
    border-radius: var(--rich-radius);
    background-color: var(--rich-bg);
    color: var(--rich-text);
    position: relative;
    transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
    margin-bottom: 0.5rem;
}

.rich-editor-container:focus-within {
    border-color: #90b5e2;
    box-shadow: 0 0 0 .25rem rgba(32, 107, 196, .2);
}

/* Toolbar */
.rich-editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    background-color: var(--rich-bg-subtle);
    border-bottom: 1px solid var(--rich-border);
    border-top-left-radius: calc(var(--rich-radius) - 1px);
    border-top-right-radius: calc(var(--rich-radius) - 1px);
    user-select: none;
}

.rich-toolbar-group {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding-right: 6px;
    margin-right: 4px;
    border-right: 1px solid var(--rich-border);
}

.rich-toolbar-group:last-child {
    border-right: none;
    padding-right: 0;
    margin-right: 0;
}

/* Buttons */
.rich-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--rich-text);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    transition: all .15s ease;
}

.rich-btn:hover {
    background-color: rgba(32, 107, 196, 0.1);
    color: var(--rich-primary);
    border-color: rgba(32, 107, 196, 0.2);
}

.rich-btn.is-active {
    background-color: var(--rich-primary);
    color: #ffffff !important;
    border-color: var(--rich-primary);
}

.rich-btn svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

.rich-btn.rich-btn-record {
    color: #d63939;
}

.rich-btn.rich-btn-record:hover {
    background-color: rgba(214, 57, 57, 0.1);
    border-color: rgba(214, 57, 57, 0.3);
    color: #d63939;
}

/* Toolbar Select */
.rich-select {
    height: 30px;
    padding: 2px 22px 2px 8px;
    font-size: 13px;
    border: 1px solid var(--rich-border);
    border-radius: 4px;
    background-color: var(--rich-bg);
    color: var(--rich-text);
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%2364748b' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 12px 10px;
    appearance: none;
}

.rich-select:focus {
    outline: none;
    border-color: var(--rich-primary);
}

/* Content Area */
.rich-editor-content {
    min-height: 200px;
    max-height: 600px;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    color: var(--rich-text);
    background-color: var(--rich-bg);
    outline: none;
    font-size: 0.975rem;
    line-height: 1.7;
    position: relative;
    word-break: break-word;
}

.rich-editor-content[placeholder]:empty:before {
    content: attr(placeholder);
    color: var(--rich-muted);
    opacity: 0.7;
    pointer-events: none;
    display: block;
}

/* HTML Source Editor */
.rich-editor-source {
    width: 100%;
    min-height: 200px;
    max-height: 600px;
    padding: 1rem 1.25rem;
    font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 13px;
    line-height: 1.5;
    background-color: var(--rich-bg-subtle);
    color: var(--rich-text);
    border: none;
    outline: none;
    resize: vertical;
    display: none;
}

/* Status Bar */
.rich-editor-statusbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 10px;
    background-color: var(--rich-bg-subtle);
    border-top: 1px solid var(--rich-border);
    font-size: 11px;
    color: var(--rich-muted);
    border-bottom-left-radius: calc(var(--rich-radius) - 1px);
    border-bottom-right-radius: calc(var(--rich-radius) - 1px);
}

/* Fullscreen Mode */
.rich-editor-container.is-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 9999 !important;
    border-radius: 0 !important;
    margin: 0 !important;
}

.rich-editor-container.is-fullscreen .rich-editor-content,
.rich-editor-container.is-fullscreen .rich-editor-source {
    flex: 1 1 auto;
    max-height: none !important;
    height: calc(100vh - 80px) !important;
}

/* Formatting inside editor content */
.rich-editor-content h1, .rich-content h1 { font-size: 1.75rem; font-weight: 700; margin-top: 1rem; margin-bottom: 0.5rem; }
.rich-editor-content h2, .rich-content h2 { font-size: 1.45rem; font-weight: 700; margin-top: 0.85rem; margin-bottom: 0.5rem; }
.rich-editor-content h3, .rich-content h3 { font-size: 1.25rem; font-weight: 600; margin-top: 0.75rem; margin-bottom: 0.4rem; }
.rich-editor-content h4, .rich-content h4 { font-size: 1.1rem; font-weight: 600; margin-top: 0.65rem; margin-bottom: 0.35rem; }
.rich-editor-content p, .rich-content p { margin-bottom: 0.75rem; }
.rich-editor-content p:last-child { margin-bottom: 0; }

.rich-editor-content blockquote, .rich-content blockquote {
    border-left: 4px solid var(--rich-primary);
    padding: 0.5rem 1rem;
    margin: 0.75rem 0;
    color: var(--rich-muted);
    background-color: var(--rich-bg-subtle);
    border-radius: 0 4px 4px 0;
    font-style: italic;
}

.rich-editor-content pre, .rich-content pre {
    background-color: var(--rich-bg-subtle);
    border: 1px solid var(--rich-border);
    border-radius: 4px;
    padding: 0.75rem 1rem;
    overflow-x: auto;
    margin: 0.75rem 0;
    font-family: SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.875rem;
}

.rich-editor-content table, .rich-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
}

.rich-editor-content table th, .rich-editor-content table td,
.rich-content table th, .rich-content table td {
    border: 1px solid var(--rich-border);
    padding: 0.5rem 0.75rem;
    text-align: left;
}

.rich-editor-content table th, .rich-content table th {
    background-color: var(--rich-bg-subtle);
    font-weight: 600;
}

/* Audio Player */
.rich-audio {
    display: block;
    width: 100%;
    max-width: 420px;
    margin: 0.5rem 0;
    border-radius: 30px;
}

/* File Attachment Card */
.rich-file-card {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    margin: 4px 0;
    background-color: var(--rich-bg-subtle);
    border: 1px solid var(--rich-border);
    border-radius: 6px;
    font-size: 0.875rem;
    color: var(--rich-text);
    text-decoration: none;
    max-width: 100%;
}

.rich-file-card svg {
    color: var(--rich-primary);
    flex-shrink: 0;
}

.rich-file-card a {
    color: var(--rich-primary);
    font-weight: 600;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rich-file-card a:hover {
    text-decoration: underline;
}

/* Video Wrapper */
.rich-video-wrapper {
    position: relative;
    width: 100%;
    max-width: 720px;
    margin: 0.75rem 0;
    border-radius: 6px;
    overflow: hidden;
}

.rich-video-wrapper iframe,
.rich-video-wrapper video {
    width: 100%;
    border: 0;
    border-radius: 6px;
}

/* Color Dropdown & Emoji Dropdown Menus */
.rich-dropdown-menu {
    position: absolute;
    z-index: 1050;
    background-color: var(--rich-bg);
    border: 1px solid var(--rich-border);
    border-radius: 6px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    padding: 8px;
    display: none;
}

.rich-dropdown-menu.show {
    display: block;
}

/* Color palette grid */
.rich-color-palette {
    display: grid;
    grid-template-columns: repeat(7, 24px);
    gap: 4px;
    margin-bottom: 6px;
}

.rich-color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: transform .1s ease;
}

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

/* Emoji Picker Grid */
.rich-emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 30px);
    gap: 4px;
    max-height: 220px;
    overflow-y: auto;
}

.rich-emoji-btn {
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    border: 0;
    background: transparent;
    cursor: pointer;
    border-radius: 4px;
}

.rich-emoji-btn:hover {
    background-color: rgba(32, 107, 196, 0.12);
}

/* Voice Recorder Modal / Dialog */
.rich-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.rich-modal {
    background-color: var(--rich-bg);
    color: var(--rich-text);
    border: 1px solid var(--rich-border);
    border-radius: 8px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
    width: 95%;
    max-width: 500px;
    overflow: hidden;
    animation: richModalFadeIn .2s ease;
}

@keyframes richModalFadeIn {
    from { opacity: 0; transform: translateY(-10px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.rich-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 18px;
    border-bottom: 1px solid var(--rich-border);
    font-weight: 600;
    font-size: 1rem;
}

.rich-modal-body {
    padding: 18px;
}

.rich-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 18px;
    border-top: 1px solid var(--rich-border);
    background-color: var(--rich-bg-subtle);
}

/* Recording Visualizer & Pulse */
.rich-record-visualizer {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 0;
}

.rich-record-circle {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background-color: #fce8e8;
    color: #d63939;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 14px;
    transition: all .2s ease;
}

.rich-record-circle.is-recording {
    background-color: #d63939;
    color: #ffffff;
    animation: richPulseRecord 1.5s infinite;
}

@keyframes richPulseRecord {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(214, 57, 57, 0.6); }
    70% { transform: scale(1.06); box-shadow: 0 0 0 16px rgba(214, 57, 57, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(214, 57, 57, 0); }
}

.rich-record-timer {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    font-variant-numeric: tabular-nums;
    margin-bottom: 8px;
}

/* Dark theme overrides */
[data-bs-theme="dark"] .rich-editor-container {
    --rich-border: rgba(128, 150, 172, 0.25);
    --rich-bg: #182433;
    --rich-bg-subtle: #141c26;
    --rich-text: #e5e7eb;
    --rich-muted: #94a3b8;
}

[data-bs-theme="dark"] .rich-modal {
    background-color: #182433;
    color: #e5e7eb;
}

[data-bs-theme="dark"] .rich-select {
    background-color: #182433;
    color: #e5e7eb;
    border-color: rgba(128, 150, 172, 0.3);
}

[data-bs-theme="dark"] .rich-file-card {
    background-color: #1e293b;
    border-color: rgba(128, 150, 172, 0.3);
}
