:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #1b1f24; --muted: #5d6673; --line: #e2e5ea;
  --brand: #0f4c5c; --brand-2: #127083; --side: #0d2a33; --side-ink: #cfe3e8; --side-muted: #7fa1aa;
  --ok: #1d7a46; --ok-bg: #e3f4ea; --warn: #8a5a00; --warn-bg: #fdf1d8; --bad: #a32020; --bad-bg: #fbe4e4;
  --info: #1c4f8a; --info-bg: #e2ecf8; --neutral-bg: #eceef1;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Noto Sans Arabic", "Noto Sans", Tahoma, sans-serif;
  color: var(--ink); background: var(--bg); line-height: 1.45; }
html[dir="rtl"] body { font-family: "Noto Sans Arabic", "Segoe UI", Tahoma, "Inter", system-ui, sans-serif; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: .95rem; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
html[dir="rtl"] h3 { text-transform: none; letter-spacing: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
code, .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .82rem; }

/* layout */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #2bb3c0, #0f4c5c);
  display: grid; place-items: center; color: #fff; font-weight: 700; }
.brand b { display: block; color: #fff; }
.brand span { font-size: .75rem; color: var(--side-muted); }
.navgrp { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--side-muted); margin: 14px 10px 6px; }
html[dir="rtl"] .navgrp { letter-spacing: 0; }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-radius: 7px;
  color: var(--side-ink); margin: 1px 0; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.nav a.on { background: rgba(43,179,192,.18); color: #fff; }
.nav .count { background: #c0392b; color: #fff; border-radius: 10px; padding: 0 7px; font-size: .72rem; }
.main { padding: 22px 28px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.topbar .who { display: flex; gap: 8px; align-items: center; }
.stopbar { background: var(--bad); color: #fff; padding: 10px 16px; border-radius: var(--radius); margin-bottom: 16px; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center; }

/* components */
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.kpi .label { color: var(--muted); font-size: .8rem; }
.kpi .value { font-size: 1.5rem; font-weight: 700; margin-top: 4px; }
.kpi .sub { font-size: .75rem; color: var(--muted); }
.kpi.alert .value { color: var(--bad); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: #fafbfc; }
html[dir="rtl"] th { text-transform: none; letter-spacing: 0; }
tr:hover td { background: #fafcfd; }
.tablewrap { overflow-x: auto; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: .74rem; font-weight: 600; white-space: nowrap; background: var(--neutral-bg); color: var(--muted); }
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-bad { background: var(--bad-bg); color: var(--bad); }
.b-info { background: var(--info-bg); color: var(--info); }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 600; }
.btn:hover { background: #f6f7f9; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { background: transparent; color: var(--side-ink); border-color: rgba(255,255,255,.2); }
.btn.sm { padding: 4px 9px; font-size: .82rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
form.f { display: grid; gap: 10px; }
label { display: grid; gap: 4px; font-size: .82rem; color: var(--muted); font-weight: 600; }
input, select, textarea { font: inherit; color: var(--ink); padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; width: 100%; }
textarea { min-height: 90px; resize: vertical; }
input[type=checkbox] { width: auto; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.notice { border-radius: 8px; padding: 10px 12px; font-size: .86rem; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.info { background: var(--info-bg); color: var(--info); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 14px; }
.kv > div:nth-child(odd) { color: var(--muted); font-size: .85rem; }
pre.json { background: #0f1720; color: #d6e2ea; padding: 12px; border-radius: 8px; overflow: auto; max-height: 420px; font-size: .78rem; direction: ltr; text-align: left; }
.toast { position: fixed; bottom: 20px; inset-inline-end: 20px; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 50; box-shadow: var(--shadow); }
.toast.bad { background: var(--bad); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 8px 12px; cursor: pointer; font: inherit; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.list { display: grid; gap: 8px; }
.item { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: #fff; }
.bar { height: 8px; background: var(--neutral-bg); border-radius: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand-2); }
.bar.over > i { background: var(--bad); }

/* org chart */
.org { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.dept h4 { margin: 0 0 2px; font-size: 1rem; }
.emp { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 7px 8px; border-radius: 7px; border: 1px solid var(--line); margin-top: 6px; }
.emp.mgr { border-color: #9fd3db; background: #f2fafb; }
.emp .t { font-weight: 600; }
.emp .c { font-size: .72rem; color: var(--muted); direction: ltr; }
.ceo-row { display: flex; justify-content: center; margin-bottom: 14px; }
.ceo { min-width: 300px; text-align: center; border: 2px solid var(--brand); }
.owner-box { text-align: center; margin-bottom: 8px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #0d2a33, #134e5e); }
.login .card { width: 380px; padding: 26px; }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; } .side { position: static; height: auto; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; } .kv { grid-template-columns: 1fr; } .main { padding: 16px; }
}
.login .brand b { color: var(--ink); font-size: 1.05rem; }
.qrbox { display: flex; justify-content: center; padding: 8px; }
.qrbox svg { max-width: 100%; height: auto; }
.secretkey { font-size: 1.05rem; letter-spacing: .08em; direction: ltr; text-align: center; background: #f6f7f9; padding: 8px; border-radius: 8px; }
.card.quick { border: 2px solid #9fd3db; background: #f7fcfd; margin-bottom: 18px; }
.card.quick code { direction: ltr; unicode-bidi: embed; background: #eef3f5; padding: 2px 6px; border-radius: 6px; font-size: .8rem; }

/* v6: sales & connectors */
.toolgrid { display: grid; gap: 6px; max-height: 260px; overflow: auto; padding: 6px; border: 1px solid var(--line, #e3e7ee); border-radius: 8px; }
.mailbody { white-space: pre-wrap; font-family: inherit; font-size: 13px; background: var(--soft, #f6f8fb); padding: 10px; border-radius: 8px; max-height: 260px; overflow: auto; }
