:root {
    --brand: #711739;
    --brand-dark: #58122d;
    --brand-light: #8a1c47;
    --brand-50: #fbeef3;
    --accent: #e0a64e;
    --accent-soft: #fbf3e4;

    --bg: #f4f5f9;
    --surface: #ffffff;
    --ink: #1f2330;
    --muted: #7a8095;
    --line: #eceef3;

    --sidebar-w: 264px;
    --topbar-h: 68px;

    --radius: 16px;
    --radius-sm: 12px;
    --shadow-sm: 0 1px 2px rgba(20, 22, 30, 0.04), 0 2px 8px rgba(20, 22, 30, 0.05);
    --shadow-md: 0 8px 24px rgba(20, 22, 30, 0.08);
    --shadow-brand: 0 10px 26px rgba(113, 23, 57, 0.28);
}

* { -webkit-font-smoothing: antialiased; }

body.app-body {
    font-family: "Tajawal", system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
    margin: 0;
}

/* ============ Layout shell ============ */
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: var(--sidebar-w);
    background: linear-gradient(185deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    z-index: 1040;
    box-shadow: var(--shadow-md);
    transition: transform 0.25s ease;
}

.app-main {
    flex: 1;
    min-width: 0;
    margin-inline-start: var(--sidebar-w);
    display: flex;
    flex-direction: column;
}

/* ============ Sidebar ============ */
.sidebar-brand {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding-inline: 1.4rem;
    font-size: 1.35rem;
    font-weight: 800;
    color: #fff;
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    letter-spacing: 0.5px;
}
.sidebar-brand .brand-mark {
    width: 38px; height: 38px;
    display: grid; place-items: center;
    background: rgba(255, 255, 255, 0.14);
    border-radius: 12px;
    font-size: 1.1rem;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.sidebar-section {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.45);
    padding: 0.9rem 0.85rem 0.35rem;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.7rem 0.85rem;
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.82);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: background 0.15s ease, color 0.15s ease;
    position: relative;
}
.sidebar-link i { width: 1.3rem; text-align: center; font-size: 1rem; opacity: 0.9; }
.sidebar-link:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.sidebar-link.active {
    background: #fff;
    color: var(--brand-dark);
    font-weight: 700;
    box-shadow: var(--shadow-sm);
}
.sidebar-link.active i { opacity: 1; color: var(--brand); }

.sidebar-footer {
    padding: 1rem 1.1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.55);
}

/* ============ Topbar ============ */
.app-topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-inline: 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}
.topbar-title { font-size: 1.15rem; font-weight: 700; margin: 0; }
.topbar-spacer { flex: 1; }

.icon-btn {
    width: 42px; height: 42px;
    display: grid; place-items: center;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover { background: var(--bg); border-color: #dfe2ec; color: var(--brand); }

.topbar-user {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.3rem 0.4rem;
    border-radius: 12px;
    cursor: pointer;
    border: 1px solid transparent;
}
.topbar-user:hover { background: var(--bg); }
.user-avatar {
    width: 40px; height: 40px;
    display: grid; place-items: center;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), var(--brand-light));
    color: #fff; font-weight: 700;
}
.user-meta { line-height: 1.15; }
.user-meta .u-name { font-weight: 600; font-size: 0.9rem; }
.user-meta .u-role { font-size: 0.74rem; color: var(--muted); }

.sidebar-toggle { display: none; }

/* ============ Content ============ */
.app-content { padding: 1.75rem; flex: 1; }
.page-head { margin-bottom: 1.5rem; }
.page-head h1 { font-size: 1.5rem; font-weight: 800; margin: 0; }
.page-head .page-sub { color: var(--muted); font-size: 0.92rem; }

/* ============ Stat cards ============ */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 1.1rem;
    margin-bottom: 1.75rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.stat-card .s-value { font-size: 1.7rem; font-weight: 800; line-height: 1.1; }
.stat-card .s-label { color: var(--muted); font-size: 0.85rem; margin-top: 0.25rem; }
.stat-icon {
    width: 54px; height: 54px;
    border-radius: 14px;
    display: grid; place-items: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}
.si-brand { background: var(--brand-50); color: var(--brand); }
.si-warning { background: #fff4e2; color: #d98a14; }
.si-danger { background: #fdeaea; color: #d64545; }
.si-info { background: #e8f1fd; color: #2f6fdb; }
.si-success { background: #e7f6ee; color: #2a9d63; }
.si-accent { background: var(--accent-soft); color: var(--accent); }

/* ============ Card / table ============ */
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.panel-head {
    padding: 1.1rem 1.4rem;
    border-bottom: 1px solid var(--line);
    font-weight: 700;
    display: flex; align-items: center; gap: 0.5rem;
}
.panel-head i { color: var(--brand); }

.table {
    margin: 0;
    --bs-table-hover-bg: var(--brand-50);
}
.table thead th {
    background: #faf7f9;
    color: var(--brand-dark);
    font-weight: 700;
    font-size: 0.82rem;
    text-transform: none;
    border-bottom: 1px solid var(--line);
    padding: 0.85rem 1.1rem;
    white-space: nowrap;
}
.table tbody td {
    padding: 0.85rem 1.1rem;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
    font-size: 0.9rem;
}
.table tbody tr:last-child td { border-bottom: 0; }

.pill {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.28rem 0.7rem;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 600;
}
.pill-success { background: #e7f6ee; color: #1f8a52; }
.pill-warning { background: #fff4e2; color: #c47e0f; }
.pill-muted { background: #eef0f5; color: #6b7180; }

/* ============ Buttons ============ */
.btn-primary {
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-dark);
    --bs-btn-hover-border-color: var(--brand-dark);
    --bs-btn-active-bg: var(--brand-dark);
    --bs-btn-active-border-color: var(--brand-dark);
    font-weight: 600;
}
a { color: var(--brand); }

/* ============ Login ============ */
.login-body {
    font-family: "Tajawal", system-ui, sans-serif;
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background:
        radial-gradient(1200px 600px at 100% 0%, rgba(224, 166, 78, 0.22), transparent 55%),
        linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 70%);
}
.login-card {
    width: 100%; max-width: 410px;
    background: var(--surface);
    border-radius: 22px;
    padding: 2.5rem 2.2rem;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.28);
}
.login-logo {
    width: 64px; height: 64px;
    margin: 0 auto 1rem;
    display: grid; place-items: center;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--brand), var(--brand-light));
    color: #fff; font-size: 1.6rem;
    box-shadow: var(--shadow-brand);
}
.login-card .form-control {
    border-radius: 12px;
    padding: 0.65rem 0.9rem;
    border-color: #e4e7ef;
}
.login-card .form-control:focus {
    border-color: var(--brand-light);
    box-shadow: 0 0 0 0.2rem rgba(113, 23, 57, 0.12);
}
.login-card .input-group-text {
    background: var(--bg);
    border-color: #e4e7ef;
    color: var(--muted);
    border-radius: 12px;
}

/* ============ Responsive ============ */
.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(15, 17, 25, 0.45);
    z-index: 1035;
}
@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-105%); }
    html[dir="rtl"] .app-sidebar { transform: translateX(105%); }
    .app-sidebar.open { transform: translateX(0); }
    .app-main { margin-inline-start: 0; }
    .sidebar-toggle { display: grid; }
    body.sidebar-open .sidebar-backdrop { display: block; }
}
