:root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --ink: #1c2530;
    --muted: #6b7785;
    --line: #dfe4ea;
    --brand: #1772b9;
    --brand-dark: #125a92;
    --ok: #1f7a4d;
    --err: #b3271e;
    --warn: #8a5a00;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.6 system-ui, -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
}

h1, h2, h3 { margin: 0 0 14px; font-weight: 700; }
h2 { font-size: 18px; }
h3 { font-size: 15px; margin-top: 4px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
a { color: var(--brand); }

/* ---------- تسجيل الدخول ---------- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}
.login-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 36px 32px 32px;
    width: 100%;
    max-width: 390px;
    box-shadow: 0 2px 14px rgba(20, 40, 70, .06);
}
.login-card h1 {
    font-size: 18px;
    text-align: center;
    margin-bottom: 26px;
    color: var(--muted);
    font-weight: 600;
}
.login-card form {
    display: flex;
    flex-direction: column;
    align-items: stretch;
}
.login-card label {
    margin: 0 0 6px;
    line-height: 1.4;
}
.login-card input {
    margin: 0 0 18px;
    padding: 11px 12px;
    line-height: 1.4;
    height: auto;
}
.login-card input:last-of-type { margin-bottom: 0; }
.login-card button {
    display: block;
    width: 100%;
    margin: 26px 0 0;
    padding: 12px;
    line-height: 1.4;
}
.login-card .msg { margin-bottom: 20px; }
.code-input { letter-spacing: 8px; text-align: center; font-size: 20px; }
.login-card .hint { text-align: center; }

/* ---------- الشعار ---------- */
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { height: 28px; width: auto; display: block; }
.login-logo {
    display: block;
    max-height: 62px;
    max-width: 230px;
    width: auto;
    height: auto;
    margin: 0 auto 24px;
}

/* ---------- الهيكل ---------- */
.topbar {
    background: var(--brand);
    color: #fff;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}
.topbar a { color: #fff; margin-inline-start: 16px; text-decoration: none; }
.topbar a:hover { text-decoration: underline; }
.topbar .muted { color: #cfe3f4; }
.sep { opacity: .5; margin: 0 6px; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 20px; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

/* ---------- الإحصاءات ---------- */
.stats { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.stat {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 22px;
    min-width: 150px;
}
.stat .num { display: block; font-size: 24px; font-weight: 700; line-height: 1.3; }
.stat .num .of { font-size: 15px; font-weight: 600; color: var(--muted); }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat.wide { flex: 1; min-width: 260px; }
.stat.wide .num { font-size: 19px; }
.stat .bar {
    display: block;
    height: 6px;
    background: var(--line);
    border-radius: 999px;
    margin-top: 10px;
    overflow: hidden;
}
.stat .bar i { display: block; height: 100%; background: var(--brand); }

/* ---------- النماذج ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
input, select {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 7px;
    font: inherit;
    background: #fff;
    color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }

button {
    background: var(--brand);
    color: #fff;
    border: 0;
    border-radius: 7px;
    padding: 10px 18px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
button:hover { background: var(--brand-dark); }
.btn-sub { background: #5a6674; }
.btn-sub:hover { background: #47515d; }
.danger button { background: var(--err); }
.danger button:hover { background: #8f1f18; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.grid .full { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.inline input { width: auto; min-width: 190px; flex: 1; }

/* ---------- الجداول ---------- */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 13px; color: var(--muted); font-weight: 600; }
tr.off { opacity: .55; }
tr.row-alert td { background: #fff6f5; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.warn-text { color: var(--warn); font-weight: 700; }
.break { word-break: break-all; }

.pill { font-size: 12px; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.pill.on { background: #e3f4ea; color: var(--ok); }
.pill.off { background: #f0f1f3; color: var(--muted); }

/* ---------- القوائم المنسدلة ----------
   تطفو فوق المحتوى، والجدول ما يقصّها لأن التمرير ينلغي عند الفتح */
.actions { position: relative; }
.actions summary {
    cursor: pointer;
    color: var(--brand);
    font-size: 13px;
    font-weight: 600;
    list-style: none;
    user-select: none;
    white-space: nowrap;
}
.actions summary::-webkit-details-marker { display: none; }
.actions summary::after { content: " ▾"; font-size: 10px; }
.actions details[open] summary::after { content: " ▴"; }

.popover {
    position: absolute;
    inset-inline-end: 0;
    top: 100%;
    z-index: 50;
    margin-top: 6px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
    width: 210px;
    box-shadow: 0 6px 20px rgba(20, 40, 70, .14);
    font-size: 12.5px;
    text-align: start;
}
.popover form {
    display: flex;
    align-items: center;
    gap: 4px;
    padding-bottom: 6px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--line);
}
.popover form:last-child { padding-bottom: 0; margin-bottom: 0; border-bottom: 0; }
.popover input {
    flex: 1;
    min-width: 0;
    width: auto;
    margin: 0;
    padding: 4px 7px;
    font-size: 12px;
    border-radius: 5px;
}
.popover button {
    flex: 0 0 auto;
    width: auto;
    margin: 0;
    padding: 5px 9px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    border-radius: 5px;
    background: #eef2f6;
    color: var(--ink);
    border: 1px solid var(--line);
}
.popover form:not(:has(input)) button { width: 100%; }
.popover button:hover { background: #e2e8ee; }
.popover .danger button { background: #fdecea; color: var(--err); border-color: #f2c9c4; }
.popover .danger button:hover { background: #f8d7d3; }

/* عند فتح أي قائمة، نوقف قص الجدول حتى تظهر كاملة */
.table-scroll:has(details[open]) { overflow: visible; }

/* ---------- الرسائل ---------- */
.msg {
    padding: 11px 14px;
    border-radius: 8px;
    margin: 0 0 14px;
    font-size: 14px;
    border: 1px solid transparent;
}
.msg.ok { background: #e8f5ee; color: var(--ok); border-color: #bfe3ce; }
.msg.err { background: #fdeceb; color: var(--err); border-color: #f5c6c2; }
.msg.warn { background: #fdf5e3; color: var(--warn); border-color: #eedcae; }
.msg.info { background: #eaf3fb; color: var(--brand-dark); border-color: #c6dff2; }
.msg.pw {
    background: #fff9e0;
    color: #6b5400;
    border-color: #ead9a0;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    word-break: break-all;
}
.secret { font-size: 17px; letter-spacing: 2px; background: #f0f2f4; padding: 10px; border-radius: 7px; }
.hint { font-size: 13px; margin-top: 14px; }
