/* ══════════════════════════════════════════════════════════════════
   KI CHAT
══════════════════════════════════════════════════════════════════ */

.ai-chat-wrap {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.ai-chat-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Left sidebar ── */
.ai-sidebar {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  background: var(--panel-soft, #f5f7fa);
  overflow: hidden;
}

.ai-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
}

.ai-sidebar-title {
  font-weight: 700;
  font-size: .9rem;
}

.ai-sidebar-section-label {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted, #7a86a4);
  padding: 8px 12px 4px;
  border-top: 1px solid var(--panel-border);
  flex-shrink: 0;
}

.ai-projects-list {
  padding: 6px;
  flex-shrink: 0;
}

.ai-project-item {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 7px 8px;
  border-radius: 9px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: .85rem;
  color: inherit;
  text-align: left;
  transition: background .12s;
}
.ai-project-item:hover { background: var(--panel-border); }
.ai-project-item.active { background: var(--accent, #0d63d6); color: #fff; }

.ai-proj-icon { font-size: 1rem; flex-shrink: 0; }
.ai-proj-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ai-convs-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ai-conv-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  padding: 6px 28px 6px 8px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: .78rem;
  color: inherit;
  text-align: left;
  transition: background .12s;
}
.ai-conv-item:hover { background: var(--panel-border); }
.ai-conv-item.active { background: rgba(13,99,214,.12); }

.ai-conv-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
  font-weight: 500;
}
.ai-conv-date { color: var(--muted); font-size: .7rem; }

.ai-conv-delete {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-size: .75rem;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity .15s;
}
.ai-conv-item:hover .ai-conv-delete { opacity: 1; }
.ai-conv-delete:hover { color: var(--danger, #e53e3e); background: rgba(229,62,62,.1); }

/* ── Chat main area ── */
.ai-chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.ai-messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.ai-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--muted);
}
.ai-welcome-icon { font-size: 3rem; }
.ai-welcome-text { font-size: .95rem; }

.ai-profile-required {
  margin: auto;
  max-width: 420px;
  padding: 24px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel-soft);
  text-align: center;
}
.ai-profile-required-title {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 8px;
}
.ai-profile-required-text {
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.45;
  margin-bottom: 14px;
}

.ai-profile-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.ai-profile-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--muted);
}
.ai-profile-field-wide { grid-column: 1 / -1; }
.ai-profile-field textarea {
  width: 100%;
  resize: vertical;
  padding: 10px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel-soft);
  color: inherit;
  font: inherit;
  font-size: .9rem;
}

/* ── Context tool panel ── */
.ai-tool-panel {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid var(--panel-border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.ai-tool-title {
  padding: 12px;
  font-weight: 700;
  font-size: .88rem;
  border-bottom: 1px solid var(--panel-border);
}
.ai-tool-search {
  margin: 10px;
  width: calc(100% - 20px);
}
.ai-template-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ai-template-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 8px 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.ai-template-item:hover { background: var(--panel-soft); }
.ai-template-item.active {
  border-color: var(--accent);
  background: rgba(13,99,214,.10);
}
.ai-template-item span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  font-size: .82rem;
}
.ai-template-item small {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: .72rem;
}
.ai-template-detail {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 0 10px 10px;
  padding: 10px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font-size: .78rem;
  background: var(--panel-soft);
}
.ai-template-detail span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}
.ai-template-detail.muted,
.ai-tool-empty {
  color: var(--muted);
  font-size: .8rem;
}
#ai-template-apply-btn {
  margin: 0 10px 10px;
}

.ai-data-board-list {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ai-data-board {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel-soft);
  cursor: pointer;
  font-size: .84rem;
}

/* ── Translate workspace ── */
.ai-translate-workspace {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  gap: 12px;
}
.ai-translate-toolbar {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}
.ai-translate-toolbar label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: .75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.ai-translate-columns {
  flex: 1;
  min-height: 360px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}
.ai-translate-columns textarea,
.ai-translate-output {
  width: 100%;
  min-height: 100%;
  padding: 14px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel-soft);
  color: inherit;
  font: inherit;
  font-size: .92rem;
  line-height: 1.5;
  overflow: auto;
}
.ai-translate-columns textarea {
  resize: none;
}

