/* ============================================================
   Note Anchors — رندر روی متن صفحه
   ============================================================ */

.note-anchor {
    cursor: pointer;
    border-radius: 3px;
    transition: filter 150ms ease, box-shadow 150ms ease;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

/* هایلایت */
.note-anchor[data-note-type="HIGHLIGHT"] {
    background-color: var(--anchor-color, #fef08a);
    padding: 0 1px;
}

/* یادداشت */
.note-anchor[data-note-type="NOTE"] {
    border-bottom: 2px solid var(--anchor-color, #f59e0b);
    padding-bottom: 1px;
}

/* ترکیبی (هم هایلایت هم یادداشت روی یه قطعه) */
.note-anchor[data-note-type="HIGHLIGHT,NOTE"],
.note-anchor[data-note-type="NOTE,HIGHLIGHT"] {
    background-color: color-mix(in srgb, var(--anchor-color, #fef08a) 60%, transparent);
    border-bottom: 2px solid var(--anchor-color, #f59e0b);
}

.note-anchor:hover {
    filter: brightness(0.92);
    box-shadow: 0 0 0 2px rgba(217, 119, 6, 0.2);
}

/* FUZZY — خط‌چین */
.note-anchor--fuzzy {
    border-bottom-style: dotted !important;
    opacity: 0.85;
}

/* Flash — از sidebar کلیک شد */
.note-anchor--flash {
    animation: anchor-flash 1.2s ease;
}

@keyframes anchor-flash {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.15); box-shadow: 0 0 0 5px rgba(251, 191, 36, 0.4); }
}

/* ============================================================
   Selection Tooltip — رنگ‌های هایلایت
   ============================================================ */

.selection-tooltip .color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.15);
    transition: transform 120ms ease, box-shadow 120ms ease;
    cursor: pointer;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.selection-tooltip .color-swatch:hover {
    transform: scale(1.15);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
}

.selection-tooltip .color-swatch:active {
    transform: scale(0.9);
}

/* dark mode */
.dark .selection-tooltip .color-swatch {
    border-color: rgba(0, 0, 0, 0.15);
}
.dark .selection-tooltip .color-swatch:hover {
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.15);
}
/* ============================================================
   Quill Editor — override برای تم پروژه
   ============================================================ */

#quillEditor {
    background: #f5f5f4;
    border-radius: 12px;
    overflow: hidden;
    direction: rtl;
    /* جدا کردن toolbar از editor به‌صورت بصری */
    border: 1px solid #e7e5e4;
}

.dark #quillEditor {
    background: #404040;
    border-color: #525252;
}

/* toolbar — رادیاس فقط بالا */
#quillEditor .ql-toolbar.ql-snow {
    border: 0;
    border-bottom: 1px solid #e7e5e4;
    padding: 8px 10px;
    direction: ltr;
    border-radius: 0;
}

.dark #quillEditor .ql-toolbar.ql-snow {
    border-bottom-color: #525252;
}

/* container — رادیاس فقط پایین */
#quillEditor .ql-container.ql-snow {
    border: 0;
    font-family: inherit;
    font-size: 14px;
    border-radius: 0;
}

#quillEditor .ql-editor {
    min-height: 120px;
    max-height: 240px;
    padding: 12px 14px;
    color: #1c1917;
    line-height: 1.9;
    direction: rtl;
    text-align: right;
}

.dark #quillEditor .ql-editor {
    color: #e7e5e4;
}

#quillEditor .ql-editor.ql-blank::before {
    color: #a8a29e;
    font-style: normal;
    left: 14px;
    right: 14px;
    text-align: right;
}

.dark #quillEditor .ql-editor.ql-blank::before {
    color: #a3a3a3;
}

/* ============================================================
   Toolbar icons — وضوح در light / dark
   ============================================================ */

/* Light mode */
#quillEditor .ql-toolbar .ql-stroke {
    stroke: #57534e;
}

