/* Agents dashboard — look from the approved mockup: dark grid, teal / blue / amber accents. */
:root {
  --bg: #0A0E13; --panel: #0F151C; --panel2: #0C1218; --field: #0A0E13; --grid: #141B23;
  --line: #1E2731; --line2: #243140; --line3: #2A3642;
  --ink: #E6EDF3; --ink2: #B7C2CD; --muted: #8B98A5; --dim: #4E5B68;
  --teal: #7FE7D6; --teal-d: #2B5E55; --teal-bg: #0F1F1C; --teal-ink: #04201B; --core: #12302B;
  --blue: #8AB4FF; --blue-d: #24405E; --blue-bg: #0F1F2E;
  --amber: #F2C26B; --amber-d: #4A3A1C; --amber-bg: #2A2111;
  --red: #F2A0A0; --red-d: #4A2626; --red-bg: #2A1414;
  --sans: 'Space Grotesk', system-ui, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  --ar: 'IBM Plex Sans Arabic', 'Space Grotesk', system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100vh; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px; background-attachment: fixed;
}
a { color: var(--teal); }
a:hover { color: #B5F3E9; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ar, [dir="auto"], [dir="rtl"] { font-family: var(--ar); }
.pre { white-space: pre-wrap; unicode-bidi: plaintext; overflow-wrap: anywhere; }

/* --- animation ------------------------------------------------------------------------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes spinr { to { transform: rotate(-360deg); } }
@keyframes pulse { 0%,100% { opacity: .45; transform: scale(.88); } 50% { opacity: 1; transform: scale(1.06); } }
@keyframes bar { 0%,100% { transform: scaleY(.25); } 50% { transform: scaleY(1); } }
@keyframes scan { 0% { top: -30%; } 100% { top: 110%; } }
@keyframes blink { 0%,49% { opacity: 1; } 50%,100% { opacity: 0; } }
@keyframes ping { 0% { transform: scale(1); opacity: .8; } 100% { transform: scale(2.6); opacity: 0; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes travel { 0% { left: -2%; opacity: 0; } 12% { opacity: 1; } 88% { opacity: 1; } 100% { left: 100%; opacity: 0; } }
@keyframes glowline { 0%,100% { opacity: .35; } 50% { opacity: .9; } }
@keyframes shimmer { 0% { transform: translateX(-120%); } 100% { transform: translateX(320%); } }
@keyframes dash { to { stroke-dashoffset: -30; } }
.scan { position: fixed; left: 0; right: 0; height: 30%; pointer-events: none; z-index: 0;
  background: linear-gradient(180deg, transparent, rgba(127,231,214,.05), transparent); animation: scan 7s linear infinite; }
.cursor { animation: blink 1s step-end infinite; color: var(--teal); }
.fade { animation: fadeUp .5s ease-out both; }
.ring-a { animation: spin 14s linear infinite; }
.ring-b { animation: spinr 9s linear infinite; }
.orbit { animation: spin 7s linear infinite; }
.pulse { animation: pulse 2.4s ease-in-out infinite; }
.sweep { background: conic-gradient(from 0deg, rgba(127,231,214,.45), transparent 28%); animation: spin 3.2s linear infinite; }
.bar { transform-origin: bottom; animation: bar 1.2s ease-in-out infinite; width: 3px; border-radius: 2px; background: var(--teal); }
.dash { stroke-dasharray: 3 7; animation: dash 1.8s linear infinite; }
@media (prefers-reduced-motion: reduce) {
  .scan, .cursor, .fade, .ring-a, .ring-b, .orbit, .pulse, .sweep, .bar, .packet, .glowline, .shimmer, .dash, .ping { animation: none !important; }
}

/* --- top bar --------------------------------------------------------------------------- */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 24px; background: rgba(10,14,19,.94); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.brand:hover { color: var(--ink); }
.brand-mark { width: 34px; height: 34px; border: 2px solid var(--teal); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--teal); }
.brand-name { display: block; font-weight: 700; letter-spacing: .04em; }
.brand-sub { display: block; font-size: 11px; color: var(--muted); }
.top-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 26px; }

