/* ===== RUDI Chat-Panel (Shared Komponente) ===== */
/* Slide-in Chat-Modal, wiederverwendbar fuer alle Module */

/* FAB - Floating Action Button (einheitlich auf allen Seiten) */
.rudi-chat-fab {
  position: fixed; bottom: 80px; right: 24px;
  width: 48px; height: 48px; border-radius: 50%;
  border: none; background: linear-gradient(135deg, #04b3d6, #0090b0);
  color: #fff; font-size: 22px; line-height: 1;
  cursor: pointer; z-index: 490;
  box-shadow: 0 4px 16px rgba(4,179,214,0.35);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.25s cubic-bezier(0.4,0,0.2,1);
}
.rudi-chat-fab:hover { transform: scale(1.08); box-shadow: 0 6px 24px rgba(4,179,214,0.45); }
.rudi-chat-fab:active { transform: scale(0.95); }
.rudi-chat-fab.hidden { opacity: 0; pointer-events: none; transform: scale(0.5); }

.rudi-chat-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 500;
  opacity: 0; visibility: hidden;
  transition: all 0.3s;
}
.rudi-chat-overlay.open { opacity: 1; visibility: visible; }

.rudi-chat-modal {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 460px; max-width: 100vw;
  background: #1a1c24;
  border-left: 1px solid rgba(255,255,255,0.1);
  z-index: 510;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: -8px 0 32px rgba(0,0,0,0.4);
}
.rudi-chat-modal.open { transform: translateX(0); }
.rudi-chat-modal.resizing { transition: none; }

.rudi-chat-resize {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 6px; cursor: col-resize; z-index: 520;
  background: transparent;
  transition: background 0.15s;
}
.rudi-chat-resize:hover, .rudi-chat-resize.active {
  background: rgba(79,195,247,0.4);
}

