/* =========================================================
   پورتال من — سیستم طراحی
   پالت: نوترال آرام + بنفش-ایندیگو (--accent) + کهربایی (--accent-2)
   تایپوگرافی: وزیرمتن برای فارسی
   امضای بصری: هاله رنگی دور آیکون هر لینک، متناسب با رنگ خودش
   ========================================================= */

@import url('https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.003/Vazirmatn-font-face.css');

:root {
    --bg: #f5f6fb;
    --surface: #ffffff;
    --surface-2: #f0f1f7;
    --ink: #1a1d29;
    --muted: #6b7280;
    --border: #e5e7f0;
    --accent: #5b5bd6;
    --accent-ink: #ffffff;
    --accent-2: #f5a524;
    --danger: #e5484d;
    --success: #30a46c;
    --shadow: 0 10px 30px rgba(30, 33, 60, 0.08);
    --shadow-lg: 0 25px 50px rgba(30, 33, 60, 0.14);
    --radius: 18px;
    --radius-sm: 12px;
}

[data-theme="dark"] {
    --bg: #12131a;
    --surface: #1a1c26;
    --surface-2: #21232f;
    --ink: #eef0f5;
    --muted: #9096a8;
    --border: #2a2d3b;
    --accent: #8080ea;
    --accent-ink: #12131a;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 25px 50px rgba(0, 0, 0, 0.5);
}

* {
    font-family: 'Vazirmatn', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
}

html { scroll-behavior: smooth; }

body {
    background: var(--bg);
    color: var(--ink);
    direction: rtl;
    text-align: right;
    min-height: 100vh;
    transition: background .25s ease, color .25s ease;
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

a { color: inherit; }

/* ===== دکمه آیکونی (تم/ورود) ===== */
.btn-icon {
    width: 38px; height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-inline-start: 6px;
    transition: all .2s ease;
}
.btn-icon:hover { background: var(--accent); color: var(--accent-ink); transform: translateY(-2px); }

/* ===== هدر / تیتر گرادیانتی ===== */
.gradient-text {
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.portal-header p { color: var(--muted); }

/* ===== نوار جستجو ===== */
.search-bar {
    position: sticky;
    top: 12px;
    z-index: 20;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 18px;
}
.search-input-wrapper {
    position: relative;
    margin-bottom: 12px;
}
.search-input-wrapper i {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
}
.search-input-wrapper input {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 10px 42px 10px 14px;
    color: var(--ink);
    font-size: 0.95rem;
    outline: none;
    transition: all .2s ease;
}
.search-input-wrapper input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(91, 91, 214, 0.12);
}

.category-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--muted);
    padding: 6px 16px;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s ease;
    white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ===== عنوان دسته‌بندی ===== */
.section-title {
    position: relative;
    padding-right: 18px;
    font-weight: 700;
    font-size: 1.15rem;
    display: flex;
    align-items: center;
    gap: 8px;
}
.section-title::before {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 5px;
    height: 22px;
    background: linear-gradient(to bottom, var(--accent), var(--accent-2));
    border-radius: 10px;
}
.badge-count {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--muted);
    background: var(--surface-2);
    border-radius: 999px;
    padding: 2px 9px;
}

/* ===== عنوان کلی بخش (سایت‌های کاربردی / لینک‌های ارتباطی) ===== */
.master-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 8px;
    border-bottom: 1px dashed var(--border);
}

/* ===== گرید لینک‌های کاربردی: سه کارت در هر ردیف، عمودی و کشیده ===== */
/* نکته: از سلکتور ترکیبی .link-grid.utility-grid استفاده شده تا specificity
   آن از قانون .link-grid (که column را با auto-fill تعیین می‌کند) بالاتر باشد
   و همیشه دقیقاً ۳ ستون رندر شود، فارغ از ترتیب قرارگیری قوانین در فایل. */
.link-grid.utility-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
}
.utility-card {
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    text-align: center;
    min-height: 270px;
    padding: 28px 20px 22px;
    position: relative;
    overflow: hidden;
    background: linear-gradient(165deg,
        color-mix(in srgb, var(--card-color, var(--accent)) 10%, var(--surface)) 0%,
        var(--surface) 60%);
    border-color: color-mix(in srgb, var(--card-color, var(--accent)) 28%, var(--border));
    transition: transform .25s cubic-bezier(.25,.46,.45,.94), box-shadow .25s ease, border-color .25s ease;
}
.utility-card::before {
    content: '';
    position: absolute;
    top: 0; right: 0; left: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--card-color, var(--accent)), color-mix(in srgb, var(--card-color, var(--accent)) 30%, var(--accent-2)));
}
.utility-card:hover {
    transform: translateY(-6px);
    border-color: var(--card-color, var(--accent));
    box-shadow: 0 22px 44px -14px color-mix(in srgb, var(--card-color, var(--accent)) 40%, transparent), var(--shadow-lg);
}
.utility-card .link-icon {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    font-size: 1.8rem;
    margin-bottom: 16px;
    background: linear-gradient(145deg,
        color-mix(in srgb, var(--card-color, var(--accent)) 26%, transparent),
        color-mix(in srgb, var(--card-color, var(--accent)) 10%, transparent));
    box-shadow: 0 8px 18px -6px color-mix(in srgb, var(--card-color, var(--accent)) 50%, transparent);
    transition: transform .3s ease, box-shadow .3s ease;
}
.utility-card:hover .link-icon {
    transform: scale(1.08) rotate(-4deg);
    box-shadow: 0 10px 22px -4px color-mix(in srgb, var(--card-color, var(--accent)) 60%, transparent);
}
.utility-card .link-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
}
.utility-card .link-title {
    white-space: normal;
    font-size: 1.04rem;
    margin-bottom: 8px;
}
.utility-card .link-desc {
    -webkit-line-clamp: 6;
    text-align: center;
    font-size: 0.82rem;
    line-height: 1.65;
    margin: 0 0 12px;
}
.utility-card .link-url {
    text-align: center;
    margin-top: auto;
    padding-top: 10px;
    width: 100%;
    border-top: 1px dashed var(--border);
}
.utility-card .link-arrow {
    position: absolute;
    top: 14px;
    left: 14px;
    transform: none;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--card-color, var(--accent)) 14%, transparent);
    font-size: 0.85rem;
}
.utility-card:hover .link-arrow {
    transform: translate(-2px, -2px);
    background: color-mix(in srgb, var(--card-color, var(--accent)) 22%, transparent);
}

