/* ===== NoteKeeper v6.0 - Telegram Edition ===== */
/* طراحی حرفه‌ای با تم تلگرام - ریسپانسیو کامل */
/* جستجوی دوگانه حرفه‌ای */

/* ===== تم روشن (پیش‌فرض - کرمی/سفید) ===== */
:root {
    --bg-primary: #faf8f5;
    --bg-secondary: #f3f0eb;
    --bg-surface: #ffffff;
    --bg-surface-hover: #f3f0eb;
    --bg-surface-active: #5b8def;
    --bg-input: #f3f0eb;
    --border-color: #e8e4de;
    --border-light: #f0ede8;
    --text-primary: #1a1a1a;
    --text-secondary: #6b6560;
    --text-muted: #a09a94;
    --accent: #5b8def;
    --accent-hover: #4a7de0;
    --accent-active: #3a6dd1;
    --accent-bg: rgba(91, 141, 239, 0.08);
    --accent-bg-strong: rgba(91, 141, 239, 0.15);
    --success: #4dcd5e;
    --success-bg: rgba(77, 205, 94, 0.08);
    --warning: #e8a12e;
    --warning-bg: rgba(232, 161, 46, 0.08);
    --danger: #e53935;
    --danger-bg: rgba(229, 57, 53, 0.08);
    --green: #4dcd5e;
    --scrollbar-thumb: #cdc7bf;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.07);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.10);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --editor-font-size: 15px;
    --cat-silver: #b0b8c4;
    --cat-silver-bg: rgba(176, 184, 196, 0.12);
    --search-highlight: rgba(91, 141, 239, 0.15);
}

/* ===== تم تاریک (تلگرام دارک) ===== */
[data-theme="dark"] {
    --bg-primary: #17212b;
    --bg-secondary: #0e1621;
    --bg-surface: #1c2733;
    --bg-surface-hover: #202b36;
    --bg-surface-active: #2b5278;
    --bg-input: #242f3d;
    --border-color: #1e2c3a;
    --border-light: #0e1621;
    --text-primary: #f5f5f5;
    --text-secondary: #708499;
    --text-muted: #5b7285;
    --accent: #3390ec;
    --accent-hover: #4da3f0;
    --accent-active: #5ab0f5;
    --accent-bg: rgba(51, 144, 236, 0.1);
    --accent-bg-strong: rgba(51, 144, 236, 0.2);
    --success: #4dcd5e;
    --success-bg: rgba(77, 205, 94, 0.12);
    --warning: #e8a12e;
    --warning-bg: rgba(232, 161, 46, 0.12);
    --danger: #e53935;
    --danger-bg: rgba(229, 57, 53, 0.12);
    --green: #4dcd5e;
    --scrollbar-thumb: #3b4f63;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);
    --search-highlight: rgba(51, 144, 236, 0.25);
}

/* ===== ریست و عمومی ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Tahoma', 'Vazirmatn', 'Vazir', 'IRANSans', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    direction: rtl;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    font-size: 14px;
    line-height: 1.5;
}

/* ===== هدر اصلی (تلگرام‌سان) ===== */
.tg-header {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    z-index: 100;
    transition: all 0.2s;
}

.tg-header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    height: 56px;
}

.header-right, .header-left {
    display: flex;
    align-items: center;
    gap: 4px;
}

.header-title-area {
    margin-right: 4px;
}

.tg-app-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

.tg-btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}
.tg-btn-icon:hover { background: var(--accent-bg); color: var(--accent); }
.tg-btn-icon:active { background: var(--accent-bg-strong); }

.hamburger-btn { display: none; }

/* ===== نوار جستجوی کامل (حرفه‌ای) ===== */
.global-search-bar {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 0 12px 10px;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.25s ease,
                padding 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.global-search-bar.active {
    max-height: 60px;
    opacity: 1;
    padding: 6px 12px 10px;
}

.global-search-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-input);
    border-radius: 22px;
    padding: 0 14px;
    height: 42px;
    border: 2px solid transparent;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.global-search-inner:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}

.global-search-inner .search-icon {
    color: var(--text-muted);
    flex-shrink: 0;
    transition: color 0.2s;
}

.global-search-inner:focus-within .search-icon {
    color: var(--accent);
}

.global-search-inner input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    direction: rtl;
    min-width: 0;
}

.global-search-inner input::placeholder {
    color: var(--text-muted);
    transition: color 0.2s;
}

