:root {
    --primary: #2f6f4e;
    --primary-dark: #1f4d36;
    --primary-light: #e8f3ee;
    --primary-lighter: #f2f8f5;
    --accent: #d9a441;
    --text: #1e2a24;
    --muted: #64766e;
    --border: #e2e8e4;
    --bg: #f5f8f6;
    --white: #ffffff;
    --error: #b3261e;
    --error-bg: #fbeceb;
    --success: #1f7a4d;
    --success-bg: #e6f4ec;
    --info-bg: #eaf1fb;
    --info: #1a4d8f;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 3px rgba(20, 40, 30, 0.06), 0 1px 2px rgba(20, 40, 30, 0.04);
    --shadow-md: 0 8px 24px rgba(20, 50, 35, 0.08), 0 2px 6px rgba(20, 50, 35, 0.05);
    --shadow-lg: 0 20px 50px rgba(20, 50, 35, 0.14), 0 6px 16px rgba(20, 50, 35, 0.08);
    --gradient-brand: linear-gradient(135deg, #2f6f4e 0%, #1f4d36 100%);
    --gradient-hero: radial-gradient(circle at 15% 20%, rgba(217, 164, 65, 0.16), transparent 45%),
                      radial-gradient(circle at 85% 15%, rgba(47, 111, 78, 0.16), transparent 40%),
                      linear-gradient(180deg, #eef6f1 0%, #f5f8f6 60%);
}

* { box-sizing: border-box; }

/* راحة الاستخدام العامة */
html { scroll-behavior: smooth; }

::selection { background: var(--primary); color: var(--white); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #b7c4bd; }

::placeholder { color: #9aa8a2; opacity: 1; }

a:focus-visible, button:focus-visible, .btn:focus-visible, .btn-outline:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 6px;
}

button, .btn, .btn-outline, .btn-link {
    transition: transform .15s ease, box-shadow .15s ease, filter .15s ease, background-color .15s ease, color .15s ease;
}
.btn:active, .btn-outline:active { transform: scale(.97); }
.btn-link:active { transform: scale(.96); }

.feature-card, .dash-card { transition: transform .22s cubic-bezier(.4,0,.2,1), box-shadow .22s cubic-bezier(.4,0,.2,1), border-color .22s ease; }
.feature-card .feature-icon, .dash-card .feature-icon { transition: transform .28s cubic-bezier(.4,0,.2,1); }
.feature-card:hover .feature-icon, .dash-card:hover .feature-icon { transform: scale(1.1) rotate(-4deg); }

.badge { transition: transform .15s ease; }

.auth-form input, .auth-form select, .auth-form textarea { transition: border-color .18s ease, box-shadow .18s ease, transform .12s ease; }

/* انتقالات سلسة بين الصفحات (بدون أي تأخير مصطنع) — تعتمد على قدرة المتصفح
   الأصلية (View Transitions)، تعمل تلقائيًا بمتصفحات Chrome/Edge الحديثة
   وتتجاهَل بأمان بالمتصفحات الأخرى (تنتقل بشكل عادي فوري بدون أي مشكلة) */
@media (prefers-reduced-motion: no-preference) {
    @view-transition {
        navigation: auto;
    }
    ::view-transition-old(root) {
        animation: baheth-fade-out .22s cubic-bezier(.4,0,.2,1) both;
    }
    ::view-transition-new(root) {
        animation: baheth-fade-in .28s cubic-bezier(.4,0,.2,1) both;
    }
    @keyframes baheth-fade-out {
        to { opacity: 0; transform: translateY(-8px); }
    }
    @keyframes baheth-fade-in {
        from { opacity: 0; transform: translateY(8px); }
    }
}

body {
    margin: 0;
    font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1140px;
    margin: 0 auto;
    padding: 0 20px;
}

a { color: var(--primary); text-decoration: none; transition: color .15s ease; }
a:hover { color: var(--primary-dark); text-decoration: underline; }

/* Topbar */
.topbar {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: saturate(180%) blur(10px);
    -webkit-backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    flex-wrap: wrap;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 900;
    font-size: 1.3rem;
    color: var(--primary-dark);
}
.brand:hover { text-decoration: none; }
.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--gradient-brand);
    color: var(--white);
    font-weight: 900;
    box-shadow: var(--shadow-sm);
}
.brand-logo {
    height: 46px;
    width: auto;
    display: block;
}
.nav-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--primary-dark);
}
.main-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.main-nav a {
    position: relative;
    color: var(--text);
    font-weight: 600;
    font-size: 0.95rem;
    padding: 8px 12px;
    border-radius: 999px;
    transition: color .18s ease;
}
.main-nav a::after {
    content: '';
    position: absolute;
    right: 14px;
    left: 14px;
    bottom: 3px;
    height: 2px;
    border-radius: 2px;
    background: var(--primary);
    transform: scaleX(0);
    opacity: 0;
    transition: transform .28s cubic-bezier(.4,0,.2,1), opacity .2s ease;
}
.main-nav a:hover { color: var(--primary-dark); text-decoration: none; }
.main-nav a:hover::after { transform: scaleX(1); opacity: 1; }
.main-nav a.active::after { transform: scaleX(1); opacity: 1; }
.main-nav a.nav-logout { color: var(--white); background: var(--gradient-brand); box-shadow: var(--shadow-sm); }
.main-nav a.nav-logout::after { display: none; }
.main-nav a.nav-logout:hover { filter: brightness(1.08); color: var(--white); }