/* Message bubbles */
.ai-msg {
  max-width: 80%;
  border-radius: 14px;
  padding: 10px 14px;
  line-height: 1.55;
  font-size: .9rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.ai-msg-user {
  align-self: flex-end;
  background: var(--accent, #0d63d6);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-msg-assistant {
  align-self: flex-start;
  background: var(--panel-soft, #f5f7fa);
  border: 1px solid var(--panel-border);
  border-bottom-left-radius: 4px;
}
.ai-msg.streaming::after {
  content: '▋';
  animation: ai-blink .7s infinite;
  margin-left: 1px;
}
@keyframes ai-blink { 0%, 100% { opacity: 1 } 50% { opacity: 0 } }

/* Markdown in assistant messages */
.ai-msg-assistant h2, .ai-msg-assistant h3, .ai-msg-assistant h4 {
  margin: .6em 0 .2em;
  font-size: 1em;
  font-weight: 700;
}
.ai-msg-assistant ul { margin: .4em 0 .4em 1.2em; padding: 0; }
.ai-msg-assistant li { margin-bottom: 2px; }
.ai-msg-assistant br { display: block; content: ''; margin: 2px 0; }
.ai-code-block {
  background: #1e2535;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 6px 0;
  overflow-x: auto;
  font-family: 'Courier New', monospace;
  font-size: .82em;
  white-space: pre;
}
.ai-inline-code {
  background: rgba(0,0,0,.08);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: 'Courier New', monospace;
  font-size: .88em;
}
.ai-msg-user .ai-inline-code { background: rgba(255,255,255,.2); }

/* Input area */
.ai-input-area {
  border-top: 1px solid var(--panel-border);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--panel);
  flex-shrink: 0;
}

.ai-msg-counter {
  font-size: .78rem;
  color: var(--muted);
  text-align: center;
  padding: 2px 0;
}
.ai-msg-counter.warn { color: var(--danger, #e53e3e); font-weight: 600; }

.ai-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.ai-input {
  flex: 1;
  min-height: 52px;
  max-height: 200px;
  resize: none;
  overflow-y: auto;
  padding: 10px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: var(--panel-soft);
  color: inherit;
  font-family: inherit;
  font-size: .9rem;
  line-height: 1.4;
  transition: border-color .15s;
}
.ai-input:focus { outline: none; border-color: var(--accent); }

.ai-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
  font-size: 1rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Right panel ── */
.ai-right-panel {
  width: 188px;
  flex-shrink: 0;
  border-left: 1px solid var(--panel-border);
  padding: 12px 10px;
  background: var(--panel-soft);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.ai-right-section { display: flex; flex-direction: column; gap: 5px; }
.ai-right-label { font-size: .75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.ai-right-section .btn.warn { border-color: var(--danger); color: var(--danger); }

/* ── Admin Settings Modal ── */
.ai-settings-layout {
  display: flex;
  min-height: 340px;
}

.ai-providers-panel {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
}

.ai-providers-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--panel-border);
  font-weight: 600;
  font-size: .85rem;
}

.ai-providers-list {
  flex: 1;
  overflow-y: auto;
}

.ai-provider-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-bottom: 1px solid var(--panel-border);
  gap: 8px;
}
.ai-provider-row:hover { background: var(--panel-soft); }

.ai-prov-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ai-prov-name { font-weight: 600; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-prov-type { font-size: .72rem; color: var(--muted); }
.ai-prov-models { font-size: .72rem; color: var(--muted); }
.ai-prov-disabled { font-size: .7rem; color: var(--danger); font-weight: 600; }
.ai-prov-actions { display: flex; gap: 4px; flex-shrink: 0; }

.ai-provider-form-panel {
  flex: 1;
  padding: 14px;
  overflow-y: auto;
}

.ai-form-title {
  font-weight: 700;
  font-size: .95rem;
  margin-bottom: 12px;
}

/* ── Dark mode ── */
[data-theme="dark"] .ai-sidebar,
[data-theme="dark"] .ai-right-panel { background: var(--panel-soft); }
[data-theme="dark"] .ai-tool-panel { background: var(--panel); }
[data-theme="dark"] .ai-msg-assistant { background: var(--panel); }
[data-theme="dark"] .ai-input { background: var(--panel); }
[data-theme="dark"] .ai-input-area { background: var(--panel); }
[data-theme="dark"] .ai-inline-code { background: rgba(255,255,255,.12); }

/* ── Responsive ── */
@media (max-width: 900px) {
  .ai-sidebar { width: 180px; }
  .ai-tool-panel { width: 220px; }
}
@media (max-width: 700px) {
  .ai-right-panel { display: none; }
  .ai-tool-panel { width: 190px; }
}
@media (max-width: 600px) {
  .ai-chat-layout { flex-direction: column; }
  .ai-sidebar { width: 100%; height: 140px; flex-direction: row; border-right: none; border-bottom: 1px solid var(--panel-border); overflow-x: auto; }
  .ai-tool-panel { width: 100%; max-height: 220px; border-right: none; border-bottom: 1px solid var(--panel-border); }
  .ai-projects-list { display: flex; flex-direction: row; padding: 4px; }
  .ai-convs-list { flex-direction: row; }
  .ai-profile-form,
  .ai-translate-columns { grid-template-columns: 1fr; }
}

/* ══════════════════════════════════════════════════════════════════
   END KI CHAT
══════════════════════════════════════════════════════════════════ */
