/* ─── ai-panel.css ────────────────────────────────────────────────────────────
 * AI Assistant panel: slide-in drawer, mode tabs (Chat / Agent), message
 * bubbles, code blocks with apply/diff buttons, session history, diff overlay
 * modal, and the Agent mode task list + log.
 * ─────────────────────────────────────────────────────────────────────────── */

/* ── AI button in header ─────────────────────────────────────────────────── */
#aip-toggle { color: var(--fae-color2); border-color: var(--border); }
#aip-toggle:hover { background: rgba(180,255,0,0.12); border-color: var(--fae-color2); color: #ffffff; }
#aip-toggle.active { background: rgba(180,255,0,0.1); border-color: var(--fae-color2); color: var(--fae-color2); }

/* ── Slide-in AI panel ───────────────────────────────────────────────────── */
.aip {
  position: fixed; top: 0; right: 0; bottom: 0; width: 380px;
  background: linear-gradient(180deg,
    rgba(10,10,20,0.92) 0%, rgba(15,15,30,0.88) 100%);
  backdrop-filter: blur(28px) saturate(1.4);
  -webkit-backdrop-filter: blur(28px) saturate(1.4);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 900;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(.22,.68,0,1.2);
  box-shadow: -12px 0 40px rgba(0,0,0,0.5);
  overflow: hidden;
}
.aip.open { transform: translateX(0); }

/* Drag handle on the left edge of the panel */
.aip-resize {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px; cursor: col-resize; z-index: 10;
}
.aip-resize:hover,
.aip-resize:active { background: var(--accent2); }

/* ── Panel title bar ─────────────────────────────────────────────────────── */
.aip-head {
  height: 46px; min-height: 46px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 0 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  flex-shrink: 0; gap: 8px;
}
.aip-title {
  font-size: 13px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 6px;
  letter-spacing: 0.03em; white-space: nowrap;
}
.aip-title svg { flex-shrink: 0; }
.aip-head-right { display: flex; align-items: center; gap: 4px; }
.aip-select {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 11px; border-radius: 3px; padding: 3px 5px;
  outline: none; max-width: 120px; cursor: pointer;
}
.aip-select:hover { border-color: var(--fae-color2); }
.aip-icon-btn {
  border: none; background: transparent; color: var(--muted);
  width: 28px; height: 28px; border-radius: 4px;
  cursor: pointer; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}
.aip-icon-btn:hover { background: var(--surface3); color: var(--text); }
#aip-close-btn {
  color: var(--text); font-size: 16px; font-weight: 600;
  margin-left: 4px;
  border-left: 1px solid var(--border);
  border-radius: 0; width: 32px;
}
#aip-close-btn:hover { background: var(--red); color: #fff; border-color: var(--red); }

/* ── Chat / Agent mode tab strip ─────────────────────────────────────────── */
.aip-mode-tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; background: rgba(255,255,255,0.03);
}
.aip-mode-tab {
  flex: 1; border: none; background: transparent; color: var(--muted);
  font-size: 12px; font-weight: 500; padding: 9px 0; cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.1s, border-color 0.1s;
  letter-spacing: 0.03em;
}
.aip-mode-tab:hover { color: var(--text); }
.aip-mode-tab.active { color: var(--fae-color2); border-bottom-color: var(--fae-color2); }

/* ── Context file pills bar ──────────────────────────────────────────────── */
.aip-ctx {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 6px; padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  min-height: 34px; flex-shrink: 0;
}
.aip-ctx-label { color: var(--muted); font-size: 11px; white-space: nowrap; }
.aip-ctx-pills { display: flex; gap: 5px; flex-wrap: wrap; flex: 1; }
.aip-ctx-pill {
  display: flex; align-items: center; gap: 3px;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 12px;
  padding: 2px 8px 2px 9px;
  font-size: 11px; color: var(--fae-color2);
  font-family: 'Cascadia Code', Consolas, monospace;
}
.aip-ctx-pill-x {
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 13px; line-height: 1; padding: 0;
}
.aip-ctx-pill-x:hover { color: var(--red); }
.aip-ctx-add {
  border: 1px dashed var(--border); background: transparent; color: var(--muted);
  border-radius: 12px; padding: 2px 10px; font-size: 11px; cursor: pointer;
}
.aip-ctx-add:hover { border-color: var(--fae-color2); color: var(--fae-color2); }

