/* ============ نظام إعدادات عامة ============ */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;800&family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --bg: #0a0d16;
    --bg-sidebar: #0d1120;
    --bg-card: #121728;
    --bg-card-hover: #171d33;
    --border: #232a42;
    --primary: #2f6fed;
    --primary-2: #3fd0ff;
    --primary-hover: #2559c4;
    --text: #e8ecf7;
    --text-dim: #8a92ab;
    --success: #2ecc71;
    --danger: #ef4444;
    --warning: #f1c40f;
    --radius: 16px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Cairo', 'Inter', Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

body[dir="ltr"] { text-align: left; }
body[dir="rtl"] { text-align: right; }

a { color: inherit; text-decoration: none; }
hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ============ صفحة تسجيل الدخول ============ */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background:
        radial-gradient(circle at 15% 15%, rgba(47,111,237,.22), transparent 42%),
        radial-gradient(circle at 85% 85%, rgba(63,208,255,.14), transparent 42%),
        radial-gradient(circle at top, #0f1428, #0a0d16 75%);
}

.login-card {
    background: linear-gradient(180deg, rgba(18,23,40,.92), rgba(10,13,22,.96));
    backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 54px 44px;
    text-align: center;
    max-width: 420px;
    box-shadow: 0 30px 90px rgba(0,0,0,.55), 0 0 60px rgba(47,111,237,.08);
}

.login-card .logo {
    font-size: 58px;
    margin-bottom: 14px;
    filter: drop-shadow(0 0 24px rgba(63,208,255,.55));
}
.brand-logo { margin-bottom: 16px; filter: drop-shadow(0 0 26px rgba(63,208,255,.5)); }
.brand-title {
    font-size: 28px; margin-bottom: 8px; font-weight: 800; letter-spacing: 2px;
    background: linear-gradient(135deg, #ffffff, var(--primary-2));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.login-card h1 { font-size: 24px; margin-bottom: 8px; font-weight: 800; letter-spacing: .3px; }
.login-card .subtitle { color: var(--text-dim); margin-bottom: 30px; font-size: 14px; line-height: 1.7; }

.lang-switcher-login { margin-bottom: 26px; display: flex; justify-content: center; gap: 6px; }

/* ============ أزرار ============ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 12px 22px; border-radius: 10px; border: none; cursor: pointer;
    font-size: 15px; font-weight: 700; font-family: inherit;
    transition: all .15s ease;
}
.btn-discord { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: white; width: 100%; box-shadow: 0 10px 26px rgba(47,111,237,.35); }
.btn-discord:hover { filter: brightness(1.1); transform: translateY(-1px); box-shadow: 0 14px 32px rgba(47,111,237,.45); }
.btn-discord:active { transform: translateY(0); }

.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: white; box-shadow: 0 6px 18px rgba(47,111,237,.25); }
.btn-primary:hover { filter: brightness(1.12); transform: translateY(-1px); box-shadow: 0 10px 24px rgba(47,111,237,.35); }
.btn-primary:active { transform: translateY(0); filter: brightness(0.98); }

.btn-secondary {
    background: var(--bg-card-hover); color: var(--text); border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); border-color: var(--primary); }

.btn-danger { background: linear-gradient(135deg, #ef4444, #b91c1c); color: white; }
.btn-danger:hover { filter: brightness(1.1); transform: translateY(-1px); }

.btn-small {
    font-size: 13px; padding: 7px 14px; border-radius: 8px;
    background: var(--bg-card-hover); border: 1px solid var(--border);
    cursor: pointer; color: var(--text); font-weight: 600;
    transition: all .15s ease;
}
.btn-small:hover { background: var(--border); border-color: var(--primary); }

/* ============ هيكل التطبيق: Sidebar + محتوى ============ */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 264px;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-inline-end: 1px solid var(--border);
    box-shadow: 4px 0 24px rgba(0,0,0,.25);
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 10;
}

.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 10px 20px;
    font-weight: 800; font-size: 17px;
}
.sidebar-brand .badge {
    width: 36px; height: 36px; border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    box-shadow: 0 6px 18px rgba(47,111,237,.4);
}

.sidebar-server {
    display: flex; align-items: center; gap: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 18px;
    font-size: 13.5px;
}
.sidebar-server .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); flex-shrink: 0; }
.sidebar-server .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-server .sub { color: var(--text-dim); font-size: 11.5px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.sidebar-nav-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .08em; padding: 14px 12px 6px; font-weight: 700; }

.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 10px;
    color: var(--text-dim); font-size: 14px; font-weight: 600;
    cursor: pointer; border: none; background: transparent; width: 100%;
    font-family: inherit; text-align: inherit;
    transition: all .15s ease;
}
.nav-item:hover { background: var(--bg-card-hover); color: var(--text); transform: translateX(2px); }
body[dir="rtl"] .nav-item:hover { transform: translateX(-2px); }
.nav-item.active { background: linear-gradient(135deg, rgba(47,111,237,.18), rgba(63,208,255,.08)); color: var(--text); box-shadow: inset 0 0 0 1px rgba(47,111,237,.35); }
.nav-item .icon { font-size: 17px; width: 22px; text-align: center; }

