/* ---------------------------------------------------------- AI chat pane */
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { gap: 4px; }
.chat-title { flex: 1; min-width: 0; font-size: var(--text-md); font-weight: 500; color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-scroll { flex: 1; min-height: 0; overflow: auto; position: relative; user-select: text; }
.msgs { display: flex; flex-direction: column; gap: 14px; padding: 16px 14px 20px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.msg.user .bubble {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 12px 12px 4px 12px;
  background: var(--raised);
  border: 1px solid var(--border);
  color: var(--text-strong);
  font-size: var(--text-md);
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-ctx { font-size: var(--text-2xs); color: var(--text-faint); }
.msg.assistant { display: flex; flex-direction: column; gap: 6px; }
.chat-md { padding: 0 2px; font-size: 13px; line-height: 1.6; }
.chat-md > :last-child { margin-bottom: 0; }
.chat-md h1, .chat-md h2, .chat-md h3 { margin-top: 0.8em; }
.chat-md h1 { font-size: 1.25em; }
.chat-md h2 { font-size: 1.12em; border: 0; padding: 0; }
.chat-md ul, .chat-md ol { padding-left: 1.3em; }

.tool-row { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--panel-2); overflow: hidden; }
.tool-head {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 6px 9px; border: 0; background: none; text-align: left;
  font-size: var(--text-sm); color: var(--text-muted);
}
.tool-head:hover { color: var(--text); background: var(--hover); }
.tool-icon { width: 20px; height: 20px; border-radius: 5px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-text); flex: none; }
.tool-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-state { display: grid; place-items: center; }
.tool-state .ok { color: var(--success); }
.tool-state .bad { color: var(--danger); }
.tool-chev { color: var(--text-faint); transition: transform var(--fast); }
.tool-row.open .tool-chev { transform: rotate(90deg); }
.tool-body { border-top: 1px solid var(--divider); padding: 8px 10px; display: grid; gap: 8px; }
.tool-body b { font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); }
.tool-body pre { margin: 4px 0 0; font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow: auto; }

.typing { display: flex; gap: 4px; padding: 6px 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

.chat-error { margin: 0 14px 14px; display: flex; gap: 8px; align-items: flex-start; padding: 9px 11px; border-radius: var(--r-md); background: var(--danger-soft); color: var(--danger); font-size: var(--text-sm); }
.chat-error svg { flex: none; margin-top: 2px; }

.chat-empty { padding: 36px 20px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; }
.chat-empty-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-text); margin-bottom: 12px; }
.chat-empty h3 { margin: 0 0 6px; font-size: var(--text-lg); font-weight: 600; color: var(--text-strong); }
.chat-empty p { margin: 0 0 18px; font-size: var(--text-sm); color: var(--text-muted); max-width: 300px; line-height: 1.5; }
.suggestions { display: flex; flex-direction: column; gap: 6px; width: 100%; max-width: 320px; }
.suggestions button {
  text-align: left; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--panel-2); color: var(--text);
  font-size: var(--text-sm);
}
.suggestions button:hover { border-color: var(--accent-line); background: var(--accent-softer); }

/* history dropdown */
.chat-history {
  position: absolute; top: calc(100% + 6px); right: 0;
  width: 320px; z-index: 50;
  border-radius: var(--r-lg);
  background: var(--raised); border: 1px solid var(--border);
  box-shadow: var(--shadow-pop);
  padding: 6px;
  animation: pop-in 120ms var(--ease);
  transform-origin: top right;
}
[data-theme='dark'] .chat-history { background: #18191c; }
.ch-search { position: relative; margin-bottom: 6px; }
.ch-search svg { position: absolute; left: 10px; top: 9px; color: var(--text-faint); }
.ch-search input {
  width: 100%; height: 32px; padding: 0 10px 0 32px;
  border-radius: var(--r-sm); border: 1px solid var(--border);
  background: var(--input-bg); color: var(--text-strong); font-size: var(--text-sm);
}
.ch-search input:focus { border-color: var(--accent-line); box-shadow: var(--focus-ring); }
.ch-list { max-height: 340px; overflow: auto; }
.ch-item { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 6px 0 10px; border-radius: var(--r-sm); cursor: pointer; font-size: var(--text-sm); color: var(--text); }
.ch-item:hover { background: var(--hover); }
.ch-item.on { background: var(--accent-soft); color: var(--text-strong); font-weight: 500; }
.ch-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-time { font-size: var(--text-xs); color: var(--text-faint); }
.ch-del { display: none; }
.ch-item:hover .ch-del { display: inline-grid; }
.ch-item:hover .ch-time { display: none; }
.ch-empty { padding: 18px; text-align: center; color: var(--text-faint); font-size: var(--text-sm); }

/* composer */
.composer {
  flex: none; margin: 0 10px 10px;
  border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  background: var(--input-bg);
  transition: border-color var(--fast), box-shadow var(--fast);
}
.composer:focus-within { border-color: var(--accent-line); box-shadow: var(--focus-ring); }
.composer-ctx { display: flex; align-items: center; gap: 5px; padding: 8px 12px 0; font-size: var(--text-2xs); color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer-ctx b { color: var(--accent-text); font-weight: 600; }
.composer textarea {
  display: block; width: 100%; resize: none; border: 0; outline: none; background: transparent;
  padding: 6px 12px 4px; font-size: var(--text-md); line-height: 1.5; color: var(--text-strong);
  max-height: 200px; user-select: text;
}
.composer textarea::placeholder { color: var(--text-faint); }
.composer-bar { display: flex; align-items: center; gap: 6px; padding: 4px 6px 6px 8px; }
.composer-bar .spacer { flex: 1; }
.model-btn {
  display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 8px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--panel-2);
  font-size: var(--text-xs); font-weight: 500; color: var(--text-muted);
}
.model-btn:hover { color: var(--text-strong); border-color: var(--border-strong); }
.send-btn {
  width: 30px; height: 30px; border-radius: 9px; border: 0;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-fg);
  transition: background var(--fast), opacity var(--fast);
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.35; cursor: default; }
.send-btn.stop { background: var(--text-strong); color: var(--bg); }
.composer textarea:focus-visible, .ch-search input:focus-visible { box-shadow: none; }
.ch-search input:focus-visible { box-shadow: var(--focus-ring); }
.ch-running { display: inline-block; vertical-align: -2px; margin-right: 6px; width: 11px; height: 11px; border-width: 1.5px; }