.rudi-chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: flex-start; gap: 12px;
  background: rgba(255,255,255,0.03);
  flex-shrink: 0;
}
.rudi-chat-back {
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.1);
  background: transparent; color: #888;
  cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.15s;
}
.rudi-chat-back:hover { background: rgba(255,255,255,0.08); color: #4fc3f7; }
.rudi-chat-header-status { font-size: 20px; margin-top: 2px; }
.rudi-chat-header-info { flex: 1; min-width: 0; }
.rudi-chat-header-ref { font-size: 14px; font-weight: 700; color: #4fc3f7; }
.rudi-chat-header-text { font-size: 12px; color: #aaa; margin-top: 4px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rudi-chat-close {
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.1);
  background: transparent; color: #888;
  cursor: pointer; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.rudi-chat-close:hover { background: rgba(255,255,255,0.08); color: #f5f5f7; }

/* History Button */
.rudi-chat-history-btn {
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.1);
  background: transparent; color: #888;
  cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.15s;
}
.rudi-chat-history-btn:hover { background: rgba(255,255,255,0.08); color: #4fc3f7; }
.rudi-chat-history-btn.active { background: rgba(79,195,247,0.15); color: #4fc3f7; border-color: rgba(79,195,247,0.3); }

/* History Panel */
.rudi-chat-history-panel {
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.15);
  max-height: 280px; overflow-y: auto;
}
.rudi-chat-history-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; position: sticky; top: 0;
  background: rgba(0,0,0,0.2); backdrop-filter: blur(10px);
  font-size: 11px; font-weight: 600; color: #888;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.rudi-chat-history-new {
  padding: 4px 10px; border-radius: 6px; border: 1px solid rgba(79,195,247,0.3);
  background: rgba(79,195,247,0.1); color: #4fc3f7;
  font-size: 11px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: all 0.15s;
}
.rudi-chat-history-new:hover { background: rgba(79,195,247,0.2); }
.rudi-chat-history-list { padding: 4px 0; }
.rudi-chat-history-item {
  padding: 10px 16px; cursor: pointer; transition: background 0.15s;
  border-left: 3px solid transparent;
}
.rudi-chat-history-item:hover { background: rgba(255,255,255,0.05); }
.rudi-chat-history-item.active {
  background: rgba(79,195,247,0.08);
  border-left-color: #4fc3f7;
}
.rudi-chat-history-item-title {
  font-size: 13px; font-weight: 500; color: #e0e0e0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rudi-chat-history-item.active .rudi-chat-history-item-title { color: #4fc3f7; }
.rudi-chat-history-item-meta {
  display: flex; gap: 8px; font-size: 10px; color: #666; margin-top: 3px;
}
.rudi-chat-history-empty {
  padding: 20px 16px; text-align: center;
  font-size: 12px; color: #555;
}

/* Kontext-Box */
.rudi-chat-context {
  padding: 12px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(79,195,247,0.04);
  flex-shrink: 0;
  max-height: 160px; overflow-y: auto;
}
.rudi-chat-context-title { font-size: 11px; font-weight: 600; color: #4fc3f7; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.rudi-chat-context-body { font-size: 12px; color: #999; line-height: 1.5; }
.rudi-chat-context-docs { margin-top: 6px; }
.rudi-chat-context-doc { font-size: 11px; color: #6a6; padding: 2px 0; }
.rudi-chat-doc-status {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 6px; font-size: 11px; font-weight: 600;
  margin-bottom: 8px;
}
.rudi-chat-doc-status.has-docs {
  background: rgba(63,185,80,0.12); color: #3fb950; border: 1px solid rgba(63,185,80,0.2);
}
.rudi-chat-doc-status.no-docs {
  background: rgba(248,81,73,0.12); color: #f85149; border: 1px solid rgba(248,81,73,0.2);
}

/* Linked Chats */
.rudi-chat-linked {
  padding: 8px 20px;
  display: none; flex-wrap: wrap; gap: 6px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.rudi-chat-linked.has-links { display: flex; }
.rudi-chat-linked-title {
  width: 100%; font-size: 10px; text-transform: uppercase;
  color: rgba(255,255,255,0.4); letter-spacing: 0.5px; margin-bottom: 2px;
}
.rudi-chat-linked-item {
  padding: 4px 10px; border-radius: 12px; font-size: 11px;
  background: rgba(129,199,132,0.1); border: 1px solid rgba(129,199,132,0.2);
  color: #81c784; cursor: pointer; text-decoration: none;
  transition: all 0.15s; white-space: nowrap;
}
.rudi-chat-linked-item:hover { background: rgba(129,199,132,0.2); border-color: #81c784; }

/* Quick-Action Chips */
.rudi-chat-chips {
  padding: 10px 20px;
  display: flex; gap: 8px; flex-wrap: wrap;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.rudi-chat-chip {
  padding: 6px 14px; border-radius: 20px;
  font-size: 12px; font-weight: 500;
  border: 1px solid rgba(79,195,247,0.2);
  background: rgba(79,195,247,0.06);
  color: #4fc3f7; cursor: pointer;
  transition: all 0.15s; white-space: nowrap;
}
.rudi-chat-chip:hover { background: rgba(79,195,247,0.15); border-color: #4fc3f7; }
.rudi-chat-chip.primary { background: rgba(79,195,247,0.15); border-color: #4fc3f7; }
.rudi-chat-chip.muted {
  opacity: 0.5; border-color: rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03); color: #888;
}
.rudi-chat-chip.muted:hover { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.12); }

/* Chat-Messages */
.rudi-chat-messages {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 16px 16px;
  display: flex; flex-direction: column; gap: 14px;
  min-width: 0; width: 100%;
}
.rudi-chat-msg {
  max-width: 92%; padding: 10px 14px;
  border-radius: 12px; font-size: 13px; line-height: 1.6;
  word-wrap: break-word; overflow-wrap: break-word;
  word-break: break-word;
  min-width: 0;
}
.rudi-chat-msg.user {
  align-self: flex-end;
  background: rgba(79,195,247,0.15);
  color: #e0e0e0;
  border-bottom-right-radius: 4px;
}
.rudi-chat-msg.assistant {
  align-self: flex-start;
  background: rgba(255,255,255,0.06);
  color: #ccc;
  border-bottom-left-radius: 4px;
}
.rudi-chat-msg.assistant p { margin: 0 0 8px; }
.rudi-chat-msg.assistant p:last-child { margin-bottom: 0; }
.rudi-chat-msg.assistant code { background: rgba(0,0,0,0.3); padding: 1px 5px; border-radius: 4px; font-size: 12px; word-break: break-all; }
.rudi-chat-msg.assistant pre { background: rgba(0,0,0,0.3); padding: 10px; border-radius: 6px; overflow-x: auto; margin: 8px 0; max-width: 100%; }
.rudi-chat-msg.assistant pre code { background: transparent; padding: 0; word-break: normal; }
.rudi-chat-msg.assistant ul, .rudi-chat-msg.assistant ol { padding-left: 18px; margin: 4px 0; }
.rudi-chat-msg.assistant li { margin-bottom: 2px; }
.rudi-chat-msg.assistant strong { color: #f5f5f7; }
.rudi-chat-msg.assistant h1, .rudi-chat-msg.assistant h2, .rudi-chat-msg.assistant h3 { margin: 10px 0 6px; color: #f5f5f7; font-weight: 600; line-height: 1.3; }
.rudi-chat-msg.assistant h1 { font-size: 16px; }
.rudi-chat-msg.assistant h2 { font-size: 15px; }
.rudi-chat-msg.assistant h3 { font-size: 14px; }
.rudi-chat-msg.assistant h1:first-child, .rudi-chat-msg.assistant h2:first-child, .rudi-chat-msg.assistant h3:first-child { margin-top: 0; }
.rudi-chat-msg.assistant a { color: #4fc3f7; text-decoration: underline; word-break: break-all; }
.rudi-chat-msg.assistant blockquote { border-left: 3px solid #4fc3f7; padding-left: 10px; margin: 8px 0; color: #999; font-style: italic; }
.rudi-chat-msg.assistant hr { border: none; border-top: 1px solid rgba(255,255,255,0.1); margin: 10px 0; }
.rudi-chat-msg.assistant .table-wrap { overflow-x: auto; margin: 8px 0; max-width: 100%; }
.rudi-chat-msg.assistant table { border-collapse: collapse; font-size: 12px; min-width: 100%; }
.rudi-chat-msg.assistant th, .rudi-chat-msg.assistant td { padding: 5px 8px; border: 1px solid rgba(255,255,255,0.1); text-align: left; white-space: nowrap; color: #e5e5e7 !important; }
.rudi-chat-msg.assistant th { background: rgba(255,255,255,0.08); color: #f5f5f7 !important; font-weight: 600; }
.rudi-chat-msg.assistant td *, .rudi-chat-msg.assistant th * { color: inherit !important; }
.rudi-chat-msg.streaming::after {
  content: ''; display: inline-block;
  width: 6px; height: 14px; background: #4fc3f7;
  margin-left: 2px; vertical-align: text-bottom;
  animation: rudi-blink 0.8s step-end infinite;
}
@keyframes rudi-blink { 50% { opacity: 0; } }

.rudi-chat-empty {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: #555; font-size: 13px; text-align: center; padding: 20px;
}

/* Tool-Status im Chat-Panel */
.rudi-chat-tool-status {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px; margin: 4px 16px;
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  font-size: 11px; color: #888;
  animation: rudi-fadeIn 0.2s ease;
}
.rudi-chat-tool-status .tool-icon { font-size: 13px; }
.rudi-chat-tool-status.running .tool-icon { animation: rudi-pulse 1.5s infinite; }
.rudi-chat-tool-status.done .tool-icon { color: #34c759; }
@keyframes rudi-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes rudi-fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Chat-Input */
.rudi-chat-input-wrap {
  padding: 12px 20px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.02);
  flex-shrink: 0;
  display: flex; gap: 10px; align-items: flex-end;
}
.rudi-chat-input {
  flex: 1; resize: none;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.05);
  color: #e0e0e0; font-size: 16px;
  font-family: inherit;
  min-height: 42px; max-height: 120px;
  outline: none;
  transition: border-color 0.15s;
}
.rudi-chat-input:focus { border-color: rgba(79,195,247,0.4); }
.rudi-chat-input::placeholder { color: #555; }
.rudi-chat-send {
  width: 42px; height: 42px; border-radius: 12px;
  border: none; background: #4fc3f7; color: #0f1117;
  cursor: pointer; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.15s;
}
.rudi-chat-send:hover { background: #81d4fa; transform: scale(1.05); }
.rudi-chat-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.rudi-chat-mic {
  width: 42px; height: 42px; border-radius: 12px;
  border: none; background: transparent; color: #888;
  cursor: pointer; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.15s;
}
.rudi-chat-mic:hover { background: rgba(255,255,255,0.08); color: #4fc3f7; }
.rudi-chat-mic.recording { color: #f44336; animation: rudi-mic-pulse 1s infinite; }
@keyframes rudi-mic-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* File Attach Button */
.rudi-chat-attach {
  background: none; border: none; color: rgba(255,255,255,0.4);
  cursor: pointer; padding: 6px; border-radius: 8px; display: flex;
  align-items: center; justify-content: center; transition: all 0.2s;
  flex-shrink: 0;
}
.rudi-chat-attach:hover { background: rgba(255,255,255,0.08); color: #4fc3f7; }

/* File Preview Bar */
.rudi-chat-file-preview {
  display: flex; gap: 8px; padding: 8px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  overflow-x: auto; flex-shrink: 0;
}
.rudi-chat-file-item {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px; padding: 6px 10px; min-width: 0; flex-shrink: 0;
  max-width: 200px;
}
.rudi-chat-file-thumb {
  width: 36px; height: 36px; border-radius: 6px; object-fit: cover; flex-shrink: 0;
}
.rudi-chat-file-icon {
  font-size: 20px; flex-shrink: 0; width: 36px; text-align: center;
}
.rudi-chat-file-info {
  display: flex; flex-direction: column; min-width: 0; gap: 1px;
}
.rudi-chat-file-name {
  font-size: 11px; color: rgba(255,255,255,0.7); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rudi-chat-file-size {
  font-size: 10px; color: rgba(255,255,255,0.35);
}
.rudi-chat-file-remove {
  background: none; border: none; color: rgba(255,255,255,0.3);
  cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 4px;
  border-radius: 4px; flex-shrink: 0; transition: all 0.2s;
}
.rudi-chat-file-remove:hover { color: #f44336; background: rgba(244,67,54,0.1); }

/* Drag over state */
.rudi-chat-messages.dragover {
  outline: 2px dashed rgba(79,195,247,0.5);
  outline-offset: -4px;
  background: rgba(79,195,247,0.03);
}

/* Mobile */
@media (max-width: 600px) {
  .rudi-chat-modal { width: 100vw !important; }
  .rudi-chat-resize { display: none; }
  .rudi-chat-header { padding: 14px 14px; }
  .rudi-chat-messages { padding: 12px 12px; }
  .rudi-chat-msg { max-width: 95%; font-size: 13px; }
  .rudi-chat-input-wrap { padding: 10px 12px 14px; gap: 8px; }
  .rudi-chat-chips { padding: 8px 12px; gap: 6px; }
  .rudi-chat-chip { padding: 5px 10px; font-size: 11px; }
  .rudi-chat-context { padding: 10px 14px; }
  .rudi-chat-attach {
    width: 40px; height: 40px; padding: 0;
    background: rgba(79,195,247,0.1);
    border-radius: 10px;
    color: #4fc3f7;
  }
  .rudi-chat-mic {
    width: 40px; height: 40px;
    background: rgba(255,255,255,0.06);
    color: #aaa;
  }
  .rudi-chat-send { width: 40px; height: 40px; }
}

/* Datumstrenner zwischen Tagen */
.rudi-chat-date-sep {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 4px;
}
.rudi-chat-date-sep::before,
.rudi-chat-date-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255,255,255,0.1);
}
.rudi-chat-date-sep span {
  font-size: 10px;
  color: #666;
  white-space: nowrap;
  letter-spacing: 0.3px;
}

/* Timestamp (in jeder Nachricht) */
.rudi-chat-timestamp {
  font-size: 10px;
  color: #666;
  margin-top: 4px;
  text-align: right;
  letter-spacing: 0.3px;
}
.rudi-chat-msg.user .rudi-chat-timestamp { color: rgba(79,195,247,0.5); }
.rudi-chat-msg.assistant .rudi-chat-timestamp { color: #555; }

/* Model-Badge (unter jeder Antwort) */
.rudi-chat-model-badge {
  display: inline-block;
  font-size: 10px;
  color: #666;
  padding: 2px 8px;
  margin-top: 4px;
  border-radius: 4px;
  background: rgba(255,255,255,0.04);
  letter-spacing: 0.5px;
}
.rudi-chat-model-badge.fallback {
  color: #ff9800;
  background: rgba(255,152,0,0.08);
}

/* CSP-konforme Helper-Klassen (loesen inline style="..." ab) */
.rudi-chat-history-panel.rudi-hidden,
.rudi-chat-file-preview.rudi-hidden { display: none; }

.rudi-chat-tool-status-container {
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: opacity 0.5s;
}
.rudi-chat-tool-status-container.fading-out { opacity: 0; }

.rudi-chat-tool-detail {
  color: #666;
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}

.rudi-chat-error-box {
  color: #ff9800;
  padding: 12px;
  background: rgba(255,152,0,0.08);
  border-radius: 8px;
  border: 1px solid rgba(255,152,0,0.2);
}
.rudi-chat-error-box a { color: #04b3d6; }
