/* ============================================
   ai-chat.css — Chat IA (refactored, no duplicates)
   ============================================ */

/* Kill parent scroll when chat is active */
#editor-scroll.ai-chat-active { overflow: hidden !important; }
#editor-scroll.ai-chat-active #special-view { height: 100%; display: flex; flex-direction: column; }

.aic-root { display: flex; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }

/* ─── Sidebar ─────────────────────────────────── */
.aic-sidebar {
  width: 280px; flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden; background: var(--bg-2);
}
.aic-sidebar-search {
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--border);
}
.aic-search-inp {
  width: 100%; padding: 8px 12px; border-radius: 8px; box-sizing: border-box;
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-size: 13px; outline: none;
  transition: border-color 0.15s ease;
}
.aic-search-inp:focus { border-color: var(--text-3); }
.aic-search-inp::placeholder { color: var(--text-3); }

.aic-new-btn {
  margin: 10px 14px; padding: 10px 14px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
  font-size: 13px; font-weight: 500; cursor: pointer;
  text-align: center; flex-shrink: 0;
  transition: background 0.15s ease, transform 0.12s ease;
}
.aic-new-btn:hover { background: var(--bg-3); transform: translateY(-1px); }
.aic-new-btn:active { transform: translateY(0); }

.aic-list {
  flex: 1; overflow-y: auto; padding: 4px 8px 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.aic-list-item {
  display: flex; align-items: flex-start; gap: 6px;
  padding: 10px 10px 10px 12px; cursor: pointer; border-radius: 8px;
  background: transparent; color: var(--text-2);
  transition: background 0.15s ease;
  position: relative; overflow: hidden;
}
.aic-list-item:hover { background: var(--bg); }
.aic-list-item.active {
  background: var(--bg); color: var(--text);
}
.aic-list-item.active::before {
  content: ''; position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 3px; background: var(--text); border-radius: 2px;
}
.aic-list-info { flex: 1; min-width: 0; padding-right: 4px; }
.aic-list-title {
  font-size: 13px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 1.3;
}
.aic-list-meta {
  font-size: 11.5px; color: var(--text-3); margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 1.3;
}
.aic-list-acts-btn {
  width: 24px; height: 24px; border-radius: 5px;
  background: transparent; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3); opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
  flex-shrink: 0; margin-top: -1px;
}
.aic-list-item:hover .aic-list-acts-btn { opacity: 1; }
.aic-list-acts-btn:hover {
  background: var(--bg-3); color: var(--text);
}
.aic-list-empty {
  padding: 24px 14px; color: var(--text-3);
  text-align: center; font-size: 12px;
}

/* ─── Sidebar action menu (floating, NOT inline) ─────── */
.aic-acts-menu {
  position: fixed;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.16), 0 2px 6px rgba(0,0,0,0.08);
  padding: 4px; z-index: 9999;
  min-width: 200px;
  animation: aic-menu-in 0.14s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes aic-menu-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.aic-acts-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 6px; cursor: pointer;
  font-size: 13px; color: var(--text);
  transition: background 0.12s ease;
  user-select: none;
}
.aic-acts-item:hover { background: var(--bg-2); }
.aic-acts-item.danger { color: #d92d20; }
.aic-acts-item.danger:hover { background: rgba(217, 45, 32, 0.08); }
.aic-acts-icon { width: 16px; text-align: center; font-size: 13px; opacity: 0.7; }
.aic-acts-sep { height: 1px; background: var(--border); margin: 4px 6px; }

/* ─── Main column ────────────────────────────── */
.aic-main {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; min-width: 0;
}

.aic-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  flex-shrink: 0; background: var(--bg);
}
.aic-title {
  border: none; background: transparent;
  font-size: 16px; font-weight: 600; color: var(--text);
  outline: none; flex: 1; padding: 6px 10px;
  border-radius: 6px; min-width: 0;
  transition: background 0.15s ease;
}
.aic-title:hover { background: var(--bg-2); }
.aic-title:focus { background: var(--bg-2); }

/* ─── Messages area (the only scrollable) ─────── */
.aic-messages {
  flex: 1; overflow-y: auto;
  padding: 24px 24px 8px;
  display: flex; flex-direction: column; gap: 16px;
  scroll-behavior: smooth;
}

.aic-msg {
  max-width: 720px; width: 100%;
  padding: 16px 20px; border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  position: relative;
  transition: background 0.2s, border-color 0.2s;
  animation: aic-bubble-in 0.28s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}
@keyframes aic-bubble-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.aic-msg-user {
  align-self: flex-end;
  background: var(--bg-2);
  border-color: var(--border);
}
.aic-msg-assistant {
  align-self: flex-start;
  background: var(--bg);
}
.aic-msg-error {
  align-self: flex-start;
  border-style: dashed; border-color: #d92d20;
}
.aic-msg-label {
  font-size: 11px; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.6px;
  margin-bottom: 8px;
}
.aic-msg-body {
  font-size: 14.5px; line-height: 1.65; color: var(--text);
  word-break: break-word;
}
.aic-msg-body strong { font-weight: 600; }
.aic-msg-body em { font-style: italic; }
.aic-msg-body ul { padding-left: 20px; margin: 6px 0; }
.aic-msg-body li { margin: 3px 0; }

.aic-code-block {
  background: var(--bg-3); border-radius: 8px;
  padding: 12px 14px; font-family: var(--font-mono);
  font-size: 13px; overflow-x: auto;
  margin: 8px 0; white-space: pre-wrap;
}
.aic-code-inline {
  background: var(--bg-3); padding: 2px 6px; border-radius: 4px;
  font-family: var(--font-mono); font-size: 13px;
}
.aic-thinking {
  color: var(--text-3); font-style: italic;
  display: inline-flex; align-items: center; gap: 6px;
}
.aic-thinking::before {
  content: ''; display: inline-block;
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--text-3); border-top-color: var(--text);
  animation: aic-spin 0.7s linear infinite;
}
@keyframes aic-spin { to { transform: rotate(360deg); } }

