/* ==========================================================================
   Fecke RAG-Prototyp - Styles
   Marke: Orange #E8801E, Dunkelgrau #58595B, Hellgrau #F4F4F5
   ========================================================================== */

:root {
  --orange: #E8801E;
  --orange-dark: #cf6e12;
  --orange-soft: #fdf1e5;
  --gray: #58595B;
  --gray-light: #8b8c8e;
  --gray-lighter: #b7b8ba;
  --surface: #F4F4F5;
  --white: #ffffff;
  --border: #e2e2e4;
  --border-strong: #cfcfd2;
  --text: #2f2f31;
  --text-muted: #6d6e70;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --success: #1e7d4f;
  --success-soft: #e7f5ee;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3, h4 { color: var(--gray); font-weight: 600; margin: 0 0 .5rem; }
a { color: var(--orange); }

/* ---------------------------------------------------------------- Buttons */
.btn {
  font-family: inherit;
  font-size: .9rem;
  font-weight: 500;
  padding: .5rem .9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--white);
  color: var(--gray);
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}
.btn:hover { background: var(--surface); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary {
  background: var(--orange);
  border-color: var(--orange);
  color: var(--white);
}
.btn-primary:hover { background: var(--orange-dark); border-color: var(--orange-dark); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: rgba(0,0,0,.05); }
.btn-danger { color: var(--danger); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: .3rem .6rem; font-size: .82rem; }

/* ---------------------------------------------------------------- Fields */
.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.field > span { font-size: .82rem; font-weight: 500; color: var(--text-muted); }
input, select, textarea {
  font-family: inherit;
  font-size: .92rem;
  padding: .55rem .65rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(232, 128, 30, .15);
}
textarea { resize: vertical; min-height: 90px; }
label.check { display: inline-flex; align-items: center; gap: .45rem; font-size: .88rem; }
label.check input { width: auto; }

/* ---------------------------------------------------------------- Badges */
.badge {
  display: inline-block;
  font-size: .72rem;
  font-weight: 600;
  padding: .15rem .5rem;
  border-radius: 999px;
  background: var(--surface);
  color: var(--gray);
  border: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: .02em;
}
.badge-orange { background: var(--orange-soft); color: var(--orange-dark); border-color: #f3d8b8; }
.badge-gray { background: #edeef0; color: var(--gray); }
.badge-red { background: var(--danger-soft); color: var(--danger); border-color: #f3c7c1; }
.badge-green { background: var(--success-soft); color: var(--success); border-color: #bfe3cf; }

/* ============================================================ LOGIN-VIEW */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #fafafb 0%, #eef0f2 100%);
  padding: 1.5rem;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2.4rem 2.2rem;
  text-align: center;
  border-top: 4px solid var(--orange);
}
.login-logo { max-width: 200px; max-height: 90px; object-fit: contain; margin-bottom: 1.2rem; }
.login-title { font-size: 1.25rem; color: var(--gray); }
.login-subtitle { color: var(--text-muted); font-size: .9rem; margin: 0 0 1.6rem; }
.login-form { text-align: left; }
.login-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #f3c7c1;
  border-radius: var(--radius-sm);
  padding: .55rem .7rem;
  font-size: .85rem;
  margin-bottom: 1rem;
}
.login-footer { margin: 1.6rem 0 0; font-size: .75rem; color: var(--gray-lighter); }

/* ============================================================ APP-SHELL */
.app-shell { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  height: 60px;
  flex: 0 0 60px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.2rem;
  box-shadow: var(--shadow);
  z-index: 5;
}
.topbar-logo { height: 34px; object-fit: contain; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.user-chip { display: flex; flex-direction: column; align-items: flex-end; gap: .15rem; line-height: 1.1; }
.user-name { font-weight: 600; font-size: .9rem; color: var(--gray); }

.app-body { flex: 1; display: flex; min-height: 0; }

.sidebar {
  flex: 0 0 220px;
  background: var(--white);
  border-right: 1px solid var(--border);
  padding: 1rem .7rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .65rem .8rem;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: .95rem;
  font-weight: 500;
  color: var(--gray);
  text-align: left;
  width: 100%;
}
.nav-item:hover { background: var(--surface); }
.nav-item.active { background: var(--orange-soft); color: var(--orange-dark); }
.nav-item.active .nav-ico { filter: none; }
.nav-ico { font-size: 1.05rem; width: 1.3rem; text-align: center; }

.content { flex: 1; overflow-y: auto; padding: 1.6rem 2rem; min-width: 0; }
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.2rem; flex-wrap: wrap; gap: .6rem; }
.view-head h2 { margin: 0; font-size: 1.3rem; }
.view-sub { color: var(--text-muted); font-size: .88rem; }

/* ---------------------------------------------------------------- Cards */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.3rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.2rem;
}
.card h3 { font-size: 1.02rem; margin-bottom: .9rem; }
.muted { color: var(--text-muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }

/* ============================================================ CHAT-VIEW */
.chat-wrap { display: flex; flex-direction: column; height: 100%; }
.chat-meta {
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: .8rem;
  display: flex;
  gap: .5rem;
  align-items: center;
  flex-wrap: wrap;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: .3rem .1rem 1rem;
}
.chat-empty { color: var(--gray-lighter); text-align: center; margin: auto; max-width: 420px; }
.chat-empty h3 { color: var(--gray-light); }

.msg { display: flex; gap: .75rem; max-width: 860px; }
.msg-avatar {
  flex: 0 0 34px; height: 34px; width: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .95rem; font-weight: 600;
}
.msg-user { align-self: flex-end; flex-direction: row-reverse; }
.msg-user .msg-avatar { background: var(--gray); color: var(--white); }
.msg-user .msg-bubble { background: var(--gray); color: var(--white); }
.msg-assistant .msg-avatar { background: var(--orange-soft); color: var(--orange-dark); }
.msg-assistant .msg-bubble { background: var(--white); border: 1px solid var(--border); }
.msg-bubble {
  padding: .7rem .95rem;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow);
}
.msg-error .msg-bubble { background: var(--danger-soft); border: 1px solid #f3c7c1; color: var(--danger); }

/* Quellen-Aufklappbereich */
.sources { margin-top: .7rem; border-top: 1px dashed var(--border-strong); padding-top: .5rem; }
.sources summary {
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
  color: var(--orange-dark);
  list-style: none;
}
.sources summary::-webkit-details-marker { display: none; }
.sources summary::before { content: "▸ "; }
.sources[open] summary::before { content: "▾ "; }
.source-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .55rem .65rem;
  margin-top: .5rem;
  background: var(--surface);
}
.source-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .3rem; flex-wrap: wrap; }
.source-title { font-weight: 600; font-size: .84rem; color: var(--gray); }
.source-meta { font-size: .74rem; color: var(--text-muted); display: flex; gap: .5rem; }
.source-snippet { font-size: .82rem; color: var(--text); font-style: italic; }

.chat-input-row {
  display: flex;
  gap: .6rem;
  align-items: flex-end;
  border-top: 1px solid var(--border);
  padding-top: .9rem;
  background: var(--surface);
}
.chat-input-row textarea { min-height: 46px; max-height: 160px; }

.typing { display: inline-flex; gap: .25rem; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--gray-lighter);
  animation: blink 1.2s infinite both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

/* ---------------------------------------------------------------- Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; background: var(--white); }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: var(--surface); font-weight: 600; color: var(--text-muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fbfbfc; }
td.actions { text-align: right; white-space: nowrap; }
.empty-row { text-align: center; color: var(--gray-lighter); padding: 1.4rem; }

/* ---------------------------------------------------------------- Tabs */
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--border); margin-bottom: 1.3rem; flex-wrap: wrap; }
.tab {
  padding: .6rem .95rem;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  font-size: .9rem;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--gray); }
