:root {
  --navy-950: #0a1930;
  --navy-900: #0f2340;
  --navy-800: #163256;
  --navy-700: #1e4270;
  --navy-600: #2a5590;
  --teal-500: #0ea5a6;
  --teal-600: #0b8a8b;
  --teal-100: #e3f7f7;
  --amber-500: #d97706;
  --amber-100: #fdf1de;
  --red-500: #dc2626;
  --red-100: #fde8e8;
  --green-600: #15803d;
  --green-100: #e3f6ea;
  --gray-50: #f6f8fb;
  --gray-100: #eef1f6;
  --gray-200: #e2e6ee;
  --gray-300: #cdd4e0;
  --gray-500: #6b7688;
  --gray-700: #3c4657;
  --gray-900: #1b2330;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 35, 64, 0.06), 0 1px 3px rgba(15, 35, 64, 0.08);
  --shadow-md: 0 4px 12px rgba(15, 35, 64, 0.08), 0 2px 4px rgba(15, 35, 64, 0.06);
  --shadow-lg: 0 12px 32px rgba(15, 35, 64, 0.14);
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--gray-50);
  color: var(--gray-900);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea {
  font-family: inherit;
}

/* ---------- App Shell ---------- */

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: linear-gradient(135deg, var(--navy-950), var(--navy-800));
  color: #fff;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 50;
}

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

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--teal-500), var(--teal-600));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
  color: #fff;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-text .title {
  font-weight: 700;
  font-size: 15.5px;
  letter-spacing: 0.01em;
}

.brand-text .subtitle {
  font-size: 11.5px;
  color: #9fb3ce;
  letter-spacing: 0.03em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 13px;
  color: #b9c8dd;
}

.topbar-right .sys-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  padding: 5px 11px;
  border-radius: 20px;
}

.dot-live {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.25);
}

.nav-tabs {
  display: flex;
  gap: 2px;
  background: var(--navy-900);
  padding: 0 24px;
  border-bottom: 1px solid var(--navy-700);
  overflow-x: auto;
}

.nav-tab {
  appearance: none;
  border: none;
  background: transparent;
  color: #a9bcd4;
  padding: 13px 18px;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  transition: color 0.15s ease, border-color 0.15s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-tab:hover { color: #fff; }

.nav-tab.active {
  color: #fff;
  border-bottom-color: var(--teal-500);
}

.nav-tab .icn { font-size: 15px; opacity: 0.9; }

main.content {
  flex: 1;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 28px 48px;
}

.view { display: none; }
.view.active { display: block; animation: fadeIn 0.18s ease; }

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

.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}

.view-header h1 {
  font-size: 22px;
  margin: 0 0 4px;
  color: var(--navy-950);
  letter-spacing: -0.01em;
}

.view-header p.hint {
  margin: 0;
  color: var(--gray-500);
  font-size: 13.5px;
  max-width: 640px;
}

.back-btn {
  appearance: none;
  border: 1px solid var(--gray-300);
  background: #fff;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.back-btn:hover { background: var(--gray-100); border-color: var(--gray-300); }

/* ---------- Cards / grids ---------- */

.card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-pad { padding: 20px 22px; }

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.entity-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 18px 20px;
  cursor: pointer;
  transition: box-shadow 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.entity-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--teal-500);
  transform: translateY(-1px);
}

.entity-card .eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--teal-600);
  font-weight: 700;
}

.entity-card h3 {
  margin: 0;
  font-size: 17px;
  color: var(--navy-950);
}

.entity-card .meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--gray-500);
}

.entity-card .stat-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.badge-ok { background: var(--green-100); color: var(--green-600); }
.badge-warn { background: var(--amber-100); color: var(--amber-500); }
.badge-neutral { background: var(--gray-100); color: var(--gray-500); }
.badge-danger { background: var(--red-100); color: var(--red-500); }

/* ---------- Tables ---------- */

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

table.data-table thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  border-bottom: 1px solid var(--gray-200);
  padding: 10px 14px;
  background: var(--gray-50);
  position: sticky;
  top: 0;
}

table.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-900);
  vertical-align: middle;
}

table.data-table tbody tr:hover { background: var(--gray-50); }
table.data-table tbody tr:last-child td { border-bottom: none; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: #fff;
}

.table-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--navy-800);
  padding: 12px 14px 0;
  letter-spacing: 0.01em;
}

.muted { color: var(--gray-500); font-style: italic; }

/* ---------- Reference chips (clickable) ---------- */

