/*
 * THX_EC ANNOTATE MODE CSS
 * Chế độ "Đọc và ghi chú" (Version 2.0)
 */

body.thx-ec-mode-annotate .thx-ec-mp,
body.thx-ec-mode-annotate .wp-block-thx-ec-mp {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0,0,0,0) !important;
    white-space: nowrap !important;
    border: 0 !important;
    padding: 0 !important;
    margin: -1px !important;
}

/* Biến màu bôi đen chuột thành trong suốt để thấy được marker nằm bên dưới */
body.thx-ec-mode-annotate .thx-ec-text-block ::selection {
    background: rgba(59, 130, 246, 0.25) !important;
}

body.thx-ec-mode-annotate .thx-ec-text-block .seg {
    -webkit-user-select: text;
    user-select: text;
    cursor: text;
}

body.thx-ec-mode-annotate .thx-ec-text-block .seg:hover {
    cursor: text;
}

/* Ép luôn hiển thị vùng văn bản khi ở chế độ Đọc và ghi chú */
body.thx-ec-mode-annotate .thx-ec-text-block.thx-ec-hidden-by-core,
body.thx-ec-mode-annotate .thx-ec-text-block,
body.thx-ec-mode-read .thx-ec-text-block.thx-ec-hidden-by-core,
body.thx-ec-mode-read .thx-ec-text-block {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
}

body.thx-ec-mode-annotate .thx-ec-text-block.thx-ec-hidden-by-core > *:not(.thx-ec-ui-control),
body.thx-ec-mode-read .thx-ec-text-block.thx-ec-hidden-by-core > *:not(.thx-ec-ui-control) {
    display: block !important;
}



body.thx-ec-mode-annotate .thx-ec-text-block .seg:hover {
    cursor: text;
}

/* Biến màu bôi đen chuột thành trong suốt để thấy được marker nằm bên dưới */
body.thx-ec-mode-annotate .thx-ec-text-block ::selection {
    background: rgba(59, 130, 246, 0.25) !important;
}

/* ═══════════════════════════════════════════════════
   ANNOTATION HIGHLIGHT MARKS (Overlapping enabled)
   ═══════════════════════════════════════════════════ */
.thx-ec-ann-hl {
    mix-blend-mode: multiply; /* Hiệu ứng trộn màu cực xịn */
    transition: background-color 0.2s ease;
    cursor: pointer;
}

/* Kéo dài background ra bên phải để lấp khoảng trống (space) giữa 2 segment nếu highlight trải dài */
.thx-ec-ann-hl.thx-ec-ann-hl-bridge {
    padding-right: 0.3em !important;
    margin-right: -0.3em !important;
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}



.thx-ec-ann-hl[data-ann-bg="yellow"]  { background-color: rgba(254, 240, 138, 0.5); }
.thx-ec-ann-hl[data-ann-bg="orange"]  { background-color: rgba(254, 215, 170, 0.5); }
.thx-ec-ann-hl[data-ann-bg="red"]     { background-color: rgba(254, 202, 202, 0.5); }
.thx-ec-ann-hl[data-ann-bg="pink"]    { background-color: rgba(251, 207, 232, 0.5); }
.thx-ec-ann-hl[data-ann-bg="purple"]  { background-color: rgba(233, 213, 255, 0.5); }
.thx-ec-ann-hl[data-ann-bg="blue"]    { background-color: rgba(191, 219, 254, 0.5); }
.thx-ec-ann-hl[data-ann-bg="teal"]    { background-color: rgba(153, 246, 228, 0.5); }
.thx-ec-ann-hl[data-ann-bg="green"]   { background-color: rgba(187, 247, 208, 0.5); }
.thx-ec-ann-hl[data-ann-bg="brown"]   { background-color: rgba(212, 186, 152, 0.5); }
.thx-ec-ann-hl[data-ann-bg="gray"]    { background-color: rgba(226, 232, 240, 0.5); } 