.tab.active { color: var(--orange-dark); border-bottom-color: var(--orange); }

/* ---------------------------------------------------------------- Status */
.status-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; }
.stat {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.stat-val { font-size: 1.7rem; font-weight: 700; color: var(--orange-dark); }
.stat-label { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: .35rem; }
.dot-ok { background: var(--success); }
.dot-off { background: var(--danger); }

/* ---------------------------------------------------------------- Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 1rem;
}
.modal {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 460px;
  max-height: 90vh; overflow-y: auto;
  padding: 1.5rem;
}
.modal h3 { margin-bottom: 1.1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.2rem; }

/* ---------------------------------------------------------------- Toasts */
.toasts { position: fixed; top: 1rem; right: 1rem; z-index: 100; display: flex; flex-direction: column; gap: .5rem; max-width: 360px; }
.toast {
  padding: .7rem .95rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: .87rem;
  color: var(--white);
  animation: slidein .2s ease;
}
.toast-error { background: var(--danger); }
.toast-success { background: var(--success); }
.toast-info { background: var(--gray); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---------------------------------------------------------------- Misc */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spinner-dark { border-color: rgba(0,0,0,.15); border-top-color: var(--orange); }
@keyframes spin { to { transform: rotate(360deg); } }
[hidden] { display: none !important; }
.row-inline { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.mt-1 { margin-top: 1rem; }
.pill-list { display: flex; flex-wrap: wrap; gap: .3rem; }

/* ---------------------------------------------------------------- Responsive */
@media (max-width: 820px) {
  .sidebar { flex-basis: 64px; }
  .nav-item span:last-child { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 1.1rem; }
}