#quillEditor .ql-toolbar .ql-fill {
    fill: #57534e;
}

#quillEditor .ql-toolbar .ql-picker-label {
    color: #57534e;
}

#quillEditor .ql-toolbar button:hover .ql-stroke,
#quillEditor .ql-toolbar button:focus .ql-stroke,
#quillEditor .ql-toolbar button.ql-active .ql-stroke {
    stroke: #d97706;
}

#quillEditor .ql-toolbar button:hover .ql-fill,
#quillEditor .ql-toolbar button:focus .ql-fill,
#quillEditor .ql-toolbar button.ql-active .ql-fill {
    fill: #d97706;
}

/* Dark mode — روشن‌تر از Light */
.dark #quillEditor .ql-toolbar .ql-stroke {
    stroke: #e7e5e4;
}

.dark #quillEditor .ql-toolbar .ql-fill {
    fill: #e7e5e4;
}

.dark #quillEditor .ql-toolbar .ql-picker-label {
    color: #e7e5e4;
}

.dark #quillEditor .ql-toolbar button:hover .ql-stroke,
.dark #quillEditor .ql-toolbar button:focus .ql-stroke,
.dark #quillEditor .ql-toolbar button.ql-active .ql-stroke {
    stroke: #fbbf24;
}

.dark #quillEditor .ql-toolbar button:hover .ql-fill,
.dark #quillEditor .ql-toolbar button:focus .ql-fill,
.dark #quillEditor .ql-toolbar button.ql-active .ql-fill {
    fill: #fbbf24;
}

/* hover background برای دکمه‌های toolbar */
#quillEditor .ql-toolbar button {
    border-radius: 6px;
    transition: background-color 120ms ease;
}

#quillEditor .ql-toolbar button:hover {
    background-color: rgba(217, 119, 6, 0.1);
}

.dark #quillEditor .ql-toolbar button:hover {
    background-color: rgba(251, 191, 36, 0.12);
}

#quillEditor .ql-toolbar button.ql-active {
    background-color: rgba(217, 119, 6, 0.15);
}

.dark #quillEditor .ql-toolbar button.ql-active {
    background-color: rgba(251, 191, 36, 0.18);
}

/* link tooltip — بالاتر از modal */
.ql-tooltip {
    z-index: 9999 !important;
    border-radius: 10px;
    border: 1px solid #e7e5e4;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.25);
}

.dark .ql-tooltip {
    background-color: #262626;
    color: #e7e5e4;
    border-color: #525252;
}

.ql-tooltip input {
    direction: ltr;
    text-align: left;
}

.ql-tooltip input,
.dark .ql-tooltip input {
    border-radius: 6px;
}

/* ============================================================
   Anchor Popover
   ============================================================ */

.anchor-popover {
    position: fixed;
    z-index: 80;
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 6px;
    border-radius: 14px;
    background: rgba(28, 25, 23, 0.95);
    color: #e7e5e4;
    backdrop-filter: blur(12px);
    box-shadow:
        0 16px 40px -12px rgba(0, 0, 0, 0.6),
        0 2px 6px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.08);
    animation: anchor-popover-in 160ms ease-out;
    transform-origin: bottom center;
}

.dark .anchor-popover {
    background: rgba(250, 250, 249, 0.96);
    color: #1c1917;
    border-color: rgba(0, 0, 0, 0.08);
    box-shadow:
        0 16px 40px -12px rgba(0, 0, 0, 0.35),
        0 2px 6px rgba(0, 0, 0, 0.15);
}

