:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --ink: #17202b;
  --ink-2: #4a5666;
  --muted: #7b8796;
  --line: #e3e7ed;
  --line-2: #eef1f5;
  --brand: #0f4c81;
  --brand-2: #e8f0f8;
  --up: #16a34a;
  --up-bg: #e9f8ef;
  --down: #dc2626;
  --down-bg: #fdecec;
  --aff: #d97706;
  --aff-bg: #fdf3e2;
  --unk: #94a3b8;
  --unk-bg: #f1f4f8;
  --off: #64748b;
  --off-bg: #eceff3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .04);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.6;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 2px; font-weight: 700; }
h2 { font-size: 1.08rem; margin: 0 0 10px; font-weight: 600; }
h3 { font-size: 1rem; margin: 0; font-weight: 600; }
h3.sub { margin: 18px 0 8px; font-size: .95rem; }
code { font-family: var(--mono); background: var(--line-2); padding: 1px 6px; border-radius: 5px; font-size: .86em; direction: ltr; unicode-bidi: embed; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono { font-family: var(--mono); font-size: .88em; }
.strong { font-weight: 600; color: var(--ink); }
.c-ok { color: var(--up); } .c-bad { color: var(--down); } .c-warn { color: var(--aff); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px;
  background: #0b2540; color: #fff; padding: 0 20px; height: 56px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; white-space: nowrap; }
.brand.big { color: var(--ink); font-size: 1.15rem; justify-content: center; margin-bottom: 18px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; position: relative;
  background: linear-gradient(135deg, #22c55e, #0ea5e9);
}
.brand-mark::after { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: #fff; }
.nav { display: flex; gap: 2px; flex: 1; }
.nav a { color: #c7d4e2; padding: 6px 12px; border-radius: 7px; font-size: .92rem; white-space: nowrap; }
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.14); color: #fff; }
.nav .logout { margin-inline-start: auto; }
.nav-toggle { display: none; background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; margin-inline-start: auto; }

.wrap { max-width: 1400px; margin: 0 auto; padding: 22px 20px 40px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 0 0 24px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 0; }
.tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- controls ---------- */
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid #d5dbe3; border-radius: 8px;
  padding: 8px 11px; width: 100%; min-height: 38px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc3e6; outline-offset: 0; border-color: #7aaedb; }
input[type=checkbox] { width: 16px; height: 16px; min-height: 0; accent-color: var(--brand); }
textarea.code { font-family: var(--mono); font-size: .8rem; background: #0f1b2a; color: #d5e3f2; border-color: #0f1b2a; line-height: 1.5; }
.tools input[type=search] { width: 260px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: .9rem; font-weight: 500;
  padding: 7px 14px; border-radius: 8px; border: 1px solid #d5dbe3; background: #fff; color: var(--ink);
  cursor: pointer; white-space: nowrap; min-height: 38px; text-decoration: none !important;
}
.btn:hover { background: #f6f8fb; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #0c3f6b; }
.btn.danger { background: var(--down); border-color: var(--down); color: #fff; }
.btn.danger-outline { color: var(--down); border-color: #f2b8b8; }
.btn.small { padding: 4px 10px; min-height: 32px; font-size: .84rem; }
.btn.tiny { padding: 2px 8px; min-height: 26px; font-size: .78rem; }
.btn.block { width: 100%; margin-top: 8px; }
.switch { display: inline-flex; align-items: center; gap: 7px; font-size: .9rem; cursor: pointer; white-space: nowrap; }

.alert { padding: 11px 14px; border-radius: 9px; margin-bottom: 14px; border: 1px solid; font-size: .92rem; }
.alert ul { margin: 6px 0 0; padding-inline-start: 20px; }
.alert-ok { background: var(--up-bg); border-color: #b8e6c8; color: #14532d; }
.alert-err { background: var(--down-bg); border-color: #f5c2c2; color: #7f1d1d; }
.alert-warn { background: var(--aff-bg); border-color: #f3d39f; color: #7c4a03; }

/* ---------- panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }
.table-panel { padding: 0; overflow: hidden; }
.table-panel .panel-head { padding: 14px 18px 0; }
.empty { padding: 18px; text-align: center; color: var(--muted); }
.empty.ok { color: var(--up); font-weight: 500; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); border-top: 3px solid var(--line); }
.kpi-v { font-size: 1.75rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-v small { font-size: .95rem; color: var(--muted); font-weight: 500; }
.kpi-l { color: var(--ink-2); font-size: .86rem; }
.k-ok { border-top-color: var(--up); } .k-bad { border-top-color: var(--down); } .k-bad .kpi-v { color: var(--down); }
.k-warn { border-top-color: var(--aff); } .k-warn .kpi-v { color: var(--aff); } .k-muted { border-top-color: var(--unk); }

/* ---------- outages list ---------- */
.outage-list { display: flex; flex-direction: column; gap: 8px; }
.outage {
  display: flex; align-items: center; gap: 14px; padding: 10px 14px; border-radius: 9px;
  background: var(--down-bg); border: 1px solid #f6caca; color: var(--ink); text-decoration: none !important;
}
.outage.site { background: var(--off-bg); border-color: #d6dce4; }
.outage:hover { filter: brightness(.985); }
.o-main { flex: 1; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.o-main .muted { width: 100%; font-size: .84rem; }
.o-aff { background: var(--aff); color: #fff; font-size: .78rem; padding: 2px 9px; border-radius: 99px; font-weight: 600; }
.o-dur { font-weight: 600; color: var(--down); white-space: nowrap; font-variant-numeric: tabular-nums; }
.outage.site .o-dur { color: var(--off); }
.ip { font-family: var(--mono); font-size: .8em; color: var(--muted); direction: ltr; unicode-bidi: embed; }

/* ---------- legend ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: .82rem; color: var(--ink-2); margin: 4px 2px 14px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 10px; height: 10px; }

/* ---------- status colors ---------- */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--unk); flex: none; }
.st-up .dot, .dot.st-up { background: var(--up); }
.st-down .dot, .dot.st-down { background: var(--down); box-shadow: 0 0 0 3px rgba(220, 38, 38, .18); }
.st-affected .dot, .dot.st-affected { background: var(--aff); }
.st-unknown .dot, .dot.st-unknown { background: var(--unk); }
.st-offline .dot, .dot.st-offline { background: var(--off); }
.st-disabled .dot, .dot.st-disabled { background: transparent; border: 2px solid #b6c0cc; }
.dot.weak, .node.weak .dot { background: var(--up); box-shadow: 0 0 0 3px #fcd34d; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 500; padding: 2px 10px; border-radius: 99px; white-space: nowrap; }
.badge i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.st-up { background: var(--up-bg); color: #15803d; }
.badge.st-down { background: var(--down-bg); color: #b91c1c; }
.badge.st-affected { background: var(--aff-bg); color: #b45309; }
.badge.st-unknown { background: var(--unk-bg); color: #64748b; }
.badge.st-offline { background: var(--off-bg); color: #475569; }
.badge.st-disabled { background: #fff; color: #94a3b8; border: 1px dashed #cbd5e1; }

/* ---------- site cards (dashboard) ---------- */
.site { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden; }
.site.offline { border-color: #cfd6df; }
.site.offline .site-head { background: repeating-linear-gradient(-45deg, #f6f7f9, #f6f7f9 10px, #eff1f4 10px, #eff1f4 20px); }
.site-head { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.site-toggle { background: none; border: 0; cursor: pointer; padding: 4px; display: flex; }
.site-title { display: flex; align-items: baseline; gap: 10px; flex: 1; min-width: 160px; }
.site-title h2 { margin: 0; font-size: 1.1rem; }
.site-state { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.site-counts { display: flex; gap: 6px; }
.cnt { min-width: 34px; text-align: center; font-size: .82rem; font-weight: 600; padding: 2px 8px; border-radius: 6px; font-variant-numeric: tabular-nums; }
.cnt.up { background: var(--up-bg); color: #15803d; } .cnt.down { background: var(--down-bg); color: #b91c1c; }
.cnt.affected { background: var(--aff-bg); color: #b45309; } .cnt.unknown { background: var(--unk-bg); color: #64748b; }
.site-body { padding: 6px 16px 14px; }
.site.collapsed .site-body { display: none; }
.site.collapsed .site-head { border-bottom: 0; }
.caret { width: 9px; height: 9px; border-inline-end: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s; margin: 0 4px; }
.collapsed > .site-head .caret, .port.collapsed .port-head .caret { transform: rotate(135deg); }
[dir=rtl] .collapsed > .site-head .caret, [dir=rtl] .port.collapsed .port-head .caret { transform: rotate(-45deg); }

.port { border-bottom: 1px dashed var(--line); padding: 8px 0; }
.port:last-child { border-bottom: 0; }
.port-head { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: 0; font: inherit; cursor: pointer; padding: 4px 0; text-align: start; color: var(--ink); }
.port-head .caret { margin-inline-start: auto; }
.port-name { font-family: var(--mono); font-weight: 600; font-size: .9rem; background: var(--brand-2); color: var(--brand); padding: 1px 9px; border-radius: 6px; direction: ltr; }
.chip { font-size: .75rem; padding: 1px 8px; border-radius: 99px; font-weight: 500; }
.chip.ok { background: var(--up-bg); color: #15803d; } .chip.bad { background: var(--down-bg); color: #b91c1c; }
.port-body { padding: 4px 0 2px; }
.port.collapsed .port-body { display: none; }

/* ---------- chains ---------- */
.chain { margin: 6px 0; }
.links { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 0; }
.wrap-links { gap: 8px; }
.arrow { width: 18px; height: 2px; background: #c3ccd7; position: relative; flex: none; }
.arrow::after { content: ""; position: absolute; inset-inline-end: -1px; top: -3px; border: 4px solid transparent; border-inline-start: 6px solid #c3ccd7; border-inline-end: 0; }
.node {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 8px; font-size: .84rem;
  background: var(--up-bg); border: 1px solid #c7ebd4; color: var(--ink); white-space: nowrap; text-decoration: none !important;
  transition: transform .08s, box-shadow .08s;
}
.node:hover { box-shadow: 0 2px 6px rgba(15, 23, 42, .12); transform: translateY(-1px); }
.node .nm { font-weight: 500; }
.node .ip { font-size: .72rem; }
.node .meta { font-size: .72rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.node.st-down { background: var(--down); border-color: var(--down); color: #fff; }
.node.st-down .ip, .node.st-down .meta { color: #ffe1e1; }
.node.st-down .dot { background: #fff; box-shadow: none; }
.node.st-affected { background: var(--aff-bg); border-color: #f2d29e; }
.node.st-unknown { background: var(--unk-bg); border-color: #dbe2ea; }
.node.st-offline { background: var(--off-bg); border-color: #d3d9e1; color: var(--ink-2); }
.node.st-disabled { background: #fff; border: 1px dashed #cbd5e1; color: var(--muted); }
.node.weak { background: #fffbeb; border-color: #fcd34d; }
.node.hit { outline: 2px solid var(--brand); outline-offset: 1px; }
.branches { margin-inline-start: 22px; padding-inline-start: 12px; border-inline-start: 2px solid var(--line); }
.branch { position: relative; padding-top: 4px; }
.branch-from { display: block; font-size: .72rem; color: var(--muted); }

/* ---------- forms ---------- */
.form label { display: block; margin-bottom: 12px; font-size: .9rem; font-weight: 500; color: var(--ink-2); }
.form label input, .form label select, .form label textarea { margin-top: 4px; }
.form label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--ink); }
.form label .muted.small { font-weight: 400; display: block; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
fieldset { border: 1px solid var(--line); border-radius: 9px; margin: 0 0 14px; padding: 10px 14px 4px; }
legend { font-weight: 600; padding: 0 6px; }
.danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 14px; border-color: #f4c7c7; }
.danger-zone p { margin: 0; }

/* ---------- tables ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.filters select, .filters input[type=search] { width: auto; min-width: 170px; }
.filters input[type=search] { min-width: 240px; }
.bulk { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafbfc; }
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tbl th { text-align: start; font-weight: 600; color: var(--ink-2); background: #f8fafc; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; font-size: .82rem; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tbody tr:hover { background: #fafcff; }
.tbl td.actions { white-space: nowrap; text-align: end; }
.cols-help td, .cols-help th { font-size: .82rem; }

/* ---------- cards (sites) ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card p { margin: 2px 0 8px; }
.card-actions { display: flex; gap: 6px; margin-top: auto; padding-top: 12px; flex-wrap: wrap; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px 14px; margin: 6px 0; }
.facts div { min-width: 0; }
.facts dt { font-size: .76rem; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; font-size: .92rem; overflow-wrap: anywhere; }
.facts dd.mono { white-space: nowrap; overflow-wrap: normal; font-size: .82rem; }

/* ---------- script steps ---------- */
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; margin-bottom: 16px; }
.step { display: flex; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-size: .9rem; }
.step b { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: .85rem; }
.notes { padding-inline-start: 20px; margin: 0 0 14px; font-size: .9rem; }
.notes li { margin-bottom: 6px; }

/* ---------- router detail ---------- */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: .82rem; color: var(--muted); margin-bottom: 4px; }
.crumbs > * + *::before { content: "‹"; margin-inline-end: 6px; color: #b4bfcc; }
.crumbs .st-down { color: var(--down); font-weight: 600; }
.crumbs .st-affected { color: var(--aff); }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 16px; align-items: start; }
.detail-grid > .panel { margin-bottom: 0; }
.detail-grid + * { margin-top: 16px; }
.status-card { border-top: 4px solid var(--unk); }
.status-card.st-up { border-top-color: var(--up); } .status-card.st-down { border-top-color: var(--down); }
.status-card.st-affected { border-top-color: var(--aff); } .status-card.st-offline { border-top-color: var(--off); }
.big-status { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.big-status .dot { width: 16px; height: 16px; }
.bs-label { font-size: 1.3rem; font-weight: 700; line-height: 1.2; }
.hint { background: var(--aff-bg); color: #7c4a03; padding: 8px 12px; border-radius: 8px; font-size: .86rem; margin: 0 0 10px; }
.hint.bad { background: var(--down-bg); color: #7f1d1d; }
.notes-box { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font-size: .88rem; margin: 10px 0 0; }
.avail { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 8px; }
.av { background: #f8fafc; border-radius: 9px; padding: 10px 12px; }
.av-v { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.av-l { font-size: .82rem; color: var(--ink-2); }
.hours { display: grid; grid-template-columns: repeat(48, 1fr); gap: 2px; height: 34px; direction: ltr; }
.hr { border-radius: 2px; background: #e5e9ef; }
.hr.ok { background: var(--up); } .hr.warn { background: #f59e0b; } .hr.bad { background: var(--down); }
.hours-axis { display: flex; justify-content: space-between; direction: ltr; margin-top: 4px; }

/* ---------- auth ---------- */
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.auth-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: 100%; max-width: 380px; box-shadow: 0 10px 30px rgba(15, 23, 42, .08); }
.auth-card.wide { max-width: 620px; }
.auth-card h1 { text-align: center; margin-bottom: 4px; }
.auth-card > p { text-align: center; margin-top: 0; }
.auth-card label { display: block; margin-bottom: 12px; font-size: .9rem; font-weight: 500; color: var(--ink-2); }
.auth-card label input, .auth-card label select { margin-top: 4px; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
  .detail-grid > .panel { margin-bottom: 0; }
}
@media (max-width: 760px) {
  .wrap { padding: 16px 16px 30px; }
  .topbar { padding: 0 16px; }
  .nav-toggle { display: block; }
  .nav { display: none; position: absolute; top: 56px; inset-inline: 0; flex-direction: column; background: #0b2540; padding: 8px 12px 14px; }
  .nav-open .nav { display: flex; }
  .nav .logout { margin: 0; }
  .grid2 { grid-template-columns: 1fr; }
  .tools input[type=search], .filters input[type=search], .filters select { width: 100%; min-width: 0; }
  .tools { width: 100%; }
  .site-counts { width: 100%; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .avail { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
  .av-v { font-size: 1.1rem; }
  .danger-zone { flex-direction: column; align-items: stretch; }
}

/* ---------- SPA additions ---------- */
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--unk); }
.live.on i { background: var(--up); box-shadow: 0 0 0 3px rgba(22, 163, 74, .2); animation: pulse 2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(22, 163, 74, 0); } }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.topbar[hidden] { display: none; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; }
#toast .alert { box-shadow: 0 8px 24px rgba(15, 23, 42, .15); margin: 0; min-width: 260px; text-align: center; }
