:root {
    --bg-color: #0b0f1a;
    --card-bg: #161e2d;
    --header-bg: rgba(22, 30, 45, 0.85);
    --primary: #0ea5e9; 
    --primary-hover: #0284c7;
    --magnet: #ef4444; 
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --log-bg: rgba(0, 0, 0, 0.6);
    --border: #1e293b;
    --error: #ef4444;
}

* { box-sizing: border-box; transition: all 0.25s ease; }

body {
    background-color: var(--bg-color); color: var(--text-main);
    font-family: 'Segoe UI', system-ui, sans-serif;
    margin: 0; padding-bottom: 50px; line-height: 1.5;
}

.container { max-width: 1100px; margin: 0 auto; padding: 0 15px; }

.main-header h1 {text-align: center; direction: rtl;}

.main-header {
    background: var(--header-bg); backdrop-filter: blur(12px);
    padding: 15px 0; position: sticky; top: 0; z-index: 1000; border-bottom: 1px solid var(--border);
}

.header-top h1 { margin: 0; font-size: 1.4rem; color: var(--primary); }

.controls { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 15px; margin-top: 20px; align-items: center; }
.filter-group { display: flex; gap: 10px; }

.btn-primary {
    background: var(--primary); color: white; border: none; padding: 10px 22px; border-radius: 10px; font-weight: bold; cursor: pointer; display: flex; align-items: center; gap: 10px;
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.select-wrapper select {
    background: #1e293b; color: white; border: 1px solid var(--border); padding: 10px 15px; border-radius: 10px; outline: none;
}

/* --- Toggle Switch --- */

.toggle-label { font-size: 0.85rem; color: var(--text-dim); }
.switch { position: relative; display: inline-block; width: 44px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #334155; transition: .4s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(22px); }

/* --- My List Button --- */
.btn-text-only {
    background: none; border: none; color: var(--text-main); font-size: 0.85rem; font-weight: 600; cursor: pointer; padding: 0 5px;
}
.btn-text-only:hover { color: var(--primary); }

/* --- Search Box --- */
.search-wrapper { position: relative; flex: 1; min-width: 250px; }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-dim); }
.clear-icon { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--magnet); cursor: pointer; font-size: 1.1rem; z-index: 5; }
.search-wrapper input { width: 100%; background: #1e293b; border: 1px solid var(--border); color: white; padding: 11px 35px 11px 38px; border-radius: 10px; outline: none; }

/* --- Activity Log --- */
.log-section { margin: 20px 0; }
.log-window { background: rgba(0,0,0,0.6); border-radius: 12px; border: 1px solid var(--border); overflow: hidden; }
.log-header { background: #1e293b; padding: 8px 15px; display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--text-dim); direction: ltr; }
.log-header button { background: none; border: none; color: #f87171; cursor: pointer; font-weight: bold; }
.log-content { height: 110px; padding: 12px; font-family: 'Consolas', monospace; font-size: 0.8rem; overflow-y: auto; direction: ltr; text-align: left; }

/* --- Anime Cards --- */
.ltr-content { direction: ltr; text-align: left; }
.anime-card { background: var(--card-bg); border-radius: 12px; margin-bottom: 12px; border: 1px solid var(--border); overflow: hidden; }
.anime-header { padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.anime-header:hover { background: rgba(30, 41, 59, 0.5); }
.anime-title { font-weight: 600; font-size: 1.05rem; }
.badge { background: rgba(14, 165, 233, 0.15); color: var(--primary); padding: 3px 12px; border-radius: 8px; font-size: 0.75rem; }

.episodes-list { display: none; background: rgba(15, 23, 42, 0.4); border-top: 1px solid var(--border); }
.episode-item { padding: 12px 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid rgba(30, 41, 59, 0.3); }
.ep-info { flex: 1; min-width: 0; padding-right: 20px; }
.ep-raw-title { display: block; font-size: 0.85rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ep-meta { font-size: 0.70rem; color: var(--text-main); margin-top: 5px; font-weight: bold; }
.ep-meta b { color: var(--text-main); font-weight: 700; }

.ep-actions { display: flex; gap: 8px; }
.btn-link, .btn-magnet { padding: 6px 14px; border-radius: 8px; text-decoration: none; font-size: 0.8rem; display: flex; align-items: center; gap: 6px; font-weight: 600; background: rgba(30, 41, 59, 0.5); }
.btn-link { color: var(--primary); border: 1px solid var(--primary); }
.btn-link:hover { background: var(--primary); color: white; }
.btn-magnet { color: var(--magnet); border: 1px solid var(--magnet); }
.btn-magnet:hover { background: var(--magnet); color: white; }

/* --- Sort Bar & Google Btn --- */
.sort-bar {
    background: rgba(15, 23, 42, 0.9); padding: 10px 20px; display: flex; gap: 12px;
    align-items: center; border-bottom: 1px solid var(--border); font-size: 0.8rem; color: var(--text-dim);
}
.sort-btn { background: #1e293b; border: 1px solid transparent; color: var(--text-dim); cursor: pointer; display: flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 6px; }
.sort-btn:hover { border-color: var(--primary); color: var(--text-main); }
.sort-btn.active { background: rgba(14, 165, 233, 0.1); color: var(--primary); border-color: var(--primary); }

/* --- Status Colors --- */
.episode-item.is-trusted { border-left: 4px solid #22c55e; background: rgba(34, 197, 94, 0.05); }
.episode-item.is-remake { border-left: 4px solid #ef4444; background: rgba(239, 68, 68, 0.05); }

@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.spinning { animation: spin 1s linear infinite; }

/* --- Modal Styles --- */
.modal {
    display: none; position: fixed; z-index: 2000; left: 0; top: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.7); backdrop-filter: blur(5px);
}
.modal-content {
    background-color: var(--card-bg); 
    margin: 20px auto; /* چسبیدن به بالای صفحه با فاصله اندک */
    padding: 20px; border: 1px solid var(--border);
    width: 90%; max-width: 500px; border-radius: 12px; box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.modal-header h3 { margin: 0; color: var(--primary); }
.close-modal { color: #aaa; font-size: 28px; font-weight: bold; cursor: pointer; }
.close-modal:hover { color: white; }
.modal textarea {
    width: 100%; height: 200px; background: #0b0f1a; color: white; border: 1px solid var(--border);
    border-radius: 8px; padding: 10px; resize: vertical; font-family: inherit; outline: none;
}
.modal-footer { text-align: right; margin-top: 15px; }

@media (max-width: 768px) {
    .controls { flex-direction: column; align-items: stretch; }
    .toggle-wrapper { order: -1; justify-content: center; }
    .search-wrapper { min-width: 100%; order: -1; }
    .anime-header { flex-direction: column; align-items: flex-start; gap: 12px; }
    .episode-item { flex-direction: column; align-items: flex-start; gap: 12px; }
}

.btn-danger {
    background: #ef4444 !important;
}
.btn-danger:hover {
    background: #dc2626 !important;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3) !important;
}
/* استایل سلکت باکس فیلتر کیفیت */
.res-filter {
    background: #1e293b;
    color: var(--primary);
    border: 1px solid var(--border);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.8rem;
    outline: none;
    cursor: pointer;
    font-weight: bold;
}

.res-filter:hover {
    border-color: var(--primary);
}

/* راه حل نمایش نام کامل تورنت */
.ep-raw-title {
    display: block;
    font-size: 0.85rem;
    color: var(--text-dim);
    white-space: nowrap; /* پیش‌فرض: یک خطی */
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer; /* نشانگر کلیک */
    transition: all 0.2s;
}

/* وقتی روی نام کلیک شود (در موبایل و دسکتاپ) */
.ep-raw-title.full-text {
    white-space: normal; /* شکستن متن و نمایش کامل */
    overflow: visible;
    word-break: break-all;
    color: var(--text-main);
    background: rgba(0,0,0,0.2);
    padding: 5px;
    border-radius: 4px;
}

/* بهینه‌سازی دکمه گوگل برای فضای کمتر */
.google-btn {
    margin-left: auto;
    font-weight: 800;
    border-color: rgba(255,255,255,0.1);
}

/* اصلاح چیدمان اکشن‌ها در موبایل */
@media (max-width: 600px) {
    .ep-actions {
        flex-direction: row;
        align-items: center;
        width: 100%;
        justify-content: flex-end;
        margin-top: 10px;
    }
    .stats-mobile {
        display: flex;
        gap: 10px;
        margin-right: auto;
        font-size: 0.8rem;
    }
}

/* ================= AniList Modal & Info Button ================= */

/* دکمه (ℹ️) کنار تعداد فایل‌ها */
.btn-info-badge {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    margin-left: 5px;
    padding: 2px 6px;
    font-size: 1rem;
    border-radius: 50%;
    transition: all 0.2s;
}
.btn-info-badge:hover {
    color: white;
    background: var(--primary);
}

/* استایل لیست نتایج جستجو */
.anilist-result-item {
    display: flex;
    gap: 15px;
    padding: 10px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
}
.anilist-result-item:hover {
    background: rgba(30, 41, 59, 0.8);
}
.anilist-result-img {
    width: 60px;
    height: 90px;
    object-fit: cover;
    border-radius: 4px;
    background: #1e293b;
}
.anilist-result-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.anilist-result-title {
    font-weight: bold;
    color: var(--text-main);
    margin-bottom: 5px;
    font-size: 0.95rem;
}
.anilist-result-meta {
    font-size: 0.8rem;
    color: var(--text-dim);
}

/* استایل نمای اطلاعات کامل انیمه */
.anilist-details {
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.anilist-details-header {
    display: flex;
    gap: 15px;
}
.anilist-details-cover {
    width: 150px;
    height: 200px;
    object-fit: cover;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}
.anilist-details-title {
    font-size: 1.2rem;
    color: var(--primary);
    font-weight: bold;
    margin-bottom: 8px;
}
.anilist-details-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.8rem;
    margin-bottom: 10px;
}
.anilist-stat-badge {
    background: #1e293b;
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    color: var(--text-main);
}
.anilist-details-desc {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-dim);
    background: rgba(0,0,0,0.2);
    padding: 12px;
    border-radius: 8px;
    max-height: 200px;
    overflow-y: auto;
}
/* دکمه بازگشت چسبنده (Sticky) */
.anilist-back-btn {
    position: sticky; /* چسبیدن به بالا */
    top: 0;
    z-index: 50; /* بالاتر از همه عناصر */
    background: var(--card-bg); /* همرنگ پس‌زمینه مودال تا متن‌ها دیده نشن */
    width: 100%;
    text-align: left;
    padding: 12px 5px;
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 15px; /* فاصله از پایین */
    box-shadow: 0 4px 6px rgba(0,0,0,0.2); /* سایه ریز برای تفکیک از محتوا */
}

.anilist-back-btn:hover {
    color: var(--primary);
    background: rgba(30, 41, 59, 1);
}

/* ================= AniList Modal & Styles (Updated) ================= */

/* دکمه آیکون AniList */
.btn-anilist-icon {
    background: none;
    border: none;
    cursor: pointer;
    margin-left: 5px;
    padding: 2px;
    display: flex;
    align-items: center;
    border-radius: 4px;
    transition: transform 0.2s;
}
.btn-anilist-icon:hover {
    transform: scale(1.2);
    background: rgba(255,255,255,0.1);
}
.btn-anilist-icon img {
    width: 20px;
    height: 20px;
}

/* استایل لیست نتایج جستجو */
.anilist-result-item {
    display: flex;
    gap: 15px;
    padding: 10px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
}
.anilist-result-item:hover { background: rgba(30, 41, 59, 0.8); }
.anilist-result-img {
    width: 60px; height: 90px; object-fit: cover;
    border-radius: 4px; background: #1e293b;
}
.anilist-result-info { flex: 1; display: flex; flex-direction: column; justify-content: center; }

.anilist-result-meta { font-size: 0.8rem; color: var(--text-dim); }

/* استایل نمای اطلاعات کامل (با بنر) */
.anilist-details { display: flex; flex-direction: column; gap: 15px; position: relative; }

/* بنر پس‌زمینه */
.anilist-banner {
    width: 100%;
    height: 140px; /* ارتفاع ثابت */
    min-height: 140px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 8px 8px 0 0;
    position: relative;
    background-color: #1e293b; /* رنگ پیش‌فرض اگر عکس لود نشد */
}
.anilist-banner::after {
    content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(to bottom, transparent, var(--card-bg));
    border-radius: 8px;
}

.anilist-header-content {
    display: flex; gap: 15px;
    margin-top: -60px; /* کشیدن کاور به سمت بالا روی بنر */
    padding: 0 10px; z-index: 2; position: relative;
}
.anilist-details-cover {
    width: 150px; height: 200px; object-fit: cover;
    border-radius: 6px; box-shadow: 0 4px 15px rgba(0,0,0,0.8); border: 2px solid var(--card-bg);
}

/* عنوان لینک‌دار */
.anilist-link-title {
    font-size: 1.3rem; color: var(--primary); font-weight: bold;
    text-decoration: none; display: inline-block; margin-bottom: 5px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}
.anilist-link-title:hover { color: #3b82f6; text-decoration: underline; }

.anilist-badges-row {
    display: flex; flex-wrap: wrap; gap: 6px; font-size: 0.75rem; margin-bottom: 10px;
}
.stat-tag {
    background: rgba(15, 23, 42, 0.9); padding: 3px 8px; border-radius: 4px;
    border: 1px solid var(--border); color: #cbd5e1; display: flex; align-items: center; gap: 4px;
}

.anilist-details-desc {
    font-size: 0.9rem; line-height: 1.6; color: #cbd5e1;
    background: rgba(0,0,0,0.3); padding: 12px; border-radius: 8px;
    max-height: 150px; overflow-y: auto;
}

/* بخش انیمه‌های مرتبط */
.anilist-relations {
    margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border);
}
.relation-title { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 8px; font-weight: bold; }
.relation-grid { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 5px; }
.relation-item {
    min-width: 100px; max-width: 100px;
    background: rgba(255,255,255,0.05); border-radius: 6px;
    padding: 5px; font-size: 0.7rem; text-align: center;
    color: var(--text-main); text-decoration: none; display: block;
}
.relation-item:hover { background: rgba(255,255,255,0.1); }
.relation-type { font-size: 0.65rem; color: var(--primary); display: block; margin-bottom: 3px; font-weight: bold;}

/* ================= My Smart List Styles ================= */

/* دکمه‌های آیکونی هدر کارت (گوگل و انی‌لیست) */
.header-icon-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid transparent;
    cursor: pointer;
    margin-left: 5px;
    padding: 4px;
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
}
.header-icon-btn:hover {
    background: rgba(255,255,255,0.15);
    border-color: var(--primary);
    transform: translateY(-2px);
}
.header-icon-btn img {
    width: 18px; height: 18px; object-fit: contain;
}

/* نتایج جستجو در لیست من */
.my-list-results {
    margin-top: 10px;
    max-height: 500px; 
    overflow-y: auto;
    background: #0f172a;
    border: 1px solid var(--border);
    border-radius: 8px;
    display: none; 
}
.add-item-row {
    display: flex; align-items: center; gap: 10px;
    padding: 8px; border-bottom: 1px solid var(--border);
    cursor: pointer; transition: background 0.2s;
}
.add-item-row:hover { background: #1e293b; }
.add-item-img { width: 60px; height: 90px; border-radius: 4px; object-fit: cover; }
/* استایل جدید برای عناوین دو خطه در جستجو */
.add-item-info-search { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow: hidden; }
.add-item-romaji { font-size: 0.9rem; font-weight: bold; color: var(--text-main); line-height: 1.2; display: block; }
.add-item-english { font-size: 0.75rem; color: var(--text-dim); line-height: 1.2; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* آیتم‌های ذخیره شده (Chips) */
.my-list-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100%, 1fr));
    gap: 8px;
}
.saved-item {
    display: flex; align-items: center; gap: 10px;
    background: #1e293b; padding: 8px; border-radius: 8px;
    border: 1px solid var(--border); position: relative;
}
.saved-item img { 
    width: 60px; height: 90px; border-radius: 4px; object-fit: cover; 
    cursor: pointer; transition: transform 0.2s;
}
.saved-item img:hover { transform: scale(1.1); filter: brightness(1.2); }
.saved-item-info { flex: 1; overflow: hidden; }
.saved-item-title { font-size: 0.9rem; font-weight: bold; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-item-sub { font-size: 0.75rem; color: var(--text-dim); }
.btn-remove-item {
    background: rgba(239, 68, 68, 0.1); color: #ef4444;
    border: none; width: 24px; height: 24px; border-radius: 50%;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.btn-remove-item:hover { background: #ef4444; color: white; }

/* استایل‌های بخش ویرایش کلمات کلیدی */
.saved-item-info { flex: 1; display: flex; flex-direction: column; cursor: pointer; }
.saved-item-title { 
    font-size: 1rem; color: var(--primary); display: block; margin-bottom: 4px; 
    cursor: pointer; /* حالت اشاره‌گر برای عنوان */
}
.saved-item-title:hover { text-decoration: underline; color: white; }
.keywords-area { font-size: 0.8rem; color: var(--text-dim); background: rgba(0,0,0,0.2); padding: 4px 8px; border-radius: 4px; border: 1px dashed #334155; }
.keywords-area:hover { border-color: var(--primary); color: white; }

/* استایل حالت ویرایش */
.edit-keywords-box { width: 100%; display: none; margin-top: 5px; }
.edit-keywords-box textarea { width: 100%; height: 80px; background: #0b0f1a; color: white; border: 1px solid var(--primary); border-radius: 6px; padding: 8px; font-size: 0.85rem; resize: none; font-family: inherit; }
.edit-actions { display: flex; gap: 10px; margin-top: 5px; justify-content: flex-end; }
.btn-edit-save { color: #22c55e; background: none; border: none; cursor: pointer; font-size: 1.1rem; }
.btn-edit-cancel { color: #ef4444; background: none; border: none; cursor: pointer; font-size: 1.1rem; }

/* استایل عنوان انگلیسی در صفحه مشخصات */
.anilist-sub-title {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-top: -5px;
    margin-bottom: 10px;
    font-weight: 500;
}

.modal-header h3 .header-icon-btn {
    background: rgba(14, 165, 233, 0.1);
    border: 1px solid rgba(14, 165, 233, 0.2);
    font-size: 1rem;
    width: 34px;
    height: 34px;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.modal-header h3 .header-icon-btn:hover {
    background: var(--primary);
    color: white !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.2);
}

/* ظاهر جدید دکمه My Anime List */
.toggle-wrapper { 
    display: flex; align-items: center; gap: 12px; 
    background: rgba(30, 41, 59, 0.7); 
    padding: 6px 15px; border-radius: 12px; 
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.3s ease;
}
.toggle-wrapper:hover {
    background: rgba(30, 41, 59, 1);
    border-color: var(--primary);
    box-shadow: 0 0 15px rgba(14, 165, 233, 0.1);
}

/* استایل ۳ خطی برای نتایج جستجوی AniList داخل پوشه‌ها */
.anilist-result-romaji { font-weight: bold; color: var(--primary); font-size: 0.95rem; display: block; line-height: 1.2; }
.anilist-result-english { font-size: 0.75rem; color: var(--text-dim); display: block; margin: 2px 0 4px 0; }
.anilist-result-meta { font-size: 0.7rem; color: #64748b; font-weight: 600; text-transform: uppercase; }

#aniListSearchInput, 
#myListSearchInput {
    padding-left: 12px !important; 
}

#aniListSearchInput {
    padding-right: 12px !important;
}
