/* نبض — واجهة عربية RTL، بلا أطر خارجية. ثيمة: حبر أزرق داكن + كهرمان كهربائي. */
:root {
  --ink: #0f172a; --ink-2: #1e293b; --paper: #f5f7fb; --card: #ffffff; --text: #0f172a; --muted: #64748b;
  --line: #e2e8f0; --amber: #f59e0b; --amber-2: #d97706; --ok: #16a34a; --run: #0284c7; --bad: #dc2626;
  --warn: #ea580c; --off: #94a3b8; --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px -16px rgba(15, 23, 42, .25);
  --ff: 'Cairo', 'Segoe UI', Tahoma, sans-serif; --r: 18px;
}
:root[data-theme="dark"] {
  --paper: #0b1220; --card: #111a2e; --text: #e5edf7; --muted: #94a3b8; --line: #22304a; --ink: #060b16; --ink-2: #0f172a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -18px rgba(0, 0, 0, .8);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0b1220; --card: #111a2e; --text: #e5edf7; --muted: #94a3b8; --line: #22304a; --ink: #060b16; --ink-2: #0f172a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -18px rgba(0, 0, 0, .8);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--text); font-family: var(--ff); font-size: 16px; line-height: 1.7; }
a { color: var(--run); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: .3rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.2rem 0 .6rem; }
h3 { font-size: 1rem; margin: .8rem 0 .4rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.tiny { font-size: .78rem; }
.b { font-weight: 700; }
.num { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
code, .mono { font-family: ui-monospace, Consolas, monospace; direction: ltr; unicode-bidi: isolate; font-size: .9em; }

/* ── شريط علوي ───────────────────────────────────────────── */
.topbar { background: var(--ink); color: #fff; padding: .55rem 1rem; display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; position: sticky; top: 0; z-index: 20; }
.topbar .brand { font-weight: 800; font-size: 1.1rem; letter-spacing: .2px; display: flex; align-items: center; gap: .4rem; }
.topbar .brand .pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 0 rgba(245, 158, 11, .7); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, .7); } 70% { box-shadow: 0 0 0 10px rgba(245, 158, 11, 0); } 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); } }
.topbar nav { display: flex; gap: .15rem; flex-wrap: wrap; }
.topbar nav a { color: #cbd5e1; padding: .3rem .7rem; border-radius: 10px; font-size: .93rem; }
.topbar nav a.active, .topbar nav a:hover { background: var(--ink-2); color: #fff; text-decoration: none; }
.topbar .spacer { flex: 1; }
.topbar .ghost { background: transparent; border: 1px solid #334155; color: #cbd5e1; border-radius: 10px; padding: .2rem .6rem; cursor: pointer; font-family: inherit; }
.devbar { background: var(--card); border-bottom: 1px solid var(--line); padding: .45rem 1rem; display: flex; gap: .2rem; align-items: center; flex-wrap: wrap; position: sticky; top: 52px; z-index: 19; }
.devbar .name { font-weight: 800; margin-inline-end: .6rem; }
.devbar a { color: var(--muted); padding: .25rem .65rem; border-radius: 10px; font-size: .92rem; }
.devbar a.active, .devbar a:hover { background: var(--paper); color: var(--text); text-decoration: none; }
main { max-width: 1180px; margin: 1.1rem auto; padding: 0 1rem; }
main.wide { max-width: 1500px; }
footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 2rem 1rem; }

/* ── بطاقات وشبكات ───────────────────────────────────────── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 1rem 1.15rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: .5rem; }

/* ── مؤشرات وأزرار ───────────────────────────────────────── */
.pill { display: inline-flex; align-items: center; gap: .35rem; padding: .1rem .65rem; border-radius: 999px; font-size: .82rem; font-weight: 700; background: var(--paper); color: var(--muted); border: 1px solid var(--line); }
.pill.ok { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.pill.run { background: #e0f2fe; color: #075985; border-color: #bae6fd; }
.pill.bad { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.pill.warn { background: #ffedd5; color: #9a3412; border-color: #fed7aa; }
.pill.off { background: #f1f5f9; color: #475569; }
.pill.amber { background: #fef3c7; color: #92400e; border-color: #fde68a; }
:root[data-theme="dark"] .pill.ok, :root[data-theme="dark"] .pill.run, :root[data-theme="dark"] .pill.bad, :root[data-theme="dark"] .pill.warn, :root[data-theme="dark"] .pill.amber { filter: brightness(.85) saturate(.9); }
.led { width: 12px; height: 12px; border-radius: 50%; display: inline-block; background: var(--off); box-shadow: inset 0 0 2px rgba(0, 0, 0, .3); }
.led.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.led.run { background: var(--run); box-shadow: 0 0 8px var(--run); animation: blink 1.2s infinite; }
.led.bad { background: var(--bad); box-shadow: 0 0 8px var(--bad); }
.led.warn { background: var(--warn); }
@keyframes blink { 50% { opacity: .45; } }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: .5rem 1rem; border-radius: 12px; font-family: inherit; font-size: .95rem; font-weight: 700; cursor: pointer; transition: transform .05s, background .15s; text-decoration: none !important; }
.btn:hover { background: var(--paper); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--amber); border-color: var(--amber-2); color: #1a1200; }
.btn.primary:hover { background: var(--amber-2); color: #fff; }
.btn.run { background: var(--ok); border-color: #15803d; color: #fff; }
.btn.stop { background: var(--bad); border-color: #b91c1c; color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: .25rem .7rem; font-size: .85rem; border-radius: 9px; }
.btn.lg { padding: .9rem 1.6rem; font-size: 1.1rem; border-radius: 16px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.danger { border-color: #fecaca; color: var(--bad); }
button.linklike { background: none; border: 0; color: var(--run); cursor: pointer; font-family: inherit; padding: 0; }

/* ── نماذج ──────────────────────────────────────────────── */
label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: .15rem; }
input, select, textarea { font-family: inherit; font-size: 1rem; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); width: 100%; }
input[type="checkbox"], input[type="radio"] { width: auto; }
input:focus, select:focus { outline: 2px solid rgba(245, 158, 11, .5); border-color: var(--amber); }
.field { margin-bottom: .7rem; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .6rem .8rem; }
.inline { display: inline-flex; gap: .5rem; align-items: center; }
.help { font-size: .82rem; color: var(--muted); }
.flash { padding: .7rem 1rem; border-radius: 12px; margin-bottom: 1rem; border: 1px solid; font-weight: 600; }
.flash.ok { background: #dcfce7; border-color: #86efac; color: #14532d; }
.flash.err { background: #fee2e2; border-color: #fca5a5; color: #7f1d1d; }
:root[data-theme="dark"] .flash.ok { background: #052e16; color: #bbf7d0; }
:root[data-theme="dark"] .flash.err { background: #450a0a; color: #fecaca; }

/* ── جداول ──────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { padding: .45rem .6rem; text-align: start; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 700; font-size: .85rem; }
tr:last-child td { border-bottom: 0; }
.tbl-wrap { overflow-x: auto; }

/* ── عدّادات حيّة ─────────────────────────────────────────── */
.gauges { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; }
.gauge { text-align: center; padding: .4rem 0 .2rem; }
.gauge svg { width: 100%; max-width: 170px; height: auto; display: block; margin: 0 auto; }
.gauge .v { font-size: 1.55rem; font-weight: 800; line-height: 1.1; margin-top: -.6rem; font-variant-numeric: tabular-nums; }
.gauge .u { font-size: .8rem; color: var(--muted); }
.gauge .l { font-size: .88rem; color: var(--muted); margin-top: .1rem; }
.hero { display: grid; grid-template-columns: 1.3fr 1fr; gap: 1rem; }
@media (max-width: 860px) { .hero { grid-template-columns: 1fr; } .devbar { top: auto; position: static; } }
.state-big { font-size: 1.6rem; font-weight: 800; display: flex; align-items: center; gap: .6rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .2rem 1rem; font-size: .95rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.terminals { display: flex; gap: .4rem; flex-wrap: wrap; }
.term { padding: .15rem .55rem; border-radius: 8px; border: 1px solid var(--line); font-size: .82rem; color: var(--muted); font-family: ui-monospace, monospace; }
.term.on { background: #dcfce7; border-color: #86efac; color: #14532d; font-weight: 700; }
:root[data-theme="dark"] .term.on { background: #052e16; color: #bbf7d0; }
.stat { text-align: center; padding: .5rem .3rem; }
.stat .v { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat .l { font-size: .82rem; color: var(--muted); }
.health { display: flex; align-items: center; gap: 1rem; }
.ring { width: 84px; height: 84px; flex: none; }
.ring text { font-family: var(--ff); font-weight: 800; font-size: 22px; fill: var(--text); }

/* ── الأسطول ─────────────────────────────────────────────── */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.tile { position: relative; display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 1rem 1.1rem 1rem 1.1rem; box-shadow: var(--shadow); color: var(--text); border-inline-start: 6px solid var(--off); transition: transform .12s, box-shadow .12s; }
.tile:hover { transform: translateY(-2px); text-decoration: none; box-shadow: 0 12px 30px -16px rgba(15, 23, 42, .4); }
.tile.run { border-inline-start-color: var(--run); }
.tile.ok { border-inline-start-color: var(--ok); }
.tile.bad { border-inline-start-color: var(--bad); }
.tile.off { border-inline-start-color: var(--off); }
.tile.muted { border-inline-start-color: var(--line); }
.tile .ic { font-size: 1.7rem; line-height: 1; }
.tile .t { font-weight: 800; font-size: 1.05rem; }
.tile .st { font-size: .9rem; color: var(--muted); }
.tile .nums { display: flex; gap: 1rem; margin-top: .6rem; font-size: .88rem; color: var(--muted); }
.tile .nums b { color: var(--text); font-variant-numeric: tabular-nums; }
.tile .badge { position: absolute; top: .8rem; inset-inline-end: .9rem; }
.add-tile { display: flex; align-items: center; justify-content: center; border: 2px dashed var(--line); border-radius: var(--r); color: var(--muted); min-height: 130px; font-weight: 700; }
.add-tile:hover { border-color: var(--amber); color: var(--amber-2); text-decoration: none; }
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.totals .card { padding: .6rem .8rem; text-align: center; }

/* ── تحكم ───────────────────────────────────────────────── */
.ctl-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; }
.ctl-grid .btn { min-height: 74px; flex-direction: column; gap: .1rem; }
.ctl-grid .btn small { font-weight: 400; opacity: .8; }
.slider { width: 100%; accent-color: var(--amber); }
.hz-big { font-size: 2.4rem; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }
.switch { display: inline-flex; align-items: center; gap: .6rem; }
.lock { border: 1px dashed var(--line); border-radius: 12px; padding: .8rem 1rem; color: var(--muted); }

/* ── الرسوم ─────────────────────────────────────────────── */
.chart { width: 100%; height: 260px; display: block; }
.chart text { font-family: var(--ff); font-size: 11px; fill: var(--muted); }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-inline-end: .3rem; border-radius: 2px; }
.bars { width: 100%; height: 180px; display: block; }
.range a { padding: .2rem .6rem; border-radius: 8px; border: 1px solid var(--line); color: var(--muted); font-size: .88rem; }
.range a.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ── المعاملات ──────────────────────────────────────────── */
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .8rem; }
.tabs button { border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 10px; padding: .3rem .75rem; cursor: pointer; font-family: inherit; font-size: .9rem; }
.tabs button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.sheet { display: none; }
.sheet.active { display: block; }
.param { display: grid; grid-template-columns: 110px 1fr auto; gap: .4rem .8rem; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.param:last-child { border-bottom: 0; }
.param .code { font-family: ui-monospace, monospace; direction: ltr; font-size: .85rem; color: var(--muted); }
.param .val { font-weight: 700; font-variant-numeric: tabular-nums; }
.param .val.changed { color: var(--amber-2); }
.param .help { grid-column: 1 / -1; }
.param form { display: flex; gap: .35rem; align-items: center; }
.param form input, .param form select { width: 130px; padding: .3rem .5rem; font-size: .9rem; }
.param form select { width: 220px; }
.param .ro { color: var(--muted); font-size: .8rem; }
.preset { border: 1px solid var(--line); border-radius: 12px; padding: .7rem .9rem; display: flex; gap: .7rem; align-items: flex-start; }
.preset .ic { font-size: 1.4rem; }
.danger-zone { border-color: #fecaca; }
.danger-zone h2 { color: var(--bad); }
.search { margin-bottom: .6rem; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .4rem 0; border-bottom: 1px solid var(--line); display: flex; gap: .7rem; align-items: baseline; }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { color: var(--muted); font-size: .82rem; white-space: nowrap; min-width: 4.5rem; font-variant-numeric: tabular-nums; }

/* ── الدخول ─────────────────────────────────────────────── */
.auth { max-width: 420px; margin: 8vh auto; }
.auth .logo { text-align: center; font-size: 2.2rem; font-weight: 800; margin-bottom: .2rem; }
.auth .logo span { color: var(--amber); }
.auth .sub { text-align: center; color: var(--muted); margin-bottom: 1.4rem; }
.auth input.code { font-size: 2rem; letter-spacing: .6rem; text-align: center; direction: ltr; }
.code-box { font-family: ui-monospace, monospace; direction: ltr; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .9rem; font-size: 1.05rem; word-break: break-all; }
.steps { counter-reset: s; list-style: none; padding: 0; }
.steps li { position: relative; padding-inline-start: 2.4rem; margin-bottom: .8rem; }
.steps li::before { counter-increment: s; content: counter(s); position: absolute; inset-inline-start: 0; top: .1rem; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: var(--amber); color: #1a1200; font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: .9rem; }
.waiting { display: inline-flex; gap: .5rem; align-items: center; }
.dots::after { content: "…"; animation: dots 1.5s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
details summary { cursor: pointer; font-weight: 700; }
.sev-critical { color: var(--bad); }
.sev-warn { color: var(--warn); }
.sev-info { color: var(--run); }
@media print { .topbar, .devbar, footer, .btn, form { display: none !important; } }
