:root {
  --bg: #0f1115;
  --surface: #161a21;
  --surface-2: #1d222b;
  --border: #2a303b;
  --text: #e6e8ec;
  --muted: #9aa3b2;
  --accent: #4fb3a9;
  --accent-ink: #062320;
  --user: #24313f;
  --ok: #5fbf77;
  --warn: #e0b452;
  --err: #ef6b6b;
  --tool: #8fa8ff;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* The hidden attribute always wins over the display of a component (.mcp-bar, .switch, ...). */
[hidden] { display: none !important; }
/* The hidden attribute always wins over the display of a component (.mcp-bar, .switch, ...). */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  display: flex;
  flex-direction: column;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip { position: absolute; left: -999px; }
.skip:focus { left: 1rem; top: 1rem; z-index: 10; background: var(--accent); color: var(--accent-ink); padding: .4rem .8rem; border-radius: 6px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button {
  font: inherit;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: .5rem .9rem;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, transform .1s ease;
}
button:active { transform: scale(.98); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--text); border-color: var(--border); font-weight: 500; }
button.ghost:hover { background: var(--surface-2); }
button.danger { background: transparent; color: var(--err); border-color: var(--err); }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand { display: flex; align-items: center; gap: .6rem; }
.brand h1 { font-size: 1rem; margin: 0; font-weight: 650; }
.muted { color: var(--muted); font-weight: 400; }
.dot { width: .6rem; height: .6rem; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.busy { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.dot.err { background: var(--err); }
@keyframes pulse { 50% { opacity: .35; } }

.meta { display: flex; gap: 1.25rem; margin: 0; flex: 1; min-width: 0; flex-wrap: wrap; }
.meta div { min-width: 0; }
.meta dt { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.meta dd { margin: 0; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 32ch; }
.meta dd.err { color: var(--err); white-space: normal; }
.actions { display: flex; gap: .5rem; }

/* Agent selector, views and agent card */
.picker { display: flex; align-items: center; gap: .5rem; }
.picker label { font-size: .8rem; color: var(--muted); }
.picker select, .monitor-bar select, .mcp-bar select {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: .4rem .6rem; max-width: 30rem;
}
.view-tabs { display: flex; gap: .25rem; }
.view-tabs [role="tab"] { background: transparent; color: var(--muted); border-color: var(--border); font-weight: 500; }
.view-tabs [role="tab"][aria-selected="true"] { color: var(--text); background: var(--surface-2); border-color: var(--accent); }
.badge {
  display: inline-block; font-size: .72rem; padding: .1rem .5rem; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted); white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.banner { margin: 0; padding: .5rem 1.25rem; background: color-mix(in srgb, var(--warn) 15%, var(--bg)); color: var(--warn); font-size: .85rem; }
.views { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view[hidden] { display: none; }
.agent-panel { flex: 1; min-height: 0; display: flex; }
.agent-panel[hidden] { display: none; }
.boot { margin: 2rem auto; }
.console { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.agent-card {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .35rem 1rem; align-items: center;
  padding: .6rem 1.25rem; border-bottom: 1px solid var(--border); background: var(--bg);
}
.agent-title { display: flex; align-items: center; gap: .5rem; }
.agent-title h2 { margin: 0; font-size: 1rem; font-family: var(--mono); }
.agent-desc { grid-column: 1 / 2; margin: 0; font-size: .85rem; color: var(--muted); max-width: 110ch; }
.agent-card .meta { grid-column: 1 / 2; }
.agent-card .actions { grid-column: 2; grid-row: 1 / span 3; align-self: start; }
.composer { flex-direction: column; align-items: stretch; }
.composer-row { display: flex; gap: .5rem; align-items: flex-end; }
.mcp-bar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; font-size: .85rem; }
.mcp-bar label { display: flex; gap: .4rem; align-items: center; }
.mcp-bar .hint { flex: 1 1 100%; margin: 0; }
.raw-switch { font-size: .8rem; color: var(--muted); }
.user-text { margin: 0; font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Monitor */
.monitor { padding: 1rem 1.25rem; overflow: auto; }
.monitor-bar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.monitor-bar h2 { margin: 0; font-size: 1rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.agents-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.agents-table th, .agents-table td { padding: .45rem .7rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.agents-table thead th { background: var(--surface); color: var(--muted); font-weight: 600; position: sticky; top: 0; }
.agents-table tbody tr:hover { background: var(--surface); }
.agents-table .err { color: var(--err); font-weight: 600; cursor: help; }
.mono { font-family: var(--mono); }
button.small { padding: .25rem .6rem; font-size: .8rem; }

/* Layout */
.layout {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 1fr);
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) minmax(0, 40vh); }
}

/* Chat */
.chat { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); }
.messages { flex: 1; overflow-y: auto; padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.empty { color: var(--muted); max-width: 60ch; margin: auto; text-align: center; }
.examples { list-style: none; padding: 0; display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.example {
  width: 100%; text-align: left; background: var(--surface); color: var(--text);
  border-color: var(--border); font-weight: 400;
}
.example:hover { border-color: var(--accent); }

.msg { max-width: 85%; padding: .7rem .95rem; border-radius: var(--radius); overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); white-space: pre-wrap; }
.msg.agent { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); }
.msg.agent.streaming::after { content: "▍"; color: var(--accent); animation: pulse 1s steps(2) infinite; }
.msg .who { display: block; font-size: .72rem; color: var(--muted); margin-bottom: .25rem; text-transform: uppercase; letter-spacing: .05em; }
.msg .footer { display: block; font-size: .75rem; color: var(--muted); margin-top: .5rem; }
.msg .err { color: var(--err); }
.msg p { margin: .4rem 0; }
.msg ul, .msg ol { margin: .4rem 0; padding-left: 1.3rem; }
.msg h3, .msg h4 { margin: .7rem 0 .3rem; font-size: 1rem; }
.msg code { font-family: var(--mono); font-size: .85em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
.msg pre { background: var(--bg); border: 1px solid var(--border); padding: .6rem; border-radius: 6px; overflow-x: auto; }
.msg pre code { background: none; padding: 0; }
.msg a { color: var(--accent); }
.msg table { border-collapse: collapse; font-size: .9em; margin: .4rem 0; }
.msg th, .msg td { border: 1px solid var(--border); padding: .25rem .5rem; text-align: left; }
.tool-chip {
  display: inline-block; font: .75rem var(--mono); color: var(--tool);
  border: 1px solid color-mix(in srgb, var(--tool) 40%, transparent);
  border-radius: 999px; padding: .05rem .5rem; margin: .2rem .25rem .2rem 0;
}

.composer {
  display: flex; gap: .5rem;
  padding: .9rem 1.25rem; border-top: 1px solid var(--border); background: var(--surface);
}
.composer textarea {
  flex: 1; resize: vertical; min-height: 2.8rem; max-height: 30vh;
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: .6rem .75rem;
}

/* Activity */
.activity { display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.activity-head { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
.activity-head h2 { font-size: .95rem; margin: 0; }
.tabs { display: flex; gap: .25rem; }
.tabs [role="tab"] { background: transparent; color: var(--muted); border-color: transparent; font-weight: 500; padding: .35rem .7rem; }
.tabs [role="tab"][aria-selected="true"] { color: var(--text); border-color: var(--border); background: var(--surface-2); }
.panel { flex: 1; min-height: 0; overflow-y: auto; padding: .75rem 1rem; }
.hint { color: var(--muted); font-size: .85rem; }

.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.timeline li {
  display: grid; grid-template-columns: 4.5rem 1.2rem minmax(0, 1fr); gap: .4rem;
  font-size: .85rem; align-items: start;
}
.timeline time { color: var(--muted); font: .75rem var(--mono); padding-top: .15rem; }
.timeline .icon { text-align: center; }
.timeline .body { min-width: 0; overflow-wrap: anywhere; }
.timeline .turn { grid-column: 1 / -1; margin-top: .6rem; padding-top: .5rem; border-top: 1px dashed var(--border); color: var(--muted); font-size: .8rem; }
.timeline .turn:first-child { margin-top: 0; border-top: 0; }
.timeline li.turn { display: block; }
.timeline .tool .name { font-family: var(--mono); color: var(--tool); }
.timeline .tool .dur { color: var(--muted); font-size: .75rem; margin-left: .4rem; }
.timeline .progress .body { font-family: var(--mono); font-size: .78rem; color: var(--text); white-space: pre-wrap; }
.timeline .error .body { color: var(--err); }
.timeline .meta-ev .body { color: var(--muted); }
.timeline details summary { cursor: pointer; color: var(--muted); }

.logs-toolbar { display: flex; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.logs-toolbar input[type="search"] {
  flex: 1; font: inherit; font-size: .85rem; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; padding: .35rem .6rem;
}
.switch { display: flex; align-items: center; gap: .35rem; font-size: .85rem; white-space: nowrap; }
.logs {
  margin: 0; font: .75rem/1.45 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: .6rem; min-height: 8rem;
}
.logs .ts { color: var(--muted); }
.logs .lvl-error { color: var(--err); }
.logs .lvl-warn { color: var(--warn); }

@media (prefers-reduced-motion: reduce) {
  *, *::after { animation: none !important; transition: none !important; }
}

/* Logout link (agent-tester) styled as a ghost button */
a.button-link {
  font-size: .9rem; color: var(--text); text-decoration: none;
  border: 1px solid var(--border); border-radius: 8px; padding: .45rem .9rem;
}
a.button-link:hover { background: var(--surface-2); }

/* Login page (agent-tester) */
.login { flex: 1; display: grid; place-items: center; padding: 1.5rem; }
.login-card {
  width: min(100%, 22rem); display: flex; flex-direction: column; gap: 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.75rem;
}
.login-card h1 { font-size: 1.1rem; margin: 0; }
.login-card label { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; color: var(--muted); }
.login-card input {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: .55rem .7rem;
}
.login-card .login-error { margin: 0; color: var(--err); font-size: .9rem; min-height: 1.35em; }