/* --- layout ---------------------------------------------------------------------------- */
main { position: relative; z-index: 1; max-width: 1280px; margin: 0 auto; padding: 28px 24px 60px; }
.kicker { font-family: var(--mono); font-size: 12px; letter-spacing: .12em; color: var(--teal); text-transform: uppercase; }
h1 { margin: 4px 0 0; font-size: 34px; letter-spacing: -.01em; }
h2 { margin: 4px 0 8px; font-size: 20px; }
h3 { margin: 0 0 6px; font-size: 16px; }
.head-row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.card { background: var(--panel); border: 1px solid var(--line2); border-radius: 14px; padding: 20px; }
.card + .card { margin-top: 18px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 260px; min-width: 0; }
.split { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.split > .main { flex: 999 1 560px; min-width: 0; }
.split > .side { flex: 1 1 300px; min-width: 0; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }
hr.dashed { border: 0; border-top: 1px dashed var(--line2); margin: 14px 0; }

/* --- controls -------------------------------------------------------------------------- */
button, input, select, textarea { font: inherit; color: inherit; }
.btn { min-height: 40px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line3); background: #111820; color: var(--ink);
  cursor: pointer; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.btn:hover { border-color: var(--teal-d); color: var(--ink); }
.btn.primary { background: var(--teal); color: var(--teal-ink); border-color: var(--teal); font-weight: 700; }
.btn.primary:hover { background: #A5EFE3; }
.btn.ghost { background: transparent; }
.btn.ok { background: var(--teal-bg); color: var(--teal); border-color: var(--teal-d); font-weight: 700; }
.btn.warn { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-d); font-weight: 700; }
.btn.danger { background: transparent; color: var(--red); border-color: var(--red-d); }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: wait; }
label.field { display: flex; flex-direction: column; gap: 5px; }
label.field > span:first-child, .label { font-family: var(--mono); font-size: 11px; color: var(--ink2); text-transform: uppercase; letter-spacing: .04em; }
input[type=text], input[type=password], input[type=date], input[type=tel], select, textarea {
  min-height: 42px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line3); background: var(--field); color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal-d); border-color: var(--teal-d); }
textarea { resize: vertical; line-height: 1.55; unicode-bidi: plaintext; }
textarea.big { min-height: 60vh; font-size: 14px; }
.check { display: inline-flex; gap: 8px; align-items: center; min-height: 32px; color: var(--ink2); font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--teal); }

/* --- badges ---------------------------------------------------------------------------- */
.badge { font-family: var(--mono); font-size: 11px; padding: 3px 8px; border-radius: 6px; white-space: nowrap; border: 1px solid var(--line3); color: var(--ink2); display: inline-block; }
.badge.ok { background: var(--teal-bg); color: var(--teal); border-color: var(--teal-d); }
.badge.blue { background: var(--blue-bg); color: var(--blue); border-color: var(--blue-d); }
.badge.amber { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-d); }
.badge.red { background: var(--red-bg); color: var(--red); border-color: var(--red-d); }
.chip { font-family: var(--mono); font-size: 11px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line3); color: var(--ink2); }