.link-desc {
    font-size: 0.76rem;
    color: var(--muted);
    line-height: 1.5;
    margin: 2px 0 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

@media (max-width: 900px) {
    .link-grid.utility-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
    .link-grid.utility-grid { grid-template-columns: 1fr; }
    .utility-card { min-height: 0; }
}

/* ===== گرید فشرده لینک‌ها (بهینه برای فضا) ===== */
.link-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.link-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    text-decoration: none;
    box-shadow: var(--shadow);
    transition: transform .25s cubic-bezier(.25,.46,.45,.94), box-shadow .25s ease, border-color .25s ease;
    animation: fadeInUp .5s ease forwards;
    opacity: 0;
}
.link-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--card-color, var(--accent));
}

.link-icon {
    flex: 0 0 auto;
    width: 42px; height: 42px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    background: color-mix(in srgb, var(--card-color, var(--accent)) 15%, transparent);
    color: var(--card-color, var(--accent));
    font-size: 1.25rem;
    transition: transform .25s ease;
}
.link-card:hover .link-icon { transform: rotate(-6deg) scale(1.08); }
.link-icon img {
    width: 100%; height: 100%;
    object-fit: contain;
    border-radius: 8px;
    padding: 4px;
}

.link-info { flex: 1 1 auto; min-width: 0; }
.link-title {
    font-weight: 700;
    font-size: 0.92rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.link-url {
    font-size: 0.72rem;
    color: var(--muted);
    direction: ltr;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.link-arrow {
    flex: 0 0 auto;
    color: var(--muted);
    opacity: 0;
    transform: translate(2px, -2px);
    transition: all .2s ease;
}
.link-card:hover .link-arrow { opacity: 1; transform: translate(0, 0); color: var(--card-color, var(--accent)); }

.empty-state { color: var(--muted); }

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

/* ===== صفحه ورود ===== */
.auth-body {
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.auth-wrapper { width: 100%; display: flex; justify-content: center; padding: 20px; }
.login-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    max-width: 420px;
    width: 100%;
}
.login-icon {
    width: 60px; height: 60px;
    border-radius: 50%;
    margin: 0 auto;
    background: color-mix(in srgb, var(--accent) 15%, transparent);
    color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.6rem;
}

/* ===== پنل مدیریت ===== */
.admin-card, .stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.stat-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 18px;
}
.stat-icon {
    width: 46px; height: 46px;
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
}
.bg-primary-soft { background: rgba(91,91,214,.12); }
.bg-success-soft { background: rgba(48,164,108,.12); }
.bg-info-soft { background: rgba(2,132,199,.12); }
.stat-number { font-size: 1.4rem; font-weight: 800; }
.stat-label { font-size: .78rem; color: var(--muted); }

.table { color: var(--ink); font-size: .88rem; }
.table th { font-weight: 700; border-bottom: 2px solid var(--border); background: var(--surface-2); }
.table td { vertical-align: middle; border-color: var(--border); }

.form-control, .form-select {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--ink);
    border-radius: var(--radius-sm);
}
.form-control:focus, .form-select:focus {
    background: var(--surface-2);
    color: var(--ink);
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(91, 91, 214, 0.12);
}
.form-control-color { padding: .3rem; height: 42px; cursor: pointer; }

.btn { font-weight: 600; border-radius: var(--radius-sm); }
.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }

.modal-content { background: var(--surface); color: var(--ink); border-radius: var(--radius); border: 1px solid var(--border); }

/* toasts */
.toast-area { position: fixed; top: 20px; left: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.mini-toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-inline-start: 4px solid var(--success);
    box-shadow: var(--shadow-lg);
    border-radius: 12px;
    padding: 10px 16px;
    font-size: .85rem;
    min-width: 220px;
    animation: fadeInUp .3s ease;
}
.mini-toast.error { border-inline-start-color: var(--danger); }

.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.status-dot.on { background: var(--success); }
.status-dot.off { background: var(--muted); }

/* پیش‌نمایش آیکون سفارشی در فرم مدیریت */
.custom-icon-preview-wrap {
    flex: 0 0 auto;
    width: 48px; height: 48px;
    border-radius: 12px;
    border: 1px dashed var(--border);
    background: var(--surface-2);
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
}
.custom-icon-preview { width: 100%; height: 100%; object-fit: contain; padding: 4px; }
.custom-icon-preview-wrap i { color: var(--muted); font-size: 1.2rem; }

.table-icon-thumb {
    width: 24px; height: 24px;
    object-fit: contain;
    border-radius: 6px;
}

/* ===== ریسپانسیو ===== */
@media (max-width: 576px) {
    .link-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
    .gradient-text { font-size: 2rem !important; }
    .search-bar { position: static; }
}
