/* Agent Chat widget — slide-out side panel.
   All rules scoped under #ac-root / .ac- to avoid clashing with the
   dashboard's own styles. */

#ac-root,
#ac-root * { box-sizing: border-box; }

#ac-root {
  --ac-bg: #0a0c0f;
  --ac-panel: #0f1318;
  --ac-elev: #151a21;
  --ac-line: #1e2630;
  --ac-line-soft: #161c24;
  --ac-text: #d6dde4;
  --ac-dim: #6b7682;
  --ac-faint: #424c57;
  --ac-accent: #4ade80;
  --ac-accent-dim: #1f7a45;
  --ac-user: #7dd3fc;
  --ac-danger: #f87171;
  --ac-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --ac-sans: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  font-family: var(--ac-sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ---- Toggle button ---- */
#ac-toggle {
  position: fixed;
  right: 22px;
  bottom: 26px;
  z-index: 99998;
  font-family: var(--ac-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--ac-bg);
  background: var(--ac-accent);
  border: none;
  border-radius: 24px;
  padding: 12px 20px;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(74, 222, 128, 0.28);
  transition: transform 0.18s ease, opacity 0.18s ease;
}
#ac-toggle:hover { transform: translateY(-2px); }
#ac-root.ac-is-open #ac-toggle { opacity: 0; pointer-events: none; }

/* ---- Panel ---- */
#ac-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 410px;
  max-width: 100vw;
  z-index: 99999;
  background: var(--ac-bg);
  border-left: 1px solid var(--ac-line);
  box-shadow: -24px 0 60px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  color: var(--ac-text);
}
#ac-root.ac-is-open #ac-panel { transform: translateX(0); }

/* ---- Header ---- */
.ac-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--ac-line-soft);
}
.ac-brand {
  font-family: var(--ac-mono);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--ac-text);
  flex: 0 0 auto;
}
.ac-brand b { color: var(--ac-accent); font-weight: 700; }
.ac-session-select {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--ac-panel);
  color: var(--ac-text);
  border: 1px solid var(--ac-line);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: var(--ac-mono);
  font-size: 11px;
  outline: none;
}
.ac-icon-btn {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border: 1px solid var(--ac-line);
  background: var(--ac-panel);
  color: var(--ac-text);
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: all 0.13s ease;
}
.ac-icon-btn:hover { border-color: var(--ac-accent-dim); color: var(--ac-accent); }
.ac-icon-btn.ac-close { font-size: 18px; }
.ac-icon-btn.ac-del:hover { border-color: var(--ac-danger); color: var(--ac-danger); }
.ac-icon-btn:disabled { opacity: 0.3; cursor: default; }
.ac-icon-btn:disabled:hover { border-color: var(--ac-line); color: var(--ac-text); }

.ac-agent-line {
  padding: 9px 16px;
  border-bottom: 1px solid var(--ac-line-soft);
  font-size: 12px;
  color: var(--ac-dim);
}
.ac-agent-line b {
  font-family: var(--ac-mono);
  color: var(--ac-text);
  font-weight: 600;
}