.global-search-inner:focus-within input::placeholder {
    color: var(--text-secondary);
}

/* شمارنده نتایج جستجو */
.search-result-count {
    font-size: 11px;
    color: var(--accent);
    background: var(--accent-bg);
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
    flex-shrink: 0;
    font-weight: 500;
}

.search-close-btn {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px;
    min-height: 32px;
    flex-shrink: 0;
}

/* ===== لایه اصلی ===== */
.tg-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* ===== سایدبار - دسته‌ها ===== */
.tg-sidebar {
    width: 240px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

/* ===== جستجوی فیلتر دسته‌ها (حرفه‌ای) ===== */
.sidebar-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    background: var(--bg-input);
    margin: 10px 8px 6px;
    border-radius: 22px;
    height: 38px;
    border: 2px solid transparent;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.sidebar-search:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}

.sidebar-search-icon {
    color: var(--text-muted);
    flex-shrink: 0;
    transition: color 0.2s;
}

.sidebar-search:focus-within .sidebar-search-icon {
    color: var(--accent);
}

.sidebar-search input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    direction: rtl;
    min-width: 0;
}

.sidebar-search input::placeholder {
    color: var(--text-muted);
    transition: color 0.2s;
}

.sidebar-search:focus-within input::placeholder {
    color: var(--text-secondary);
}

/* دکمه پاک کردن فیلتر دسته */
.cat-search-clear {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
    width: 26px;
    height: 26px;
}

.cat-search-clear:hover {
    background: var(--accent-bg);
    color: var(--accent);
}

/* لیست دسته‌ها */
.cat-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.cat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.15s, opacity 0.2s, transform 0.2s;
    user-select: none;
    margin-bottom: 2px;
}

.cat-item:hover {
    background: var(--bg-surface-hover);
}

.cat-item.active {
    background: var(--accent-bg-strong);
    color: var(--accent);
}

.cat-item.search-match {
    background: var(--accent-bg);
}

.cat-item.filtered-out {
    opacity: 0;
    max-height: 0;
    padding: 0 12px;
    margin: 0;
    overflow: hidden;
    transform: scale(0.95);
}

.cat-item.filtered-in {
    opacity: 1;
    max-height: 60px;
    transform: scale(1);
}

.cat-dot {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}

.cat-dot img {
    display: none;
}

.cat-name {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cat-name mark {
    background: var(--search-highlight);
    color: var(--accent);
    border-radius: 2px;
    padding: 0 2px;
}

.cat-count {
    font-size: 11px;
    color: var(--cat-silver);
    background: var(--cat-silver-bg);
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 22px;
    text-align: center;
    font-weight: 500;
}

/* آمار سایدبار */
.sidebar-stats {
    padding: 8px 16px;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    border-top: 1px solid var(--border-color);
}

/* دکمه افزودن دسته */
.tg-add-cat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    margin: 8px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}

.tg-add-cat-btn:hover {
    background: var(--accent-hover);
}

.tg-add-cat-btn:active {
    transform: scale(0.98);
}

/* اورلی سایدبار موبایل */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 49;
    transition: opacity 0.25s;
}

.sidebar-overlay.visible {
    display: block;
}

/* ===== پنل یادداشت‌ها ===== */
.tg-notes-panel {
    width: 300px;
    background: #ffffff;
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.notes-panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface);
    min-height: 56px;
}

.notes-panel-title {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mobile-back-btn {
    display: none !important;
}

/* لیست یادداشت‌ها */
.note-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px;
}

.note-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
    user-select: none;
}

.note-item:hover {
    background: var(--bg-surface-hover);
}

.note-item.active {
    background: var(--accent-bg-strong);
}

.note-item-title {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.note-pin-icon {
    color: var(--accent);
    margin-left: 4px;
}

.note-item-preview {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}

/* هایلایت نتایج جستجو */
.note-item-preview mark {
    background: var(--search-highlight);
    color: var(--accent);
    border-radius: 2px;
    padding: 0 2px;
}

.note-item-title mark {
    background: var(--search-highlight);
    color: var(--accent);
    border-radius: 2px;
    padding: 0 2px;
}

.note-item-date {
    font-size: 11px;
    color: var(--text-muted);
}

.note-cat-badge {
    font-size: 10px;
    color: #fff;
    padding: 1px 6px;
    border-radius: 8px;
}

.note-item-badge {
    font-size: 11px;
    color: var(--text-muted);
}

/* حالت خالی */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 16px;
    color: var(--text-muted);
    text-align: center;
    gap: 8px;
}