@keyframes anchor-popover-in {
    from { opacity: 0; transform: translateY(4px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* swatch های رنگ داخل popover */
.anchor-popover__swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.15);
    cursor: pointer;
    transition: transform 120ms ease, box-shadow 120ms ease;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.anchor-popover__swatch:hover {
    transform: scale(1.15);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
}

.anchor-popover__swatch:active {
    transform: scale(0.9);
}

.anchor-popover__swatch.is-current {
    box-shadow:
        0 0 0 2px rgba(255, 255, 255, 0.15),
        inset 0 0 0 2px rgba(255, 255, 255, 0.6);
}

.dark .anchor-popover__swatch {
    border-color: rgba(0, 0, 0, 0.15);
}

.dark .anchor-popover__swatch:hover {
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.15);
}

.dark .anchor-popover__swatch.is-current {
    box-shadow:
        0 0 0 2px rgba(0, 0, 0, 0.1),
        inset 0 0 0 2px rgba(0, 0, 0, 0.4);
}

/* دکمه‌های آیکونی */
.anchor-popover__btn {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: transparent;
    color: inherit;
    border: 0;
    cursor: pointer;
    transition: background-color 120ms ease, transform 120ms ease;
    -webkit-tap-highlight-color: transparent;
}

.anchor-popover__btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.dark .anchor-popover__btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

.anchor-popover__btn:active {
    transform: scale(0.9);
}

.anchor-popover__btn--danger:hover {
    background: rgba(239, 68, 68, 0.18);
    color: #fca5a5;
}

.dark .anchor-popover__btn--danger:hover {
    background: rgba(220, 38, 38, 0.12);
    color: #dc2626;
}

.anchor-popover__divider {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.12);
    margin: 0 2px;
}

.dark .anchor-popover__divider {
    background: rgba(0, 0, 0, 0.08);
}
/* ============================================================
   My Notes Sidebar — items
   ============================================================ */

.note-list-item {
    position: relative;
    padding: 10px 12px 10px 14px;
    border-radius: 14px;
    background: #fff;
    border: 1px solid rgba(231, 229, 228, 0.7);
    cursor: pointer;
    transition: border-color 150ms ease, background-color 150ms ease, transform 150ms ease;
}

.dark .note-list-item {
    background: rgba(38, 38, 38, 0.6);
    border-color: rgba(64, 64, 64, 0.7);
}

.note-list-item:hover {
    border-color: rgba(217, 119, 6, 0.5);
}

.dark .note-list-item:hover {
    border-color: rgba(251, 191, 36, 0.4);
}

.note-list-item:active {
    transform: scale(0.98);
}

/* نوار رنگی کنار */
.note-list-item::before {
    content: '';
    position: absolute;
    top: 10px;
    bottom: 10px;
    right: 0;
    width: 3px;
    border-radius: 3px;
    background: var(--item-color, #f59e0b);
}

/* حالت صفحه‌ی فعلی */
.note-list-item.is-current-page {
    background: rgba(254, 243, 199, 0.4);
    border-color: rgba(245, 158, 11, 0.4);
}

.dark .note-list-item.is-current-page {
    background: rgba(120, 53, 15, 0.15);
    border-color: rgba(245, 158, 11, 0.3);
}

/* flash وقتی از sidebar پرش شد */
.note-list-item.is-flashing {
    animation: sidebar-item-flash 1.4s ease;
}

@keyframes sidebar-item-flash {
    0%, 100% { box-shadow: 0 0 0 0 rgba(251, 191, 36, 0); }
    40% { box-shadow: 0 0 0 6px rgba(251, 191, 36, 0.25); }
}

/* بج صفحه */
.note-list-item .note-page-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 999px;
    font-variant-numeric: tabular-nums;
    background: rgba(120, 113, 108, 0.1);
    color: #57534e;
}

.dark .note-list-item .note-page-badge {
    background: rgba(168, 162, 158, 0.12);
    color: #d6d3d1;
}

/* وضعیت */
.note-list-item .note-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 9px;
    padding: 2px 6px;
    border-radius: 999px;
    font-weight: 600;
}

.note-list-item .note-status-badge--fuzzy {
    background: rgba(251, 191, 36, 0.18);
    color: #b45309;
}

.dark .note-list-item .note-status-badge--fuzzy {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
}