.ref-chip {
  appearance: none;
  border: 1px solid var(--teal-500);
  background: var(--teal-100);
  color: var(--teal-600);
  font-weight: 700;
  font-size: 12.5px;
  padding: 2px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-family: "SFMono-Regular", Consolas, monospace;
  transition: background 0.12s ease;
}
.ref-chip:hover { background: var(--teal-600); color: #fff; }

.ref-chip.ref-order { border-color: var(--navy-600); background: #e8eefb; color: var(--navy-700); }
.ref-chip.ref-order:hover { background: var(--navy-700); color: #fff; }

.doc-link {
  appearance: none;
  border: none;
  background: none;
  color: var(--teal-600);
  font-size: 12.5px;
  text-decoration: underline;
  text-decoration-style: dotted;
  cursor: pointer;
  padding: 0;
  font-family: "SFMono-Regular", Consolas, monospace;
}
.doc-link:hover { color: var(--teal-500); }

/* ---------- Chat ---------- */

.chat-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  height: calc(100vh - 210px);
  min-height: 520px;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.msg {
  display: flex;
  gap: 12px;
  max-width: 88%;
}

.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.ai { align-self: flex-start; }

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.msg.user .msg-avatar { background: var(--navy-700); }
.msg.ai .msg-avatar { background: linear-gradient(135deg, var(--teal-500), var(--teal-600)); }

.msg-bubble {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--gray-900);
}

.msg.user .msg-bubble {
  background: var(--navy-800);
  color: #eef2f9;
  border-color: var(--navy-800);
}

.msg.ai .msg-bubble { max-width: 100%; }

.msg-content > *:first-child { margin-top: 0; }
.msg-content > *:last-child { margin-bottom: 0; }

.msg-sources {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--gray-300);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.msg-sources .label {
  font-size: 11px;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 4px;
}

.msg-table-wrap {
  margin-top: 12px;
}

.typing-indicator {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}
.typing-indicator span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--gray-500);
  animation: blink 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.chat-input-row {
  border-top: 1px solid var(--gray-200);
  padding: 14px 16px;
  display: flex;
  gap: 10px;
  background: #fff;
}

.chat-input-row input {
  flex: 1;
  border: 1px solid var(--gray-300);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease;
}
.chat-input-row input:focus { border-color: var(--teal-500); box-shadow: 0 0 0 3px rgba(14,165,166,0.15); }

.send-btn {
  appearance: none;
  border: none;
  background: var(--teal-600);
  color: #fff;
  font-weight: 700;
  font-size: 13.5px;
  padding: 0 20px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.send-btn:hover { background: var(--teal-500); }
.send-btn:disabled { background: var(--gray-300); cursor: not-allowed; }

.chat-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.side-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.side-card h4 {
  margin: 0 0 10px;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
}

.example-chip {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 12.5px;
  color: var(--navy-800);
  cursor: pointer;
  margin-bottom: 7px;
  line-height: 1.4;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.example-chip:hover { border-color: var(--teal-500); background: var(--teal-100); }
.example-chip:last-child { margin-bottom: 0; }

.architecture-note {
  font-size: 12px;
  color: var(--gray-500);
  line-height: 1.6;
}
.architecture-note b { color: var(--gray-700); }

/* ---------- Detail views ---------- */

.detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  align-items: start;
}

.kv-list { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; font-size: 13.5px; }
.kv-list dt { color: var(--gray-500); font-weight: 600; }
.kv-list dd { margin: 0; color: var(--gray-900); }

.section-title {
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--navy-800);
  margin: 26px 0 10px;
}
.section-title:first-child { margin-top: 0; }

/* ---------- Timeline (Audit Log) ---------- */

.timeline {
  position: relative;
  padding-left: 26px;
}
.timeline::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--gray-200);
}
.timeline-item {
  position: relative;
  padding-bottom: 18px;
}
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before {
  content: "";
  position: absolute;
  left: -26px;
  top: 3px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--teal-500);
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--teal-500);
}
.timeline-item .tl-date {
  font-size: 11.5px;
  color: var(--gray-500);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.timeline-item .tl-body {
  font-size: 13.5px;
  color: var(--gray-900);
  margin-top: 2px;
}
.timeline-item .tl-meta {
  font-size: 11.5px;
  color: var(--gray-500);
  margin-top: 2px;
}

/* ---------- Audit log view filters ---------- */

.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-bar select, .filter-bar input[type="search"] {
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 13px;
  background: #fff;
}
.filter-bar input[type="search"] { flex: 1; min-width: 200px; }

/* ---------- Modal (Dokumentvorschau) ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 40, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.modal-overlay.open { display: flex; }

.modal-box {
  background: #fff;
  border-radius: 14px;
  max-width: 560px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  background: linear-gradient(135deg, var(--navy-900), var(--navy-700));
  color: #fff;
  padding: 18px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 { margin: 0; font-size: 15px; }
.modal-close {
  background: none; border: none; color: #cdd8ea; font-size: 20px; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: #fff; }

.doc-preview {
  padding: 24px 26px;
}

.doc-sheet {
  border: 2px dashed var(--gray-300);
  border-radius: 10px;
  padding: 22px;
  background: repeating-linear-gradient(135deg, #fff, #fff 12px, #fafcff 12px, #fafcff 24px);
}
.doc-sheet .sheet-title { font-size: 15px; font-weight: 700; color: var(--navy-950); margin-bottom: 4px; }
.doc-sheet .sheet-sub { font-size: 12px; color: var(--gray-500); margin-bottom: 14px; }
.doc-sheet .sheet-row { display: flex; justify-content: space-between; font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--gray-100); }
.doc-sheet .sheet-row:last-child { border-bottom: none; }

.doc-preview .path-note {
  margin-top: 14px;
  font-size: 12px;
  color: var(--gray-500);
  background: var(--gray-50);
  border-radius: 8px;
  padding: 10px 12px;
}
.doc-preview .path-note code { color: var(--navy-800); }

/* ---------- Empty states ---------- */

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--gray-500);
}
.empty-state .big-icn { font-size: 34px; margin-bottom: 10px; }

/* ---------- Search box (Teile view) ---------- */

.search-box {
  width: 100%;
  max-width: 340px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13.5px;
  margin-bottom: 16px;
}

@media (max-width: 980px) {
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .detail-grid { grid-template-columns: 1fr; }
}