.thx-ec-ann-hl.hl-active[data-ann-bg="yellow"]  { background-color: rgba(254, 240, 138, 0.85); }
.thx-ec-ann-hl.hl-active[data-ann-bg="orange"]  { background-color: rgba(254, 215, 170, 0.85); }
.thx-ec-ann-hl.hl-active[data-ann-bg="red"]     { background-color: rgba(254, 202, 202, 0.85); }
.thx-ec-ann-hl.hl-active[data-ann-bg="pink"]    { background-color: rgba(251, 207, 232, 0.85); }
.thx-ec-ann-hl.hl-active[data-ann-bg="purple"]  { background-color: rgba(233, 213, 255, 0.85); }
.thx-ec-ann-hl.hl-active[data-ann-bg="blue"]    { background-color: rgba(191, 219, 254, 0.85); }
.thx-ec-ann-hl.hl-active[data-ann-bg="teal"]    { background-color: rgba(153, 246, 228, 0.85); }
.thx-ec-ann-hl.hl-active[data-ann-bg="green"]   { background-color: rgba(187, 247, 208, 0.85); }
.thx-ec-ann-hl.hl-active[data-ann-bg="brown"]   { background-color: rgba(212, 186, 152, 0.85); }
.thx-ec-ann-hl.hl-active[data-ann-bg="gray"]    { background-color: rgba(226, 232, 240, 0.85); } 
.thx-ec-ann-hl[data-ann-bg="transparent"] { background-color: transparent; }
.thx-ec-ann-hl[data-ann-color="blue"] {
    color: #2563eb;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
}

/* Chấm note indicator */
.thx-ec-ann-hl[data-ann-note]::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #f59e0b;
    border-radius: 50%;
    margin-left: 2px;
    vertical-align: super;
}

/* ═══════════════════════════════════════════════════
   1. ACTION TOOLTIP (khi bôi đen)
   ═══════════════════════════════════════════════════ */
.thx-ec-ann-action-tt {
    position: fixed;
    z-index: 100000;
    display: none;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    border: 1px solid #e2e8f0;
    padding: 6px;
    transform: translateY(10px);
    opacity: 0;
    transition: all 0.15s ease;
}

.thx-ec-ann-action-tt.is-visible {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.ann-action-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
}

.ann-action-sep {
    width: 1px;
    height: 24px;
    background: #e2e8f0;
    margin: 0 4px;
}

.ann-btn-icon {
    background: transparent;
    color: #475569;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.ann-btn-icon:hover { background: #f1f5f9; color: #0f172a; }

.ann-btn-icon.ann-btn-highlight {
    color: #334155;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.ann-btn-icon.ann-btn-highlight:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.ann-btn-icon svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    stroke: currentColor;
    stroke-width: 0.5;
}

.ann-btn-icon.ann-btn-highlight svg {
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    width: 17px;
    height: 17px;
}

.ann-swatches-dropdown {
    display: none;
    gap: 4px;
    margin-left: 4px;
    padding-left: 4px;
    border-left: 1px solid #e2e8f0;
    animation: fadeIn 0.2s;
}

.thx-ec-ann-action-tt:hover .ann-swatches-dropdown {
    display: flex;
}

.ann-btn-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.05); /* Viền mờ bên trong cho các màu nhạt */
}
.ann-btn-swatch:hover, .ann-btn-swatch.is-active { border-color: #94a3b8; transform: scale(1.15); box-shadow: 0 2px 6px rgba(0,0,0,0.1); }

/* ═══════════════════════════════════════════════════
   2. RICH EDITOR MODAL
   ═══════════════════════════════════════════════════ */
.thx-ec-ann-rich-modal {
    position: absolute; /* Gắn với văn bản thay vì fixed popup */
    z-index: 5;
    display: none;
    width: auto;
    min-width: 320px;
    max-width: 90vw;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.15);
    border: 1px solid #e2e8f0;
    flex-direction: column;
    overflow: hidden;
    font-family: inherit;
}