/* Hero */
.hero {
    text-align: center;
    padding: 90px 20px 70px;
    background: var(--gradient-hero);
    border-radius: 0 0 40px 40px;
    margin-bottom: 10px;
}
.hero-logo-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
}
.hero-logo-wrap::before {
    content: '';
    position: absolute;
    inset: -36px;
    background: radial-gradient(circle, rgba(47, 111, 78, 0.32) 0%, rgba(217, 164, 65, 0.2) 55%, transparent 75%);
    filter: blur(28px);
    z-index: 0;
    border-radius: 50%;
}
.hero-logo {
    position: relative;
    z-index: 1;
    height: 108px;
    width: auto;
    background: var(--white);
    padding: 16px;
    border-radius: 22px;
    box-shadow: var(--shadow-lg);
}
.hero-eyebrow {
    display: inline-block;
    background: var(--white);
    color: var(--primary-dark);
    font-weight: 700;
    font-size: 0.85rem;
    padding: 6px 16px;
    border-radius: 999px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 18px;
}
.hero h1 {
    font-size: clamp(2.1rem, 4vw, 3rem);
    margin: 0 0 16px;
    color: var(--primary-dark);
    font-weight: 900;
    line-height: 1.3;
}
.hero-sub { color: var(--muted); max-width: 620px; margin: 0 auto 32px; font-size: 1.15rem; }
.hero-actions { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }

.btn {
    display: inline-block;
    background: var(--gradient-brand);
    color: var(--white);
    border: none;
    padding: 13px 26px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    box-shadow: var(--shadow-sm);
    transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); filter: brightness(1.05); text-decoration: none; color: var(--white); }
.btn:active { transform: translateY(0); }
.btn-outline { background: var(--white); border: 2px solid var(--primary); color: var(--primary); padding: 11px 24px; box-shadow: none; }
.btn-outline:hover { background: var(--primary-lighter); color: var(--primary-dark); }
.btn-lg { padding: 16px 32px; font-size: 1.1rem; }
.btn-block { display: block; text-align: center; margin-bottom: 16px; }
.btn-link {
    display: inline-block;
    background: var(--primary-lighter);
    border: 1px solid var(--primary-light);
    color: var(--primary-dark);
    cursor: pointer;
    font: inherit;
    font-size: 0.82rem;
    font-weight: 700;
    padding: 6px 13px;
    border-radius: 999px;
    text-decoration: none;
    white-space: nowrap;
}
.btn-link:hover { background: var(--primary-light); text-decoration: none; }

/* Features */
.features { padding: 40px 0 70px; }
.features h2 { text-align: center; margin-bottom: 8px; color: var(--primary-dark); font-size: 1.7rem; }
.features-sub { text-align: center; color: var(--muted); margin: 0 auto 36px; max-width: 500px; }
.features-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 22px; }
.feature-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 30px 26px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: transform .18s ease, box-shadow .18s ease;
}
.feature-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.feature-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--primary-light);
    font-size: 1.7rem;
    margin-bottom: 14px;
}
.feature-card h3 { margin: 8px 0; color: var(--primary-dark); font-size: 1.1rem; }
.feature-card p { color: var(--muted); margin: 0; font-size: 0.95rem; }
.features-note { text-align: center; color: var(--muted); margin-top: 34px; font-size: 0.9rem; background: var(--primary-lighter); display: inline-block; padding: 10px 20px; border-radius: 999px; }
.features-note-wrap { text-align: center; }