.aic-alt-badge {
  font-size: 11px; color: var(--text-3); margin-top: 6px;
  padding: 3px 8px; background: var(--bg-3);
  border-radius: 99px; display: inline-block;
}

/* Message actions on hover */
.aic-msg-acts {
  display: flex; gap: 4px; flex-wrap: wrap; margin-top: 10px;
  opacity: 0; transition: opacity 0.15s ease;
}
.aic-msg:hover .aic-msg-acts { opacity: 1; }
.aic-act-btn {
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text-2); padding: 4px 10px; border-radius: 6px;
  font-size: 11.5px; cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.aic-act-btn:hover {
  background: var(--bg-2); color: var(--text); border-color: var(--text-3);
}

.aic-highlight { animation: aic-flash 1.5s ease; }
@keyframes aic-flash {
  0%, 50% { background: color-mix(in srgb, var(--text) 10%, transparent); }
  100% { background: transparent; }
}

/* Branch label */
.aic-branch-label {
  font-size: 11px; color: var(--text-3); margin-bottom: 6px;
  padding: 3px 8px; background: var(--bg-3);
  border-radius: 4px; display: inline-block;
  border-left: 2px solid var(--text-3);
}

/* Tool action cards */
.aic-tool-cards { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.aic-tool-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: var(--bg-2);
  border-radius: 10px; border: 1px solid var(--border);
  animation: aic-card-in 0.22s ease-out;
}
@keyframes aic-card-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.aic-tool-card.error { border-color: #d92d20; border-style: dashed; }
.aic-tool-status { font-size: 16px; font-weight: 600; flex-shrink: 0; }
.aic-tool-status:first-child { color: #16a34a; }
.aic-tool-card.error .aic-tool-status { color: #d92d20; }
.aic-tool-msg { font-size: 13px; color: var(--text); flex: 1; }
.aic-tool-card .aic-act-btn { flex-shrink: 0; }

/* Pending parent chip */
.aic-pending-area { flex-shrink: 0; padding: 0 24px; }
.aic-pending-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg-3); border-radius: 99px;
  padding: 6px 14px; font-size: 12px;
  color: var(--text-2); margin-bottom: 6px;
}
.aic-pending-x {
  background: transparent; border: none; color: var(--text-3);
  cursor: pointer; font-size: 14px; padding: 0 4px;
}
.aic-pending-x:hover { color: var(--text); }

/* ─── Composer ───────────────────────────────── */
.aic-composer {
  flex-shrink: 0; border-top: 1px solid var(--border);
  background: var(--bg); padding: 12px 20px 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.aic-prov-wrap {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
}
.aic-prov-sel, .aic-model-inp {
  border: 1px solid var(--border); background: var(--bg-2);
  color: var(--text-2); padding: 5px 10px; border-radius: 6px;
  font-size: 11.5px; outline: none;
}
.aic-prov-sel { cursor: pointer; }
.aic-model-inp { width: 130px; }
.aic-model-inp:focus, .aic-prov-sel:focus {
  border-color: var(--text); color: var(--text);
}
.aic-settings-link {
  font-size: 11.5px; color: var(--text-3);
  cursor: pointer; background: transparent; border: none;
  padding: 5px 8px; border-radius: 6px;
  transition: background 0.15s ease, color 0.15s ease;
}
.aic-settings-link:hover { color: var(--text); background: var(--bg-2); }

.aic-input-row {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 14px; padding: 8px 8px 8px 16px;
  transition: border-color 0.15s ease;
}
.aic-input-row:focus-within { border-color: var(--text-3); }
.aic-input {
  flex: 1; border: none; padding: 8px 0;
  font-size: 14px; color: var(--text); background: transparent;
  outline: none; resize: none; min-height: 22px; max-height: 140px;
  font-family: inherit; line-height: 1.5; overflow-y: auto;
}
.aic-input::placeholder { color: var(--text-3); }
.aic-send {
  width: 34px; height: 34px; border-radius: 8px; border: none;
  background: var(--text); color: var(--bg);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: opacity 0.15s, transform 0.15s;
}
.aic-send:hover:not(:disabled) { transform: scale(1.06); }
.aic-send:disabled { opacity: 0.25; cursor: not-allowed; }

/* ─── Confirm modal input ────────────────────── */
.aig-confirm-input {
  width: 100%; padding: 10px 14px; margin-top: 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg-2); color: var(--text); font-size: 14.5px;
  outline: none; box-sizing: border-box;
  transition: border-color 0.15s ease;
}
.aig-confirm-input:focus { border-color: var(--text-3); }

/* ─── Responsive ───────────────────────────── */
@media (max-width: 768px) {
  .aic-sidebar { display: none; }
  .aic-messages { padding: 12px; }
  .aic-msg { max-width: 100%; padding: 12px 14px; }
  .aic-composer { padding: 8px 12px; }
  .aic-input-row { padding: 6px 6px 6px 12px; }
}


/* Read tool preview */
.aic-tool-preview {
  background: var(--bg-3); border-radius: 8px;
  padding: 10px 14px; font-size: 12.5px; line-height: 1.55;
  color: var(--text-2); font-family: var(--font-mono);
  white-space: pre-wrap; word-break: break-word;
  max-height: 280px; overflow-y: auto;
  border: 1px solid var(--border);
  margin-top: -2px;
  animation: aic-card-in 0.22s ease-out;
}
