/* NetWatch dashboard — Arabic RTL, light/dark. */
:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface-1: #fcfcfb;
  --card: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #8a8984;
  --border: #e4e3df;
  --grid: #ecebe7;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;  /* latency */
  --series-2: #eb6834;  /* loss / availability */
  --input-bg: #ffffff;
  --hover: #f0efec;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  /* status (reserved; always paired with icon + label) */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --offline: #8a8984;
  --good-bg: #e8f6e8;
  --warning-bg: #fdf3dc;
  --serious-bg: #fcebe3;
  --critical-bg: #fbe7e7;
  --offline-bg: #efefed;
  --radius: 12px;
  --font: system-ui, "Segoe UI", Tahoma, "Noto Sans Arabic", "Geeza Pro", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "DejaVu Sans Mono", monospace;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface-1: #1a1a19;
  --card: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --border: #2e2e2b;
  --grid: #2a2a27;
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --input-bg: #121211;
  --hover: #242422;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  --good-bg: #13280f;
  --warning-bg: #2d2410;
  --serious-bg: #2e1c14;
  --critical-bg: #2e1616;
  --offline-bg: #262624;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font); font-size: 15px; line-height: 1.55;
  background: var(--bg); color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 1.45rem; font-weight: 700; }
h2 { font-size: 1.12rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
code, pre, .mono { font-family: var(--mono); font-size: .86em; direction: ltr; unicode-bidi: isolate; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.container { max-width: 1320px; margin: 0 auto; padding: 22px 20px 60px; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 22px;
  padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 750; font-size: 1.1rem; color: var(--text-primary); }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a { color: var(--text-secondary); padding: 7px 12px; border-radius: 8px; font-weight: 550; }
.nav a:hover { background: var(--hover); text-decoration: none; }
.nav a.active { color: var(--text-primary); background: var(--hover); }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-secondary); font-size: .92rem; margin-top: 2px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.small { font-size: .86rem; }
.mt { margin-top: 18px; }
.mb { margin-bottom: 14px; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.site-card { position: relative; overflow: hidden; cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; padding-top: 18px; }
.site-card:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(0,0,0,.08); }
.site-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.site-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--st, var(--offline)); }
.site-card .name { font-size: 1.1rem; font-weight: 700; }
.site-card .loc { color: var(--text-secondary); font-size: .88rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; margin-top: 12px; font-size: .9rem; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; color: var(--text-primary); overflow-wrap: anywhere; }
.metrics { display: flex; gap: 18px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.metric .v { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.metric .v small { font-size: .7em; font-weight: 500; color: var(--text-secondary); margin-inline-start: 2px; }
.metric .l { color: var(--text-muted); font-size: .8rem; white-space: nowrap; }
.counts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ---------- status badges (icon + label, never color alone) ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 3px 10px 3px 10px; border-radius: 999px; font-size: .82rem; font-weight: 650;
  background: var(--offline-bg); color: var(--text-primary);
}
.badge .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--offline); flex: none; }
.badge .ico { font-size: .8rem; line-height: 1; }
.st-ok       { --st: var(--good); }
.st-warning  { --st: var(--warning); }
.st-serious  { --st: var(--serious); }
.st-critical { --st: var(--critical); }
.st-offline  { --st: var(--offline); }
.badge.st-ok { background: var(--good-bg); } .badge.st-ok .dot { background: var(--good); }
.badge.st-warning { background: var(--warning-bg); } .badge.st-warning .dot { background: var(--warning); }
.badge.st-serious { background: var(--serious-bg); } .badge.st-serious .dot { background: var(--serious); }
.badge.st-critical { background: var(--critical-bg); } .badge.st-critical .dot { background: var(--critical); }
.badge.st-offline .dot { background: var(--offline); }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: .8rem; padding: 2px 9px; border-radius: 999px; background: var(--hover); color: var(--text-secondary); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--st, var(--offline)); }
.pill { display: inline-block; min-width: 20px; padding: 0 6px; margin-inline-start: 4px; border-radius: 999px; background: var(--critical); color: #fff; font-size: .75rem; font-weight: 700; text-align: center; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .92rem;
  padding: 8px 16px; border-radius: 9px; border: 1px solid transparent; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
}
.btn:hover { filter: brightness(1.07); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-ghost { background: transparent; color: var(--text-primary); border-color: var(--border); }
.btn-ghost:hover { background: var(--hover); filter: none; }
.btn-danger { background: var(--critical); color: #fff; }
.btn-sm { padding: 5px 11px; font-size: .84rem; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--text-primary); cursor: pointer; font-size: 1rem; }
.icon-btn:hover { background: var(--hover); text-decoration: none; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg button { font: inherit; font-size: .86rem; padding: 6px 13px; border: 0; background: transparent; color: var(--text-secondary); cursor: pointer; }
.seg button + button { border-inline-start: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: #fff; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: .88rem; color: var(--text-secondary); font-weight: 550; }
label.field .hint { font-weight: 400; color: var(--text-muted); font-size: .8rem; }
input, select, textarea {
  font: inherit; font-size: .94rem; color: var(--text-primary);
  background: var(--input-bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
input[dir="ltr"], .ltr-input { direction: ltr; text-align: left; }
.check { flex-direction: row; align-items: center; gap: 8px; }
.check input { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.error { color: var(--critical); font-size: .9rem; margin-top: 10px; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px 14px; margin: 14px 0 0; }
legend { padding: 0 6px; color: var(--text-secondary); font-size: .88rem; font-weight: 600; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 10px 10px; text-align: start; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--text-muted); font-weight: 600; font-size: .8rem; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--hover); }
td.num { font-variant-numeric: tabular-nums; direction: ltr; text-align: right; white-space: nowrap; }
tr.disabled td { opacity: .55; }

/* ---------- check cards / charts ---------- */
.check-card .card-head { margin-bottom: 6px; }
.check-card .target { color: var(--text-secondary); font-size: .85rem; }
.check-card .value { font-size: .88rem; color: var(--text-secondary); margin-bottom: 10px; }
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.chart-box { direction: ltr; }
.chart-box .chart-title { direction: rtl; font-size: .82rem; color: var(--text-secondary); margin-bottom: 4px; font-weight: 600; }
.chart-box .canvas-wrap { position: relative; height: 170px; }
.chart-empty { display: grid; place-items: center; height: 170px; color: var(--text-muted); font-size: .88rem; direction: rtl; border: 1px dashed var(--border); border-radius: 8px; }
@media (max-width: 760px) { .charts { grid-template-columns: 1fr; } .grid-2 { grid-template-columns: 1fr; } .nav a { padding: 6px 8px; } }

/* ---------- misc ---------- */
.login-wrap { min-height: 80vh; display: grid; place-items: center; }
.login-card { width: min(380px, 92vw); }
.login-card .brand { justify-content: center; margin-bottom: 18px; font-size: 1.35rem; }
pre.code {
  background: var(--hover); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; overflow-x: auto; white-space: pre; text-align: left; margin: 8px 0 0;
}
.notice { border-radius: 10px; padding: 11px 14px; background: var(--warning-bg); border: 1px solid color-mix(in srgb, var(--warning) 45%, transparent); font-size: .9rem; }
.notice.info { background: color-mix(in srgb, var(--accent) 9%, var(--card)); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.empty { text-align: center; padding: 40px 16px; color: var(--text-secondary); }
.toast {
  position: fixed; bottom: 22px; inset-inline-start: 50%; transform: translateX(50%);
  background: var(--text-primary); color: var(--card); padding: 10px 18px; border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,.2); z-index: 100; font-weight: 550; max-width: 90vw;
}
.toast.err { background: var(--critical); color: #fff; }
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--card); color: var(--text-primary); width: min(760px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .dlg-body { padding: 20px 22px; max-height: 80vh; overflow-y: auto; }
dialog .dlg-foot { padding: 12px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-start; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters label.field { min-width: 160px; }
.updated { font-size: .8rem; color: var(--text-muted); }

/* ================= notifications module ================= */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tabs a { padding: 9px 14px; color: var(--text-secondary); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { text-decoration: none; color: var(--text-primary); }
.tabs a.on { color: var(--text-primary); border-bottom-color: var(--accent); }
.grow { flex: 1; min-width: 180px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .slider { position: relative; width: 40px; height: 22px; border-radius: 999px; background: var(--border); transition: background .15s; flex: none; }
.switch .slider::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: inset-inline-start .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + .slider { background: var(--good); }
.switch input:checked + .slider::after { inset-inline-start: 21px; }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }
.secret-mask { font-family: var(--mono); letter-spacing: 2px; color: var(--text-secondary); padding: 8px 0; }
.result { margin-top: 12px; padding: 10px 12px; border-radius: 9px; font-size: .9rem; }
.result.ok { background: var(--good-bg); }
.result.err { background: var(--critical-bg); }
.result pre { white-space: pre-wrap; word-break: break-word; }
.err-text { color: var(--critical); }
.add-row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.add-row .field { min-width: 150px; flex: 1; }
.add-row .field.check { flex: 0; min-width: auto; white-space: nowrap; padding-bottom: 8px; }

/* code editor */
.code-editor { position: relative; height: 430px; border: 1px solid var(--border); border-radius: 9px; background: var(--hover); overflow: hidden; margin-top: 8px; }
.code-editor .ce-hl, .code-editor .ce-ta {
  position: absolute; inset: 0; margin: 0; padding: 12px 14px; border: 0;
  font: 12.5px/1.6 var(--mono); white-space: pre; tab-size: 2; direction: ltr; text-align: left;
  overflow: auto; letter-spacing: 0; word-spacing: 0;
}
.code-editor .ce-hl { pointer-events: none; overflow: hidden; color: var(--text-primary); }
.code-editor .ce-hl code { font: inherit; }
.code-editor .ce-ta { color: transparent; background: transparent; caret-color: var(--text-primary); resize: none; outline: none; border-radius: 9px; }
.code-editor .ce-ta::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); color: transparent; }
.code-editor:focus-within { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); }
.tk-tag { color: #2a78d6; } .tk-attr { color: #8a3fb8; } .tk-str { color: #0a7d4a; } .tk-com { color: var(--text-muted); font-style: italic; }
.tk-mus { color: #c2410c; font-weight: 700; } .tk-sec { color: #b4235a; font-weight: 700; }
:root[data-theme="dark"] .tk-tag { color: #6da7ec; } :root[data-theme="dark"] .tk-attr { color: #c39bf0; }
:root[data-theme="dark"] .tk-str { color: #5fd49b; } :root[data-theme="dark"] .tk-mus { color: #f59e5b; } :root[data-theme="dark"] .tk-sec { color: #f07aa8; }

/* templates page */
.brand-card summary { cursor: pointer; list-style: none; }
.brand-card summary::-webkit-details-marker { display: none; }
.brand-card summary h2::before { content: "▸ "; color: var(--text-muted); }
.brand-card[open] summary h2::before { content: "▾ "; }
.brand-card input[type="color"] { height: 38px; padding: 3px; }
.logo-preview { max-height: 40px; max-width: 160px; border: 1px solid var(--border); border-radius: 6px; background: #fff; padding: 3px; }
.tpl-layout { display: grid; grid-template-columns: 250px 1fr; gap: 16px; align-items: start; }
.tpl-side .seg { width: 100%; margin-bottom: 10px; }
.tpl-side .seg button { flex: 1; }
.tpl-list { display: flex; flex-direction: column; gap: 3px; }
.tpl-item { display: flex; justify-content: space-between; align-items: center; text-align: start; font: inherit; font-size: .92rem; padding: 9px 11px; border-radius: 8px; border: 0; background: transparent; color: var(--text-secondary); cursor: pointer; }
.tpl-item:hover { background: var(--hover); }
.tpl-item.on { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--text-primary); font-weight: 650; }
.dot-custom { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.tpl-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.vars { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; max-height: 120px; overflow-y: auto; direction: ltr; justify-content: flex-end; }
.var-chip { font: 11.5px var(--mono); padding: 3px 7px; border-radius: 6px; border: 1px solid var(--border); background: var(--card); color: #c2410c; cursor: pointer; }
.var-chip.sec { color: #b4235a; }
.var-chip:hover { border-color: var(--accent); }
.tpl-errors { margin-top: 10px; padding: 10px 12px; border-radius: 9px; background: var(--critical-bg); font-size: .88rem; display: grid; gap: 4px; }
.subject-preview { font-weight: 650; margin: 2px 0 8px; unicode-bidi: plaintext; }
.preview-frame { width: 100%; height: 560px; border: 1px solid var(--border); border-radius: 9px; background: #f4f4f2; }
.preview-frame.tall { height: 60vh; }
.tg-wrap { background: color-mix(in srgb, #6da7ec 18%, var(--bg)); border-radius: 12px; padding: 16px; min-height: 200px; }
.tg-bubble { background: var(--card); border-radius: 12px 12px 12px 4px; padding: 10px 13px; white-space: pre-wrap; max-width: 420px; box-shadow: var(--shadow); font-size: .92rem; unicode-bidi: plaintext; }
.tg-bubble code, .tg-bubble pre { background: var(--hover); padding: 1px 4px; border-radius: 4px; }
@media (max-width: 1100px) { .tpl-cols { grid-template-columns: 1fr; } }
@media (max-width: 800px) { .tpl-layout { grid-template-columns: 1fr; } }

/* notifications log */
.stat-row { display: flex; gap: 14px; flex-wrap: wrap; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; min-width: 190px; box-shadow: var(--shadow); border-top: 4px solid var(--st, var(--offline)); }
.stat-v { font-size: 1.9rem; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-l { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: .85rem; margin-top: 4px; }
.stat-l .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--st, var(--offline)); }
tr.clickable { cursor: pointer; }
tr.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.notif-table td.subj { max-width: 320px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
dialog.wide { width: min(1000px, 96vw); }
