:root {
    color-scheme: light;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-primary-soft: #eff6ff;
    --color-accent: #ea580c;
    --color-accent-hover: #c2410c;
    --color-background: #f8fafc;
    --color-surface: #ffffff;
    --color-foreground: #172033;
    --color-muted-foreground: #64748b;
    --color-border: #e2e8f0;
    --color-border-strong: #cbd5e1;
    --color-success: #15803d;
    --color-success-soft: #f0fdf4;
    --color-warning: #b45309;
    --color-warning-soft: #fffbeb;
    --color-danger: #dc2626;
    --color-danger-soft: #fef2f2;
    --sidebar-bg: #0b1220;
    --sidebar-surface: #131d31;
    --sidebar-text: #cbd5e1;
    --sidebar-muted: #7f8ca3;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-md: 0 12px 32px rgba(15, 23, 42, .07);
    --sidebar-width: 278px;
    --header-height: 74px;
}

* { box-sizing: border-box; }

html {
    min-width: 320px;
    scroll-padding-top: calc(var(--header-height) + 16px);
    background: var(--color-background);
}

body {
    margin: 0;
    min-width: 320px;
    min-height: 100vh;
    overflow-x: hidden;
    background:
        radial-gradient(circle at 85% -10%, rgba(37, 99, 235, .08), transparent 28rem),
        var(--color-background);
    color: var(--color-foreground);
    font-family: "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif;
    font-size: 16px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--color-primary); }

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 3px solid rgba(37, 99, 235, .42);
    outline-offset: 2px;
}

::selection { background: #bfdbfe; color: #172033; }

.app-icon {
    display: block;
    flex: 0 0 auto;
}

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

.app-shell .sidebar {
    position: sticky;
    inset-block-start: 0;
    width: var(--sidebar-width);
    height: 100vh;
    flex: 0 0 var(--sidebar-width);
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    z-index: 50;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, .025), transparent 18rem),
        var(--sidebar-bg);
    border-inline-start: 1px solid rgba(255, 255, 255, .06);
    scrollbar-width: thin;
    scrollbar-color: #334155 transparent;
}

.sidebar .brand {
    min-height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
}

.sidebar .brand-logo {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    color: white;
    border-radius: 13px;
    background: linear-gradient(145deg, #3b82f6, #1d4ed8);
    box-shadow: 0 10px 24px rgba(37, 99, 235, .28);
}

.sidebar .brand-copy { display: grid; min-width: 0; }
.sidebar .brand-name { color: white; font-size: 1.08rem; font-weight: 800; letter-spacing: -.02em; }
.sidebar .brand-copy small { color: var(--sidebar-muted); font-size: .72rem; }

.sidebar .nav-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 16px 12px 22px;
}

.sidebar .nav-group {
    margin-block-start: 15px;
    padding: 0 12px 5px;
    color: var(--sidebar-muted);
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .08em;
}