.empty-state p {
    font-size: 13px;
}

/* حالت بدون نتیجه جستجو */
.search-no-result {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 20px;
    color: var(--text-muted);
    text-align: center;
    gap: 12px;
    animation: fadeInUp 0.3s ease;
}

.search-no-result svg {
    opacity: 0.3;
}

.search-no-result p {
    font-size: 14px;
    font-weight: 500;
}

.search-no-result span {
    font-size: 12px;
    opacity: 0.7;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== پنل ادیتور ===== */
.tg-editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    min-width: 0;
    position: relative;
}

.editor-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface);
    min-height: 52px;
}

.editor-back-btn {
    display: none !important;
}

.editor-header-info {
    flex: 1;
    min-width: 0;
}

.editor-title-input {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    outline: none;
    direction: rtl;
    padding: 4px 0;
}

.editor-title-input:disabled {
    opacity: 0.4;
}

.editor-title-input::placeholder {
    color: var(--text-muted);
}

.editor-header-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

/* دکمه ذخیره دستی در هدر ادیتور */
.save-note-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 14px;
    border: none;
    border-radius: 18px;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(51, 144, 236, 0.25);
    user-select: none;
    -webkit-user-select: none;
    white-space: nowrap;
}

.save-note-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 3px 8px rgba(51, 144, 236, 0.35);
    transform: translateY(-1px);
}

.save-note-btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(51, 144, 236, 0.2);
}

.save-note-btn:disabled {
    background: var(--bg-input);
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: none;
    opacity: 0.6;
}

.save-note-btn:disabled:hover {
    transform: none;
}

/* حالت dirty - یادداشت تغییر کرده و آماده ذخیره است */
.save-note-btn.dirty {
    background: var(--warning);
    color: #fff;
    box-shadow: 0 2px 6px rgba(232, 161, 46, 0.4);
}

.save-note-btn.dirty:hover:not(:disabled) {
    background: #d68f1f;
    box-shadow: 0 3px 10px rgba(232, 161, 46, 0.5);
}

/* حالت saving - در حال ذخیره (در UI خوش‌بینانه استفاده نمی‌شود، فقط برای fallback) */
.save-note-btn.saving {
    background: var(--text-muted);
    color: #fff;
    cursor: wait;
    animation: none;
    opacity: 0.85;
}

.save-note-btn.saving svg {
    animation: none;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* حالت saved - یادداشت ذخیره شده */
.save-note-btn.saved {
    background: var(--success);
    color: #fff;
    animation: none;
}

.save-note-btn.saved:hover:not(:disabled) {
    background: #3fb84f;
}

/* روی موبایل دکمه ذخیره فقط آیکون نشون بده */
@media (max-width: 768px) {
    .save-note-btn {
        padding: 0;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        gap: 0;
    }
    .save-note-btn span {
        display: none;
    }
}

/* نوار ابزار */
.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface);
    flex-wrap: wrap;
}

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

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

.tool-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    transition: all 0.12s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
}

.tool-btn:hover {
    background: var(--accent-bg);
    color: var(--accent);
}

.tool-btn:active {
    background: var(--accent-bg-strong);
}

.tool-btn-media {
    color: var(--accent);
}

/* ادیتور */
.editor-body {
    flex: 1;
    position: relative;
    overflow-y: auto;
    padding: 0;
}

