/* MADIX Guard panel — right-to-left, light and dark. */
@font-face { font-family: "Plex Arabic"; font-weight: 400; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-arabic-400-normal.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+2010-2011, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: "Plex Arabic"; font-weight: 500; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-arabic-500-normal.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+2010-2011, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: "Plex Arabic"; font-weight: 600; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-arabic-600-normal.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+2010-2011, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: "Plex Arabic"; font-weight: 700; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-arabic-700-normal.woff2) format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+2010-2011, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: "Plex Arabic"; font-weight: 400; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-latin-400-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+2212; }
@font-face { font-family: "Plex Arabic"; font-weight: 500; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-latin-500-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+2212; }
@font-face { font-family: "Plex Arabic"; font-weight: 600; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-latin-600-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+2212; }
@font-face { font-family: "Plex Arabic"; font-weight: 700; font-display: swap; src: url(fonts/ibm-plex-sans-arabic-latin-700-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC, U+2122, U+2212; }

:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --border: #e2e7ef;
  --text: #121a2b;
  --muted: #5b6678;
  --primary: #2453d6;
  --primary-hover: #1c45b8;
  --primary-soft: #e9effd;
  --ok: #157a46;
  --ok-soft: #e5f5ec;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 14px rgba(16, 24, 40, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1220;
    --surface: #141c2e;
    --surface-2: #19233a;
    --border: #26324b;
    --text: #e8edf6;
    --muted: #9aa6bb;
    --primary: #5b86ff;
    --primary-hover: #7399ff;
    --primary-soft: rgba(91, 134, 255, .16);
    --ok: #4cc38a;
    --ok-soft: rgba(76, 195, 138, .14);
    --warn: #f0b44c;
    --warn-soft: rgba(240, 180, 76, .14);
    --danger: #ff6b6b;
    --danger-soft: rgba(255, 107, 107, .14);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.65 "Plex Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .6rem; }
h1 { font-size: 1.45rem; font-weight: 700; }
h2 { font-size: 1.1rem; font-weight: 700; }
h3 { font-size: .98rem; font-weight: 600; }
p { margin: 0 0 .7rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Plex Arabic", monospace; font-size: .9em; direction: ltr; unicode-bidi: isolate; }
small, .muted { color: var(--muted); }
[hidden] { display: none !important; }

/* top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar .inner { max-width: 1240px; margin: 0 auto; padding: .7rem 1rem; display: flex; align-items: center; gap: 1rem; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand img { width: 30px; height: 30px; }
.brand span small { display: block; font-size: .72rem; font-weight: 500; color: var(--muted); line-height: 1.1; }
.nav { display: flex; gap: .25rem; margin-inline-start: auto; flex-wrap: wrap; align-items: center; }
.nav a, .nav button { padding: .42rem .8rem; border-radius: 10px; color: var(--muted); font-weight: 500; background: none; border: 0; font: inherit; cursor: pointer; }
.nav a:hover, .nav button:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }

.page { max-width: 1240px; margin: 0 auto; padding: 1.3rem 1rem 3rem; }
.page-head { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.page-head .actions { margin-inline-start: auto; display: flex; gap: .5rem; flex-wrap: wrap; }

/* cards & grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; }
.card + .card { margin-top: 1rem; }
.card-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .8rem; }
.card-head h2 { margin: 0; }
.card-head .end { margin-inline-start: auto; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.device-layout { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(320px, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 980px) { .device-layout, .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* devices list */
.device-card { display: flex; flex-direction: column; gap: .55rem; }
.device-card .name { font-weight: 700; font-size: 1.08rem; color: var(--text); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .25rem .8rem; font-size: .93rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.primary { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

/* buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.3; min-height: 40px; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost-danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.btn.small { padding: .32rem .7rem; min-height: 32px; font-size: .88rem; }
.btn.block { width: 100%; }
.btns { display: flex; gap: .5rem; flex-wrap: wrap; }
.cmd-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .5rem; }
.cmd-grid form { margin: 0; }
.cmd-grid .btn { width: 100%; }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.field { margin-bottom: .85rem; }
.field .hint { font-size: .82rem; color: var(--muted); margin-top: .25rem; }
input[type=text], input[type=password], input[type=number], input[type=tel], textarea, select {
  width: 100%; padding: .55rem .75rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; min-height: 42px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus, .btn:focus-visible { outline: 3px solid var(--primary-soft); border-color: var(--primary); }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.check input { width: 18px; height: 18px; }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; }
.inline-form .field { margin: 0; flex: 1 1 160px; }

/* flash & toast */
.flash { padding: .75rem 1rem; border-radius: 12px; margin-bottom: 1rem; font-weight: 500; border: 1px solid transparent; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--danger-soft); color: var(--danger); }
.toast { position: fixed; inset-inline: 0; bottom: 1.2rem; margin: 0 auto; width: max-content; max-width: calc(100% - 2rem); padding: .75rem 1.1rem; border-radius: 12px; background: #121a2b; color: #fff; box-shadow: var(--shadow); z-index: 50; font-weight: 500; }
.toast.error { background: var(--danger); }

/* map */
.map-wrap { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); }
#map { height: 520px; width: 100%; }
@media (max-width: 640px) { #map { height: 380px; } }
.map-tools { position: absolute; top: .6rem; inset-inline-start: .6rem; z-index: 5; display: flex; gap: .35rem; flex-wrap: wrap; }
.map-tools .btn { box-shadow: var(--shadow); }
.map-tools .btn.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.map-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 1rem; pointer-events: none; }
.live-line { display: flex; gap: .8rem; flex-wrap: wrap; font-size: .9rem; color: var(--muted); margin-top: .6rem; }
.live-line b { color: var(--text); font-weight: 600; }
.maplibregl-popup-content { font-family: inherit; color: #121a2b; direction: rtl; text-align: right; }

/* timeline & tables */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .55rem 0; border-bottom: 1px dashed var(--border); display: flex; gap: .6rem; align-items: baseline; }
.timeline li:last-child { border-bottom: 0; }
.timeline time { color: var(--muted); font-size: .82rem; white-space: nowrap; min-width: 6.5rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); text-align: right; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; background: var(--surface-2); }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .6rem; }
.photos a { display: block; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); }
.photos img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; display: block; }
.photos small { display: block; padding: .3rem .45rem; font-size: .75rem; }