.sidebar .nav-list > .nav-link {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    color: var(--sidebar-text);
    text-decoration: none;
    border: 1px solid transparent;
    border-radius: 11px;
    font-size: .88rem;
    font-weight: 600;
    transition: color 180ms ease, background-color 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.sidebar .nav-list > .nav-link:hover {
    color: white;
    background: rgba(255, 255, 255, .055);
    transform: translateX(-2px);
}

.sidebar .nav-list > .nav-link.active {
    color: white;
    background: var(--sidebar-surface);
    border-color: rgba(96, 165, 250, .22);
    box-shadow: inset -3px 0 0 #60a5fa;
}

.sidebar .nav-list > .nav-link.active .app-icon { color: #60a5fa; }

.sidebar .nav-footer {
    margin-top: auto;
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) 42px;
    align-items: center;
    gap: 10px;
    padding: 15px 14px;
    border-top: 1px solid rgba(255, 255, 255, .07);
    background: rgba(0, 0, 0, .12);
}

.user-avatar {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    color: white;
    background: #334155;
    border: 1px solid #475569;
    border-radius: 50%;
    font-size: .88rem;
    font-weight: 800;
}

.user-copy { display: grid; min-width: 0; }
.user-copy strong { color: #f8fafc; font-size: .76rem; font-weight: 700; }
.sidebar .nav-user { overflow: hidden; color: var(--sidebar-muted); font-size: .7rem; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .nav-logout { width: 42px; height: 42px; display: grid; place-items: center; color: #fda4af; border-radius: 10px; text-decoration: none; }
.sidebar .nav-logout:hover { color: white; background: rgba(220, 38, 38, .16); }

.app-shell .main-col {
    min-width: 0;
    flex: 1 1 auto;
    background: transparent;
}

.main-col .scope-bar {
    position: sticky;
    inset-block-start: 0;
    z-index: 30;
    min-height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px clamp(18px, 3vw, 36px);
    background: rgba(255, 255, 255, .9);
    border-bottom: 1px solid rgba(226, 232, 240, .9);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(14px);
}

.scope-heading { display: grid; min-width: 150px; }
.scope-heading .scope-eyebrow { color: var(--color-muted-foreground); font-size: .68rem; font-weight: 700; letter-spacing: .06em; }
.scope-heading strong { color: var(--color-foreground); font-size: .95rem; font-weight: 800; }
.scope-context { margin-inline-start: auto; display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

.main-col .scope-chip {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 11px;
    color: #1e40af;
    background: var(--color-primary-soft);
    border: 1px solid #dbeafe;
    border-radius: 10px;
    font-size: .77rem;
    font-weight: 700;
}

.main-col .scope-warn {
    padding: 7px 11px;
    color: var(--color-warning);
    background: var(--color-warning-soft);
    border: 1px solid #fde68a;
    border-radius: 10px;
    font-size: .78rem;
    font-weight: 700;
}

.mobile-menu-button {
    display: none;
    width: 44px;
    height: 44px;
    place-items: center;
    color: var(--color-foreground);
    background: white;
    border: 1px solid var(--color-border);
    border-radius: 11px;
    cursor: pointer;
}

.nav-backdrop { display: none; }

.main-col .content-area {
    width: 100%;
    max-width: 1640px;
    margin-inline: auto;
    padding: clamp(20px, 3vw, 38px);
}

.content-area h1.pt,
.content-area h1.page-title {
    margin: 0 0 24px;
    color: var(--color-foreground);
    font-size: clamp(1.55rem, 2.2vw, 2rem);
    font-weight: 800;
    letter-spacing: -.035em;
    line-height: 1.3;
}

.content-area h1.pt::after,
.content-area h1.page-title::after {
    content: "";
    display: block;
    width: 38px;
    height: 4px;
    margin-block-start: 10px;
    background: var(--color-accent);
    border-radius: 999px;
}

.content-area .hint { margin: -14px 0 22px; color: var(--color-muted-foreground); font-size: .9rem; }

body .content-area .card,
body .content-area .setup-card {
    position: relative;
    max-width: none;
    margin-bottom: 20px;
    padding: clamp(18px, 2.2vw, 26px);
    overflow-x: auto;
    background: rgba(255, 255, 255, .96);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

body .content-area .card::before {
    content: "";
    position: absolute;
    inset-block: 22px;
    inset-inline-start: 0;
    width: 3px;
    background: #bfdbfe;
    border-radius: 0 4px 4px 0;
}

.content-area .card h2,
.content-area .card h3,
.content-area .setup-card h2 {
    margin: 0 0 18px;
    color: var(--color-foreground);
    font-size: 1rem;
    font-weight: 800;
}

body .content-area .grid { gap: 16px; margin-bottom: 20px; }
body .content-area .f label,
body .content-area .setup-grid label { margin-bottom: 7px; color: #334155; font-size: .78rem; font-weight: 700; }

body .content-area :where(input:not([type="checkbox"]), select, textarea),
body .login-wrap :where(input, select, textarea) {
    min-height: 46px;
    width: 100%;
    padding: 10px 13px;
    color: var(--color-foreground);
    background: white;
    border: 1px solid var(--color-border-strong);
    border-radius: 10px;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, .025);
    transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

body .content-area :where(input:not([type="checkbox"]), select, textarea):hover,
body .login-wrap :where(input, select, textarea):hover { border-color: #94a3b8; }

body .content-area :where(input:not([type="checkbox"]), select, textarea):focus,
body .login-wrap :where(input, select, textarea):focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
}

input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--color-primary); }

body .content-area button.btn,
body .content-area .setup-button,
body .content-area a.btn-link,
body .login-wrap button.btn,
body .wrap a.btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    color: white;
    background: var(--color-primary);
    border: 1px solid var(--color-primary);
    border-radius: 10px;
    box-shadow: 0 5px 14px rgba(37, 99, 235, .16);
    font-size: .88rem;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

body .content-area button.btn:hover:not(:disabled),
body .content-area .setup-button:hover:not(:disabled),
body .login-wrap button.btn:hover:not(:disabled) {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
    box-shadow: 0 8px 20px rgba(37, 99, 235, .2);
    transform: translateY(-1px);
}

body .content-area button:disabled,
body .login-wrap button:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }

body .content-area button.mini {
    min-height: 38px;
    padding: 7px 12px;
    color: #1e40af;
    background: var(--color-primary-soft);
    border: 1px solid #dbeafe;
    border-radius: 9px;
    font-size: .76rem;
    font-weight: 700;
    cursor: pointer;
}

body .content-area table {
    width: 100%;
    min-width: 680px;
    border-collapse: separate;
    border-spacing: 0;
    font-size: .82rem;
}

body .content-area th {
    padding: 12px 14px;
    color: #475569;
    background: #f8fafc;
    border-block: 1px solid var(--color-border);
    font-size: .72rem;
    font-weight: 800;
    text-align: start;
    white-space: nowrap;
}

body .content-area th:first-child { border-start-start-radius: 10px; border-end-start-radius: 10px; }
body .content-area th:last-child { border-start-end-radius: 10px; border-end-end-radius: 10px; }
body .content-area td { padding: 13px 14px; color: #334155; border-bottom: 1px solid #edf2f7; font-size: .82rem; vertical-align: middle; }
body .content-area tbody tr { transition: background-color 140ms ease; }
body .content-area tbody tr:hover { background: #f8fbff; }

/* Shared administration pattern: compact forms, discoverable filters and safe record actions. */
.admin-page-head { display:flex; align-items:flex-end; justify-content:space-between; gap:16px; margin-bottom:20px; }
.admin-page-head h1 { margin:0; color:var(--color-foreground); font-size:clamp(1.45rem, 2vw, 1.9rem); }
.admin-page-head p { margin:5px 0 0; color:var(--color-muted-foreground); font-size:.84rem; }
.admin-count { min-width:84px; padding:8px 12px; color:#1e40af; background:var(--color-primary-soft); border:1px solid #dbeafe; border-radius:999px; font-size:.76rem; font-weight:800; text-align:center; }
.admin-card-title { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:16px; }
.admin-card-title h2 { margin:0; color:var(--color-foreground); font-size:1rem; }
.admin-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(185px,1fr)); gap:14px; margin-bottom:18px; align-items:end; }
.admin-field label { display:block; margin-bottom:7px; color:#334155; font-size:.76rem; font-weight:800; }
.admin-field input:not([type=checkbox]), .admin-field select { width:100%; min-height:42px; box-sizing:border-box; padding:9px 11px; color:var(--color-foreground); background:white; border:1px solid var(--color-border); border-radius:9px; font:inherit; font-size:.84rem; }
.admin-check { min-height:42px; display:flex; align-items:center; }
.admin-check label { display:flex; align-items:center; gap:8px; margin:0; cursor:pointer; }
.admin-check input { width:17px; height:17px; accent-color:var(--color-primary); }
.admin-form-actions, .admin-row-actions, .admin-pagination { display:flex; align-items:center; flex-wrap:wrap; gap:8px; }
.admin-form-actions .btn { display:inline-flex; align-items:center; justify-content:center; gap:7px; }
.admin-secondary, .admin-table-action { display:inline-flex; align-items:center; justify-content:center; gap:6px; min-height:38px; padding:7px 11px; color:#1e40af; background:white; border:1px solid #bfdbfe; border-radius:9px; font-size:.75rem; font-weight:800; cursor:pointer; transition:background-color 160ms ease, border-color 160ms ease, color 160ms ease; }
.admin-secondary:hover, .admin-table-action:hover { background:var(--color-primary-soft); border-color:#93c5fd; }
.admin-table-action.danger { color:#b91c1c; border-color:#fecaca; }
.admin-table-action.danger:hover { background:#fff1f2; border-color:#fca5a5; }
.admin-table-action.restore { color:#047857; border-color:#a7f3d0; }
.admin-table-action.restore:hover { background:#ecfdf5; border-color:#6ee7b7; }
.admin-toolbar { display:flex; align-items:end; justify-content:space-between; gap:12px; margin-bottom:16px; }
.admin-filters { flex:1; display:grid; grid-template-columns:minmax(220px, 1fr) minmax(150px, 190px); gap:10px; }
.admin-search { position:relative; }
.admin-search .app-icon { position:absolute; inset-inline-start:12px; top:50%; transform:translateY(-50%); color:#64748b; pointer-events:none; }
.admin-search input { padding-inline-start:40px !important; }
.table-wrap { width:100%; overflow-x:auto; border-radius:10px; }
.admin-status { display:inline-flex; align-items:center; gap:6px; padding:5px 9px; border-radius:999px; font-size:.7rem; font-weight:800; white-space:nowrap; }
.admin-status::before { content:""; width:6px; height:6px; border-radius:50%; background:currentColor; }
.admin-status.active { color:#047857; background:#ecfdf5; }
.admin-status.archived { color:#64748b; background:#f1f5f9; }
.admin-status.current { color:#1d4ed8; background:#eff6ff; }
.admin-confirm { display:flex; align-items:center; justify-content:space-between; gap:14px; margin:0 0 16px; padding:13px 14px; color:#9f1239; background:#fff1f2; border:1px solid #fecdd3; border-radius:11px; font-size:.82rem; font-weight:700; }
.admin-empty { padding:28px 16px; color:var(--color-muted-foreground); background:#f8fafc; border:1px dashed #cbd5e1; border-radius:11px; text-align:center; }
.admin-empty strong { display:block; margin-bottom:4px; color:#334155; }
.admin-pagination { justify-content:space-between; margin-top:16px; padding-top:14px; border-top:1px solid var(--color-border); color:var(--color-muted-foreground); font-size:.76rem; }
.admin-pagination-controls { display:flex; gap:7px; }
.admin-pagination button { min-width:38px; min-height:36px; color:#334155; background:white; border:1px solid var(--color-border); border-radius:8px; cursor:pointer; }
.admin-pagination button:hover:not(:disabled) { color:var(--color-primary); border-color:#93c5fd; background:var(--color-primary-soft); }
.admin-pagination button:disabled { opacity:.45; cursor:not-allowed; }
.admin-feedback { margin-bottom:16px; padding:12px 14px; border-radius:11px; font-size:.82rem; }
.admin-feedback.success { color:#047857; background:#ecfdf5; border:1px solid #a7f3d0; }
.visually-hidden { position:absolute !important; width:1px !important; height:1px !important; padding:0 !important; margin:-1px !important; overflow:hidden !important; clip:rect(0,0,0,0) !important; white-space:nowrap !important; border:0 !important; }

body .content-area :where(.err, .error-box) {
    padding: 12px 14px;
    color: #991b1b;
    background: var(--color-danger-soft);
    border: 1px solid #fecaca;
    border-radius: 11px;
    font-size: .84rem;
}

body .content-area .ok { color: var(--color-success); background: var(--color-success-soft); border: 1px solid #bbf7d0; border-radius: 11px; }
body .content-area .warn { color: var(--color-warning); background: var(--color-warning-soft); border: 1px solid #fde68a; border-radius: 11px; }
body .content-area .muted { color: var(--color-muted-foreground); }

body .content-area .tiles {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

body .content-area .tile {
    min-height: 154px;
    display: grid;
    grid-template-columns: 52px 1fr;
    grid-template-rows: 1fr auto;
    align-items: start;
    gap: 8px 14px;
    padding: 22px;
    color: var(--color-foreground);
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    transition: transform 190ms ease, box-shadow 190ms ease, border-color 190ms ease;
}

body .content-area .tile:hover { border-color: #bfdbfe; box-shadow: var(--shadow-md); transform: translateY(-3px); }
.tile-icon { grid-row: 1 / 3; width: 52px; height: 52px; display: grid; place-items: center; color: var(--color-primary); background: var(--color-primary-soft); border-radius: 14px; }
body .content-area .tile-num { align-self: end; color: var(--color-foreground); font-size: 2rem; font-weight: 800; line-height: 1; }
body .content-area .tile-lbl { color: var(--color-muted-foreground); font-size: .8rem; font-weight: 700; }

body .login-wrap {
    position: relative;
    isolation: isolate;
    min-height: 100vh;
    padding: 24px;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: #0b1220;
}

body .login-wrap::before,
body .login-wrap::after {
    content: "";
    position: absolute;
    z-index: -1;
    width: 32rem;
    height: 32rem;
    border-radius: 50%;
    filter: blur(2px);
}

body .login-wrap::before { inset: -14rem -10rem auto auto; background: radial-gradient(circle, rgba(37, 99, 235, .55), transparent 68%); }
body .login-wrap::after { inset: auto auto -17rem -10rem; background: radial-gradient(circle, rgba(234, 88, 12, .25), transparent 68%); }

body .login-card {
    width: min(100%, 430px);
    padding: clamp(28px, 5vw, 42px);
    color: var(--color-foreground);
    background: rgba(255, 255, 255, .98);
    border: 1px solid rgba(255, 255, 255, .7);
    border-radius: 22px;
    box-shadow: 0 32px 90px rgba(0, 0, 0, .34);
    text-align: start;
}

body .login-logo {
    width: 62px;
    height: 62px;
    margin: 0 auto 20px;
    display: grid;
    place-items: center;
    color: white;
    background: linear-gradient(145deg, #3b82f6, #1d4ed8);
    border-radius: 18px;
    box-shadow: 0 14px 30px rgba(37, 99, 235, .25);
}

body .login-title { margin: 0; color: var(--color-foreground); font-size: 1.45rem; font-weight: 800; text-align: center; }
body .login-sub { margin: 6px 0 28px; color: var(--color-muted-foreground); font-size: .86rem; text-align: center; }
body .login-wrap .field { margin-bottom: 17px; text-align: start; }
body .login-wrap .field label { margin-bottom: 7px; color: #334155; font-size: .78rem; font-weight: 700; }
body .login-wrap button.btn { width: 100%; margin-top: 4px; }
body .login-wrap .error { color: #991b1b; background: var(--color-danger-soft); border: 1px solid #fecaca; }

#blazor-error-ui { z-index: 1000; color: #7c2d12; background: #fff7ed; border-top: 1px solid #fed7aa; }

@media (max-width: 1180px) {
    body .content-area .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 959px) {
    :root { --header-height: 66px; }
    body .app-shell { display: block; }
    .app-shell .sidebar {
        position: fixed;
        inset: 0 0 0 auto;
        width: min(86vw, 300px);
        height: 100dvh;
        transform: translateX(105%);
        transition: transform 220ms ease;
        box-shadow: -24px 0 60px rgba(2, 6, 23, .28);
    }
    .app-shell.menu-open .sidebar { transform: translateX(0); }
    .mobile-menu-button { display: grid; }
    .nav-backdrop {
        position: fixed;
        inset: 0;
        z-index: 40;
        display: block;
        width: 100%;
        height: 100%;
        padding: 0;
        background: rgba(2, 6, 23, .48);
        border: 0;
        backdrop-filter: blur(2px);
        cursor: pointer;
    }
    .main-col .scope-bar { padding-inline: 14px; }
    .scope-heading { min-width: 0; }
}

@media (max-width: 640px) {
    .main-col .content-area { padding: 18px 14px 28px; }
    .scope-context { display: none; }
    .scope-heading { margin-inline-end: auto; }
    body .content-area .tiles { grid-template-columns: 1fr; }
    body .content-area .tile { min-height: 124px; }
    body .content-area .grid { grid-template-columns: 1fr; }
    body .content-area .hdr { align-items: stretch; }
    body .content-area .search { min-width: 100%; }
    body .content-area button.btn,
    body .content-area .setup-button { width: 100%; }
    .admin-page-head, .admin-toolbar, .admin-confirm { align-items:stretch; flex-direction:column; }
    .admin-count { align-self:flex-start; }
    .admin-filters { grid-template-columns:1fr; }
    .admin-form-actions > *, .admin-confirm .admin-row-actions > * { flex:1; }
    .admin-pagination { align-items:stretch; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

@media print {
    .sidebar, .scope-bar, .mobile-menu-button, .nav-backdrop { display: none !important; }
    .content-area { max-width: none !important; padding: 0 !important; }
    body { background: white !important; }
    body .content-area .card { border: 0; box-shadow: none; }
}