.sidebar-footer { display: flex; flex-direction: column; gap: 8px; padding-top: 14px; border-top: 1px solid var(--border); margin-top: 10px; }

/* ============ منطقة المحتوى ============ */
.main-area { flex: 1; min-width: 0; }

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 30px;
    background: rgba(13,17,32,.7);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 19px; font-weight: 800; display: flex; align-items: center; gap: 10px; }
.topbar-user { display: flex; align-items: center; gap: 16px; font-size: 14px; color: var(--text-dim); }

.lang-switcher { display: flex; gap: 4px; background: var(--bg); border-radius: 8px; padding: 3px; border: 1px solid var(--border); }
.lang-btn { background: transparent; border: none; color: var(--text-dim); padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 12.5px; font-weight: 700; font-family: inherit; }
.lang-btn.active { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: white; }

.container { max-width: 1180px; margin: 0 auto; padding: 30px 30px 60px; }
.container h1 { font-size: 21px; margin-bottom: 22px; font-weight: 800; }

/* ============ أقسام لوحة السيرفر (بدل البوب-أب القديم) ============ */
.section-panel { display: none; }
.section-panel.active { display: block; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.panel-card {
    background: linear-gradient(180deg, var(--bg-card), rgba(18,23,40,.7));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 18px;
    transition: border-color .15s ease;
}
.panel-card:hover { border-color: rgba(47,111,237,.35); }
.panel-card-title { font-size: 15.5px; font-weight: 800; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }

/* ============ نظرة عامة: بطاقات إحصائيات ============ */
.overview-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 18px; margin-bottom: 18px; }
@media (max-width: 860px) { .overview-grid { grid-template-columns: 1fr; } }

.score-card { display: flex; align-items: center; gap: 26px; }
.score-ring {
    --pct: 0;
    width: 128px; height: 128px; border-radius: 50%; flex-shrink: 0;
    background: conic-gradient(var(--primary-2) calc(var(--pct) * 1%), var(--border) 0);
    display: flex; align-items: center; justify-content: center;
    position: relative;
}
.score-ring::before { content: ""; position: absolute; inset: 10px; background: var(--bg-card); border-radius: 50%; }
.score-ring-text { position: relative; z-index: 1; text-align: center; }
.score-ring-text .num { font-size: 30px; font-weight: 800; display: block; line-height: 1; }
.score-ring-text .label { font-size: 10.5px; color: var(--text-dim); }

.status-list { display: flex; flex-direction: column; gap: 10px; }
.status-row { display: flex; align-items: center; justify-content: space-between; font-size: 13.5px; }
.status-row .dot { width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 8px; display: inline-block; }
.status-row .dot.on { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-row .dot.off { background: var(--text-dim); }
.status-row .tag { font-size: 11px; padding: 2px 9px; border-radius: 999px; font-weight: 700; }
.status-row .tag.on { background: rgba(46,204,113,.15); color: var(--success); }
.status-row .tag.off { background: rgba(138,146,171,.15); color: var(--text-dim); }

.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 700px) { .stat-cards { grid-template-columns: 1fr; } }
.stat-card { background: linear-gradient(180deg, var(--bg-card), rgba(18,23,40,.7)); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; transition: transform .15s ease, border-color .15s ease; }
.stat-card:hover { transform: translateY(-2px); border-color: rgba(47,111,237,.35); }
.stat-card .stat-label { font-size: 11.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; margin-bottom: 8px; }
.stat-card .stat-value { font-size: 30px; font-weight: 800; background: linear-gradient(135deg, #fff, var(--primary-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat-card .stat-sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* ============ عناصر الإعدادات ============ */
.setting-block { margin-bottom: 6px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 14px; }
.setting-row label { font-size: 14.5px; font-weight: 600; }

.setting-sub {
    display: flex; flex-wrap: wrap; gap: 14px;
    background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
    padding: 14px; font-size: 13px; color: var(--text-dim);
}
.setting-sub label { display: flex; flex-direction: column; gap: 4px; }

.block-label { display: block; font-weight: 700; margin-bottom: 10px; font-size: 14px; }

.mini-input {
    width: 70px; padding: 7px 8px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 13px;
}

select, input[type="text"], input[type="number"], input[type="email"], textarea {
    background: var(--bg); border: 1px solid var(--border); color: var(--text);
    border-radius: 10px; padding: 10px 13px; font-size: 14px; width: 100%; font-family: inherit;
}
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,111,237,.15); }
textarea { resize: vertical; }

input[type="color"] { width: 46px; height: 40px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); cursor: pointer; padding: 2px; }

