:root {
  --paper: #EEF2F0;
  --surface: #FFFFFF;
  --ink: #1B2A31;
  --ink-soft: #52646C;
  --line: #CFD9D6;
  --teal: #0E6B63;
  --teal-soft: #DDEDEA;
  --amber: #C98A0B;
  --amber-soft: #FBF1DC;
  --red: #B93A26;
  --red-soft: #F8E2DD;
  --led-off: #A9B6B3;
  --radius: 6px;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.7 "IBM Plex Sans Arabic", system-ui, sans-serif;
}
a { color: var(--teal); }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 .75rem; }
.muted { color: var(--ink-soft); }
.mono, code { font-family: var(--mono); font-size: .9em; direction: ltr; unicode-bidi: isolate; }
code { background: var(--teal-soft); padding: .05rem .35rem; border-radius: 4px; }

/* ---------- top bar ---------- */
.topbar { background: var(--ink); color: #fff; }
.topbar .wrap { display: flex; align-items: center; gap: 1.5rem; min-height: 56px; flex-wrap: wrap; }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: .5rem; }
.brand svg { width: 22px; height: 22px; }
.nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.nav a { color: #C6D3D0; text-decoration: none; padding: .35rem .7rem; border-radius: var(--radius); }
.nav a:hover { color: #fff; }
.nav a.active { color: #fff; background: rgba(255, 255, 255, .1); }
.who { display: flex; align-items: center; gap: .75rem; font-size: .9rem; color: #C6D3D0; }
.who form { margin: 0; }
.who button { background: none; border: 0; color: #C6D3D0; cursor: pointer; font: inherit; text-decoration: underline; }
.acting { background: var(--amber); color: var(--ink); font-size: .9rem; }
.acting .wrap { display: flex; justify-content: space-between; align-items: center; padding-block: .4rem; }
.acting button { background: var(--ink); color: #fff; border: 0; border-radius: var(--radius); padding: .2rem .7rem; font: inherit; cursor: pointer; }

.wrap { max-width: 1120px; margin: 0 auto; padding-inline: 16px; }
main.wrap { padding-block: 1.75rem 3rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head p { margin: 0; }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.panel > h2:first-child { margin-bottom: .9rem; }
.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid > .panel { margin-bottom: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 1.25rem; }
.stat { padding: 1rem 1.25rem; border-inline-start: 1px solid var(--line); }
.stat:first-child { border-inline-start: 0; }
.stat b { display: block; font-size: 1.5rem; font-weight: 600; }
.stat span { color: var(--ink-soft); font-size: .9rem; }

/* ---------- patch panel (the network map) ---------- */
.patch { background: var(--ink); color: #fff; border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.patch-head { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.patch-head h1 { margin: 0; }
.patch-head .mono { color: #9FC9C3; }
.rail { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.port {
  flex: 0 0 132px; background: #24363E; border: 1px solid #34505A; border-radius: 4px;
  padding: .65rem .7rem; color: #fff; text-decoration: none; display: flex; flex-direction: column; gap: .2rem;
}
.port:hover { border-color: #6FB5AB; }
.port.server { background: var(--teal); border-color: var(--teal); }
.port.disabled { opacity: .45; }
.port .socket { width: 30px; height: 22px; border: 2px solid #6F8A92; border-radius: 3px; position: relative; margin-bottom: .2rem; }
.port .socket::after { content: ""; position: absolute; inset: 5px 7px 0; border: 2px solid #6F8A92; border-bottom: 0; }
.port.server .socket, .port.server .socket::after { border-color: #BFE3DD; }
.port strong { font-size: .88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.port .mono { font-size: .75rem; color: #9FC9C3; }
.port .kind { font-size: .75rem; color: #9DB0B6; }
.port.add { background: transparent; border-style: dashed; justify-content: center; align-items: center; color: #9DB0B6; min-height: 112px; }

.led { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--led-off); vertical-align: middle; }
.led.on { background: #3FD08E; box-shadow: 0 0 6px #3FD08E; }
.port .led { position: absolute; }
.port { position: relative; }
.port > .led { top: .7rem; inset-inline-end: .7rem; }
@media (prefers-reduced-motion: no-preference) {
  .led.on { animation: blink 2.4s ease-in-out infinite; }
  @keyframes blink { 0%, 92%, 100% { opacity: 1; } 95% { opacity: .35; } }
}

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th { text-align: start; font-weight: 600; color: var(--ink-soft); padding: .5rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: end; }
td.actions form { display: inline; }

/* ---------- forms ---------- */
label { display: block; font-weight: 500; margin-bottom: .25rem; }
.field { margin-bottom: .9rem; }
.hint { font-size: .85rem; color: var(--ink-soft); margin-top: .2rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff; color: var(--ink); font: inherit;
}
input.ltr { direction: ltr; text-align: left; font-family: var(--mono); }
input:focus, select:focus, textarea:focus { border-color: var(--teal); outline: 2px solid var(--teal-soft); }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.row { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.inline-form { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { margin: 0; flex: 1; min-width: 140px; }
.error { color: var(--red); font-size: .85rem; margin-top: .2rem; }

.btn {
  display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--teal); background: var(--teal); color: #fff;
  padding: .5rem 1rem; border-radius: var(--radius); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #0B5A53; }
.btn.ghost { background: transparent; color: var(--teal); }
.btn.ghost:hover { background: var(--teal-soft); }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn.danger:hover { background: var(--red-soft); }
.btn.small { padding: .2rem .6rem; font-size: .85rem; }

/* ---------- badges & alerts ---------- */
.badge { display: inline-block; padding: .05rem .55rem; border-radius: 999px; font-size: .8rem; background: var(--teal-soft); color: var(--teal); white-space: nowrap; }
.badge.warn { background: var(--amber-soft); color: #8A5E00; }
.badge.bad { background: var(--red-soft); color: var(--red); }
.badge.off { background: #E3E8E7; color: var(--ink-soft); }
.alert { border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem; border: 1px solid; }
.alert.success { background: var(--teal-soft); border-color: #A9D3CD; }
.alert.warning { background: var(--amber-soft); border-color: #EBCB8B; }
.alert.danger { background: var(--red-soft); border-color: #E6B0A6; }
.alert ul { margin: 0; padding-inline-start: 1.2rem; }

/* ---------- peer page ---------- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: .5rem .9rem; font: inherit; color: var(--ink-soft); cursor: pointer; margin-bottom: -1px; }
.tabs button[aria-selected=true] { color: var(--ink); border-bottom-color: var(--teal); font-weight: 600; }
.tab-panel[hidden] { display: none; }
.steps { padding-inline-start: 1.3rem; margin: 0 0 1rem; }
.steps li { margin-bottom: .6rem; }
.copy { display: flex; gap: .5rem; align-items: flex-start; margin: .4rem 0 .8rem; }
.copy pre { flex: 1; margin: 0; padding: .6rem .8rem; background: var(--ink); color: #D7EAE6; border-radius: var(--radius); font-family: var(--mono); font-size: .8rem; direction: ltr; text-align: left; white-space: pre-wrap; word-break: break-all; }
.qr { background: #fff; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); display: inline-block; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.25rem; margin: 0; }
.kv dt { color: var(--ink-soft); }
.kv dd { margin: 0; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-box { width: 100%; max-width: 420px; }
.auth-box .brand { color: var(--ink); justify-content: center; margin-bottom: 1.25rem; font-size: 1.3rem; }
.auth-box .panel { padding: 1.5rem; }

.empty { color: var(--ink-soft); padding: .5rem 0; }
.pagination { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: 1rem; }
.pagination a, .pagination span { padding: .25rem .6rem; border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; }

@media (max-width: 640px) {
  h1 { font-size: 1.35rem; }
  .stat { border-inline-start: 0; border-top: 1px solid var(--line); }
  .stat:first-child { border-top: 0; }
  .kv { grid-template-columns: 1fr; }
  .kv dt { margin-top: .4rem; }
}

/* ================= v2: icons, pickers, lists ================= */
.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; }
.nav a { display: inline-flex; align-items: center; gap: .4rem; }
.btn .icon { width: 1em; height: 1em; }

/* section header with action on the side */
.section-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .9rem; flex-wrap: wrap; }
.section-head h2 { margin: 0; display: flex; align-items: center; gap: .5rem; }
.count { color: var(--ink-soft); font-weight: 400; font-size: .9rem; }

/* segmented tabs (add panel) */
.seg { display: inline-flex; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 3px; gap: 2px; flex-wrap: wrap; margin-bottom: 1.1rem; }
.seg button { border: 0; background: transparent; padding: .45rem .9rem; border-radius: 4px; font: inherit; color: var(--ink-soft); cursor: pointer; display: inline-flex; align-items: center; gap: .4rem; }
.seg button[aria-selected=true] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--line); }

/* platform picker */
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: .5rem; margin-bottom: 1rem; }
.picker label { margin: 0; cursor: pointer; }
.picker input { position: absolute; opacity: 0; pointer-events: none; }
.picker .opt { display: flex; flex-direction: column; align-items: center; gap: .35rem; padding: .8rem .5rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); font-weight: 500; font-size: .92rem; text-align: center; }
.picker .opt .icon { width: 26px; height: 26px; color: var(--ink-soft); }
.picker input:checked + .opt { border-color: var(--teal); background: var(--teal-soft); box-shadow: inset 0 0 0 1px var(--teal); }
.picker input:checked + .opt .icon { color: var(--teal); }
.picker input:focus-visible + .opt { outline: 2px solid var(--teal); outline-offset: 2px; }

/* rows list (devices, links) */
.rows { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.row-item { display: grid; grid-template-columns: auto 1fr auto; gap: .9rem; align-items: center; padding: .8rem 1rem; border-top: 1px solid var(--line); text-decoration: none; color: inherit; }
.row-item:first-child { border-top: 0; }
a.row-item:hover { background: #F6F9F8; }
.row-item .glyph { width: 40px; height: 40px; border-radius: 8px; background: var(--paper); display: grid; place-items: center; color: var(--ink-soft); position: relative; }
.row-item .glyph .icon { width: 22px; height: 22px; }
.row-item .glyph .led { position: absolute; top: -3px; inset-inline-start: -3px; border: 2px solid var(--surface); width: 12px; height: 12px; }
.row-item .title { font-weight: 600; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.row-item .meta { color: var(--ink-soft); font-size: .88rem; display: flex; gap: .9rem; flex-wrap: wrap; }
.row-item .side { text-align: end; font-size: .88rem; color: var(--ink-soft); white-space: nowrap; }
.row-item .side form { display: inline; }
.empty-box { padding: 1.5rem 1rem; text-align: center; color: var(--ink-soft); }
.empty-box .icon { width: 32px; height: 32px; display: block; margin: 0 auto .5rem; color: var(--led-off); }

/* layout: main + aside */
.split { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1.25rem; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

/* setup steps with platform tabs */
.platform-tabs { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.platform-tabs button { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--line); background: var(--surface); padding: .45rem .8rem; border-radius: 999px; font: inherit; cursor: pointer; color: var(--ink-soft); }
.platform-tabs button[aria-selected=true] { border-color: var(--teal); color: var(--teal); background: var(--teal-soft); font-weight: 600; }
.steps-list { list-style: none; counter-reset: s; padding: 0; margin: 0 0 1rem; }
.steps-list > li { counter-increment: s; position: relative; padding-inline-start: 2.4rem; margin-bottom: 1rem; min-height: 1.8rem; }
.steps-list > li::before { content: counter(s); position: absolute; inset-inline-start: 0; top: 0; width: 1.75rem; height: 1.75rem; border-radius: 50%; background: var(--teal-soft); color: var(--teal); font-weight: 600; display: grid; place-items: center; font-size: .9rem; }
.actions-row { display: flex; gap: .5rem; flex-wrap: wrap; margin: .4rem 0; }
.mode-box { border: 1px dashed var(--line); border-radius: var(--radius); padding: 1rem; margin-top: 1rem; background: #FAFCFB; }
.mode-box h3 { display: flex; align-items: center; gap: .4rem; }

/* domain status */
.dns-help { background: var(--amber-soft); border: 1px solid #EBCB8B; border-radius: var(--radius); padding: .6rem .8rem; font-size: .88rem; margin-top: .4rem; }
.dns-help code { background: #fff; }
.ok-line { color: var(--teal); display: inline-flex; align-items: center; gap: .3rem; }
.bad-line { color: var(--red); display: inline-flex; align-items: center; gap: .3rem; }

/* aside facts */
.facts { list-style: none; margin: 0; padding: 0; }
.facts li { display: flex; justify-content: space-between; gap: 1rem; padding: .5rem 0; border-top: 1px solid var(--line); }
.facts li:first-child { border-top: 0; }
.facts li span:first-child { color: var(--ink-soft); }
.meter { height: 6px; background: var(--paper); border-radius: 3px; overflow: hidden; margin-top: .25rem; }
.meter i { display: block; height: 100%; background: var(--teal); }

@media (max-width: 640px) {
  .row-item { grid-template-columns: auto 1fr; }
  .row-item .side { grid-column: 1 / -1; text-align: start; }
  .seg { display: flex; }
  .seg button { flex: 1; justify-content: center; }
}

/* auth split */
.auth { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding: 0; gap: 0; place-items: stretch; }
.auth-side { background: var(--ink); color: #fff; padding: 2.5rem; display: flex; flex-direction: column; justify-content: space-between; gap: 2rem; }
.auth-side .brand { color: #fff; font-size: 1.2rem; justify-content: flex-start; margin: 0; }
.auth-pitch { font-size: 1.6rem; font-weight: 600; line-height: 1.4; max-width: 22ch; margin-bottom: 1.25rem; }
.auth-foot { color: #9DB0B6; font-size: .92rem; max-width: 40ch; margin: 0; }
.rail.mini .port { flex-basis: 96px; min-height: 0; }
.auth > .auth-box { align-self: center; justify-self: center; padding: 2rem 16px; }
@media (min-width: 901px) { .auth-brand-mobile { display: none !important; } }
@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; place-items: center; padding: 16px; }
  .auth-side { display: none; }
}

/* ================= v3: mobile fixes ================= */
@media (max-width: 760px) {
  .topbar .wrap { gap: .25rem 1rem; padding-block: .5rem 0; }
  .who { margin-inline-start: auto; }
  /* القائمة سطر واحد بيتسحب بالعرض بدل ما تتكسر على كذا سطر */
  .nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-inline: -16px; padding: .25rem 16px .5rem; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { white-space: nowrap; flex: none; }
}
@media (max-width: 640px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); overflow: hidden; }
  .stats .stat { border: 0; background: var(--surface); }
  .stats .stat:last-child:nth-child(odd) { grid-column: 1 / -1; }
}

/* ================= v4: monitoring ================= */
.mini-seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.mini-seg label { margin: 0; cursor: pointer; }
.mini-seg input { position: absolute; opacity: 0; pointer-events: none; }
.mini-seg span { display: block; padding: .4rem .85rem; border-inline-start: 1px solid var(--line); background: var(--surface); }
.mini-seg label:first-child span { border-inline-start: 0; }
.mini-seg input:checked + span { background: var(--teal); color: #fff; }
.mini-seg input:focus-visible + span { outline: 2px solid var(--teal); outline-offset: -2px; }
.down-now { border-color: #E6B0A6; background: #FDF6F4; }
.down-now h2 { color: var(--red); display: flex; align-items: center; gap: .4rem; }
.stat.bad b { color: var(--red); }

/* v5: طرق تانية مطوية */
details.mode-box > summary { cursor: pointer; font-weight: 600; color: var(--muted, #667); margin-bottom: .25rem; }
details.mode-box[open] > summary { margin-bottom: .75rem; }