/* pairing */
.pair-box { display: grid; grid-template-columns: auto 1fr; gap: 1.2rem; align-items: center; }
@media (max-width: 640px) { .pair-box { grid-template-columns: 1fr; } }
.qr { background: #fff; padding: 10px; border-radius: 12px; width: 220px; height: 220px; display: grid; place-items: center; border: 1px solid var(--border); }
.qr svg { width: 200px; height: 200px; }
.code-big { font-family: ui-monospace, Menlo, Consolas, "Plex Arabic", monospace; font-size: 2rem; letter-spacing: .25em; font-weight: 700; direction: ltr; unicode-bidi: isolate; color: var(--primary); }
.steps { margin: 0; padding-inline-start: 1.2rem; }
.steps li { margin-bottom: .35rem; }

/* checklist */
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.checklist li { display: flex; gap: .55rem; align-items: center; }
.checklist .mark { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: .78rem; flex: none; }
.checklist .yes { background: var(--ok-soft); color: var(--ok); }
.checklist .no { background: var(--warn-soft); color: var(--warn); }

/* login */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background:
  radial-gradient(1200px 600px at 100% -10%, var(--primary-soft), transparent 60%), var(--bg); }
.auth .card { width: 100%; max-width: 400px; padding: 1.8rem; }
.auth .brand { justify-content: center; margin-bottom: 1.2rem; font-size: 1.25rem; }
.auth .brand img { width: 44px; height: 44px; }

details.danger-zone { border: 1px solid var(--danger-soft); border-radius: var(--radius); padding: .9rem 1.1rem; background: var(--surface); }
details.danger-zone summary { cursor: pointer; font-weight: 700; color: var(--danger); }
section[id] { scroll-margin-top: 80px; }
.footer { text-align: center; color: var(--muted); font-size: .82rem; padding: 1rem; }
