:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --brand: #0f766e;
    --brand-dark: #115e59;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --danger: #b91c1c;
    --success: #15803d;
    --warn: #b45309;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: 'Cairo', 'Segoe UI', Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    direction: rtl;
    min-height: 100vh;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.6rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--brand-dark);
}

.brand small { display: block; font-weight: 400; font-size: .7rem; color: var(--muted); }

.topbar nav {
    display: flex;
    gap: .25rem;
    flex: 1;
    flex-wrap: wrap;
}

.topbar nav a {
    color: var(--muted);
    padding: .45rem .8rem;
    border-radius: var(--radius);
    font-size: .9rem;
}

.topbar nav a:hover, .topbar nav a.active { color: var(--brand-dark); background: #ecfdf5; text-decoration: none; }

.nav-group { position: relative; }
.nav-group-btn {
    display: inline-block;
    padding: .45rem .8rem;
    border-radius: var(--radius);
    font-size: .9rem;
    color: var(--muted);
    cursor: pointer;
}
.nav-group:hover .nav-group-btn,
.nav-group.active .nav-group-btn { color: var(--brand-dark); background: #ecfdf5; }
.nav-drop {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 80;
    min-width: 200px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 12px 30px rgba(15, 23, 42, .18);
    padding: .4rem;
    flex-direction: column;
}
.nav-group:hover .nav-drop,
.nav-group:focus-within .nav-drop { display: flex; }
.nav-drop a {
    display: block;
    padding: .5rem .8rem;
    border-radius: var(--radius);
    font-size: .9rem;
    color: var(--ink);
}
.nav-drop a:hover { background: #ecfdf5; color: var(--brand-dark); text-decoration: none; }
.nav-drop a.active { background: #ecfdf5; color: var(--brand-dark); font-weight: 600; }

.top-user {
    display: flex;
    align-items: center;
    gap: .7rem;
    font-size: .85rem;
}

.top-user .role-tag {
    background: #ecfdf5;
    color: var(--brand-dark);
    border-radius: 999px;
    padding: .15rem .6rem;
    font-size: .72rem;
}

.btn-logout {
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--muted);
    border-radius: var(--radius);
    padding: .35rem .8rem;
    cursor: pointer;
    font-size: .8rem;
    font-family: inherit;
}
.btn-logout:hover { color: var(--danger); border-color: #fecaca; }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
    margin: 0 0 .75rem;
}

.grid { display: grid; gap: 1rem; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem 1.25rem;
}

.stat .num { font-size: 1.6rem; font-weight: 800; color: var(--brand-dark); }
.stat .lbl { color: var(--muted); font-size: .85rem; margin-top: .25rem; }

.btn {
    display: inline-block;
    background: var(--brand);
    color: #fff;
    border: 0;
    border-radius: var(--radius);
    padding: .55rem 1.1rem;
    font-size: .9rem;
    font-family: inherit;
    cursor: pointer;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }

.btn-sm { padding: .3rem .7rem; font-size: .8rem; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #991b1b; }
.btn-outline {
    background: transparent;
    color: #fff;
    border: 1px solid var(--brand);
}
.btn-outline:hover { background: var(--brand); color: #fff; }

.btn-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}

th, td { padding: .6rem .7rem; text-align: right; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f8fafc; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr { transition: background .12s ease, color .12s ease; }
tbody tr:hover { background: color-mix(in srgb, var(--surface) 88%, var(--brand) 12%); color: var(--ink); }
tbody tr:hover td { color: var(--ink); }

.muted { color: var(--muted); }
.small { font-size: .8rem; }

.badge {
    display: inline-block;
    border-radius: 999px;
    padding: .15rem .6rem;
    font-size: .72rem;
    font-weight: 600;
}

.badge-green { background: #dcfce7; color: #166534; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-brand { background: #ccfbf1; color: #134e4a; }

.alert {
    border-radius: var(--radius);
    padding: .75rem 1rem;
    margin-bottom: 1rem;
    font-size: .9rem;
    border: 1px solid;
}
.alert-success { background: #dcfce7; border-color: #bbf7d0; color: #166534; }
.alert-danger { background: #fee2e2; border-color: #fecaca; color: #991b1b; }

form .field { margin-bottom: 1rem; }
form .field label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; color: var(--ink); }
form .field .req { color: var(--danger); }
form input[type=text], form input[type=email], form input[type=password],
form input[type=number], form input[type=date], form input[type=search],
form select, form textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: .55rem .7rem;
    font-family: inherit;
    font-size: .9rem;
    background: var(--surface);
    color: var(--ink);
}
form input:focus, form select:focus, form textarea:focus {
    outline: 2px solid #99f6e4;
    border-color: var(--brand);
}
form .error { color: var(--danger); font-size: .8rem; margin-top: .25rem; }

.kv { display: grid; grid-template-columns: 200px 1fr; gap: .35rem 1rem; font-size: .9rem; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; }

.pagination { display: flex; justify-content: center; gap: .25rem; margin-top: 1rem; }
.pagination a, .pagination span {
    padding: .35rem .7rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: .85rem;
    color: var(--brand);
    background: var(--surface);
}
.pagination .active { background: var(--brand); color: #fff; border-color: var(--brand); }

.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filters input[type=search], .filters select { width: auto; min-width: 180px; }

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #0f766e 0%, #134e4a 100%);
    padding: 1rem;
}

.auth-card {
    background: var(--surface);
    border-radius: 16px;
    box-shadow: 0 20px 45px rgba(0,0,0,.25);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
}

.auth-card h1 { margin: 0 0 .2rem; font-size: 1.5rem; }
.auth-card .subtitle { color: var(--muted); margin: 0 0 1.5rem; font-size: .9rem; }

.money { direction: ltr; text-align: right; }
.text-danger { color: var(--danger); font-weight: 700; }

.empty { text-align: center; color: var(--muted); padding: 2rem; }

/* ---- smart bank picker ---- */
.bp-input { position: relative; }
.bp-list {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    left: 0;
    z-index: 60;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 10px 25px rgba(15, 23, 42, .14);
    max-height: 260px;
    overflow: auto;
    display: none;
    text-align: right;
}
.bp-list.bp-open { display: block; }
.bp-opt {
    display: block;
    width: 100%;
    text-align: right;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: none;
    padding: .55rem .8rem;
    font-family: inherit;
    font-size: .9rem;
    cursor: pointer;
    color: var(--ink);
}
.bp-opt:last-child { border-bottom: 0; }
.bp-opt:hover, .bp-opt.bp-active { background: #ecfdf5; }
.bp-empty { padding: .6rem .75rem; color: var(--muted); font-size: .85rem; }
.bp-branch.bp-hidden { display: none; }
.bp-no-branch { display: none; }
.center { text-align: center; }
.table-scroll { overflow-x: auto; }
.table-scroll table { min-width: 1100px; }


/* ============================================================
   أنظمة القوالب الاحترافية الأربعة (System Themes)
   ============================================================ */
html[data-theme="emerald"], :root {
    --bg: #f0fdfa;
    --surface: #ffffff;
    --brand: #0f766e;
    --brand-dark: #115e59;
    --accent: #d97706;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #d1fae5;
    --danger: #b91c1c;
    --success: #15803d;
    --warn: #b45309;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .05);
    --grad: linear-gradient(135deg, #ecfdf5, #f0fdfa);
    --chart-1: #0f766e; --chart-2: #d97706; --chart-3: #2563eb; --chart-4: #7c3aed; --chart-5: #dc2626; --chart-6: #059669;
}

html[data-theme="ocean"] {
    --bg: #eff6ff;
    --surface: #ffffff;
    --brand: #1d4ed8;
    --brand-dark: #1e40af;
    --accent: #0ea5e9;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #dbeafe;
    --danger: #b91c1c;
    --success: #15803d;
    --warn: #b45309;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(30, 64, 175, .06), 0 8px 24px rgba(30, 64, 175, .05);
    --grad: linear-gradient(135deg, #eff6ff, #f8fafc);
    --chart-1: #1d4ed8; --chart-2: #0ea5e9; --chart-3: #059669; --chart-4: #7c3aed; --chart-5: #dc2626; --chart-6: #d97706;
}

html[data-theme="rose-gold"] {
    --bg: #fdf2f8;
    --surface: #ffffff;
    --brand: #be185d;
    --brand-dark: #9d174d;
    --accent: #b45309;
    --ink: #1f2937;
    --muted: #6b7280;
    --line: #fce7f3;
    --danger: #b91c1c;
    --success: #15803d;
    --warn: #b45309;
    --radius: 16px;
    --shadow: 0 1px 3px rgba(190, 24, 93, .06), 0 8px 24px rgba(190, 24, 93, .06);
    --grad: linear-gradient(135deg, #fdf2f8, #fffbeb);
    --chart-1: #be185d; --chart-2: #b45309; --chart-3: #7c3aed; --chart-4: #059669; --chart-5: #1d4ed8; --chart-6: #dc2626;
}

html[data-theme="graphite"] {
    --bg: #f8fafc;
    --surface: #ffffff;
    --brand: #334155;
    --brand-dark: #1e293b;
    --accent: #0ea5e9;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --danger: #b91c1c;
    --success: #15803d;
    --warn: #b45309;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 6px 18px rgba(15, 23, 42, .05);
    --grad: linear-gradient(135deg, #f8fafc, #f1f5f9);
    --chart-1: #334155; --chart-2: #0ea5e9; --chart-3: #d97706; --chart-4: #059669; --chart-5: #7c3aed; --chart-6: #dc2626;
}


/* ============================================================
   4 أنظمة واجهات احترافية (Professional Theme System)
   - تعمم على كامل النظام عبر data-theme على عنصر <html>
   - لكل ثيم: لوحة أساسية + ألوان مخصصة للرسوم البيانية
   ============================================================ */
html[data-theme="emerald"], :root {
    --bg: #f0fdfa;
    --surface: #ffffff;
    --brand: #0f766e;
    --brand-dark: #115e59;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #d1fae5;
    --danger: #b91c1c;
    --success: #15803d;
    --warn: #b45309;
    --radius: 14px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 12px 32px rgba(15, 79, 118, .08);
    --border-glow: #a7f3d0;
    --bg-grad: linear-gradient(160deg, #ecfdf5 0%, #f0fdfa 45%, #e0f2fe 100%);
    --chart-1: #0f766e; --chart-2: #0ea5e9; --chart-3: #f59e0b; --chart-4: #8b5cf6; --chart-5: #10b981; --chart-6: #ef4444; --chart-7: #3b82f6; --chart-8: #ec4899;
}

html[data-theme="ocean"] {
    --bg: #eff6ff;
    --surface: #ffffff;
    --brand: #1d4ed8;
    --brand-dark: #1e40af;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #dbeafe;
    --danger: #b91c1c;
    --success: #15803d;
    --warn: #b45309;
    --radius: 14px;
    --shadow: 0 1px 3px rgba(30, 64, 175, .08), 0 12px 32px rgba(30, 64, 175, .10);
    --border-glow: #bfdbfe;
    --bg-grad: linear-gradient(160deg, #eff6ff 0%, #f8fafc 50%, #e0f2fe 100%);
    --chart-1: #1d4ed8; --chart-2: #06b6d4; --chart-3: #f97316; --chart-4: #7c3aed; --chart-5: #22c55e; --chart-6: #ef4444; --chart-7: #0ea5e9; --chart-8: #a855f7;
}

html[data-theme="graphite"] {
    --bg: #f8fafc;
    --surface: #ffffff;
    --brand: #334155;
    --brand-dark: #1e293b;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --danger: #b91c1c;
    --success: #15803d;
    --warn: #b45309;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
    --border-glow: #cbd5e1;
    --bg-grad: linear-gradient(160deg, #f8fafc 0%, #f1f5f9 100%);
    --chart-1: #334155; --chart-2: #6366f1; --chart-3: #f59e0b; --chart-4: #10b981; --chart-5: #3b82f6; --chart-6: #ef4444; --chart-7: #a855f7; --chart-8: #ec4899;
}

html[data-theme="royal"] {
    --bg: #fdf2f8;
    --surface: #ffffff;
    --brand: #9d174d;
    --brand-dark: #831843;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #fce7f3;
    --danger: #b91c1c;
    --success: #15803d;
    --warn: #b45309;
    --radius: 14px;
    --shadow: 0 1px 3px rgba(157, 23, 77, .08), 0 12px 32px rgba(157, 23, 77, .10);
    --border-glow: #fbcfe8;
    --bg-grad: linear-gradient(160deg, #fdf2f8 0%, #fdf4ff 50%, #fef3c7 100%);
    --chart-1: #9d174d; --chart-2: #d946ef; --chart-3: #f59e0b; --chart-4: #7c3aed; --chart-5: #22c55e; --chart-6: #ef4444; --chart-7: #3b82f6; --chart-8: #10b981;
}