.note-list-item .note-status-badge--orphaned {
    background: rgba(239, 68, 68, 0.12);
    color: #b91c1c;
}

.dark .note-list-item .note-status-badge--orphaned {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
}

/* خط‌کلیپ متن */
.note-list-item .note-snippet {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.75;
}

.note-list-item .note-snippet--html {
    /* برای یادداشت‌هایی که HTML هستن */
    unicode-bidi: plaintext;
}

/* empty state */
.notes-sidebar-empty {
    text-align: center;
    padding: 40px 20px;
}

.notes-sidebar-empty .emoji {
    font-size: 36px;
    display: block;
    margin-bottom: 12px;
    opacity: 0.4;
}
/* ============================================================
   Orphan Notes Modal
   ============================================================ */

.orphan-note-item {
    position: relative;
    padding: 12px 14px;
    border-radius: 14px;
    background: #fff;
    border: 1px solid rgba(231, 229, 228, 0.7);
    transition: border-color 150ms ease;
}

.dark .orphan-note-item {
    background: rgba(38, 38, 38, 0.6);
    border-color: rgba(64, 64, 64, 0.7);
}

.orphan-note-item::before {
    content: '';
    position: absolute;
    top: 12px;
    bottom: 12px;
    right: 0;
    width: 3px;
    border-radius: 3px;
    background: var(--item-color, #f59e0b);
}

.orphan-note-item:hover {
    border-color: rgba(217, 119, 6, 0.4);
}

.orphan-note-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border-radius: 9px;
    font-size: 11px;
    font-weight: 600;
    transition: all 150ms ease;
    -webkit-tap-highlight-color: transparent;
}

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

.orphan-note-btn--primary {
    background: rgba(217, 119, 6, 0.12);
    color: #b45309;
}

.orphan-note-btn--primary:hover {
    background: rgba(217, 119, 6, 0.2);
}

.dark .orphan-note-btn--primary {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
}

.dark .orphan-note-btn--primary:hover {
    background: rgba(251, 191, 36, 0.22);
}

.orphan-note-btn--danger {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
}

.orphan-note-btn--danger:hover {
    background: rgba(239, 68, 68, 0.18);
}

.dark .orphan-note-btn--danger {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
}
/* ============================================================
   Image Anchor — نسخه تصویری (یکپارچه با نسخه متنی)
   ============================================================ */

.image-anchor-wrap {
    position: relative;
    display: block;
    max-width: 100%;
    width: fit-content;
    line-height: 0;
    margin-inline: auto;
}

.image-anchor-img {
    display: block;
    max-width: 100%;
    height: auto;
    user-select: none;
    -webkit-user-drag: none;
    margin-inline: auto;
}

/* لایه‌ی تعامل — همیشه فعال */
.image-anchor-layer {
    position: absolute;
    inset: 0;
    pointer-events: auto;
    cursor: crosshair;
    z-index: 5;
}

/* پیش‌نمایش مستطیل در حال کشیدن */
.image-highlight-preview {
    position: absolute;
    border: 2px dashed rgba(217, 119, 6, 0.7);
    background: rgba(251, 191, 36, 0.15);
    border-radius: 3px;
    pointer-events: none;
    z-index: 6;
}

/* ─── Rect (هایلایت یا یادداشت روی تصویر) ─── */

.image-rect {
    position: absolute;
    cursor: pointer;
    padding: 0;
    border-radius: 3px;
    transition: filter 150ms ease, box-shadow 150ms ease;
    z-index: 6;
    -webkit-tap-highlight-color: transparent;
}

