/* ==========================================================================
   MA Document Editor — Complete Stylesheet
   Replaces all inline _injectStyles(). Load once via <link>.
   ========================================================================== */

/* ---------- A4 Page Layout ---------- */
.ma-doced-wrap {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.ma-doced-body {
    display: flex;
    flex: 1;
    /* No overflow — .ma-content is the scroll container */
}

/* Remove .ma-main padding when doc editor is active (full-width editor) */
.ma-main:has(.ma-doced-wrap) {
    padding: 0;
    max-width: none;
}

.ma-doced-editor-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #e5e7eb;
    /* No overflow — scrolls with .ma-doced-body */
    position: relative;
    min-width: 0;
}

.ma-doced-page {
    background: #fff;
    width: 100%;
    max-width: 800px;
    margin: 24px auto;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.04);
    border-radius: 2px;
}

/* ---------- Quill Editor Overrides ---------- */
/* Toolbar moved outside .ma-doced-page by JS → sticky in .ma-content scroll */
.ma-doced-editor-col > .ql-toolbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #f8fafc;
    border: none;
    border-bottom: 1px solid #e2e8f0;
    padding: 8px 16px;
}

/* Fallback if JS hasn't moved the toolbar yet */
.ma-doced-page .ql-toolbar {
    background: #f8fafc;
    border: none;
    border-bottom: 1px solid #e2e8f0;
    padding: 8px 16px;
}

.ma-doced-page .ql-container {
    border: none;
}

.ma-doced-page .ql-editor {
    padding: 48px 64px;
    min-height: 800px;
    font-family: 'Georgia', 'Times New Roman', serif;
    font-size: 11pt;
    line-height: 1.6;
    color: #1a1a1a;
    overflow-y: visible !important; /* Expand to content, scroll with page */
}

.ma-doced-page .ql-editor h1 {
    font-size: 20pt;
    font-weight: 700;
    color: #0f172a;
    margin: 24px 0 12px;
}

.ma-doced-page .ql-editor h2 {
    font-size: 16pt;
    font-weight: 600;
    color: #1e293b;
    margin: 20px 0 8px;
}

.ma-doced-page .ql-editor h3 {
    font-size: 13pt;
    font-weight: 600;
    color: #334155;
    margin: 16px 0 6px;
}

.ma-doced-page .ql-editor h4 {
    font-size: 11pt;
    font-weight: 600;
    color: #475569;
    margin: 12px 0 4px;
}

.ma-doced-page .ql-editor p {
    margin: 0 0 8px;
}

.ma-doced-page .ql-editor ul,
.ma-doced-page .ql-editor ol {
    padding-left: 24px;
    margin: 4px 0 8px;
}

.ma-doced-page .ql-editor blockquote {
    border-left: 3px solid #3b82f6;
    padding-left: 16px;
    color: #475569;
    font-style: italic;
    margin: 12px 0;
}

/* ---------- Toolbar Separators ---------- */
.ma-doced-toolbar-sep {
    display: inline-block;
    width: 1px;
    height: 24px;
    background: #d1d5db;
    margin: 0 6px;
    vertical-align: middle;
}

/* ---------- Comment Highlights (in-text) ---------- */
.ql-comment-highlight {
    background: #fef9c3;
    border-bottom: 2px solid #eab308;
    cursor: pointer;
    transition: background 0.15s;
    border-radius: 1px;
}

.ql-comment-highlight:hover,
.ql-comment-highlight.hover {
    background: #fde68a;
    box-shadow: 0 0 0 2px rgba(234,179,8,0.25);
}

.ql-comment-highlight.active {
    background: #fde68a;
    box-shadow: 0 0 0 1px #eab308;
}

.ql-comment-highlight.resolved {
    background: #dcfce7;
    border-bottom-color: #22c55e;
    opacity: 0.65;
}