/* ── File picker dropdown ────────────────────────────────────────────────── */
.aip-file-picker {
  position: fixed;
  background: linear-gradient(135deg, rgba(20,20,35,0.95), rgba(15,15,28,0.95));
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.55);
  z-index: 1500; padding: 6px;
  min-width: 220px; max-height: 260px; overflow-y: auto;
}
.aip-file-picker-item {
  width: 100%; text-align: left; border: none; background: transparent;
  color: var(--text); padding: 6px 10px; font-size: 12px; cursor: pointer;
  font-family: 'Cascadia Code', Consolas, monospace;
  border-radius: 2px; display: block;
}
.aip-file-picker-item:hover { background: rgba(180,255,0,0.12); color: #fff; }
.aip-file-picker-item.selected { color: var(--accent); }

/* ── Messages list ───────────────────────────────────────────────────────── */
.aip-msgs {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column;
  padding: 12px 12px 6px; gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

/* Welcome empty state */
.aip-welcome {
  display: flex; flex-direction: column; align-items: center;
  margin: auto; gap: 14px; text-align: center; padding: 24px 16px;
}
.aip-welcome-icon { font-size: 28px; color: var(--accent); opacity: 0.8; }
.aip-welcome-text { color: var(--muted); font-size: 13px; line-height: 1.55; max-width: 260px; }

/* Individual message bubble */
.aip-msg { display: flex; flex-direction: column; gap: 3px; animation: aip-fadein 0.15s ease; }
@keyframes aip-fadein {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.aip-msg-meta { font-size: 10px; color: var(--muted); padding: 0 2px; opacity: 0.7; }
.aip-msg-user .aip-msg-meta { text-align: right; }
.aip-msg-body {
  padding: 9px 12px; border-radius: 6px;
  font-size: 12.5px; line-height: 1.55; word-break: break-word;
}
.aip-msg-user .aip-msg-body {
  background: rgba(180,255,0,0.08);
  border: 1px solid rgba(180,255,0,0.25);
  color: #eeffcc; border-bottom-right-radius: 2px;
  align-self: flex-end; max-width: 92%; white-space: pre-wrap;
}
.aip-msg-ai .aip-msg-body {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text); backdrop-filter: blur(8px);
  border-bottom-left-radius: 2px;
}
.aip-msg-loading .aip-msg-body { background: transparent; border: none; }

/* Typing indicator */
.aip-typing { display: flex; gap: 5px; align-items: center; padding: 4px 0; }
.aip-typing span {
  width: 6px; height: 6px;
  background: var(--accent); border-radius: 50%;
  animation: aip-bounce 1.1s infinite;
}
.aip-typing span:nth-child(2) { animation-delay: 0.18s; }
.aip-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes aip-bounce {
  0%,80%,100% { transform: translateY(0); opacity: .4; }
  40%          { transform: translateY(-5px); opacity: 1; }
}

/* Code block inside AI messages */
.aip-code-block {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border); border-radius: 8px;
  margin: 8px 0; overflow: hidden;
}
.aip-code-block-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 10px;
  background: rgba(255,255,255,0.05);
  border-bottom: 1px solid var(--border); gap: 8px;
}
.aip-code-lang { font-size: 10px; color: var(--muted); font-family: 'Cascadia Code', Consolas, monospace; }
.aip-code-file { font-size: 11px; color: var(--accent); font-family: 'Cascadia Code', Consolas, monospace; flex: 1; }
.aip-code-actions { display: flex; gap: 4px; }
.aip-code-btn {
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  border-radius: 2px; font-size: 10px; padding: 2px 7px; cursor: pointer;
}
.aip-code-btn:hover { background: var(--surface3); color: var(--text); }
.aip-code-btn-apply { border-color: var(--fae-color2); color: var(--fae-color2); }
.aip-code-btn-apply:hover { background: var(--fae-color2); color: #000; }

/* Apply-all footer under AI message */
.aip-apply-footer {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 0 2px; margin-top: 4px;
  border-top: 1px solid var(--border);
}
.aip-apply-btn-keep {
  background: linear-gradient(135deg, var(--fae-color1) 0%, var(--fae-color2) 100%);
  color: #000; border: none; border-radius: 3px;
  font-size: 11px; padding: 4px 12px; cursor: pointer; font-weight: 700;
  animation: faeHueRotate 5s linear infinite;
}
.aip-apply-btn-keep:hover { filter: brightness(1.1); }
.aip-apply-btn-undo {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 3px;
  font-size: 11px; padding: 4px 10px; cursor: pointer;
}
.aip-apply-btn-undo:hover { background: var(--surface3); color: var(--text); }
.aip-apply-status { font-size: 10px; color: var(--accent); margin-left: 2px; }

.aip-code-pre {
  padding: 10px 12px; margin: 0; overflow-x: auto;
  font-family: 'Cascadia Code', Consolas, monospace;
  font-size: 12px; line-height: 1.5; color: var(--text); white-space: pre;
}

/* ── Message input footer ────────────────────────────────────────────────── */
.aip-foot {
  min-height: 74px;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,0.03); backdrop-filter: blur(20px);
  display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px;
  flex-shrink: 0;
}
.aip-input-wrap { flex: 1; min-width: 0; }
.aip-input {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 13px; line-height: 1.45; padding: 8px 10px;
  outline: none; resize: none;
  font-family: 'Inter', 'Segoe UI', Tahoma, sans-serif;
  min-height: 42px; max-height: 160px; overflow-y: auto;
  transition: border-color 0.15s; backdrop-filter: blur(8px);
}
.aip-input:focus {
  border-color: rgba(180,255,0,0.4);
  box-shadow: 0 0 0 2px rgba(180,255,0,0.08);
}
.aip-input::placeholder { color: var(--border); }
.aip-send {
  width: 36px; height: 36px; border-radius: 6px; border: none;
  background: linear-gradient(135deg, var(--fae-color1) 0%, var(--fae-color2) 100%);
  color: #000; font-size: 16px; cursor: pointer; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; align-self: flex-end;
  transition: filter 0.15s;
  animation: faeHueRotate 5s linear infinite;
}
.aip-send:hover { filter: brightness(1.15); }
.aip-send:disabled { background: var(--surface3); color: var(--muted); cursor: not-allowed; }