.note-editor {
    min-height: 100%;
    padding: 16px 20px;
    font-size: var(--editor-font-size, 15px) !important;
    line-height: 1.7;
    outline: none;
    color: var(--text-primary);
    direction: rtl;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* اطمینان از اینکه اندازه فونت به همه عناصر داخل ادیتور هم اعمال میشه
   (متن موجود در div/p/span که مرورگر ممکنه font-size خودش رو گذاشته باشه) */
.note-editor div,
.note-editor p,
.note-editor span,
.note-editor li,
.note-editor td,
.note-editor th,
.note-editor blockquote {
    font-size: inherit !important;
}

.note-editor[contenteditable="false"] {
    opacity: 0.5;
    cursor: default;
}

/* عکس در ادیتور */
.note-editor img {
    max-width: 100%;
    border-radius: var(--radius-md);
    margin: 8px 0;
    cursor: pointer;
    transition: opacity 0.2s;
}

.note-editor img:hover {
    opacity: 0.85;
}

/* ویدیو در ادیتور */
.note-editor video {
    max-width: 100%;
    border-radius: var(--radius-md);
    margin: 8px 0;
    display: block;
}

/* روی دسکتاپ ویدیو کوچک‌تر باشد (حداکثر 480 پیکسل عرض) */
@media (min-width: 769px) {
    .note-editor video {
        max-width: 480px;
        max-height: 360px;
    }
    .note-editor .nk-media-wrap {
        max-width: 480px;
    }
}

/* wrapper برای ویدیو/عکس/فایل پیوست با دکمه حذف */
.note-editor .nk-media-wrap,
.note-editor .nk-file-wrap {
    position: relative;
    display: inline-block;
    max-width: 100%;
}

/* دکمه حذف (X) که روی hover ظاهر می‌شود */
.note-editor .nk-delete-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(229, 57, 53, 0.92);
    color: #fff;
    border: 2px solid #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
    opacity: 0;
    transform: scale(0.7);
    transition: opacity 0.15s, transform 0.15s, background 0.15s;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    user-select: none;
    -webkit-user-select: none;
}

.note-editor .nk-media-wrap:hover .nk-delete-btn,
.note-editor .nk-file-wrap:hover .nk-delete-btn {
    opacity: 1;
    transform: scale(1);
}

.note-editor .nk-delete-btn:hover {
    background: var(--danger);
    transform: scale(1.1);
}

/* روی موبایل دکمه حذف همیشه visible باشد */
@media (max-width: 768px) {
    .note-editor .nk-delete-btn {
        opacity: 1;
        transform: scale(1);
        width: 24px;
        height: 24px;
        font-size: 14px;
        top: 4px;
        right: 4px;
    }
}

/* لینک در ادیتور */
.note-editor a.nk-link, .note-editor a:not(.nk-file-embed) {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid var(--accent);
    padding-bottom: 1px;
    transition: all 0.15s;
}

.note-editor a.nk-link:hover, .note-editor a:not(.nk-file-embed):hover {
    color: var(--accent-hover);
    border-bottom-color: var(--accent-hover);
}

/* فایل پیوست در ادیتور */
.nk-file-embed {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px 14px;
    margin: 6px 0;
    text-decoration: none !important;
    color: var(--text-primary) !important;
    transition: all 0.15s;
    border-bottom: none !important;
}

.nk-file-embed:hover {
    background: var(--bg-surface-hover);
    border-color: var(--accent);
}

.nk-file-icon {
    font-size: 18px;
    color: var(--accent);
}

.nk-file-info {
    display: flex;
    flex-direction: column;
}

.nk-file-name {
    font-size: 13px;
    font-weight: 500;
}

.nk-file-size {
    font-size: 11px;
    color: var(--text-muted);
}

/* پیام خالی ادیتور */
.empty-editor-msg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-muted);
    pointer-events: none;
}

.empty-editor-msg p {
    margin-top: 12px;
    font-size: 14px;
}

.empty-editor-msg .sub {
    font-size: 12px;
    margin-top: 4px;
    opacity: 0.7;
}

/* پاورقی ادیتور */
.editor-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-surface);
    font-size: 11px;
    color: var(--text-muted);
    min-height: 32px;
}

.note-info {
    flex: 1;
}

.save-indicator {
    font-size: 11px;
}

.word-count {
    font-size: 11px;
}

/* نوار پیشرفت آپلود */
.upload-progress {
    position: absolute;
    bottom: 36px;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--bg-input);
    display: flex;
    align-items: center;
    z-index: 10;
}

.upload-progress-bar {
    height: 100%;
    background: var(--accent);
    transition: width 0.2s;
    border-radius: 2px;
    width: 0;
}

.upload-progress-text {
    position: absolute;
    right: 12px;
    font-size: 10px;
    color: var(--accent);
    background: var(--bg-surface);
    padding: 2px 6px;
    border-radius: 4px;
    top: -20px;
}

/* ===== منوی راست‌کلیک ===== */
.context-menu {
    position: fixed;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    z-index: 1000;
    display: none;
    min-width: 140px;
}

.ctx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.12s;
}

.ctx-item:hover {
    background: var(--accent-bg);
}

/* ===== مودال ===== */
.tg-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
    animation: modalFadeIn 0.2s ease;
}

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