/* HIGHLIGHT — مشابه متن: پس‌زمینه پررنگ */
.image-rect[data-note-type="HIGHLIGHT"] {
    background-color: color-mix(in srgb, var(--rect-color, #fef08a) 55%, transparent);
    border: 1.5px solid var(--rect-color, #f59e0b);
}

.image-rect[data-note-type="HIGHLIGHT"]:hover {
    background-color: color-mix(in srgb, var(--rect-color, #fef08a) 75%, transparent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--rect-color, #f59e0b) 40%, transparent);
}

/* NOTE — مشابه متن: پس‌زمینه‌ی ملایم + بوردر خط‌چین */
.image-rect[data-note-type="NOTE"] {
    background-color: color-mix(in srgb, var(--rect-color, #f59e0b) 18%, transparent);
    border: 1.5px dashed var(--rect-color, #d97706);
}

.image-rect[data-note-type="NOTE"]:hover {
    background-color: color-mix(in srgb, var(--rect-color, #f59e0b) 32%, transparent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--rect-color, #f59e0b) 35%, transparent);
}

/* ترکیبی (اگر یادداشت رنگ گروه و highlight داشته باشه) */
.image-rect[data-note-type="HIGHLIGHT,NOTE"],
.image-rect[data-note-type="NOTE,HIGHLIGHT"] {
    background-color: color-mix(in srgb, var(--rect-color, #fef08a) 40%, transparent);
    border: 1.5px dashed var(--rect-color, #d97706);
}

/* Fuzzy */
.image-rect--fuzzy {
    border-style: dotted !important;
    opacity: 0.85;
}

.image-rect--flash {
    animation: image-pin-flash 1.4s ease;
}

@keyframes image-pin-flash {
    0%, 100% { box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25); }
    40% { box-shadow: 0 0 0 12px rgba(251, 191, 36, 0.35), 0 2px 6px rgba(0, 0, 0, 0.25); }
}
/* ============================================================
   Assign Region Banner
   ============================================================ */

.assign-region-banner {
    position: absolute;
    top: 12px;
    right: 12px;
    left: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 14px;
    background: rgba(217, 119, 6, 0.96);
    color: #fff;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(10px);
    z-index: 20;
    animation: assign-banner-in 240ms ease-out;
    direction: rtl;
}

.dark .assign-region-banner {
    background: rgba(217, 119, 6, 0.98);
}

@keyframes assign-banner-in {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.assign-region-banner__icon {
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0;
}

.assign-region-banner__text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.assign-region-banner__text strong {
    font-size: 12px;
    font-weight: 700;
    line-height: 1.3;
}

.assign-region-banner__text small {
    font-size: 10px;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.assign-region-banner__cancel {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 0;
    cursor: pointer;
    transition: background-color 150ms ease;
    -webkit-tap-highlight-color: transparent;
}

.assign-region-banner__cancel:hover {
    background: rgba(255, 255, 255, 0.25);
}

.assign-region-banner__cancel:active {
    transform: scale(0.92);
}

/* لایه‌ی تصویر در حالت assign */
.image-anchor-layer--assigning {
    cursor: crosshair;
    background: rgba(217, 119, 6, 0.06);
    outline: 2px dashed rgba(217, 119, 6, 0.55);
    outline-offset: -6px;
    border-radius: 8px;
}

/* دکمه‌ی assign در سایدبار */
.note-item-assign-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 8px;
    padding: 5px 10px;
    border-radius: 9px;
    background: rgba(217, 119, 6, 0.1);
    color: #b45309;
    font-size: 10px;
    font-weight: 700;
    border: 1px dashed rgba(217, 119, 6, 0.4);
    cursor: pointer;
    transition: all 150ms ease;
    -webkit-tap-highlight-color: transparent;
    direction: rtl;
}

.note-item-assign-btn:hover {
    background: rgba(217, 119, 6, 0.18);
    border-style: solid;
}

.note-item-assign-btn:active {
    transform: scale(0.96);
}

.note-item-assign-btn svg {
    flex-shrink: 0;
}

.dark .note-item-assign-btn {
    background: rgba(251, 191, 36, 0.12);
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.35);
}

.dark .note-item-assign-btn:hover {
    background: rgba(251, 191, 36, 0.2);
}