:root {
  color-scheme: dark;
  --bg: #0d0f14; --panel: #161a22; --line: #262c38; --text: #e9ecf2; --muted: #8d96a8;
  --accent: #6ea8ff; --live: #ff4d6a; --ok: #3ecf8e; --warn: #ffb547; --bad: #ff6b6b;
  font: 15px/1.45 system-ui, "Segoe UI", "Noto Sans Arabic", Tahoma, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); }
h1, h2 { margin: 0; font-weight: 650; }
h2 { font-size: 1rem; margin-block: 1.5rem .6rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
:lang(ar) h2 { letter-spacing: 0; }
button, input, textarea { font: inherit; color: inherit; }
button { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .8rem; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #08101f; font-weight: 600; }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-family: ui-monospace, monospace; font-size: .85em; }
input, textarea { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; }
label { display: grid; gap: .3rem; color: var(--muted); font-size: .9rem; }
.muted { color: var(--muted); }
.error, [role="alert"] { color: var(--bad); min-height: 1.2em; margin: 0; }
.grow { flex: 1; }

#login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
#login form { width: min(22rem, 100%); display: grid; gap: 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 1.5rem; }
.langs { display: flex; gap: .3rem; flex-wrap: wrap; }
.langs button { padding: .2rem .55rem; font-size: .85rem; }
.langs .on, nav .on { border-color: var(--accent); color: var(--accent); }

header { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; padding: .7rem 1rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 2; }
#who { color: var(--muted); font-size: .9rem; }
.pill { border-radius: 99px; padding: .15rem .65rem; font-size: .8rem; font-weight: 600; border: 1px solid currentColor; }
.pill.live { color: var(--ok); }
.pill.live::before { content: "● "; animation: blink 1.6s infinite; }
.pill.reconnecting, .pill.delayed { color: var(--warn); }
@keyframes blink { 50% { opacity: .25; } }

nav { display: flex; gap: .4rem; padding: .6rem 1rem; overflow-x: auto; border-bottom: 1px solid var(--line); }
nav button { white-space: nowrap; display: flex; gap: .45rem; align-items: center; }
nav b { background: var(--warn); color: #201400; border-radius: 99px; padding: 0 .45rem; font-size: .78rem; }
nav b.live { background: var(--live); color: #fff; }
#view { padding: 0 1rem 3rem; max-width: 90rem; margin-inline: auto; }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr)); gap: .7rem; margin-top: 1rem; }
h2 + .tiles { margin-top: 0; }
.tile { display: grid; gap: .15rem; text-align: start; padding: .9rem 1rem; border-radius: 12px; }
.tile b { font-size: 1.9rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: .9rem; }
.tile:disabled { cursor: default; opacity: 1; }
.tile.queue.has { border-color: var(--warn); }
.tile.queue.has b { color: var(--warn); }
.tile.live.has b { color: var(--live); }

#feed { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 12px; max-height: 60vh; overflow-y: auto; }
#feed li { display: flex; gap: .7rem; align-items: baseline; flex-wrap: wrap; padding: .5rem .8rem; border-inline-start: 3px solid var(--line); }
#feed li + li { border-top: 1px solid var(--line); }
#feed time { color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }
#feed .note { color: var(--muted); overflow-wrap: anywhere; }
#feed .n { font-variant-numeric: tabular-nums; }
#feed li.live { border-inline-start-color: var(--live); }
#feed li.report, #feed li.flag { border-inline-start-color: var(--bad); }
#feed li.withdraw, #feed li.topup, #feed li.kyc { border-inline-start-color: var(--warn); }
#feed li.user, #feed li.support { border-inline-start-color: var(--accent); }
#feed li.admin { border-inline-start-color: var(--ok); }
#feed li.fresh { animation: flash 2.5s ease-out; }
@keyframes flash { from { background: #26324a; } to { background: transparent; } }

.search { display: flex; gap: .5rem; margin-bottom: .8rem; max-width: 32rem; }
.scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: start; padding: .55rem .7rem; border-bottom: 1px solid var(--line); max-width: 22rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: var(--panel); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.acts { display: flex; gap: .35rem; max-width: none; overflow: visible; }
td.acts button { padding: .25rem .6rem; font-size: .85rem; }
#list > button { margin-top: .8rem; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; width: min(28rem, calc(100% - 2rem)); padding: 1.2rem; }
dialog::backdrop { background: rgb(0 0 0 / .6); }
dialog form { display: grid; gap: .9rem; }
dialog h2 { margin: 0; color: var(--text); text-transform: none; letter-spacing: 0; overflow-wrap: anywhere; }
menu { display: flex; justify-content: flex-end; gap: .5rem; margin: 0; padding: 0; }
.toast { position: fixed; inset-block-end: 1rem; inset-inline: 0; margin-inline: auto; width: fit-content; max-width: calc(100% - 2rem); background: var(--ok); color: #04130c; padding: .55rem 1rem; border-radius: 10px; font-weight: 600; z-index: 5; }
.toast.bad { background: var(--bad); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel); }
#detail { width: min(40rem, calc(100% - 2rem)); }
dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; max-height: 65vh; overflow-y: auto; }
dt { color: var(--muted); font-size: .85rem; }
dd { margin: 0; overflow-wrap: anywhere; }
#bell.on { border-color: var(--ok); color: var(--ok); }
.health { font-size: .85rem; margin-top: 1rem; }

/* W9 agents pages */
h3 { margin: 1.2rem 0 .5rem; font-size: .95rem; color: var(--muted); }
.fields { display: grid; gap: .8rem; }
label small { font-size: .8rem; }
textarea { resize: vertical; }
.quote { margin: 0; padding: .5rem .7rem; border: 1px dashed var(--accent); border-radius: 8px; color: var(--accent); font-variant-numeric: tabular-nums; }
#agent { width: min(60rem, calc(100% - 2rem)); }
#agent-body { max-height: 70vh; overflow-y: auto; }
#agent-body h2 { margin-top: 0; }
#agent-title:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#view h2:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); margin: 0; font-size: .9em; }
