/* pi-agent-lab chat */
:root {
  --bg: #0f1419;
  --panel: #1a222c;
  --text: #e7ecf1;
  --muted: #8b9aab;
  --accent: #3d9cf0;
  --tool: #c9a227;
  --user: #2a3542;
  --bot: #1e2a36;
  --border: #2c3848;
  --danger: #e35d6a;
  --ok: #3dba7a;
  --running: #e0a23a;
  --font: "IBM Plex Sans", "Source Han Sans SC", "Noto Sans SC", sans-serif;
  --mono: "IBM Plex Mono", "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, #1b2a3a 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #243018 0%, transparent 45%),
    var(--bg);
  color: var(--text);
}

.app {
  max-width: 960px;
  margin: 0 auto;
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 20px 16px 16px;
  gap: 14px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.header h1 { margin: 0; font-size: 1.35rem; letter-spacing: 0.02em; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 0.9rem; }
.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.tabs {
  display: flex;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  min-height: auto;
}
.tab.active {
  background: color-mix(in srgb, var(--accent) 28%, var(--panel));
  color: var(--text);
}
.meta {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  max-width: 280px;
  text-align: right;
  white-space: pre-line;
}

.view { display: grid; gap: 14px; min-height: 0; }
.view-chat {
  grid-template-rows: 1fr auto;
  min-height: calc(100vh - 120px);
}
.view-runs {
  grid-template-rows: auto 1fr;
  min-height: calc(100vh - 120px);
}
.hidden { display: none !important; }

.log {
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  overflow-y: auto;
  min-height: 360px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  border-radius: 12px;
  padding: 10px 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user { background: var(--user); align-self: flex-end; max-width: 85%; }
.msg.bot { background: var(--bot); align-self: stretch; }
.msg .role {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 4px;
  font-family: var(--mono);
}
.msg.tool {
  background: transparent;
  border: 1px dashed color-mix(in srgb, var(--tool) 55%, var(--border));
  color: #e8d59a;
  font-family: var(--mono);
  font-size: 0.82rem;
}
.msg.error {
  border: 1px solid color-mix(in srgb, var(--danger) 50%, var(--border));
  color: #ffc0c6;
  background: color-mix(in srgb, var(--danger) 12%, var(--bot));
}
.msg .meter {
  margin-top: 8px;
  font-size: 0.7rem;
  font-family: var(--mono);
  color: var(--muted);
  line-height: 1.4;
  opacity: 0.92;
}
.msg.user .meter {
  text-align: right;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}
textarea {
  width: 100%;
  resize: vertical;
  min-height: 56px;
  max-height: 180px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 12px;
  font: inherit;
}
textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  border-color: var(--accent);
}
button {
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #041018;
  font-weight: 600;
  padding: 12px 18px;
  cursor: pointer;
  min-height: 56px;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.85rem;
}
.btn-ghost:hover {
  border-color: var(--accent);
}

.runs-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.runs-toolbar-left {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.runs-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); color: var(--text); }
.chip.active {
  background: color-mix(in srgb, var(--accent) 22%, var(--panel));
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
  color: var(--text);
}
.runs-list .fail-hint {
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--danger);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.runs-hint { color: var(--muted); font-size: 0.88rem; }
.muted { color: var(--muted); }

.runs-layout {
  display: grid;
  grid-template-columns: minmax(220px, 34%) 1fr;
  gap: 12px;
  min-height: 420px;
}

.runs-list {
  list-style: none;
  margin: 0;
  padding: 6px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.runs-list li {
  border-radius: 10px;
  padding: 10px 10px;
  cursor: pointer;
  border: 1px solid transparent;
}
.runs-list li:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.runs-list li.active {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.runs-list .row1 {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin-bottom: 4px;
}
.runs-list .user-text {
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.runs-list .time {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.badge {
  font-family: var(--mono);
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.badge.running {
  color: #f0d09a;
  border-color: color-mix(in srgb, var(--running) 50%, var(--border));
}
.badge.done {
  color: #a8e6c4;
  border-color: color-mix(in srgb, var(--ok) 45%, var(--border));
}
.badge.failed {
  color: #ffc0c6;
  border-color: color-mix(in srgb, var(--danger) 50%, var(--border));
}
.badge.channel {
  text-transform: uppercase;
}

.runs-detail {
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  overflow-y: auto;
}
.runs-detail h2 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}
.runs-detail .kv {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 6px 10px;
  font-size: 0.88rem;
  margin-bottom: 14px;
}
.runs-detail .kv dt { color: var(--muted); }
.runs-detail .kv dd { margin: 0; word-break: break-word; }

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.timeline li {
  position: relative;
  padding-left: 14px;
  margin-left: 4px;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.45;
}
.timeline li::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.timeline li.err::before { background: var(--danger); }
.timeline li.tool::before { background: var(--tool); }
.timeline .ts { color: var(--muted); margin-right: 8px; }

@media (max-width: 720px) {
  .header { flex-direction: column; }
  .header-right { align-items: stretch; }
  .meta { text-align: left; max-width: none; }
  .runs-layout { grid-template-columns: 1fr; }
}


.balance {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  min-height: auto;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: right;
}
.balance:hover {
  border-color: var(--accent);
}
.balance-label {
  font-size: 0.68rem;
  color: var(--muted);
  font-family: var(--mono);
  letter-spacing: 0.04em;
}
.balance-value {
  font-family: var(--mono);
  font-size: 0.86rem;
  font-weight: 650;
}
.balance.ok .balance-value { color: #a8e6c4; }
.balance.bad .balance-value { color: #ffc0c6; }
.balance.warn .balance-value { color: #f0d09a; }


.view-memo {
  grid-template-rows: auto 1fr;
  min-height: calc(100vh - 120px);
}
.memo-panel {
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.memo-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--bot) 70%, transparent);
}
.memo-card h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}
.memo-card .row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}
.memo-meta {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.5;
}
.memo-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.memo-items li {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: start;
}
.memo-items .title {
  font-size: 0.92rem;
  font-weight: 600;
}
.memo-items .closed {
  opacity: 0.55;
}
.btn-danger {
  background: color-mix(in srgb, var(--danger) 85%, #400);
  color: #fff;
  min-height: 34px;
  padding: 6px 12px;
  font-size: 0.8rem;
}
.btn-danger:hover {
  filter: brightness(1.08);
}