.tg-modal {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 400px;
    max-height: 85vh;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: modalSlideUp 0.25s ease;
    display: flex;
    flex-direction: column;
}

@keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.tg-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.tg-modal-title {
    font-size: 16px;
    font-weight: 600;
}

.tg-modal-body {
    padding: 20px;
}

.tg-modal-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
}

/* دکمه‌ها */
.tg-btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    background: var(--bg-input);
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.tg-btn:hover {
    background: var(--bg-surface-hover);
}

.tg-btn-primary {
    background: var(--accent);
    color: #fff;
}

.tg-btn-primary:hover {
    background: var(--accent-hover);
}

.tg-btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

/* فرم */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    background: var(--bg-input);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.form-input:focus {
    border-color: var(--accent);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-select {
    width: 100%;
    background: var(--bg-input);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    cursor: pointer;
}

.form-select:focus {
    border-color: var(--accent);
}

/* رنگ‌ها */
.color-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.color-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
}

.color-btn:hover {
    transform: scale(1.1);
}

.color-btn.selected {
    border-color: var(--text-primary);
    transform: scale(1.15);
}

/* تنظیمات */
.settings-section {
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.settings-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.settings-section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 0;
}

.settings-label {
    font-size: 13px;
    color: var(--text-primary);
}

/* مودال فشرده */
.tg-modal-compact {
    max-width: 360px;
}

.tg-modal-body-compact {
    padding: 14px 18px;
    max-height: 75vh;
    overflow-y: auto;
}

/* سوییچ تلگرامی */
.tg-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.tg-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.tg-switch-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-input);
    border: 2px solid var(--text-muted);
    border-radius: 24px;
    transition: all 0.25s;
}

.tg-switch-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 2px;
    bottom: 2px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all 0.25s;
}

.tg-switch input:checked + .tg-switch-slider {
    background: var(--accent);
    border-color: var(--accent);
}

.tg-switch input:checked + .tg-switch-slider::before {
    background: #fff;
    transform: translateX(20px);
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
}

.toast {
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    animation: toastIn 0.3s ease;
    pointer-events: auto;
    white-space: nowrap;
}

.toast-success {
    background: var(--success);
    color: #fff;
}

.toast-error {
    background: var(--danger);
    color: #fff;
}

.toast-warning {
    background: var(--warning);
    color: #fff;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== ناوبری موبایل ===== */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    padding: 6px 0;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    z-index: 90;
}

.mobile-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 10px;
    font-family: inherit;
    cursor: pointer;
    transition: color 0.15s;
}

.mobile-nav-btn.active {
    color: var(--accent);
}

.mobile-nav-btn svg {
    width: 22px;
    height: 22px;
}

