/* Nia Web-Chat — EIPL Corporate Design */

:root {
  --orange: #F49E00;
  --orange-hover: #E08F00;
  --orange-light: #FFF3E0;
  --gray-text: #2D363B;
  --gray-icon: #7B909B;
  --gray-light: #CDD5D9;
  --gray-bg: #F5F6F7;
  --white: #FFFFFF;
  --red: #D32F2F;
  --green: #388E3C;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 0.2s ease;
}

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

body {
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--gray-bg);
  color: var(--gray-text);
  height: 100dvh;
  overflow: hidden;
}

.view {
  display: flex;
  height: 100dvh;
}

.view[hidden] {
  display: none;
}

/* --- Login --- */
#login-view {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--gray-bg) 0%, #E8ECEE 100%);
}

.login-container {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  margin: 20px;
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.logo-circle {
  width: 64px;
  height: 64px;
  background: var(--orange);
  color: var(--white);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 12px;
}

.logo-img {
  width: 160px;
  height: auto;
  border-radius: 16px;
  
  
  margin-bottom: 12px;
  box-shadow: var(--shadow-md);
}

.login-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--gray-text);
}

.subtitle {
  color: var(--gray-icon);
  font-size: 14px;
  margin-top: 4px;
}

.login-step {
  display: none;
}

.login-step.active {
  display: block;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-icon);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--gray-light);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 15px;
  color: var(--gray-text);
  transition: border-color var(--transition);
  outline: none;
}

.form-group input:focus {
  border-color: var(--orange);
}

.form-group input::placeholder {
  color: var(--gray-light);
}

#twofa-code {
  font-size: 24px;
  text-align: center;
  letter-spacing: 8px;
  font-weight: 600;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--orange);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  margin-top: 8px;
}

.btn-primary:hover {
  background: var(--orange-hover);
}

.btn-primary:disabled {
  background: var(--gray-light);
  cursor: not-allowed;
}

.btn-secondary {
  width: 100%;
  padding: 10px;
  background: transparent;
  color: var(--gray-icon);
  border: 1.5px solid var(--gray-light);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: all var(--transition);
  margin-top: 8px;
}

.btn-secondary:hover {
  border-color: var(--gray-icon);
  color: var(--gray-text);
}

.error-msg {
  color: var(--red);
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
}

.twofa-info {
  text-align: center;
  color: var(--gray-icon);
  font-size: 14px;
  margin-bottom: 20px;
}

.twofa-info strong {
  color: var(--gray-text);
}

/* --- Chat View --- */
#chat-view {
  flex-direction: column;
  background: var(--white);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-light);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-circle-sm {
  width: 36px;
  height: 36px;
  background: var(--orange);
  color: var(--white);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
}

.logo-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.chat-header h2 {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
}

.header-subtitle {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-icon);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-badge {
  font-size: 14px;
  color: var(--gray-text);
  font-weight: 600;
}

.btn-icon {
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  color: var(--gray-text);
  border-radius: 6px;
  transition: all var(--transition);
  display: flex;
  align-items: center;
}

.btn-icon:hover {
  background: var(--gray-bg);
  color: var(--gray-text);
}

.eipl-header-logo {
  display: none;
}

.eipl-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 20px;
  background: var(--gray-bg);
  border-bottom: 1px solid var(--gray-light);
  flex-shrink: 0;
  min-height: 36px;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-right {
  display: flex;
  align-items: center;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--orange);
  border: 1px solid var(--orange);
  padding: 5px 16px;
  cursor: pointer;
  color: #000;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  transition: all var(--transition);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

a.toolbar-btn {
  text-decoration: none;
}

.toolbar-btn:hover {
  background: var(--orange-hover);
  border-color: var(--orange-hover);
  color: #000;
  box-shadow: 0 2px 6px rgba(244, 158, 0, 0.35);
}

.toolbar-btn.active {
  background: var(--orange-hover);
  border-color: #000;
  color: #000;
}

.eipl-logo {
  height: 78px;
  width: auto;
  opacity: 0.4;
}

/* --- Messages --- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.welcome-msg {
  text-align: center;
  padding: 40px 20px;
  margin: auto 0;
}

.logo-circle-lg {
  width: 80px;
  height: 80px;
  background: var(--orange);
  color: var(--white);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 16px;
}

.logo-img-lg {
  width: 280px;
  height: auto;
  border-radius: 20px;
  
  
  margin-bottom: 16px;
  box-shadow: var(--shadow-md);
}

.welcome-msg h3 {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 12px;
}

.welcome-msg p {
  color: var(--gray-icon);
  font-size: 16px;
  font-weight: 600;
  max-width: 400px;
  margin: 0 auto;
  line-height: 1.6;
}

.message {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: fadeIn 0.2s ease;
}

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

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

.message.assistant {
  align-self: flex-start;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.message.user .msg-avatar {
  background: var(--gray-bg);
  color: var(--gray-icon);
}

.message.assistant .msg-avatar {
  background: var(--orange);
  color: var(--white);
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.message.user .msg-bubble {
  background: var(--orange);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

.message.assistant .msg-bubble {
  background: var(--gray-bg);
  color: var(--gray-text);
  border-bottom-left-radius: 4px;
}

/* Markdown in Nachrichten */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 8px 0 4px;
}