/* --- toast / errors -------------------------------------------------------------------- */
.toast { position: fixed; z-index: 20; left: 50%; bottom: 22px; transform: translateX(-50%); max-width: min(680px, calc(100% - 32px));
  padding: 12px 16px; border-radius: 10px; background: var(--red-bg); color: #FFD2D2; border: 1px solid var(--red-d); box-shadow: 0 12px 40px rgba(0,0,0,.5); }
.toast.good { background: var(--teal-bg); color: var(--teal); border-color: var(--teal-d); }
.error { color: var(--red); font-size: 14px; }
.note { color: var(--ink2); font-size: 13px; }
.note.warn { color: var(--amber); }
.note.bad { color: var(--red); font-weight: 600; }

/* --- login ----------------------------------------------------------------------------- */
.login-wrap { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.login { width: min(400px, 100%); }
.login .core-big { margin: 0 auto 18px; }

/* --- the agent core -------------------------------------------------------------------- */
.core { position: relative; width: 64px; height: 64px; flex: none; }
.core .r1 { position: absolute; inset: 0; border-radius: 50%; border: 2px dashed var(--teal-d); }
.core .r2 { position: absolute; inset: 7px; border-radius: 50%; border: 2px solid transparent; border-top-color: var(--teal); border-right-color: var(--teal); }
.core .orb { position: absolute; inset: -4px; }
.core .orb i { position: absolute; top: 0; left: 50%; width: 6px; height: 6px; margin-left: -3px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 8px var(--blue); }
.core .heart { position: absolute; inset: 15px; border-radius: 50%; background: var(--core); border: 1px solid var(--teal); overflow: hidden;
  display: flex; align-items: center; justify-content: center; font-family: var(--ar); font-weight: 700; font-size: 11px; color: var(--teal); }
.core .heart .sweep { position: absolute; inset: 0; border-radius: 50%; }
.core .heart b { position: relative; }
.core.big { width: 84px; height: 84px; }
.core.big .r2 { inset: 10px; }
.core.big .heart { inset: 22px; font-size: 13px; }

/* --- home cards ------------------------------------------------------------------------ */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 20px; }
.agent-card { display: block; text-decoration: none; color: inherit; background: var(--panel); border: 1px solid var(--line2); border-radius: 14px; padding: 22px;
  transition: transform .25s ease, border-color .25s ease, box-shadow .25s ease; }
.agent-card:hover { color: inherit; transform: translateY(-4px); border-color: var(--teal); box-shadow: 0 0 0 1px rgba(127,231,214,.4), 0 16px 50px rgba(127,231,214,.12); }
.agent-card .top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.agent-card .who { display: flex; gap: 14px; align-items: center; }
.agent-card .name { font-size: 22px; font-weight: 700; }
.agent-card .role { font-size: 13px; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 18px; }
.stat { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.stat .k { font-family: var(--mono); font-size: 10px; color: var(--muted); text-transform: uppercase; }
.stat .v { font-size: 20px; font-weight: 700; }
.stat.warn .v { color: var(--amber); }
.agent-card .foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-top: 16px; padding-top: 12px;
  border-top: 1px dashed var(--line2); font-family: var(--mono); font-size: 12px; color: var(--muted); }
.agent-card .foot .go { color: var(--teal); }
.dot { position: relative; width: 8px; height: 8px; flex: none; display: inline-block; }
.dot i { position: absolute; inset: 0; border-radius: 50%; background: var(--teal); }
.dot i.ping { animation: ping 2.2s ease-out infinite; }

/* --- message flow (agent header) ------------------------------------------------------- */
.flow { display: flex; align-items: center; flex-wrap: wrap; row-gap: 12px; background: var(--panel2); border: 1px solid var(--line); border-radius: 14px; padding: 14px 18px; margin-bottom: 20px; }
.flow .col { display: flex; flex-direction: column; gap: 5px; }
.flow .wire { flex: 1 1 100px; position: relative; height: 2px; margin: 0 14px; background: var(--line); }
.flow .wire .glowline { position: absolute; inset: 0; background: var(--teal-d); animation: glowline 2.8s ease-in-out infinite; }
.flow .wire.b .glowline { background: var(--blue-d); }
.packet { position: absolute; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 12px var(--teal); animation: travel 2.8s linear infinite; }
.flow .wire.b .packet { background: var(--blue); box-shadow: 0 0 12px var(--blue); }
.packet.d1 { animation-delay: -.9s; } .packet.d2 { animation-delay: -1.9s; }
.flow .hub { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-radius: 12px; border: 1px solid var(--teal-d); background: var(--teal-bg); }
.flow .hub .beat { width: 12px; height: 12px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 14px var(--teal); }
.chip.blue { border-color: var(--blue-d); color: var(--blue); }
.chip.amber { border-color: var(--amber-d); color: var(--amber); }

/* --- agent page header + tabs ---------------------------------------------------------- */
.agent-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.agent-head .who { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.agent-head .title { font-size: 30px; font-weight: 700; }
.back { font-family: var(--mono); font-size: 13px; text-decoration: none; }
.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.tabs a { min-height: 44px; padding: 0 12px; display: flex; align-items: center; font-family: var(--mono); font-size: 13px; color: var(--muted);
  text-decoration: none; border-bottom: 2px solid transparent; }
.tabs a:hover { color: var(--ink); }
.tabs a.on { color: var(--ink); border-bottom-color: var(--teal); }
.tabs a .n { margin-left: 6px; color: var(--amber); }

/* --- chat ------------------------------------------------------------------------------ */
.chatlog { display: flex; flex-direction: column; gap: 14px; min-height: 280px; max-height: 64vh; overflow-y: auto; padding: 6px 2px; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 12px; font-size: 15px; line-height: 1.6; }
.msg .txt { white-space: pre-wrap; unicode-bidi: plaintext; overflow-wrap: anywhere; font-family: var(--ar); }
.msg .who { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.msg.me { align-self: flex-start; background: #151C24; border: 1px solid var(--line3); }
.msg.agent { align-self: flex-end; background: var(--core); border: 1px solid var(--teal-d); }
.msg .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; direction: ltr; }
.trace { margin-top: 6px; font-size: 12px; color: var(--muted); direction: ltr; text-align: left; }
.trace summary { cursor: pointer; font-family: var(--mono); }
.trace pre { white-space: pre-wrap; font-size: 11px; margin: 4px 0; max-height: 220px; overflow: auto; background: var(--field); border: 1px solid var(--line); border-radius: 6px; padding: 6px; }
.fb { margin-top: 10px; display: grid; gap: 8px; direction: ltr; }
.fb textarea { min-height: 70px; }
.done { margin-top: 8px; font-size: 13px; direction: ltr; }
.done.ok { color: var(--teal); }
.done.corrected { color: var(--blue); }
.typing { align-self: flex-end; font-family: var(--mono); font-size: 12px; color: var(--teal); }
.composer { display: flex; gap: 10px; margin-top: 14px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 48px; max-height: 180px; }
ol.how { margin: 10px 0 0; padding-left: 18px; color: var(--ink2); font-size: 14px; line-height: 1.7; }

/* --- lists ----------------------------------------------------------------------------- */
.item { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; background: var(--field); }
.item.retired { opacity: .6; }
.item .body { font-size: 14px; line-height: 1.6; white-space: pre-wrap; unicode-bidi: plaintext; overflow-wrap: anywhere; }
.item .sub { margin-top: 6px; font-size: 13px; color: var(--ink2); white-space: pre-wrap; unicode-bidi: plaintext; }
.item .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.item .acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.item .k { font-family: var(--mono); font-size: 11px; color: var(--muted); text-transform: uppercase; margin-top: 8px; }
.hist { margin-top: 10px; border-top: 1px dashed var(--line2); padding-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.hist .h { font-size: 13px; }
.hist .h .when { font-family: var(--mono); font-size: 11px; color: var(--muted); }
blockquote.q { margin: 4px 0; padding: 6px 12px; border-inline-start: 2px solid var(--teal-d); color: var(--ink2); font-size: 14px; white-space: pre-wrap; unicode-bidi: plaintext; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* --- jobs / progress ------------------------------------------------------------------- */
.job { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--field); margin-top: 12px; }
.progress { margin-top: 8px; height: 5px; border-radius: 5px; background: #1A222B; overflow: hidden; }
.progress > div { position: relative; overflow: hidden; height: 100%; width: 0; background: var(--blue); transition: width .4s ease; }
.progress > div.done { background: var(--teal); }
.progress > div.failed { background: var(--red); }
.shimmer { position: absolute; top: 0; bottom: 0; width: 35%; background: linear-gradient(90deg, transparent, rgba(255,255,255,.5), transparent); animation: shimmer 1.8s ease-in-out infinite; }
.score { display: flex; align-items: center; gap: 16px; }
.ring { position: relative; width: 68px; height: 68px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; }
.ring > span { position: relative; width: 56px; height: 56px; border-radius: 50%; background: var(--panel); display: flex; align-items: center; justify-content: center; font-weight: 700; }

/* --- tables ---------------------------------------------------------------------------- */
.tablebox { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-family: var(--mono); font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; background: var(--panel2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
td .pre { max-width: 420px; }

.big-number { font-size: 34px; font-weight: 700; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kv > div { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.kv .k { font-family: var(--mono); font-size: 11px; color: var(--muted); text-transform: uppercase; }
.kv .v { font-size: 22px; font-weight: 700; margin-top: 4px; }

/* --- phones ---------------------------------------------------------------------------- */
@media (max-width: 640px) {
  main { padding: 18px 12px 50px; }
  .topbar { padding: 10px 12px; }
  .bars { display: none; }
  h1 { font-size: 26px; }
  .agent-head .title { font-size: 24px; }
  .msg { max-width: 94%; }
  .flow { display: none; }
  .card { padding: 14px; }
  .tabs a { padding: 0 8px; font-size: 12px; }
}

/* --- login: the agents hub (not one agent's core) ---------------------------------------- */
.agents-hub { position: relative; width: 150px; height: 150px; margin: 0 auto 14px; }
.agents-hub .ring { position: absolute; border-radius: 50%; border: 1px dashed var(--line, #2a3a3a); }
.agents-hub .ring.a { inset: 0; animation: spin 40s linear infinite; }
.agents-hub .ring.b { inset: 22px; border-style: solid; border-color: transparent; border-top-color: var(--blue-d); border-bottom-color: var(--teal-d); animation: spinr 14s linear infinite; }
.agents-hub .arm { position: absolute; inset: 0; }
.agents-hub .arm.s1 { animation: spin 9s linear infinite; }
.agents-hub .arm.s2 { animation: spin 13s linear infinite reverse; }
.agents-hub .arm.s3 { animation: spin 17s linear infinite; }
.agents-hub .arm.s4 { animation: spin 22s linear infinite reverse; }
.agents-hub .arm i { position: absolute; left: 50%; width: 12px; height: 12px; margin-left: -6px; border-radius: 4px; }
.agents-hub .arm.s1 i { top: -2px; background: var(--teal); box-shadow: 0 0 10px var(--teal); }
.agents-hub .arm.s2 i { top: 20px; background: var(--blue); box-shadow: 0 0 10px var(--blue); }
.agents-hub .arm.s3 i { bottom: -2px; background: var(--amber); box-shadow: 0 0 10px var(--amber); }
.agents-hub .arm.s4 i { bottom: 20px; width: 9px; height: 9px; margin-left: -4px; background: var(--muted, #8a9a9a); opacity: .7; }
.agents-hub .arm i::after { content: ""; position: absolute; left: 50%; top: 100%; width: 1px; height: 52px; margin-left: -.5px;
  background: linear-gradient(currentColor, transparent); color: inherit; opacity: .35; animation: glowline 2.4s ease-in-out infinite; }
.agents-hub .arm.s3 i::after, .agents-hub .arm.s4 i::after { top: auto; bottom: 100%; background: linear-gradient(transparent, currentColor); }
.agents-hub .center { position: absolute; inset: 52px; border-radius: 12px; background: var(--core); border: 1px solid var(--teal-d);
  display: flex; align-items: center; justify-content: center; font-family: "JetBrains Mono", monospace; font-size: 10px;
  letter-spacing: .14em; color: var(--teal); }
.agents-hub .center::before { content: ""; position: absolute; inset: -6px; border-radius: 16px; border: 1px solid var(--teal); opacity: 0;
  animation: ping 3s ease-out infinite; }
@media (prefers-reduced-motion: reduce) { .agents-hub * { animation: none !important; } }