.ann-rt-drag-handle {
    height: 16px;
    background: #f8fafc;
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ann-rt-drag-handle:active { cursor: grabbing; }
.ann-rt-drag-handle::before {
    content: '';
    width: 32px;
    height: 4px;
    background: #cbd5e1;
    border-radius: 2px;
}

.thx-ec-ann-rich-modal.is-visible { display: flex; }

.ann-rt-toolbar {
    display: flex;
    align-items: center;
    padding: 6px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    gap: 4px;
}

.ann-rt-toolbar button {
    background: transparent;
    border: none;
    padding: 4px 6px;
    cursor: pointer;
    border-radius: 4px;
    color: #475569;
    font-size: 13px;
    font-family: monospace;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ann-rt-toolbar button:hover { background: #e2e8f0; color: #0f172a; }

.ann-rt-toolbar button svg { width: 14px; height: 14px; }

.ann-rt-sep {
    width: 1px;
    height: 18px;
    background: #cbd5e1;
    margin: 0 2px;
}

.ann-rt-spacer { flex-grow: 1; }

.ann-rt-delete-btn svg { width: 15px; height: 15px; stroke: #ef4444; fill: none; stroke-width: 2; }
.ann-rt-delete-btn:hover { background: #fee2e2 !important; }

.ann-rt-editor-area {
    min-height: 120px;
    height: 150px;
    overflow-y: auto;
    resize: both;
    padding: 12px;
    font-size: 14px;
    line-height: 1.6;
    color: #334155;
    outline: none;
}
.ann-rt-editor-area:empty:before {
    content: attr(placeholder);
    color: #94a3b8;
    pointer-events: none;
    display: block; /* For Firefox */
}

.ann-rt-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
}

.ann-rt-color-picker {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: wrap;
    max-width: 150px;
}

.ann-rt-save-status {
    font-size: 13px;
    font-weight: 500;
    margin-right: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.3s ease;
    white-space: nowrap;
    flex-shrink: 0;
}
.ann-rt-save-status.is-visible { opacity: 1; }
.ann-rt-save-status.is-saving { color: #64748b; }
.ann-rt-save-status.is-saved { color: #10b981; }
.ann-rt-save-status.is-error { color: #ef4444; }

@keyframes ann-spin {
    to { transform: rotate(360deg); }
}
.ann-spinner {
    display: inline-block;
    width: 12px; height: 12px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: ann-spin 0.75s linear infinite;
}

.ann-rt-footer button {
    padding: 6px 16px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
}
.ann-rt-cancel { background: transparent; color: #64748b; }
.ann-rt-cancel:hover { background: #e2e8f0; }
.ann-rt-save { background: #8b5cf6; color: #fff; }
.ann-rt-save:hover { background: #7c3aed; }

/* ═══════════════════════════════════════════════════
   3. HOVER STACK TOOLTIP
   ═══════════════════════════════════════════════════ */
.thx-ec-ann-hover-tt {
    position: fixed;
    z-index: 100000;
    display: none;
    width: 280px;
    flex-direction: column;
    gap: 8px;
}

.thx-ec-ann-hover-tt.is-visible { display: flex; }

.hover-stack-item {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    border: 1px solid #e2e8f0;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stack-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stack-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.stack-actions button {
    background: none;
    border: none;
    color: #475569;
    cursor: pointer;
    font-size: 14px;
    padding: 4px;
    display: flex;
    align-items: center;
    border-radius: 4px;
}
.stack-actions button svg {
    width: 14px;
    height: 14px;
}
.stack-actions button:hover { color: #0f172a; background: #e2e8f0; }

.stack-actions .btn-delete:hover {
    color: #ef4444;
    background: #fee2e2;
}

.stack-excerpt {
    font-size: 13px;
    color: #334155;
    line-height: 1.5;
    margin-bottom: 6px;
    word-break: break-word;
}
.stack-excerpt.has-mask::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: linear-gradient(transparent, #fff);
    pointer-events: none;
}
.stack-excerpt ul, .stack-excerpt ol {
    margin-top: 4px;
    margin-bottom: 4px;
    padding-left: 20px;
}
.stack-excerpt p {
    margin: 4px 0;
}

.stack-link {
    display: inline-block;
    font-size: 13px;
    color: #2563eb;
    text-decoration: none;
    margin-bottom: 4px;
    padding: 4px 8px;
    background: #eff6ff;
    border-radius: 4px;
}
.stack-link:hover {
    text-decoration: underline;
    background: #dbeafe;
}

.btn-read-full {
    align-self: flex-start;
    background: transparent;
    border: none;
    color: #8b5cf6;
    font-size: 12px;
    font-weight: 600;
    padding: 0;
    cursor: pointer;
}
.btn-read-full:hover { text-decoration: underline; }

/* ═══════════════════════════════════════════════════
   4. FULL READER MODAL
   ═══════════════════════════════════════════════════ */
.thx-ec-ann-full-reader-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 100005;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.thx-ec-ann-full-reader-overlay.is-visible { display: flex; }

.thx-ec-ann-full-reader {
    background: #fff;
    width: 100%;
    max-width: 600px;
    max-height: 85vh;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}

.reader-header {
    display: flex;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid #e2e8f0;
}

.reader-header .reader-color-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    margin-right: 12px;
}

.reader-header .reader-title {
    font-weight: 700;
    font-size: 16px;
    color: #1e293b;
    flex-grow: 1;
}

.reader-close {
    background: transparent;
    border: none;
    font-size: 24px;
    color: #94a3b8;
    cursor: pointer;
    line-height: 1;
}
.reader-close:hover { color: #f43f5e; }

.reader-content {
    padding: 24px;
    overflow-y: auto;
    font-size: 15px;
    line-height: 1.7;
    color: #334155;
}

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

/* ═══════════════════════════════════════════════════
   ANNOTATION PANEL (SIDEBAR UI)
   ═══════════════════════════════════════════════════ */
.thx-ec-annotation-panel {
    border-radius: 16px;
    background: linear-gradient(145deg, #ffffff, #f8fafc);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), inset 0 2px 4px rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(226, 232, 240, 0.8);
    overflow: hidden;
    font-family: "Inter", sans-serif;
    
    /* Floating Behavior */
    position: fixed;
    top: 50%;
    left: 60px;
    width: 320px;
    max-width: calc(100vw - 80px);
    z-index: 9999;
    
    /* Hidden State */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-45%) scale(0.95);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.thx-ec-annotation-panel.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(-50%) scale(1);
}

/* Specific Toggle Button Position */
#thx-ec-annotate-trigger.thx-ec-floating-btn {
    margin-top: 72px;
}

@media (max-width: 768px) {
    .thx-ec-annotation-panel {
        left: 42px !important;
    }
    #thx-ec-annotate-trigger.thx-ec-floating-btn {
        margin-top: 75px !important;
    }
}

.thx-ec-annotation-panel::before {
    content: "";
    position: absolute;
    top: 0; left: 0; width: 100%; height: 4px;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6, #ec4899);
}

.thx-ec-ap-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px 12px;
    border-bottom: 1px solid rgba(226, 232, 240, 0.5);
}

.thx-ec-ap-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 15px;
    color: #1e293b;
    letter-spacing: -0.2px;
}

.thx-ec-ap-title svg {
    color: #8b5cf6;
}

.thx-ec-ap-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: #10b981;
    background: rgba(16, 185, 129, 0.1);
    padding: 4px 10px;
    border-radius: 20px;
}

.thx-ec-ap-pulse {
    display: block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    animation: thx-ec-pulse-anim 2s infinite;
}

@keyframes thx-ec-pulse-anim {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.thx-ec-ap-body {
    padding: 16px 20px 20px;
}

.thx-ec-ap-name-label {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.thx-ec-ap-name-wrap {
    background: #f1f5f9;
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 24px;
    border-left: 3px solid #3b82f6;
}

.thx-ec-ap-name {
    font-size: 14px;
    font-weight: 600;
    color: #334155;
    line-height: 1.4;
    word-break: break-word;
}

.thx-ec-ap-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.thx-ec-ap-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

/* Primary Button */
.thx-ec-ap-btn-primary {
    background: #3b82f6;
    color: #ffffff;
    border: none;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}

.thx-ec-ap-btn-primary:hover {
    background: #2563eb;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.3);
}

.thx-ec-ap-btn-primary:active {
    transform: translateY(0);
}

/* Secondary Button */
.thx-ec-ap-btn-secondary {
    background: #ffffff;
    color: #64748b;
    border: 1.5px dashed #cbd5e1;
}

.thx-ec-ap-btn-secondary:hover {
    color: #3b82f6;
    border-color: #2563eb;
    background: #f8fafc;
}

.thx-ec-ap-btn-secondary:active {
    transform: translateY(1px);
}

/* Close button */
.thx-ec-ap-close-btn {
    background: transparent;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #9ca3af;
    transition: all 0.2s;
    padding: 0;
}
.thx-ec-ap-close-btn:hover {
    background-color: #ef4444;
    color: #ffffff;
}

#thx-ec-annotate-trigger.thx-ec-floating-btn:hover svg {
    transform: none !important;
}

/* PREMIUM TOOLTIP CHO BUTTON TRONG PANEL */
.thx-ec-tooltip-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.thx-ec-tooltip-wrap::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: #1e293b;
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    pointer-events: none;
    z-index: 999999;
}

.thx-ec-tooltip-wrap::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    border-width: 5px;
    border-style: solid;
    border-color: #1e293b transparent transparent transparent;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    pointer-events: none;
    z-index: 999999;
    margin-bottom: -10px;
}

.thx-ec-tooltip-wrap:hover::after,
.thx-ec-tooltip-wrap:hover::before {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(-2px);
}

