:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --success: #16a34a;
    --success-light: #dcfce7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --sidebar-bg: #111827;
    --sidebar-text: #cbd5e1;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* أيقونات SVG: تتبع حجم ولون النص المحيط بها (بديل الإيموجي) */
svg.i { width: 1em; height: 1em; display: inline-block; vertical-align: -0.15em; flex-shrink: 0; }

body {
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

a { text-decoration: none; color: inherit; }
ul { list-style: none; }

/* ---------- شاشات الدخول ---------- */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
    padding: 20px;
}
.auth-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 40px 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}
.auth-card h1 {
    text-align: center;
    font-size: 22px;
    margin-bottom: 4px;
}
.auth-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 24px;
}
.auth-card .brand-icon-lg {
    display: block;
    text-align: center;
    font-size: 42px;
    margin-bottom: 8px;
}

/* ---------- نماذج عامة ---------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    color: var(--text);
    transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); }
select.form-control { cursor: pointer; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform .1s, box-shadow .15s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-block { width: 100%; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-size: 14px; }
.alert-success { background: var(--success-light); color: var(--success); }
.alert-danger { background: var(--danger-light); color: var(--danger); }
.alert-warning { background: var(--warning-light); color: var(--warning); }
.alert-info { background: var(--primary-light); color: var(--primary); }

/* ---------- التخطيط الرئيسي ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transition: transform .2s;
    z-index: 100;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px;
    font-weight: 700;
    font-size: 15px;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.brand-icon { font-size: 22px; }
.sidebar-nav { padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    color: var(--sidebar-text);
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav a.active { background: var(--primary); color: #fff; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.nav-section-title {
    font-size: 11px;
    text-transform: uppercase;
    color: #64748b;
    padding: 14px 14px 4px;
    letter-spacing: .5px;
}

.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 14px 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-title { font-weight: 700; font-size: 17px; }
.menu-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; }
.topbar-user { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.role-badge {
    background: var(--primary-light);
    color: var(--primary);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}
.user-name { font-weight: 600; }
.logout-btn {
    background: var(--danger-light);
    color: var(--danger);
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    font-size: 15px;
}

.content { flex: 1; padding: 24px; max-width: 1400px; width: 100%; margin: 0 auto; }
.app-footer { text-align: center; padding: 16px; font-size: 12px; color: var(--text-muted); }

/* ---------- بطاقات إحصائية ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 18px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 14px;
}
.stat-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}
.stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-icon.red { background: var(--danger-light); color: var(--danger); }
.stat-icon.orange { background: var(--warning-light); color: var(--warning); }
.stat-label { font-size: 13px; color: var(--text-muted); margin-bottom: 2px; }
.stat-value { font-size: 20px; font-weight: 700; }

/* ---------- بطاقات ولوحات ---------- */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
    margin-bottom: 20px;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    flex-wrap: wrap;
    gap: 10px;
}
.card-header h2 { font-size: 16px; font-weight: 700; }

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- محافظ ---------- */
.wallets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 18px;
}
.wallet-card {
    border-radius: var(--radius);
    padding: 20px;
    color: #fff;
    position: relative;
    box-shadow: var(--shadow);
    min-height: 140px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.wallet-card .wallet-type { font-size: 12px; opacity: .85; }
.wallet-card .wallet-name { font-size: 17px; font-weight: 700; margin: 6px 0; }
.wallet-card .wallet-balance { font-size: 22px; font-weight: 800; }
.wallet-card .wallet-actions { display: flex; gap: 8px; margin-top: 12px; }
.wallet-card .wallet-actions a {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(255,255,255,0.2);
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 12px;
}
.wallet-card .wallet-actions a:hover { background: rgba(255,255,255,0.35); }

/* ---------- جداول ---------- */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
table th, table td { padding: 12px 14px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
table th { color: var(--text-muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; }
table tr:hover td { background: #fafbfc; }

.badge { padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; display: inline-block; }
.badge-income { background: var(--success-light); color: var(--success); }
.badge-expense { background: var(--danger-light); color: var(--danger); }
.badge-transfer { background: var(--primary-light); color: var(--primary); }
.badge-active { background: var(--success-light); color: var(--success); }
.badge-inactive { background: var(--danger-light); color: var(--danger); }

.text-success { color: var(--success); font-weight: 700; }
.text-danger { color: var(--danger); font-weight: 700; }

.actions-cell { display: flex; gap: 6px; }
.icon-btn {
    width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: 13px;
    cursor: pointer;
}
.icon-btn:hover { background: var(--border); }
.icon-btn.danger { color: var(--danger); }
.icon-btn.danger:hover { background: var(--danger-light); }

/* ---------- Modal ---------- */
.modal-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(15,23,42,0.5);
    align-items: center; justify-content: center;
    z-index: 1000;
    padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: #fff;
    border-radius: var(--radius);
    width: 100%; max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
}
.modal-box h3 { margin-bottom: 18px; font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- صلاحيات (مصفوفة) ---------- */
.perm-matrix { width: 100%; border-collapse: collapse; }
.perm-matrix th, .perm-matrix td { padding: 10px; border-bottom: 1px solid var(--border); text-align: center; }
.perm-matrix td:first-child, .perm-matrix th:first-child { text-align: right; }
.perm-matrix input[type=checkbox] { width: 18px; height: 18px; cursor: pointer; }

/* ---------- تبويبات ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab-btn {
    padding: 10px 18px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--primary); border-color: var(--primary); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 40px; margin-bottom: 10px; }

.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.filter-bar .form-control { max-width: 200px; }

/* ---------- استجابة للجوال ---------- */
@media (max-width: 880px) {
    .sidebar {
        position: fixed;
        right: 0;
        transform: translateX(100%);
        box-shadow: -4px 0 20px rgba(0,0,0,0.2);
    }
    .sidebar.open { transform: translateX(0); }
    .menu-toggle { display: block; }
    .content { padding: 16px; }
    .grid-2 { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; gap: 0; }
    table th, table td { font-size: 13px; padding: 10px; }
}
