/* =============================================
   KImatiX Chat – Design basierend auf kimatix.koeln
   Farben: Teal #0CD5AD, Hintergrund #F7F7F7
   ============================================= */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --teal:        #0CD5AD;
  --teal-dark:   #09b896;
  --teal-light:  #e6faf6;
  --bg:          #F7F7F7;
  --surface:     #ffffff;
  --border:      #e4e4e4;
  --text:        #1a1a1a;
  --text-muted:  #6b7280;
  --user-bg:     #1a1a1a;
  --user-text:   #ffffff;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 2px 12px rgba(12, 213, 173, 0.08);
  --shadow-md:   0 4px 24px rgba(0,0,0,0.08);
  --header-h:    60px;
  --input-max:   760px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

/* ── Header ─────────────────────────────────── */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: relative;
}

.logo {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.logo-img {
  height: 32px;
  width: auto;
  display: block;
}

.header-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
  white-space: nowrap;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d1d5db;
  transition: background 0.3s;
}

.status-dot.online  { background: var(--teal); }
.status-dot.error   { background: #ef4444; }

/* ── Main layout ─────────────────────────────── */
.main {
  padding-top: var(--header-h);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 0 1rem;
  min-height: 0;
}

/* ── Messages ────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 2rem 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* Welcome screen */
.welcome-message {
  text-align: center;
  padding: 3rem 1rem;
  margin: auto;
  max-width: 480px;
}

.welcome-icon {
  margin-bottom: 1rem;
}

.welcome-message h2 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 0.6rem;
  color: var(--text);
}

.welcome-message p {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.7;
}

/* Message rows */
.message-row {
  display: flex;
  gap: 0.75rem;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message-row.user {
  flex-direction: row-reverse;
}

/* Avatars */
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  margin-top: 2px;
}

.avatar.agent {
  background: var(--teal-light);
  color: var(--teal-dark);
  border: 1.5px solid var(--teal);
}

.avatar.user {
  background: var(--user-bg);
  color: var(--user-text);
}

/* Wrapper um Bubble + Zeitstempel */
.msg-wrapper {
  min-width: 0;
  max-width: min(70%, 600px);
  display: flex;
  flex-direction: column;
}

.message-row.user .msg-wrapper {
  align-items: flex-end;
}

/* Bubble */
.bubble {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  line-height: 1.65;
  word-break: break-word;
}

.message-row.agent .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
  box-shadow: var(--shadow);
}

.message-row.user .bubble {
  background: var(--user-bg);
  color: var(--user-text);
  border-top-right-radius: 4px;
}

/* Rich text inside agent bubble */
.bubble h1, .bubble h2, .bubble h3 {
  margin-top: 0.8em;
  margin-bottom: 0.3em;
  line-height: 1.3;
}

.bubble h1 { font-size: 1.2em; }
.bubble h2 { font-size: 1.1em; }
.bubble h3 { font-size: 1em; }

.bubble p { margin-bottom: 0.6em; }
.bubble p:last-child { margin-bottom: 0; }

.bubble ul, .bubble ol {
  padding-left: 1.4em;
  margin-bottom: 0.6em;
}

.bubble li { margin-bottom: 0.2em; }

.bubble a {
  color: var(--teal-dark);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bubble code {
  font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.88em;
  background: #f0faf8;
  border: 1px solid #c5ede6;
  border-radius: 4px;
  padding: 0.1em 0.35em;
}

.bubble pre {
  background: #f6f8fa;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  overflow-x: auto;
  margin: 0.6em 0;
}

.bubble pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.86em;
}

.bubble blockquote {
  border-left: 3px solid var(--teal);
  margin: 0.6em 0;
  padding: 0.2em 0.8em;
  color: var(--text-muted);
  background: var(--teal-light);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.6em 0;
  font-size: 0.9em;
}

.bubble th, .bubble td {
  border: 1px solid var(--border);
  padding: 0.4em 0.7em;
  text-align: left;
}

.bubble th {
  background: var(--teal-light);
  font-weight: 600;
}

.bubble tr:nth-child(even) td { background: #fafafa; }

/* Timestamp */
.msg-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  padding: 0 0.2rem;
}

.message-row.user .msg-time { text-align: right; }

/* File attachments in bubble */
.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.attachment-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  padding: 0.25rem 0.7rem;
  font-size: 0.8rem;
  color: inherit;
}

.message-row.agent .attachment-chip {
  background: var(--teal-light);
  border-color: var(--teal);
  color: var(--teal-dark);
}

.attachment-chip svg { flex-shrink: 0; }

/* Image attachments */
.msg-image {
  max-width: 280px;
  max-height: 200px;
  border-radius: var(--radius-sm);
  margin-top: 0.5rem;
  display: block;
  cursor: pointer;
  transition: opacity 0.2s;
}

.msg-image:hover { opacity: 0.9; }

/* ── Typing indicator ────────────────────────── */
.typing-indicator[hidden] { display: none; }

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0 0 0.5rem;
}

.typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.5rem 0.75rem;
}

.typing-bubble span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--teal);
  animation: bounce 1.2s infinite;
}

.typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

.typing-text {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Input area ──────────────────────────────── */
.input-area {
  padding: 0.75rem 0 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

/* File preview strip */
.file-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 0 0.6rem;
}

.preview-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--teal-light);
  border: 1px solid var(--teal);
  border-radius: 20px;
  padding: 0.25rem 0.5rem 0.25rem 0.7rem;
  font-size: 0.8rem;
  color: var(--teal-dark);
  max-width: 220px;
}

.preview-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-chip .remove-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--teal-dark);
  display: flex;
  align-items: center;
  padding: 0;
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity 0.15s;
}

.preview-chip .remove-btn:hover { opacity: 1; }

/* Input row */
.input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-row:focus-within {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(12, 213, 173, 0.12);
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--teal-light);
  color: var(--teal-dark);
}

.textarea-wrapper {
  flex: 1;
}

textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  background: transparent;
  color: var(--text);
  max-height: 160px;
  overflow-y: auto;
  padding: 0.25rem 0;
}

textarea::placeholder { color: var(--text-muted); }

.send-btn {
  background: var(--teal);
  border: none;
  cursor: pointer;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
  background: var(--teal-dark);
  transform: scale(1.05);
}

.send-btn:disabled {
  background: var(--border);
  cursor: not-allowed;
  transform: none;
}

.input-hint {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
  opacity: 0.7;
}

/* ── Toast ───────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a1a;
  color: white;
  padding: 0.6rem 1.2rem;
  border-radius: 20px;
  font-size: 0.85rem;
  z-index: 200;
  animation: toastIn 0.2s ease;
  white-space: nowrap;
}

.toast.error  { background: #ef4444; }
.toast.success { background: var(--teal-dark); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Drag & Drop overlay ─────────────────────── */
body.drag-over::after {
  content: 'Datei(en) hier ablegen';
  position: fixed;
  inset: 0;
  background: rgba(12, 213, 173, 0.15);
  border: 3px dashed var(--teal);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--teal-dark);
  z-index: 300;
  pointer-events: none;
}

/* ── Responsive ──────────────────────────────── */
@media (max-width: 600px) {
  .logo-sub { display: none; }
  .bubble { max-width: 88%; }
  .msg-image { max-width: 200px; }
}