/* ── Diff overlay modal ──────────────────────────────────────────────────── */
.aip-diff-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  z-index: 2000; display: none; align-items: center; justify-content: center;
}
.aip-diff-overlay.open { display: flex; }
.aip-diff-modal {
  background: linear-gradient(135deg, rgba(18,18,30,0.96), rgba(12,12,22,0.96));
  backdrop-filter: blur(28px); -webkit-backdrop-filter: blur(28px);
  border: 1px solid var(--border); border-radius: 14px;
  width: min(860px, 92vw); max-height: 82vh;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 80px rgba(0,0,0,0.7); overflow: hidden;
}
.aip-diff-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: rgba(255,255,255,0.04); border-bottom: 1px solid var(--border);
  gap: 12px; flex-shrink: 0;
}
.aip-diff-title { font-size: 13px; color: var(--text); }
.aip-diff-title span { color: var(--accent); font-family: 'Cascadia Code', Consolas, monospace; }
.aip-diff-actions { display: flex; gap: 8px; }
.aip-diff-body { flex: 1; overflow: auto; font-family: 'Cascadia Code', Consolas, monospace; font-size: 12px; line-height: 1.6; }

.diff-line { display: flex; padding: 0 16px; min-width: max-content; }
.diff-line-num { width: 38px; min-width: 38px; text-align: right; color: var(--muted); padding-right: 10px; user-select: none; opacity: 0.5; }
.diff-line-sig { width: 16px; min-width: 16px; text-align: center; user-select: none; }
.diff-line-text { white-space: pre; }
.diff-line-add    { background: rgba(137,209,133,0.1); color: var(--green); }
.diff-line-add .diff-line-sig    { color: var(--green); }
.diff-line-remove { background: rgba(244,135,113,0.1); color: var(--red); }
.diff-line-remove .diff-line-sig { color: var(--red); }
.diff-line-same   { color: var(--muted); opacity: 0.7; }