/* Page */
.page { padding: 36px 20px 60px; }
.page-title { color: var(--primary-dark); margin-bottom: 22px; font-size: 1.6rem; }

/* Alerts */
.alert { padding: 14px 18px; border-radius: var(--radius-sm); margin-bottom: 20px; box-shadow: var(--shadow-sm); }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-error { background: var(--error-bg); color: var(--error); }
.alert-info { background: var(--info-bg); color: var(--info); }
.alert ul { margin: 0; padding-inline-start: 20px; }

/* Auth forms */
.auth-box {
    max-width: 430px;
    margin: 30px auto;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 34px;
    box-shadow: var(--shadow-md);
}
.auth-box-wide { max-width: 580px; }
.auth-form label { display: block; margin-bottom: 16px; font-weight: 700; color: var(--text); font-size: 0.92rem; }
.auth-form input, .auth-form select, .auth-form textarea {
    display: block;
    width: 100%;
    margin-top: 7px;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    background: var(--white);
    color: var(--text);
    font-weight: 400;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.auth-form input:focus, .auth-form select:focus, .auth-form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.auth-form textarea { resize: vertical; }
.auth-alt { text-align: center; margin-top: 18px; color: var(--muted); }

/* Panels */
.panel {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}
.panel h2 { margin-top: 0; color: var(--primary-dark); font-size: 1.2rem; }
.hint { color: var(--muted); font-size: 0.92rem; }

/* Dashboard */
.usage-banner {
    background: var(--gradient-brand);
    color: var(--white);
    padding: 16px 20px;
    border-radius: var(--radius);
    margin-bottom: 26px;
    box-shadow: var(--shadow-md);
}
.usage-banner strong { color: var(--white); }
.usage-banner a { color: var(--white); text-decoration: underline; }
.usage-warning { color: #ffe1b8; font-weight: 700; margin-inline-start: 8px; }
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 18px; margin-bottom: 24px; }
.dash-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    color: var(--text);
    box-shadow: var(--shadow-sm);
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.dash-card:hover { border-color: var(--primary); text-decoration: none; transform: translateY(-3px); box-shadow: var(--shadow-md); }
.dash-card h3 { font-size: 1.9rem; color: var(--primary-dark); margin: 6px 0; font-weight: 800; }
.dash-card p { color: var(--muted); margin: 0; font-size: 0.92rem; }
.dash-card-static:hover { border-color: var(--border); transform: none; box-shadow: var(--shadow-sm); }

/* Payment methods */
.payment-methods { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.payment-method-card {
    background: var(--primary-lighter);
    border: 1px solid var(--primary-light);
    border-radius: var(--radius-sm);
    padding: 14px 20px;
    min-width: 200px;
}
.payment-method-number { font-size: 1.2rem; font-weight: 800; color: var(--primary-dark); margin: 8px 0 0; letter-spacing: .5px; direction: ltr; text-align: right; }

/* Sources / references */
.source-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 18px 20px;
    margin-bottom: 14px;
    background: var(--white);
    box-shadow: var(--shadow-sm);
}
.source-card h3 { margin: 8px 0; font-size: 1.05rem; color: var(--primary-dark); }
.citation-text { line-height: 1.8; }

/* Tables */
.table-scroll { overflow-x: auto; margin: 0 -6px; padding: 0 6px; }
.data-table { width: 100%; border-collapse: collapse; min-width: 560px; }
.data-table th, .data-table td { text-align: right; padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table th { color: var(--muted); font-weight: 700; font-size: 0.88rem; white-space: nowrap; }
.data-table tbody tr { transition: background .12s ease; }
.data-table tbody tr:hover { background: var(--primary-lighter); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
.inline-form { display: contents; }

.btn-xs { padding: 6px 15px; font-size: 0.82rem; border-radius: 999px; box-shadow: none; }
.btn-danger { background: var(--error); }
.btn-danger:hover { background: #96201a; filter: none; }
.btn-danger-outline { background: var(--white); border: 1.5px solid var(--error); color: var(--error); padding: 5px 14px; }
.btn-danger-outline:hover { background: var(--error-bg); color: var(--error); }

/* قائمة إجراءات منسدلة (⋮) لصفوف الجداول ذات الإجراءات الثانوية المتعددة */
.row-menu { position: relative; display: inline-flex; }
.row-menu-toggle {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--white);
    color: var(--muted);
    font-size: 1.15rem;
    letter-spacing: 2px;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.row-menu-toggle:hover, .row-menu.open .row-menu-toggle {
    background: var(--primary-lighter);
    border-color: var(--primary);
    color: var(--primary-dark);
}
.row-menu-dropdown {
    position: fixed;
    min-width: 195px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    z-index: 100;
    opacity: 0;
    transform: translateY(-6px) scale(.97);
    pointer-events: none;
    transition: opacity .16s ease, transform .16s ease;
}
.row-menu.open .row-menu-dropdown { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.row-menu-dropdown form { margin: 0; }
.row-menu-dropdown button {
    display: block;
    width: 100%;
    text-align: right;
    background: none;
    border: none;
    padding: 10px 12px;
    border-radius: 8px;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
}
.row-menu-dropdown button:hover { background: var(--primary-lighter); color: var(--primary-dark); }
.row-menu-dropdown button.danger { color: var(--error); }
.row-menu-dropdown button.danger:hover { background: var(--error-bg); }

.badge { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 0.82rem; font-weight: 700; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-error { background: var(--error-bg); color: var(--error); }
.badge-info { background: var(--info-bg); color: var(--info); }

/* AI output */
.ai-output { white-space: pre-wrap; line-height: 1.9; }

/* Chat */
.chat-layout { display: grid; grid-template-columns: 250px 1fr; gap: 20px; align-items: start; }
.chat-sidebar {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}
.conversation-list { list-style: none; margin: 0; padding: 0; }
.conversation-list li a {
    display: block;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conversation-list li a:hover, .conversation-list li a.active { background: var(--primary-light); color: var(--primary-dark); text-decoration: none; }
.conversation-list li.empty { color: var(--muted); padding: 8px 10px; font-size: 0.9rem; }

.chat-main {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    height: 65vh;
    min-height: 420px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.chat-main-embedded { height: 40vh; min-height: 300px; border: none; box-shadow: none; }
.chat-messages { flex: 1; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.chat-empty { color: var(--muted); text-align: center; margin-top: 40px; }
.chat-msg { max-width: 80%; padding: 12px 18px; border-radius: 16px; white-space: pre-wrap; line-height: 1.7; box-shadow: var(--shadow-sm); }
.chat-msg-user { align-self: flex-end; background: var(--gradient-brand); color: var(--white); border-bottom-left-radius: 4px; }
.chat-msg-assistant { align-self: flex-start; background: var(--primary-lighter); color: var(--text); border-bottom-right-radius: 4px; box-shadow: none; border: 1px solid var(--border); }
.chat-form { display: flex; gap: 10px; padding: 16px; border-top: 1px solid var(--border); background: var(--white); }
.chat-form textarea {
    flex: 1;
    resize: none;
    min-height: 48px;
    max-height: 140px;
    padding: 11px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color .15s ease;
}
.chat-form textarea:focus { outline: none; border-color: var(--primary); }

/* Install page */
.install-page { max-width: 640px; margin: 40px auto; }
.install-box {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 34px;
    box-shadow: var(--shadow-lg);
}
.install-form h2 { font-size: 1.05rem; margin: 26px 0 12px; color: var(--primary-dark); padding-bottom: 8px; border-bottom: 2px solid var(--primary-light); }
.install-form h2:first-of-type { margin-top: 12px; }

/* Footer */
.site-footer {
    text-align: center;
    padding: 28px 0;
    color: var(--muted);
    border-top: 1px solid var(--border);
    margin-top: 50px;
    font-size: 0.88rem;
}

@media (max-width: 720px) {
    .nav-toggle { display: block; }
    .main-nav { display: none; width: 100%; flex-direction: column; align-items: stretch; gap: 4px; padding-top: 14px; }
    .main-nav a { text-align: center; }
    .main-nav.open { display: flex; }
    .chat-layout { grid-template-columns: 1fr; }
    .chat-sidebar { order: 2; }
    .hero { padding: 60px 20px 44px; border-radius: 0 0 28px 28px; }
}
