:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --sidebar: #0f2b46;
    --sidebar-active: #13395e;
    --primary: #0e8a76;
    --primary-600: #0b7263;
    --primary-050: #e4f4f1;
    --text: #1b2733;
    --text-muted: #64748b;
    --border: #e6eaf0;
    --good: #16a34a;
    --good-bg: #e7f7ec;
    --bad: #dc2626;
    --bad-bg: #fdeaea;
    --warn: #d97706;
    --warn-bg: #fdf3e2;
    --info: #2563eb;
    --info-bg: #e8f0fe;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
    --radius: 14px;
    font-family: "Segoe UI", Tahoma, "Helvetica Neue", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.55;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; color: var(--text); }
a { color: var(--primary-600); text-decoration: none; }

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

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: #cdd9e5;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: 1.25rem 1.25rem;
    font-size: 1.15rem;
    font-weight: 800;
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sidebar-brand .logo { font-size: 1.5rem; }
.sidebar-brand small { display: block; font-size: .7rem; font-weight: 500; color: #8aa0b6; }

.nav-list { list-style: none; margin: 0; padding: .75rem; display: flex; flex-direction: column; gap: .2rem; flex: 1; }
.nav-list a {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .7rem .85rem;
    border-radius: 10px;
    color: #cdd9e5;
    font-weight: 600;
    transition: background .15s, color .15s;
}
.nav-list a:hover { background: var(--sidebar-active); color: #fff; }
.nav-list a.active { background: var(--primary); color: #fff; }
.nav-list a .ico { font-size: 1.15rem; width: 1.4rem; text-align: center; }

.sidebar-foot { padding: 1rem; border-top: 1px solid rgba(255, 255, 255, .08); font-size: .8rem; color: #8aa0b6; }

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

.topbar {
    height: 64px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 5;
}
.topbar .page-title { font-size: 1.15rem; font-weight: 700; }
.user-chip { display: flex; align-items: center; gap: .6rem; }
.user-chip .avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary-050); color: var(--primary-600);
    display: grid; place-items: center; font-weight: 800;
}
.user-chip .who { line-height: 1.15; }
.user-chip .who b { font-size: .9rem; }
.user-chip .who span { font-size: .72rem; color: var(--text-muted); }

.content { padding: 1.5rem; max-width: 1280px; width: 100%; margin: 0 auto; }

/* ---- Cards / stats ------------------------------------------------------ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-head { padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-head h3 { font-size: 1rem; }
.card-body { padding: 1.25rem; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.15rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}
.stat .stat-ico { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; font-size: 1.4rem; }
.stat .stat-num { font-size: 1.9rem; font-weight: 800; line-height: 1; }
.stat .stat-label { color: var(--text-muted); font-size: .85rem; margin-top: .25rem; }
.i-total { background: var(--primary-050); color: var(--primary-600); }
.i-good { background: var(--good-bg); color: var(--good); }
.i-bad { background: var(--bad-bg); color: var(--bad); }
.i-warn { background: var(--warn-bg); color: var(--warn); }
.i-info { background: var(--info-bg); color: var(--info); }

/* ---- Tables ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: .7rem .9rem; text-align: start; white-space: nowrap; }
table.data thead th { background: #f8fafc; color: var(--text-muted); font-weight: 700; border-bottom: 1px solid var(--border); font-size: .8rem; }
table.data tbody tr { border-bottom: 1px solid var(--border); }
table.data tbody tr:hover { background: #f9fbfc; }
table.data tbody tr:last-child { border-bottom: none; }

.badge { display: inline-block; padding: .18rem .55rem; border-radius: 999px; font-size: .74rem; font-weight: 700; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.muted { background: #eef1f5; color: var(--text-muted); }

.rank { font-weight: 800; color: var(--text-muted); }
.rank.top { color: var(--primary-600); }

/* ---- Buttons / forms ---------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .6rem 1.1rem; border-radius: 10px; border: 1px solid transparent;
    font-weight: 700; font-size: .9rem; cursor: pointer; transition: background .15s, box-shadow .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: #f3f5f8; }

.input, select.input {
    width: 100%; padding: .6rem .8rem; border: 1px solid var(--border);
    border-radius: 10px; font-size: .9rem; background: #fff; color: var(--text);
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-050); }
.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.field label { font-size: .85rem; font-weight: 600; color: var(--text-muted); }

.toolbar { display: flex; gap: .75rem; align-items: end; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .field { margin-bottom: 0; min-width: 200px; }
.spacer { flex: 1; }

/* ---- Pagination --------------------------------------------------------- */
.pager { display: flex; gap: .5rem; align-items: center; justify-content: center; padding: 1rem; color: var(--text-muted); font-size: .85rem; }

/* ---- Login -------------------------------------------------------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #0f2b46, #0e8a76); padding: 1rem; }
.login-card { background: #fff; border-radius: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.25); width: 100%; max-width: 400px; padding: 2rem; }
.login-card .brand { text-align: center; margin-bottom: 1.5rem; }
.login-card .brand .logo { font-size: 2.5rem; }
.login-card .brand h1 { font-size: 1.35rem; margin-top: .4rem; }
.login-card .brand p { color: var(--text-muted); font-size: .85rem; margin: .25rem 0 0; }
.alert { padding: .7rem .9rem; border-radius: 10px; font-size: .85rem; margin-bottom: 1rem; }
.alert.error { background: var(--bad-bg); color: var(--bad); }
.hint { text-align: center; font-size: .78rem; color: var(--text-muted); margin-top: 1rem; }

/* ---- Misc --------------------------------------------------------------- */
.page-loading, .empty { padding: 2.5rem; text-align: center; color: var(--text-muted); }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.meter { margin-bottom: 1.1rem; }
.meter:last-child { margin-bottom: 0; }
.meter-top { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: .35rem; }
.meter-top b { color: var(--text); }
.meter-track { height: 10px; background: #eef1f5; border-radius: 999px; overflow: hidden; }
.meter-fill { height: 100%; border-radius: 999px; transition: width .4s ease; }

.changes { display: flex; flex-direction: column; gap: .2rem; white-space: normal; }
.chg { font-size: .8rem; }
.chg .f { font-weight: 700; }
.chg .b { color: var(--bad); text-decoration: line-through; }
.chg .a { color: var(--good); }

/* Blazor error UI */
#blazor-error-ui { background: #fff3cd; bottom: 0; box-shadow: 0 -1px 8px rgba(0,0,0,.1); display: none; left: 0; padding: .8rem 1.2rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; left: 1rem; top: .75rem; }
.blazor-error-boundary { background: #b32121; padding: 1rem; color: white; border-radius: 8px; }
.blazor-error-boundary::after { content: "حدث خطأ غير متوقع."; }

@media (max-width: 820px) {
    .sidebar { position: fixed; right: -260px; z-index: 30; transition: right .2s; }
    .sidebar.open { right: 0; }
    .content { padding: 1rem; }
}

/* ---- Bar list (single-hue magnitude bars) ------------------------------- */
.barlist { display: flex; flex-direction: column; gap: .85rem; }
.barlist-row { display: grid; grid-template-columns: 130px 1fr auto; align-items: center; gap: .75rem; }
.barlist-label { font-size: .85rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barlist-track { height: 10px; background: #eef1f5; border-radius: 999px; overflow: hidden; }
.barlist-fill { height: 100%; border-radius: 999px; background: var(--primary); transition: width .4s ease; }
.barlist-val { font-size: .82rem; font-weight: 700; color: var(--text-muted); min-width: 2.5rem; text-align: end; }

/* ---- Timeline (mini vertical bars) -------------------------------------- */
.spark { display: flex; align-items: end; gap: .4rem; height: 130px; padding-top: .5rem; }
.spark-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .35rem; min-width: 0; }
.spark-bar { width: 100%; max-width: 34px; background: var(--primary-050); border-radius: 6px 6px 0 0; position: relative; transition: height .4s ease; }
.spark-bar > span { position: absolute; top: -1.15rem; left: 50%; transform: translateX(-50%); font-size: .7rem; font-weight: 700; color: var(--text-muted); }
.spark-bar.hot { background: var(--primary); }
.spark-label { font-size: .68rem; color: var(--text-muted); white-space: nowrap; }

/* ---- Two-column responsive grid ----------------------------------------- */
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1.25rem; align-items: start; }
.grid-2.even { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .grid-2, .grid-2.even { grid-template-columns: 1fr; } }

/* ---- Modal -------------------------------------------------------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 43, 70, .45); display: grid; place-items: center; z-index: 100; padding: 1rem; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: 0 24px 70px rgba(0,0,0,.3); width: 100%; max-width: 460px; max-height: 92vh; overflow-y: auto; }
.modal-head { padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-size: 1.05rem; }
.modal-body { padding: 1.25rem; }
.modal-foot { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; gap: .6rem; justify-content: flex-start; }
.icon-btn { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--text-muted); line-height: 1; }

/* ---- Buttons (extra) ---------------------------------------------------- */
.btn-sm { padding: .4rem .7rem; font-size: .8rem; border-radius: 8px; }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-danger:disabled { opacity: .6; cursor: not-allowed; }
.row-actions { display: flex; gap: .4rem; }

/* ---- Alerts (extra) ----------------------------------------------------- */
.alert.success { background: var(--good-bg); color: var(--good); }
.alert.info { background: var(--info-bg); color: var(--info); }

/* ---- Role + status pills ------------------------------------------------ */
.badge.admin { background: var(--primary-050); color: var(--primary-600); }
.badge.tech { background: var(--info-bg); color: var(--info); }
.badge.off { background: #eef1f5; color: var(--text-muted); }

/* ---- Credential reveal -------------------------------------------------- */
.mono { font-family: "Consolas", "Courier New", monospace; }
.pw-chip { display: inline-flex; align-items: center; gap: .5rem; background: #0f2b46; color: #eaf3ff; padding: .3rem .7rem; border-radius: 8px; font-family: "Consolas", monospace; font-weight: 700; letter-spacing: .04em; }
.cred-note { font-size: .78rem; color: var(--warn); margin-top: .35rem; }

/* ---- Checkbox list (permissions) --------------------------------------- */
.perm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem .8rem; }
.perm-grid label { display: flex; align-items: center; gap: .45rem; font-size: .82rem; font-weight: 500; color: var(--text); cursor: pointer; }
.perm-grid input { width: auto; }