.msg-bubble h1:first-child, .msg-bubble h2:first-child, .msg-bubble h3:first-child {
  margin-top: 0;
}

.msg-bubble p {
  margin: 4px 0;
}

.msg-bubble ul, .msg-bubble ol {
  margin: 4px 0;
  padding-left: 20px;
}

.msg-bubble li {
  margin: 2px 0;
}

.msg-bubble code {
  background: rgba(0,0,0,0.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 13px;
  font-family: 'SF Mono', 'Menlo', monospace;
}

.msg-bubble pre {
  background: rgba(0,0,0,0.06);
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
}

.msg-bubble pre code {
  background: none;
  padding: 0;
}

.msg-bubble strong {
  font-weight: 600;
}

.msg-bubble a {
  color: inherit;
  text-decoration: underline;
}

.message.user .msg-bubble code {
  background: rgba(255,255,255,0.2);
}

.message.user .msg-bubble pre {
  background: rgba(255,255,255,0.15);
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  gap: 10px;
  align-self: flex-start;
  max-width: 85%;
}

.typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: var(--gray-bg);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--gray-icon);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

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

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

.typing-label {
  font-size: 12px;
  color: var(--gray-icon);
  margin-top: 4px;
}

/* Route Badge */
.msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.route-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 500;
}

.route-badge.ollama {
  background: #E8F5E9;
  color: #2E7D32;
}

.route-badge.openclaw-data,
.route-badge.openclaw-complex {
  background: #E3F2FD;
  color: #1565C0;
}

.route-badge.call {
  background: #FFF3E0;
  color: #E65100;
}

.elapsed-time {
  font-size: 10px;
  color: var(--gray-light);
}

/* --- Input Area --- */
.chat-input-area {
  padding: 12px 20px 20px;
  background: var(--white);
  border-top: 1px solid var(--gray-light);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--gray-bg);
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  border: 1.5px solid transparent;
  transition: border-color var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--orange);
  background: var(--white);
}

.upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  cursor: pointer;
  color: var(--gray-icon);
  border-radius: 6px;
  transition: color var(--transition);
  flex-shrink: 0;
}

.upload-btn:hover {
  color: var(--orange);
}

#message-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  color: var(--gray-text);
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.5;
  padding: 4px 0;
}

#message-input::placeholder {
  color: var(--gray-light);
}

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--orange);
  color: var(--white);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}

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

.send-btn:disabled {
  background: var(--gray-light);
  cursor: not-allowed;
}

/* File Preview */
.file-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0;
  width: 100%;
}

.file-preview[hidden] {
  display: none;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--orange-light);
  border-radius: 4px;
  font-size: 12px;
  color: var(--gray-text);
}

.file-chip button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gray-icon);
  font-size: 14px;
  padding: 0;
  line-height: 1;
}

/* Loading Overlay */
.btn-primary.loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.btn-primary.loading::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2px solid var(--white);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

@keyframes spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* --- Responsive --- */
@media (max-width: 600px) {
  .login-container {
    padding: 28px 24px;
    margin: 12px;
  }

  .chat-messages {
    padding: 12px;
  }

  .chat-input-area {
    padding: 8px 12px 12px;
  }

  .message {
    max-width: 92%;
  }

  .user-badge {
    display: none;
  }

  .welcome-msg {
    padding: 30px 12px;
  }
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--gray-light);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--gray-icon);
}

/* Modal */
.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}

.modal-content {
  position: relative;
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px;
  width: 100%;
  max-width: 400px;
  margin: 20px;
}

.modal-content h3 {
  margin-bottom: 20px;
  font-size: 18px;
}

.success-msg {
  color: var(--green);
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
}

/* Drag & Drop */
.drag-over {
  position: relative;
}

.drag-over::after {
  content: 'Datei hier ablegen';
  position: absolute;
  inset: 0;
  background: rgba(244, 158, 0, 0.1);
  border: 2px dashed var(--orange);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: var(--orange);
  pointer-events: none;
  z-index: 10;
}

/* Download-Links */
.download-link {
  display: inline-block;
  background: #F49E00;
  color: #fff !important;
  padding: 6px 14px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: bold;
  margin: 4px 0;
}
.download-link:hover {
  background: #d48800;
}

/* Markdown-Tabellen */
.md-table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 13px;
}
.md-table th, .md-table td {
  border: 1px solid #CDD5D9;
  padding: 6px 10px;
  text-align: left;
}
.md-table th {
  background: #F49E00;
  color: #fff;
  font-weight: 600;
}
.md-table tr:nth-child(even) {
  background: #f8f9fa;
}
.md-table tr:hover {
  background: #fff3e0;
}


/* Portal Route Badge */
.route-badge.portal {
  background: #F49E00;
  color: #fff;
}