/* ===== اسکرولبار ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== ریسپانسیو موبایل ===== */
@media (max-width: 768px) {
    .hamburger-btn { display: flex; }

    .tg-sidebar {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 280px;
        z-index: 50;
        transform: translateX(100%);
        transition: transform 0.25s ease;
    }

    .tg-sidebar.sidebar-open {
        transform: translateX(0);
    }

    .tg-notes-panel {
        width: 100%;
        flex: 1;
    }

    .tg-editor-panel {
        position: fixed;
        inset: 0;
        top: 56px;
        z-index: 40;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

    .tg-editor-panel.editor-visible {
        transform: translateX(0);
    }

    .editor-back-btn { display: flex !important; }
    .mobile-back-btn { display: flex !important; }

    .mobile-nav {
        display: flex;
    }

    body {
        padding-bottom: 56px;
    }

    .tg-layout {
        height: calc(100vh - 56px - 56px);
        height: calc(100dvh - 56px - 56px);
    }

    .toast-container {
        bottom: 70px;
    }

    .empty-editor-msg {
        padding: 0 20px;
    }

    /* جستجوی کامل در موبایل */
    .global-search-bar.active {
        padding: 6px 8px 10px;
    }

    .global-search-inner {
        height: 40px;
    }

    .global-search-inner input {
        font-size: 16px; /* جلوگیری از زوم در iOS */
    }

    /* فیلتر دسته در موبایل */
    .sidebar-search {
        margin: 8px 6px 4px;
        height: 36px;
    }

    .sidebar-search input {
        font-size: 16px; /* جلوگیری از زوم در iOS */
    }

    /* مودال در موبایل */
    .tg-modal {
        max-width: 95vw;
        max-height: 80vh;
    }

    .tg-modal-compact {
        max-width: 95vw;
    }

    .tg-modal-body {
        max-height: 60vh;
        overflow-y: auto;
    }
}

/* ===== ریسپانسیو تبلت ===== */
@media (min-width: 769px) and (max-width: 1024px) {
    .tg-sidebar {
        width: 200px;
    }

    .tg-notes-panel {
        width: 260px;
    }

    .sidebar-search {
        margin: 8px 6px 4px;
    }
}

/* ===== ریسپانسیو دسکتاپ بزرگ ===== */
@media (min-width: 1200px) {
    .tg-sidebar {
        width: 280px;
    }

    .tg-notes-panel {
        width: 340px;
    }
}

/* ===== انتخاب متن ===== */
::selection {
    background: var(--accent-bg-strong);
    color: var(--text-primary);
}

/* ===== محتوای ادیتور - هدینگ ===== */
.note-editor h2 {
    font-size: 1.4em;
    font-weight: 700;
    margin: 12px 0 6px;
}

.note-editor h3 {
    font-size: 1.15em;
    font-weight: 700;
    margin: 10px 0 4px;
}

.note-editor ul, .note-editor ol {
    padding-right: 20px;
    margin: 8px 0;
}

.note-editor b, .note-editor strong {
    font-weight: 700;
}

.note-editor i, .note-editor em {
    font-style: italic;
}

.note-editor u {
    text-decoration: underline;
}

.note-editor s, .note-editor strike {
    text-decoration: line-through;
}

/* ===== نتایج جستجوی پیشرفته ===== */
.search-result-category {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    display: inline-block;
    margin-bottom: 4px;
    font-weight: 600;
}
.search-result-snippet {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
    line-height: 1.6;
    background: var(--accent-bg);
    padding: 4px 8px;
    border-radius: 6px;
    border-right: 2px solid var(--accent);
}
.search-result-match {
    color: var(--danger);
    font-weight: 700;
    background: var(--danger-bg);
    padding: 0 2px;
    border-radius: 3px;
}
.search-result-badges {
    display: flex;
    gap: 4px;
    margin-top: 4px;
    flex-wrap: wrap;
}
.search-badge {
    font-size: 10px;
    padding: 1px 8px;
    border-radius: 10px;
    background: var(--accent-bg);
    color: var(--accent);
    border: 1px solid var(--border-color);
}
.search-badge.match-title {
    background: var(--warning-bg);
    color: var(--warning);
    border-color: var(--warning);
}
.search-badge.match-content {
    background: var(--success-bg);
    color: var(--success);
    border-color: var(--success);
}

/* ===== جستجوی سراسری یادداشت‌ها (v5.3) ===== */

/* دکمه جستجو در هدر */
#globalSearchBtn {
    position: relative;
}

/* نوار جستجوی سراسری در هدر */
.global-search-bar {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
}

.global-search-bar .global-search-inner {
    height: 40px;
}

/* شمارنده نتایج جستجو */
.search-result-count {
    font-size: 11px;
    color: var(--accent);
    background: var(--accent-bg);
    padding: 3px 10px;
    border-radius: 12px;
    white-space: nowrap;
    flex-shrink: 0;
    font-weight: 600;
    border: 1px solid var(--accent);
}

/* دکمه بستن جستجو */
.search-close-btn {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px;
    min-height: 32px;
    flex-shrink: 0;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.search-close-btn:hover {
    background: var(--bg-surface-hover);
    color: var(--danger);
}

/* بهبود نمایش نتایج جستجو */
.note-item .search-result-snippet {
    margin-top: 6px;
    line-height: 1.7;
    font-size: 12.5px;
}

/* برجسته‌سازی کلمه کلیدی در نتایج جستجو */
.search-result-match {
    color: #fff !important;
    background: var(--accent) !important;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

[data-theme="dark"] .search-result-match {
    color: #fff !important;
    background: var(--accent) !important;
    box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

/* برچسب نوع تطابق */
.search-badge {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

/* مخفی کردن فیلدهای هانی‌پات (فریب مرورگر) */
input[name^="fake-"] {
    position: absolute !important;
    left: -9999px !important;
    top: -9999px !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* استایل‌های Webkit برای جلوگیری از نمایش لیست پر شدن خودکار */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--text-primary) !important;
    -webkit-box-shadow: 0 0 0 1000px var(--bg-input) inset !important;
    transition: background-color 9999s ease-in-out 0s;
}