/* Temporary highlight overlay (used when CommentBlot spans don't exist) */
.ma-doced-temp-highlight {
    background: rgba(253, 224, 71, 0.45);
    border-bottom: 2px solid #eab308;
    border-radius: 2px;
    pointer-events: none;
    z-index: 5;
    animation: ma-doced-flash 0.8s ease-in-out 2;
}

@keyframes ma-doced-flash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ---------- Comment Sidebar ---------- */
.ma-doced-comments-col {
    width: 320px;
    min-width: 320px;
    background: #f8fafc;
    border-left: 1px solid #e2e8f0;
    /* No overflow — scrolls with .ma-doced-body (synced with editor) */
}

/* Sidebar header + hint stays sticky at top */
.ma-doced-sidebar-sticky-header {
    position: sticky;
    top: 0;
    z-index: 5;
    background: #f8fafc;
}

.ma-doced-comments-header {
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 600;
    color: #1e293b;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ma-doced-comments-body {
    position: relative;
    flex: 1;
    padding: 8px;
}

/* ---------- Comment Cards ---------- */
.ma-doced-comment-card {
    position: absolute;
    width: calc(100% - 16px);
    left: 8px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: border-color 0.15s, box-shadow 0.15s;
    cursor: pointer;
}

.ma-doced-comment-card:hover {
    border-color: #cbd5e1;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.ma-doced-comment-card.active {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59,130,246,0.12);
}

.ma-doced-comment-card.resolved {
    opacity: 0.55;
}

.ma-doced-comment-card .connector-line {
    position: absolute;
    left: -9px;
    top: 16px;
    width: 9px;
    height: 1px;
    background: #94a3b8;
}

/* ---------- Comment Card Internals ---------- */
.ma-doced-cmt-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.ma-doced-cmt-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.ma-doced-cmt-author {
    font-size: 12px;
    font-weight: 600;
    color: #1e293b;
}

.ma-doced-cmt-time {
    font-size: 11px;
    color: #94a3b8;
    margin-left: auto;
}

.ma-doced-cmt-quote {
    font-size: 11px;
    color: #64748b;
    font-style: italic;
    border-left: 2px solid #3b82f6;
    padding-left: 8px;
    margin: 4px 0 6px;
    line-height: 1.4;
    max-height: 36px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ma-doced-cmt-text {
    font-size: 12px;
    color: #334155;
    line-height: 1.5;
    margin-bottom: 6px;
}

.ma-doced-cmt-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.ma-doced-cmt-btn {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    transition: all 0.15s;
}

.ma-doced-cmt-btn:hover {
    background: #f1f5f9;
    color: #334155;
}

.ma-doced-cmt-btn.resolve {
    color: #16a34a;
    border-color: #bbf7d0;
}

.ma-doced-cmt-btn.resolve:hover {
    background: #f0fdf4;
}

.ma-doced-cmt-btn.reopen {
    color: #f59e0b;
    border-color: #fde68a;
}

.ma-doced-cmt-btn.reopen:hover {
    background: #fffbeb;
}

.ma-doced-cmt-resolved-badge {
    font-size: 11px;
    color: #16a34a;
    font-weight: 600;
}

/* ---------- Reply Styles ---------- */
.ma-doced-cmt-replies {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid #f1f5f9;
}

.ma-doced-cmt-reply {
    display: flex;
    gap: 6px;
    padding: 4px 0;
    font-size: 11px;
}

.ma-doced-cmt-reply-avatar {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.ma-doced-cmt-reply-body {
    flex: 1;
}

.ma-doced-cmt-reply-author {
    font-weight: 600;
    color: #475569;
}

.ma-doced-cmt-reply-text {
    color: #64748b;
    margin-top: 1px;
}

.ma-doced-cmt-reply-form {
    margin-top: 6px;
    display: flex;
    gap: 6px;
}

.ma-doced-cmt-reply-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 11px;
    resize: none;
    min-height: 28px;
    font-family: inherit;
}

.ma-doced-cmt-reply-input:focus {
    outline: none;
    border-color: #3b82f6;
}

.ma-doced-cmt-reply-submit {
    padding: 4px 10px;
    border: none;
    border-radius: 6px;
    background: #3b82f6;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}

.ma-doced-cmt-reply-submit:hover {
    background: #2563eb;
}

/* ---------- Floating Comment Button & Popup ---------- */
.ma-doced-float-comment {
    position: absolute;
    z-index: 100;
    display: flex;
    gap: 4px;
    align-items: center;
}

.ma-doced-float-btn {
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #3b82f6;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: all 0.15s;
}

.ma-doced-float-btn:hover {
    background: #eff6ff;
    border-color: #3b82f6;
}

.ma-doced-float-popup {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    width: 260px;
}

.ma-doced-float-textarea {
    width: 100%;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 12px;
    resize: none;
    min-height: 50px;
    font-family: inherit;
    box-sizing: border-box;
}

.ma-doced-float-textarea:focus {
    outline: none;
    border-color: #3b82f6;
}

.ma-doced-float-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 6px;
}

.ma-doced-float-submit {
    padding: 4px 14px;
    border: none;
    border-radius: 6px;
    background: #3b82f6;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.ma-doced-float-submit:hover {
    background: #2563eb;
}

.ma-doced-float-cancel {
    padding: 4px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #fff;
    color: #64748b;
    font-size: 12px;
    cursor: pointer;
}

.ma-doced-float-cancel:hover {
    background: #f1f5f9;
}

/* ---------- Header, Footer, Status ---------- */
.ma-doced-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid #e2e8f0;
    background: #fff;
    flex-wrap: wrap;
}