.inline-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline-form select, .inline-form input[type="text"] { flex: 1; min-width: 140px; }

/* ============ مفتاح تشغيل/تعطيل ============ */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background: var(--border); border-radius: 999px; transition: .2s; }
.slider::before { content: ""; position: absolute; height: 20px; width: 20px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: linear-gradient(135deg, var(--primary), var(--primary-2)); }
.switch input:checked + .slider::before { transform: translateX(20px); }
body[dir="rtl"] .switch input:checked + .slider::before { transform: translateX(-20px); }

/* ============ قوائم (رتب / قنوات حذف تلقائي) ============ */
.item-list { max-height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.item-row {
    display: flex; align-items: center; gap: 10px;
    background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px;
}
.role-color-dot { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; }
.item-row input[type="text"] { flex: 1; padding: 6px 10px; font-size: 13px; }
.item-row input[type="color"] { width: 36px; height: 32px; }
.item-row .item-name { flex: 1; font-size: 13.5px; font-weight: 600; }
.item-row .item-sub { font-size: 12px; color: var(--text-dim); }
.item-row button {
    background: var(--bg-card-hover); border: 1px solid var(--border); color: var(--text);
    border-radius: 7px; padding: 6px 10px; cursor: pointer; font-size: 12px; font-weight: 600; font-family: inherit;
}
.item-row button:hover { background: var(--border); }
.item-row .btn-delete { color: var(--danger); }

/* ============ حفظ / حالة ============ */
.btn-save { width: 100%; margin-top: 18px; }
.save-status { text-align: center; font-size: 13px; margin-top: 10px; min-height: 18px; font-weight: 600; }
.save-status.success { color: var(--success); }
.save-status.error { color: var(--danger); }

/* ============ شبكة اختيار السيرفر (dashboard_home) ============ */
.guild-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 18px; }
.guild-card {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 24px; text-align: center; transition: all .15s ease;
}
.guild-card:not(.disabled):hover { background: var(--bg-card-hover); border-color: var(--primary); transform: translateY(-3px); }
.guild-card.disabled { opacity: .5; }
.guild-icon img, .guild-icon-fallback { width: 64px; height: 64px; border-radius: 50%; margin: 0 auto 12px; object-fit: cover; }
.guild-icon-fallback { background: linear-gradient(135deg, var(--primary), var(--primary-2)); display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 800; color: white; }
.guild-name { font-weight: 700; margin-bottom: 14px; }
.badge-warning { display: inline-block; background: rgba(241,196,15,.15); color: var(--warning); padding: 6px 12px; border-radius: 8px; font-size: 12px; font-weight: 700; }
.empty-state { color: var(--text-dim); grid-column: 1 / -1; text-align: center; padding: 40px; }

/* ============ بوب-أب الدعم (يبقى بوب-أب لأنه عائم بكل الصفحات) ============ */
.popup-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.65); align-items: center; justify-content: center; z-index: 999; padding: 20px; }
.popup-overlay.open { display: flex; }
.popup-box { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); width: 100%; max-width: 480px; max-height: 85vh; overflow-y: auto; box-shadow: 0 25px 70px rgba(0,0,0,.5); }
.popup-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); font-weight: 800; font-size: 16px; position: sticky; top: 0; background: var(--bg-card); }
.popup-close { background: none; border: none; color: var(--text-dim); font-size: 18px; cursor: pointer; }
.popup-close:hover { color: var(--text); }
.popup-body { padding: 22px; }

/* ============ زر الدعم العائم ============ */
.support-fab {
    position: fixed; bottom: 26px; inset-inline-end: 26px;
    width: 56px; height: 56px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    border: none; color: white; font-size: 24px; cursor: pointer;
    box-shadow: 0 10px 30px rgba(47,111,237,.5); z-index: 900;
    transition: transform .15s ease;
}
.support-fab:hover { transform: scale(1.08); }

/* ============ صفحة رسائل الدعم ============ */
.support-messages-list { display: flex; flex-direction: column; gap: 14px; }
.support-msg-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.support-msg-card.unread { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.support-msg-header { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-bottom: 10px; font-size: 13px; color: var(--text-dim); }
.support-msg-name { font-weight: 700; color: var(--text); }
.support-msg-time { margin-inline-start: auto; }
.support-msg-body { line-height: 1.7; white-space: pre-wrap; }
.support-msg-guild { margin-top: 10px; font-size: 12px; color: var(--text-dim); }

/* ============ استجابة للموبايل ============ */
@media (max-width: 900px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: relative; flex-direction: row; overflow-x: auto; padding: 12px; }
    .sidebar-brand, .sidebar-server, .sidebar-nav-label, .sidebar-footer { display: none; }
    .sidebar-nav { flex-direction: row; }
    .nav-item { white-space: nowrap; }
    .overview-grid { grid-template-columns: 1fr; }
}