/* ═══════════════════════════════════════════════════════════
   admin-v2.css — Design System
   ═══════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --brand-primary: #2c6db4;
    --brand-primary-hover: #1e5a9e;
    --brand-primary-light: #e0f2fe;

    --success: #10b981;
    --success-light: #d1fae5;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --info: #3b82f6;
    --info-light: #dbeafe;

    --bg-page: #f1f5f9;
    --bg-surface: #ffffff;
    --bg-elevated: #ffffff;
    --bg-hover: #f8fafc;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;

    --border-color: #e2e8f0;
    --border-color-strong: #cbd5e1;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    --shadow-xs: 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, .06);
    --shadow: 0 2px 8px rgba(15, 23, 42, .08);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, .1);
    --shadow-lg: 0 10px 30px rgba(15, 23, 42, .12);

    --sidebar-width: 260px;
    --topbar-height: 60px;
    /* ⚡ افزایش نرمی از 0.2s به 0.3s برای انیمیشن‌های طبیعی‌تر */
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-page: #0f172a;
    --bg-surface: #1e293b;
    --bg-elevated: #293548;
    --bg-hover: #334155;

    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;

    --border-color: #334155;
    --border-color-strong: #475569;

    --brand-primary: #3b82f6;
    --brand-primary-hover: #60a5fa;
    --brand-primary-light: #1e3a8a;

    --success-light: #064e3b;
    --warning-light: #78350f;
    --danger-light: #7f1d1d;
    --info-light: #1e3a8a;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .3);
    --shadow: 0 2px 8px rgba(0, 0, 0, .35);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, .4);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, .5);
}

html, body {
    font-family: 'Yekan', 'Vazir', system-ui, sans-serif;
    direction: rtl;
    background: var(--bg-page);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--brand-primary); text-decoration: none; }
a:hover { color: var(--brand-primary-hover); }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

/* ─── Top Bar ─── */
.admin-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: var(--sidebar-width);
    height: var(--topbar-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 1000;
    /* ⚡ transition روی right (که از --sidebar-width استفاده می‌کند) */
    transition: right var(--transition);
}

.topbar-start, .topbar-end { display: flex; align-items: center; gap: 16px; }

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1rem;
    color: var(--brand-primary);
}
.topbar-brand i { font-size: 1.2rem; }

.sidebar-toggle {
    display: none;
    font-size: 1.4rem;
    color: var(--text-secondary);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    background: var(--bg-hover);
    transition: all var(--transition);
    position: relative;
}
.icon-btn:hover { background: var(--brand-primary-light); color: var(--brand-primary); }

.theme-toggle-btn .icon-sun { display: none; }
.theme-toggle-btn .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle-btn .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle-btn .icon-moon { display: none; }

/* Notifications */
.notification-wrapper { position: relative; }

.notif-badge {
    position: absolute;
    top: 4px;
    left: 4px;
    background: var(--danger);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

.notif-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 340px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: none;
    z-index: 1100;
    overflow: hidden;
}
.notif-dropdown.show { display: block; }

.notif-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.notif-header h4 { font-size: 0.95rem; font-weight: 700; }
.link-btn { color: var(--brand-primary); font-size: 0.82rem; font-weight: 500; }

.notif-list { max-height: 400px; overflow-y: auto; }

.notif-item {
    padding: 12px 18px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    display: flex;
    gap: 10px;
    transition: background var(--transition);
}
.notif-item:hover { background: var(--bg-hover); }
.notif-item.unread { background: var(--brand-primary-light); }
.notif-empty { padding: 30px; text-align: center; color: var(--text-muted); }

/* Profile */
.profile-wrapper { position: relative; }

.profile-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px 6px 6px;
    background: var(--bg-hover);
    border-radius: var(--radius-full);
    transition: background var(--transition);
}
.profile-btn:hover { background: var(--brand-primary-light); }

.profile-btn .avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 0.95rem;
}

.profile-info { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.profile-name { font-size: 0.85rem; font-weight: 600; color: var(--text-primary); }
.profile-role { font-size: 0.7rem; color: var(--text-muted); }
.profile-btn > i { font-size: 0.7rem; color: var(--text-muted); }

.profile-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 220px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    display: none;
    z-index: 1100;
    padding: 8px;
}
.profile-dropdown.show { display: block; }

