/* Mirfaq — application shell. Every asset here is local: no CDN, no remote font, no analytics.
   The product has to run inside a compound's server room with the internet unplugged. */

@font-face {
    font-family: 'Cairo';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('../fonts/cairo/cairo-400-arabic.woff2') format('woff2');
    unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}

@font-face {
    font-family: 'Cairo';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('../fonts/cairo/cairo-400-latin.woff2') format('woff2');
}

@font-face {
    font-family: 'Cairo';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url('../fonts/cairo/cairo-600-arabic.woff2') format('woff2');
    unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}

@font-face {
    font-family: 'Cairo';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url('../fonts/cairo/cairo-600-latin.woff2') format('woff2');
}

@font-face {
    font-family: 'Cairo';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('../fonts/cairo/cairo-700-arabic.woff2') format('woff2');
    unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}

:root {
    --brand: #146b5f;
    --brand-dark: #0e4f46;
    --brand-soft: #e6f2f0;
    --ink: #1c2b33;
    --muted: #6b7c86;
    --line: #e2e8ec;
    --surface: #ffffff;
    --canvas: #f4f6f8;
    --sidebar-width: 268px;
}

html, body {
    height: 100%;
}

body {
    font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
    background: var(--canvas);
    color: var(--ink);
    font-size: 0.95rem;
}

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

a:hover {
    color: var(--brand);
}

/* ---------- shell ---------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: linear-gradient(180deg, var(--brand-dark), #0a3a34);
    color: #d8e8e5;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.app-brand {
    padding: 1.1rem 1.1rem 0.9rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.app-brand .brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: #ffffff1a;
    display: grid;
    place-items: center;
    font-size: 1.25rem;
    color: #fff;
}

.app-brand .brand-text {
    color: #fff;
    font-weight: 700;
    line-height: 1.2;
}

.app-brand .brand-text small {
    display: block;
    font-weight: 400;
    font-size: 0.72rem;
    color: #a9cfc8;
}

.nav-group-title {
    padding: 0.9rem 1.1rem 0.35rem;
    font-size: 0.72rem;
    letter-spacing: 0.02em;
    color: #8fbdb5;
    text-transform: none;
}

.app-sidebar .nav-link {
    color: #d8e8e5;
    padding: 0.5rem 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    border-inline-start: 3px solid transparent;
    font-size: 0.9rem;
}

.app-sidebar .nav-link:hover {
    background: #ffffff12;
    color: #fff;
}

.app-sidebar .nav-link.active {
    background: #ffffff1f;
    color: #fff;
    border-inline-start-color: #6fd3c1;
    font-weight: 600;
}

.app-sidebar .nav-link i {
    font-size: 1rem;
    width: 1.2rem;
    text-align: center;
}

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

.app-topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 0.6rem 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 20;
}

.app-content {
    padding: 1.1rem;
    flex: 1 1 auto;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.9rem;
    flex-wrap: wrap;
}

.page-head h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
}

.page-head .page-sub {
    color: var(--muted);
    font-size: 0.85rem;
    margin: 0.15rem 0 0;
}

/* ---------- surfaces ---------- */

.card {
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(20, 40, 50, 0.04);
}

.card-header {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    font-weight: 600;
    border-radius: 12px 12px 0 0 !important;
}

.stat-tile {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.9rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    height: 100%;
}

.stat-tile .stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--brand-soft);
    color: var(--brand-dark);
    display: grid;
    place-items: center;
    font-size: 1.25rem;
    flex: 0 0 auto;
}

.stat-tile .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.1;
}

.stat-tile .stat-label {
    color: var(--muted);
    font-size: 0.82rem;
}

.table {
    --bs-table-bg: var(--surface);
    margin-bottom: 0;
}

.table > thead th {
    background: #f7f9fa;
    border-bottom: 1px solid var(--line);
    font-weight: 600;
    font-size: 0.85rem;
    color: #47606d;
    white-space: nowrap;
}

.table > tbody td {
    vertical-align: middle;
    font-size: 0.9rem;
}

.table-wrap {
    overflow-x: auto;
}

.btn-brand {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

.btn-brand:hover, .btn-brand:focus {
    background: var(--brand-dark);
    border-color: var(--brand-dark);
    color: #fff;
}

.btn-icon {
    padding: 0.2rem 0.45rem;
    line-height: 1.4;
}

.badge-soft {
    background: var(--brand-soft);
    color: var(--brand-dark);
    font-weight: 600;
}

/* ---------- banners ---------- */

.banner-impersonating {
    background: #7a4b00;
    color: #fff;
    padding: 0.4rem 1.1rem;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.banner-readonly {
    background: #8a1c1c;
    color: #fff;
    padding: 0.4rem 1.1rem;
    font-size: 0.85rem;
}

.banner-warning {
    background: #fff4d6;
    color: #6b4f00;
    padding: 0.4rem 1.1rem;
    font-size: 0.85rem;
    border-bottom: 1px solid #f0dfae;
}

/* ---------- auth ---------- */

.auth-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #0e4f46, #146b5f 55%, #1d8a78);
    padding: 1rem;
}

.auth-card {
    width: min(420px, 100%);
    background: #fff;
    border-radius: 16px;
    padding: 1.75rem;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}

.auth-card .auth-brand {
    text-align: center;
    margin-bottom: 1.25rem;
}

.auth-card .auth-brand .mark {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--brand-soft);
    color: var(--brand-dark);
    display: grid;
    place-items: center;
    font-size: 1.6rem;
    margin: 0 auto 0.6rem;
}

/* ---------- permission matrix ---------- */

.perm-group {
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 0.75rem;
    overflow: hidden;
}

.perm-group > header {
    background: #f7f9fa;
    padding: 0.5rem 0.85rem;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.perm-group .perm-list {
    padding: 0.6rem 0.85rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.35rem 1rem;
}

/* ---------- misc ---------- */

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

.empty-state i {
    font-size: 2rem;
    display: block;
    margin-bottom: 0.5rem;
    opacity: 0.5;
}

.text-muted-sm {
    color: var(--muted);
    font-size: 0.82rem;
}

.sidebar-backdrop {
    display: none;
}

@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        inset-inline-start: 0;
        top: 0;
        z-index: 1040;
        transform: translateX(100%);
        transition: transform 0.2s ease;
    }

    html[dir="ltr"] .app-sidebar {
        transform: translateX(-100%);
    }

    .app-sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop.show {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(10, 20, 25, 0.45);
        z-index: 1035;
    }
}

@media print {
    .app-sidebar, .app-topbar, .no-print {
        display: none !important;
    }

    .app-content {
        padding: 0;
    }
}