/* ── Session history slide-over ──────────────────────────────────────────── */
.aip-hist {
  position: absolute; inset: 0;
  background: linear-gradient(180deg,
    rgba(10,10,20,0.96) 0%, rgba(12,12,24,0.94) 100%);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  z-index: 20; display: flex; flex-direction: column;
  transform: translateX(-100%); transition: transform 0.18s ease;
}
.aip-hist.open { transform: translateX(0); }
.aip-hist-head {
  height: 46px; min-height: 46px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.04); flex-shrink: 0;
}
.aip-hist-title { font-size: 13px; font-weight: 600; color: var(--text); }
.aip-hist-list {
  flex: 1; overflow-y: auto; padding: 6px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.aip-hist-empty { padding: 32px 20px; text-align: center; color: var(--muted); font-size: 12px; }
.aip-hist-item {
  display: flex; align-items: flex-start; gap: 0; cursor: pointer;
  padding: 0; border-bottom: 1px solid var(--border);
}
.aip-hist-item:hover { background: rgba(255,255,255,0.05); }
.aip-hist-item-body {
  flex: 1; min-width: 0; padding: 9px 12px;
  display: flex; flex-direction: column; gap: 3px;
}
.aip-hist-item-title {
  font-size: 12.5px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.aip-hist-item-meta { font-size: 10px; color: var(--muted); }
.aip-hist-item-del {
  flex-shrink: 0; border: none; background: transparent; color: var(--muted);
  width: 32px; height: 46px; cursor: pointer; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.1s;
}
.aip-hist-item:hover .aip-hist-item-del { opacity: 1; }
.aip-hist-item-del:hover { color: var(--red); }
.aip-hist-item.active-session { border-left: 2px solid var(--fae-color2); }
.aip-hist-item.active-session .aip-hist-item-title { color: var(--fae-color2); }

/* ── Agent mode panel ────────────────────────────────────────────────────── */
.agent-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.agent-goal-wrap {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  flex-shrink: 0; display: flex; flex-direction: column; gap: 6px;
}
.agent-goal-label {
  font-size: 10px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600;
}
.agent-goal-input {
  width: 100%; background: var(--bg);
  border: 1px solid var(--border); border-radius: 4px;
  color: var(--text); font-size: 12.5px; line-height: 1.5; padding: 7px 10px;
  outline: none; resize: none;
  font-family: 'Segoe UI', Tahoma, sans-serif;
  min-height: 60px; max-height: 120px; overflow-y: auto; box-sizing: border-box;
}
.agent-goal-input:focus { border-color: var(--accent); }

.agent-controls { display: flex; gap: 6px; align-items: center; }
.agent-btn-start {
  flex: 1; background: #1a7f3c; border: 1px solid #1f9a49; color: #fff;
  border-radius: 3px; font-size: 12px; font-weight: 600; padding: 6px 10px; cursor: pointer;
}
.agent-btn-start:hover { background: #1f9a49; }
.agent-btn-start:disabled {
  background: #1a3d28; border-color: #1a4d2e; color: #4a8a5e; cursor: not-allowed;
}
.agent-btn-pause {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: 3px; font-size: 11px; padding: 6px 10px; cursor: pointer;
}
.agent-btn-pause:hover { color: var(--text); background: var(--surface3); }
.agent-btn-stop {
  background: transparent; border: 1px solid #6b2020; color: #c97c7c;
  border-radius: 3px; font-size: 11px; padding: 6px 10px; cursor: pointer;
}
.agent-btn-stop:hover { background: #4a1010; color: #ffaaaa; }

.agent-status-bar {
  padding: 5px 12px; font-size: 11px; color: var(--muted);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
  display: flex; align-items: center; gap: 6px; min-height: 28px;
}
.agent-status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); flex-shrink: 0;
}
.agent-status-dot.running { background: var(--green); animation: agent-pulse 1.2s infinite; }
.agent-status-dot.paused  { background: #e5a532; }
.agent-status-dot.error   { background: var(--red); }
@keyframes agent-pulse {
  0%,100% { opacity: 1; }
  50%      { opacity: 0.3; }
}

.agent-iter-badge {
  display: inline-block; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 10px; color: var(--muted); padding: 1px 7px;
}

.agent-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }

.agent-tasks-wrap { flex-shrink: 0; border-bottom: 1px solid var(--border); max-height: 220px; overflow-y: auto; }
.agent-tasks-head { display: flex; align-items: center; justify-content: space-between; padding: 7px 12px 5px; }
.agent-tasks-title {
  font-size: 10px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600;
}
.agent-task-list { list-style: none; margin: 0; padding: 0 12px 8px; display: flex; flex-direction: column; gap: 3px; }
.agent-task {
  display: flex; align-items: flex-start; gap: 7px;
  font-size: 11.5px; padding: 4px 8px; border-radius: 3px; color: var(--text);
}
.agent-task.done    { color: var(--muted); text-decoration: line-through; }
.agent-task.active  { background: rgba(180,255,0,0.08); color: #eeffcc; border-left: 2px solid var(--fae-color2); border-radius: 4px; }
.agent-task.pending { color: var(--muted); }
.agent-task.error   { color: var(--red); background: rgba(244,135,113,0.07); border-left: 2px solid var(--red); border-radius: 4px; }
.agent-task-icon    { flex-shrink: 0; font-size: 11px; margin-top: 1px; }

.agent-log {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 8px 12px; display: flex; flex-direction: column; gap: 4px;
  scrollbar-width: thin;
}
.agent-log-entry { font-size: 11px; line-height: 1.45; padding: 3px 6px; border-radius: 2px; color: var(--muted); }
.agent-log-entry.info  { color: var(--text); }
.agent-log-entry.apply { color: var(--fae-color2); background: rgba(180,255,0,0.06); border-radius: 3px; }
.agent-log-entry.error { color: #f48771; background: #2a1010; }
.agent-log-entry.step  { color: #c9c94a; }
.agent-log-entry.done  { color: var(--green); }