.ma-doced-back {
    color: #3b82f6;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
}

.ma-doced-back:hover {
    text-decoration: underline;
}

.ma-doced-title {
    font-size: 17px;
    font-weight: 700;
    color: #0f172a;
    flex: 1;
}

.ma-doced-meta {
    font-size: 11px;
    color: #94a3b8;
}

.ma-doced-status {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ma-doced-version {
    font-size: 12px;
    font-weight: 600;
    color: #475569;
}

.ma-doced-approval {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid;
    font-weight: 600;
}

.ma-doced-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: #1e293b;
    border-top: 1px solid #334155;
}

.ma-doced-footer-left,
.ma-doced-footer-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

.ma-doced-btn {
    padding: 5px 14px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
}

.ma-doced-btn-primary {
    background: #3b82f6;
    color: #fff;
}

.ma-doced-btn-primary:hover {
    background: #2563eb;
}

.ma-doced-btn-secondary {
    background: #f1f5f9;
    color: #475569;
}

.ma-doced-btn-secondary:hover {
    background: #e2e8f0;
}

.ma-doced-btn-ghost {
    background: transparent;
    color: #94a3b8;
    border-color: #475569;
}

.ma-doced-btn-ghost:hover {
    color: #fff;
    border-color: #64748b;
}

.ma-doced-btn-success {
    background: #10b981;
    color: #fff;
}

.ma-doced-btn-success:hover {
    background: #059669;
}

.ma-doced-autosave {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: #94a3b8;
    background: rgba(255,255,255,0.9);
    padding: 2px 12px;
    border-radius: 12px;
}

.ma-doced-view-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 700;
    color: #fff;
    border: 2px solid #1e293b;
}

.ma-doced-version-panel {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin: 8px 16px;
    padding: 12px;
    max-height: 200px;
    overflow-y: auto;
    display: none;
}

.ma-doced-version-panel.visible {
    display: block;
}

/* ---------- Legacy Comments Section ---------- */
.ma-doced-legacy-comments {
    padding: 12px;
    border-top: 1px solid #e2e8f0;
}

.ma-doced-legacy-title {
    font-size: 12px;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.ma-doced-legacy-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 6px;
}
