:root {
  --bg: #F3F5F4; --card: #FFFFFF; --ink: #17211E; --muted: #55625D; --line: #DFE4E2; --soft: #EEF2F0;
  --brand: #0B6E63; --brand-2: #08564D; --brand-ink: #FFFFFF;
  --ok-bg: #E3F1EC; --ok: #0B5A51; --warn-bg: #FFF2DE; --warn: #6B3A00;
  --bad-bg: #FBE6E2; --bad: #8F2B17; --info-bg: #E9ECF7; --info: #2F3A73;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1513; --card: #18211E; --ink: #E6EEEB; --muted: #A3B1AC; --line: #2B3733; --soft: #1F2A27;
    --brand: #3FA597; --brand-2: #57B8AA; --brand-ink: #0B1513;
    --ok-bg: #173A34; --ok: #9FDCCF; --warn-bg: #3D2A10; --warn: #F3C98B;
    --bad-bg: #3F1E18; --bad: #F2B2A5; --info-bg: #222A45; --info: #BAC3EE;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: "IBM Plex Sans Arabic", system-ui, "Segoe UI", Tahoma, sans-serif; font-size: 16px; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.3; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 16px; }
a { color: var(--brand); }

.top { position: sticky; top: 0; z-index: 20; display: flex; gap: 10px; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--brand); color: var(--brand-ink); }
.brand { font-size: 20px; font-weight: 700; flex: 1; }
.tag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: rgba(255,255,255,.22); vertical-align: middle; }
.top-end { display: flex; gap: 8px; align-items: center; }
.net { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: rgba(255,255,255,.18); }
.net.off { background: #FFE0B2; color: #5A3300; }
.who { border: 0; background: rgba(255,255,255,.18); color: inherit; border-radius: 999px; padding: 4px 12px; font-size: 14px; cursor: pointer; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { border: 0; background: transparent; color: inherit; font-size: 22px; cursor: pointer; padding: 0 4px; }

.layout { display: flex; min-height: calc(100vh - 56px); }
main { flex: 1; min-width: 0; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; width: 100%; outline: none; }
body.desk main { max-width: 1180px; padding-bottom: 32px; }

/* شريط سفلي للجوال (المراقب) */
.tabs { position: fixed; bottom: 0; inset-inline: 0; z-index: 20; display: grid; grid-template-columns: repeat(var(--n, 4), 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 10px; font-size: 12px; color: var(--muted); text-decoration: none; position: relative; }
.tabs a .ico { font-size: 20px; line-height: 1; }
.tabs a.on { color: var(--brand); font-weight: 700; }
.tabs a .dot { position: absolute; top: 4px; inset-inline-start: calc(50% + 6px); min-width: 18px; height: 18px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; display: grid; place-items: center; padding: 0 4px; }

/* قائمة جانبية للكمبيوتر (رئيس القسم) */
.side { width: 240px; flex: none; background: var(--card); border-inline-end: 1px solid var(--line); padding: 12px 8px; position: sticky; top: 56px; height: calc(100vh - 56px); overflow: auto; }
.side a { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; color: var(--ink); text-decoration: none; margin-bottom: 2px; }
.side a:hover { background: var(--soft); }
.side a.on { background: var(--ok-bg); color: var(--ok); font-weight: 700; }
.side .count { background: var(--bad); color: #fff; border-radius: 999px; font-size: 12px; padding: 0 8px; }
.side .sep { border-top: 1px solid var(--line); margin: 10px 4px; }
@media (max-width: 860px) {
  .side { position: fixed; top: 56px; bottom: 0; inset-inline-start: 0; z-index: 30; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .side:not(.open) { display: none; }
  body.desk #menuBtn { display: inline-block !important; }
}
@media (min-width: 861px) { #menuBtn { display: none !important; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card.tight { padding: 12px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 8px; }
.grid { display: grid; gap: 12px; }
.grid.kpi { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.kpi-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-decoration: none; color: inherit; display: block; box-shadow: var(--shadow); }
.kpi-card .n { font-size: 30px; font-weight: 700; line-height: 1.1; }
.kpi-card.bad .n { color: var(--bad); } .kpi-card.warn .n { color: var(--warn); } .kpi-card.ok .n { color: var(--ok); }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: 8px; text-decoration: none; }

label { display: block; font-weight: 600; margin: 10px 0 4px; font-size: 14px; }
input[type=text], input[type=search], input[type=number], input[type=date], input[type=password], input[type=tel], input[type=email], input:not([type]), select, textarea {
  width: 100%; color: inherit; font: inherit; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); min-height: 46px; }
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 1px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink);
  border-radius: 10px; padding: 10px 16px; min-height: 46px; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn.secondary { background: transparent; color: var(--brand); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.actions-bar { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); background: var(--bg); padding: 10px 0; display: flex; gap: 8px; z-index: 5; }
.actions-bar .btn { flex: 1; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--ok-bg); color: var(--ok); } .b-warn { background: var(--warn-bg); color: var(--warn); }
.b-bad { background: var(--bad-bg); color: var(--bad); } .b-info { background: var(--info-bg); color: var(--info); }
.b-muted { background: var(--soft); color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; }
.item { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 8px; color: inherit; text-decoration: none; }
a.item:hover { border-color: var(--brand); }
.item .t { font-weight: 700; }
.item .m { color: var(--muted); font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

.seg { display: grid; grid-template-columns: repeat(var(--n, 2), 1fr); gap: 6px; }
.seg button { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 6px; min-height: 46px; cursor: pointer; font-weight: 600; }
.seg button.on { border-color: var(--brand); background: var(--ok-bg); color: var(--ok); }
.seg button.on.bad { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }

.cat { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; background: var(--card); overflow: hidden; }
.cat-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px; }
.cat-head .name { font-weight: 700; }
.cat-body { border-top: 1px solid var(--line); padding: 12px; background: var(--soft); }
.type { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.type > .chk { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-weight: 600; margin: 0; }
.type input[type=checkbox] { width: 22px; height: 22px; margin-top: 2px; flex: none; accent-color: var(--brand); }
.type .detail { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }
.reg { font-size: 13px; color: var(--muted); }

.thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.thumbs img, .thumbs .ph { width: 76px; height: 76px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--soft); }
.thumbs.big img { width: 140px; height: 140px; cursor: zoom-in; }
.thumb-wrap { position: relative; }
.thumb-wrap button { position: absolute; top: 2px; inset-inline-end: 2px; border: 0; border-radius: 50%; width: 24px; height: 24px; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; line-height: 1; }

.steps { display: flex; gap: 4px; margin-bottom: 12px; }
.steps span { flex: 1; height: 5px; border-radius: 3px; background: var(--line); }
.steps span.on { background: var(--brand); }

table.tbl { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; font-size: 14px; }
.tbl th, .tbl td { text-align: start; padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { background: var(--soft); font-weight: 700; color: var(--muted); font-size: 13px; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: var(--soft); }
.tbl-wrap { overflow-x: auto; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters > * { flex: 1 1 160px; }

.note { padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 12px; }
.note.warn { background: var(--warn-bg); color: var(--warn); }
.note.info { background: var(--info-bg); color: var(--info); }
.note.bad { background: var(--bad-bg); color: var(--bad); }
.note.ok { background: var(--ok-bg); color: var(--ok); }

.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: grid; place-items: end center; }
@media (min-width: 700px) { .modal { place-items: center; } }
.modal-card { background: var(--card); width: min(560px, 100%); max-height: 90vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 16px 16px calc(84px + env(safe-area-inset-bottom)); }
/* مسافة سفلية حتى لا تغطي شارة الاستضافة العائمة أزرار النافذة على الجوال */
@media (min-width: 700px) { .modal-card { padding-bottom: 16px; } }
@media (min-width: 700px) { .modal-card { border-radius: 16px; } }
.modal-card.img { width: min(960px, 100%); padding: 8px; } .modal-card.img img { width: 100%; height: auto; display: block; border-radius: 10px; }

.toast { position: fixed; bottom: calc(80px + env(safe-area-inset-bottom)); inset-inline: 16px; margin: auto; max-width: 520px; z-index: 60; background: #17211E; color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.login-users { display: grid; gap: 8px; }
.login-users button { text-align: start; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 14px; cursor: pointer; }
.login-users button:hover { border-color: var(--brand); }
.login-users .r { font-size: 13px; color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.spin { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: s 0.8s linear infinite; vertical-align: middle; }
@keyframes s { to { transform: rotate(360deg); } }
hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }

/* شاشة النطاقات: قائمة بجانب الخريطة على الكمبيوتر، وفوقها على الجوال */
.areas-grid { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 12px; align-items: start; }
@media (max-width: 960px) { .areas-grid { grid-template-columns: 1fr; } .areas-grid > :last-child { order: -1; } }
/* الخريطة في طبقة مستقلة: طبقات Leaflet الداخلية (حتى 1000) لا تعلو القائمة الجانبية ولا النوافذ */
.leaflet-container { position: relative; z-index: 0; isolation: isolate; }
