:root {
  --bg: #0e1116; --panel: #161b22; --panel2: #1c232d; --border: #2a3340; --text: #e6edf3; --muted: #8b98a8;
  --accent: #58a6ff; --ok: #3fb950; --warn: #d29922; --bad: #f85149; --radius: 10px;
  font-family: "Noto Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--accent); }
code, pre, .mono { font-family: "JetBrains Mono", Consolas, monospace; direction: ltr; unicode-bidi: isolate; }
pre { white-space: pre-wrap; word-break: break-word; background: #0b0e13; padding: 10px; border-radius: 8px; border: 1px solid var(--border); max-height: 60vh; overflow: auto; text-align: left; }
button { background: var(--panel2); color: var(--text); border: 1px solid var(--border); border-radius: 7px; padding: 6px 12px; cursor: pointer; font: inherit; }
button:hover { border-color: var(--accent); }
button.primary { background: #1f6feb; border-color: #1f6feb; }
button.danger { border-color: var(--bad); color: var(--bad); }
input, textarea, select { background: #0b0e13; color: var(--text); border: 1px solid var(--border); border-radius: 7px; padding: 7px 10px; font: inherit; }
textarea { width: 100%; resize: vertical; }
.muted { color: var(--muted); }
.err { color: var(--bad); }

/* layout */
.app { display: grid; grid-template-columns: 220px 1fr; height: 100vh; }
nav { background: var(--panel); border-left: 1px solid var(--border); overflow-y: auto; padding: 12px 8px; }
nav h2 { font-size: 15px; margin: 4px 8px 12px; }
nav a { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; margin-bottom: 2px; }
nav a.active, nav a:hover { background: var(--panel2); }
nav .badge { margin-inline-start: auto; }
main { overflow-y: auto; padding: 18px 22px; }
main h1 { font-size: 20px; margin: 0 0 14px; display: flex; gap: 10px; align-items: center; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.card h3 { margin: 0 0 8px; font-size: 14px; display: flex; gap: 8px; align-items: center; }
.big { font-size: 26px; font-weight: 600; }
.bar { height: 8px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.bar > div { height: 100%; background: var(--accent); }
.bar.warn > div { background: var(--warn); } .bar.bad > div { background: var(--bad); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: right; vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); } .dot.warn { background: var(--warn); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 11px; background: var(--panel2); border: 1px solid var(--border); }
.badge.ok { color: var(--ok); border-color: var(--ok); } .badge.bad { color: var(--bad); border-color: var(--bad); } .badge.warn { color: var(--warn); border-color: var(--warn); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.section { margin-bottom: 20px; }
.section > h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); }
details { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; margin-bottom: 6px; }
details summary { cursor: pointer; }
.modal { position: fixed; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal > .card { width: min(1000px, 94vw); max-height: 90vh; overflow: auto; }
.toast { position: fixed; bottom: 16px; left: 16px; background: var(--panel2); border: 1px solid var(--border); padding: 10px 14px; border-radius: 8px; z-index: 60; }

/* chat consoles (RTL-correct, dir=auto per message) */
.chat { display: grid; grid-template-columns: 260px 1fr; gap: 12px; height: calc(100vh - 90px); }
.chat .list { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow-y: auto; padding: 8px; }
.chat .list .item { padding: 8px; border-radius: 7px; cursor: pointer; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat .list .item.active, .chat .list .item:hover { background: var(--panel2); }
.chat .pane { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); min-height: 0; }
.chat .msgs { flex: 1; overflow-y: auto; padding: 14px; }
.msg { margin-bottom: 12px; padding: 10px 14px; border-radius: 10px; line-height: 1.75; unicode-bidi: plaintext; }
.msg.user { background: #1f3a5f; margin-inline-start: 15%; }
.msg.assistant { background: var(--panel2); margin-inline-end: 5%; }
.msg.tool { background: transparent; border: 1px dashed var(--border); font-size: 12px; color: var(--muted); padding: 6px 10px; }
.msg.reasoning { font-size: 12px; color: var(--muted); border-inline-start: 3px solid var(--border); background: transparent; }
.msg p { margin: 0.3em 0; unicode-bidi: plaintext; }
.msg li { unicode-bidi: plaintext; }
.msg pre { max-height: 40vh; }
.msg table { font-size: 13px; }
.composer { border-top: 1px solid var(--border); padding: 10px; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 30vh; unicode-bidi: plaintext; }
.perm { border: 1px solid var(--warn); border-radius: 8px; padding: 10px; margin: 8px 0; }

/* terminal */
#term { height: calc(100vh - 130px); background: #000; border-radius: 8px; padding: 6px; direction: ltr; }

/* KB */
.kb { display: grid; grid-template-columns: 280px 1fr; gap: 12px; height: calc(100vh - 90px); }
.kb .tree { overflow-y: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; font-size: 13px; }
.kb .tree .f { color: var(--muted); margin-top: 6px; font-weight: 600; }
.kb .tree .n { padding: 3px 8px; cursor: pointer; border-radius: 5px; }
.kb .tree .n:hover { background: var(--panel2); }
.kb .view { overflow-y: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; line-height: 1.8; unicode-bidi: plaintext; }
.kb .view p, .kb .view li, .kb .view h1, .kb .view h2, .kb .view h3 { unicode-bidi: plaintext; }
#graph { height: calc(100vh - 140px); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.wikilink { color: #d2a8ff; cursor: pointer; text-decoration: underline dotted; }

.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 28px; width: 320px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; font-size: 20px; }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  nav { display: flex; overflow-x: auto; border-left: 0; border-bottom: 1px solid var(--border); padding: 6px; }
  nav h2 { display: none; } nav a { white-space: nowrap; }
  .chat, .kb { grid-template-columns: 1fr; height: auto; }
  .chat .list, .kb .tree { max-height: 180px; }
  .chat .pane { height: 75vh; }
}

/* ---- team additions ---- */
.who { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.who b { color: #d2a8ff; font-weight: 600; }
.chip { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; background: #22314a; color: #9ecbff; margin-inline-start: 6px; }
.chip.src-telegram { background: #173a4f; color: #7cd3ff; } .chip.src-api_server { background: #2b2250; color: #c9b6ff; }
.busy { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); display: inline-block; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.older { display: block; margin: 0 auto 12px; }
.userbox { margin: 12px 8px; padding: 10px; background: var(--panel2); border-radius: 8px; font-size: 12px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.filters input { flex: 1; min-width: 140px; }
.list .item .meta { font-size: 11px; color: var(--muted); }
.act td { font-size: 12px; } .act .cmd { font-family: "JetBrains Mono", monospace; direction: ltr; text-align: left; unicode-bidi: isolate; word-break: break-all; }
.k-actor { font-weight: 600; } .k-hermes { color: #d2a8ff; } .k-opencode { color: #7ee787; } .k-ssh { color: #79c0ff; } .k-dashboard { color: #ffa657; }
.kind-delete { color: var(--bad); } .kind-rename { color: var(--warn); }
.iframe { width: 100%; height: calc(100vh - 120px); border: 1px solid var(--border); border-radius: var(--radius); background: #000; }

/* login center: stacked cards on phones */
@media (max-width: 760px) {
  table.logins tr:first-child { display: none; }
  table.logins tr { display: grid; grid-template-columns: 18px 1fr; gap: 4px 8px; padding: 10px 0; border-bottom: 1px solid var(--border, #2a2f3a); }
  table.logins td { display: block; border: 0; padding: 0; }
  table.logins td:nth-child(3), table.logins td:nth-child(4) { grid-column: 2; }
  table.logins .row { flex-wrap: wrap; }
  table.logins input { width: 100%; }
}