/* ---- Model bar ---- */
.ac-modelbar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--ac-line-soft);
}
.ac-modellabel {
  font-family: var(--ac-mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  color: var(--ac-faint);
  flex: 0 0 auto;
}
.ac-model-current {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--ac-accent);
  font-family: var(--ac-mono);
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ac-usage {
  flex: 0 0 auto;
  font-family: var(--ac-mono);
  font-size: 10.5px;
  color: var(--ac-dim);
  letter-spacing: 0.04em;
  min-width: 0;
  white-space: nowrap;
}

/* ---- Messages ---- */
.ac-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.ac-empty {
  margin: auto;
  text-align: center;
  color: var(--ac-faint);
  font-family: var(--ac-mono);
  font-size: 12px;
  line-height: 1.7;
}

.ac-row { display: flex; }
.ac-row.ac-user { justify-content: flex-end; }
.ac-bubble { max-width: 90%; }
.ac-row.ac-user .ac-bubble { max-width: 85%; }

.ac-tag {
  font-family: var(--ac-mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ac-faint);
  margin-bottom: 4px;
}
.ac-row.ac-user .ac-tag { text-align: right; color: var(--ac-user); opacity: 0.7; }

.ac-content {
  white-space: pre-wrap;
  line-height: 1.6;
  word-break: break-word;
  border-radius: 9px;
  padding: 11px 13px;
  font-size: 13.5px;
}
.ac-row.ac-assistant .ac-content {
  background: var(--ac-panel);
  border: 1px solid var(--ac-line-soft);
}
.ac-row.ac-user .ac-content {
  background: rgba(125, 211, 252, 0.06);
  border: 1px solid rgba(125, 211, 252, 0.18);
  color: #e3eef6;
}
.ac-caret { color: var(--ac-accent); animation: ac-blink 1s steps(2) infinite; }
@keyframes ac-blink { 50% { opacity: 0; } }

.ac-status {
  font-family: var(--ac-mono);
  font-size: 11.5px;
  color: var(--ac-accent);
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.04em;
}
.ac-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ac-accent);
  box-shadow: 0 0 8px var(--ac-accent);
  animation: ac-pulse 1.1s ease-in-out infinite;
}
@keyframes ac-pulse { 0%,100% { opacity: 0.4; } 50% { opacity: 1; } }

/* ---- Composer ---- */
.ac-composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--ac-line-soft);
}
.ac-composer textarea {
  flex: 1;
  resize: none;
  background: var(--ac-panel);
  border: 1px solid var(--ac-line);
  border-radius: 8px;
  color: var(--ac-text);
  font-family: var(--ac-sans);
  font-size: 13.5px;
  padding: 10px 12px;
  line-height: 1.45;
  max-height: 130px;
  outline: none;
  transition: border-color 0.15s;
}
.ac-composer textarea:focus { border-color: var(--ac-accent-dim); }
.ac-send {
  font-family: var(--ac-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ac-bg);
  background: var(--ac-accent);
  border: none;
  border-radius: 8px;
  padding: 0 18px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.ac-send:disabled { opacity: 0.35; cursor: default; }

/* ---- Agent picker overlay (inside panel) ---- */
.ac-picker {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: rgba(8, 10, 13, 0.92);
  backdrop-filter: blur(2px);
  display: none;
  flex-direction: column;
  padding: 18px 16px;
  gap: 10px;
  overflow-y: auto;
}
#ac-root.ac-picking .ac-picker { display: flex; }
.ac-picker-title {
  font-family: var(--ac-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ac-dim);
  margin-bottom: 4px;
}
.ac-picker-label {
  font-family: var(--ac-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ac-faint);
}
.ac-picker-field { display: flex; flex-direction: column; gap: 6px; }
.ac-picker-model {
  background: var(--ac-elev);
  color: var(--ac-accent);
  border: 1px solid var(--ac-line);
  border-radius: 7px;
  padding: 9px 10px;
  font-family: var(--ac-mono);
  font-size: 12px;
  outline: none;
  cursor: pointer;
}
.ac-picker-model optgroup { color: var(--ac-dim); font-style: normal; }
.ac-picker-model option { color: var(--ac-text); }
.ac-picker-agents { display: flex; flex-direction: column; gap: 9px; }
.ac-agent-card {
  text-align: left;
  background: var(--ac-elev);
  border: 1px solid var(--ac-line);
  border-radius: 9px;
  padding: 13px;
  cursor: pointer;
  transition: all 0.14s ease;
}
.ac-agent-card:hover { border-color: var(--ac-accent-dim); transform: translateY(-1px); }
.ac-agent-card .n { font-family: var(--ac-mono); font-weight: 700; font-size: 13px; }
.ac-agent-card .d { font-size: 11.5px; color: var(--ac-dim); margin: 5px 0 8px; line-height: 1.4; }
.ac-agent-card .m { font-family: var(--ac-mono); font-size: 10px; color: var(--ac-accent); }

#ac-root ::-webkit-scrollbar { width: 8px; }
#ac-root ::-webkit-scrollbar-thumb { background: var(--ac-line); border-radius: 6px; }
#ac-root ::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 480px) {
  #ac-panel { width: 100vw; border-left: none; }
}