.profile-dropdown a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.88rem;
    transition: background var(--transition);
}
.profile-dropdown a:hover { background: var(--bg-hover); color: var(--brand-primary); }
.profile-dropdown .divider { height: 1px; background: var(--border-color); margin: 6px 0; }
.profile-dropdown .logout-link { color: var(--danger); }

/* ─── Sidebar ─── */
.admin-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 1050;
    /* ⚡ width + transform هر دو باید transition داشته باشند */
    transition: width var(--transition), transform var(--transition);
    will-change: width, transform;
}

/* ─── Main Content ─── */
.admin-main {
    margin-right: var(--sidebar-width);
    margin-top: var(--topbar-height);
    padding: 24px;
    min-height: calc(100vh - var(--topbar-height));
    /* ⚡ transition روی margin-right */
    transition: margin-right var(--transition);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    gap: 16px;
}
.page-title { font-size: 1.5rem; font-weight: 700; color: var(--text-primary); }
.page-subtitle { font-size: 0.88rem; color: var(--text-muted); margin-top: 4px; }
.page-header-end { display: flex; gap: 8px; flex-shrink: 0; }

/* ─── Alerts ─── */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    position: relative;
}
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid var(--success); }
.alert-danger  { background: var(--danger-light);  color: var(--danger);  border: 1px solid var(--danger); }
.alert-warning { background: var(--warning-light); color: var(--warning); border: 1px solid var(--warning); }
.alert-info    { background: var(--info-light);    color: var(--info);    border: 1px solid var(--info); }

.alert-dismissible { padding-left: 48px; }

.alert-close {
    position: absolute;
    top: 50%;
    left: 12px;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0,0,0,0.05);
    color: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    cursor: pointer;
    opacity: 0.6;
    transition: all 0.15s;
}
.alert-close:hover { opacity: 1; background: rgba(0,0,0,0.1); }

/* ─── Overlay (Smooth) ─── */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 1040;
    /* ⚡ بجای display، از opacity/visibility استفاده می‌کنیم */
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition), visibility var(--transition);
    pointer-events: none;
}

body.sidebar-open .sidebar-overlay {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Mobile body scroll lock */
@media (max-width: 991.98px) {
    body.sidebar-open {
        overflow: hidden;
    }
}

/* ─── Responsive ─── */
@media (max-width: 991.98px) {
    :root { --sidebar-width: 0; }

    .admin-topbar { right: 0; padding: 0 16px; }
    .admin-main   { margin-right: 0; padding: 16px; }
    .sidebar-toggle { display: inline-flex; }

    .admin-sidebar {
        transform: translateX(100%);
        width: 280px;
        box-shadow: -4px 0 20px rgba(0, 0, 0, .15);
    }

    body.sidebar-open .admin-sidebar { transform: translateX(0); }

    .profile-info { display: none; }
    .topbar-brand span { display: none; }
}

@media (max-width: 575.98px) {
    .page-title { font-size: 1.25rem; }
    .admin-main { padding: 12px; }
}

/* ─── Forbidden / Setup ─── */
.forbidden-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.forbidden-card {
    text-align: center;
    background: var(--bg-surface);
    padding: 60px 40px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 480px;
}
.forbidden-card > i { font-size: 4rem; color: var(--danger); margin-bottom: 20px; }
.forbidden-card h1 { font-size: 1.8rem; margin-bottom: 12px; }
.forbidden-card p { margin-bottom: 16px; color: var(--text-secondary); }
.forbidden-card code { background: var(--bg-hover); padding: 2px 8px; border-radius: var(--radius-sm); font-size: 0.85rem; }

.setup-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.setup-card {
    background: var(--bg-surface);
    padding: 40px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
}
.setup-card h2 { margin-bottom: 24px; text-align: center; }
/* ─── Avatar (image + fallback) ─── */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 0.9rem;
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

/* اگر تصویر خطا داد (onerror)، حرف اول جایگزین می‌شود */
.avatar-image .avatar-initial {
    display: none;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
}

.avatar-image.avatar-fallback .avatar-initial {
    display: flex;
}