/* ------------------------------------------------ right pane tabs + generations */
.right-pane { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.rp-tabs { flex: none; display: flex; gap: 2px; padding: 6px 8px 0; border-bottom: 1px solid var(--divider); }
.rp-tabs button {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border: 0; background: none; font-size: var(--text-sm); font-weight: 500; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.rp-tabs button:hover { color: var(--text-strong); }
.rp-tabs button.on { color: var(--text-strong); border-bottom-color: var(--accent); }
.rp-badge { min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px; display: inline-grid; place-items: center; font-size: 10px; font-weight: 700; }
.rp-badge.warn { background: color-mix(in srgb, var(--warning) 20%, transparent); color: var(--warning); }
.rp-badge.live { background: var(--accent-soft); color: var(--accent-text); }
.rp-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.rp-body > .chat { flex: 1; min-height: 0; }

.gens { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.gens-wallet { flex: none; display: flex; align-items: center; gap: 10px; padding: 12px 12px 10px; border-bottom: 1px solid var(--divider); }
.gw-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.gw-main { flex: 1; display: flex; flex-direction: column; line-height: 1.2; }
.gw-main small { font-size: var(--text-2xs); color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.gw-main b { font-size: var(--text-lg); color: var(--text-strong); font-weight: 600; font-variant-numeric: tabular-nums; }
.gens-bulk { flex: none; display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--divider); }
.gens-list { flex: 1; min-height: 0; overflow: auto; padding: 4px 10px 14px; }
.gens-sec { padding: 12px 2px 6px; font-size: var(--text-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-faint); }
.gens-empty { padding: 34px 16px; text-align: center; display: flex; flex-direction: column; align-items: center; }
.gens-empty h3 { margin: 0 0 6px; font-size: var(--text-md); color: var(--text-strong); }
.gens-empty p { margin: 0; font-size: var(--text-sm); color: var(--text-muted); line-height: 1.5; max-width: 300px; }
.gen-card { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--panel-2); padding: 10px 11px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 7px; }
.gen-card.s-staged { border-color: color-mix(in srgb, var(--warning) 35%, var(--border)); }
.gen-card.s-failed { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.gen-head { display: flex; align-items: center; gap: 8px; }
.gen-model { flex: 1; min-width: 0; font-size: var(--text-xs); font-weight: 600; color: var(--text-muted); font-family: var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gen-status { display: inline-flex; align-items: center; gap: 5px; font-size: var(--text-2xs); font-weight: 600; padding: 2px 7px; border-radius: 999px; background: var(--active); color: var(--text-muted); white-space: nowrap; }
.gen-status .spinner { width: 9px; height: 9px; border-width: 1.5px; }
.gen-status.s-staged { background: color-mix(in srgb, var(--warning) 15%, transparent); color: var(--warning); }
.gen-status.s-done { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.gen-status.s-failed { background: var(--danger-soft); color: var(--danger); }
.gen-prompt { font-size: var(--text-sm); color: var(--text); line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; user-select: text; }
.gen-chips { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.gen-chip { font-size: 10.5px; color: var(--text-faint); background: var(--active); border-radius: 5px; padding: 1px 6px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gen-chip b { color: var(--text-muted); font-weight: 500; }
.gen-thumb { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; border: 1px solid var(--divider); cursor: pointer; }
.gen-log { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gen-error { font-size: var(--text-xs); color: var(--danger); line-height: 1.4; }
.gen-outputs { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.gen-out { display: flex; flex-direction: column; gap: 3px; cursor: pointer; min-width: 0; }
.gen-out .gen-thumb { width: 100%; height: auto; aspect-ratio: 1; }
.gen-out span { font-size: 10px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gen-foot { display: flex; justify-content: space-between; font-size: var(--text-2xs); color: var(--text-faint); }
.gen-cost { font-variant-numeric: tabular-nums; color: var(--text-muted); font-weight: 600; }
.gen-actions { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.gen-need { font-size: var(--text-xs); color: var(--warning); }
.topup-presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.mono-text { font-family: var(--font-mono); font-size: 12px; }
.rp-tabs .grow { flex: 1; }
.rp-tabs .rp-close { align-self: center; width: 26px; height: 26px; padding: 0; margin-bottom: 4px; border-bottom: 0; }
