/* =========================================================================
   NYO Automation — Design-Tokens (navy/slate, industrial enterprise)
   ========================================================================= */
:root {
  --page-bg: #f1f4f8;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --surface-sunken: #eef1f6;
  --border: rgba(15, 23, 42, 0.09);
  --border-strong: rgba(15, 23, 42, 0.16);

  --text-primary: #0f172a;
  --text-secondary: #47536b;
  --text-muted: #8b95a8;
  --text-on-accent: #ffffff;

  --accent: #1d4d8c;
  --accent-strong: #123a6b;
  --accent-wash: #e8f0fb;
  --accent-wash-strong: #d7e6f9;

  --good: #0a7d0a;
  --good-bg: #e7f6e7;
  --warning: #92600a;
  --warning-bg: #fbf0d9;
  --serious: #b23e14;
  --serious-bg: #fbe6dc;
  --neutral-badge-bg: #eef1f6;
  --neutral-badge-text: #47536b;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);

  --sidebar-w: 248px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--page-bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
table { border-collapse: collapse; }
::selection { background: var(--accent-wash-strong); }

/* =========================================================================
   Shell layout
   ========================================================================= */
.shell {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #0e223f;
  background-image: linear-gradient(180deg, #12294a 0%, #0c1e37 100%);
  color: #cfdcef;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 16px;
}
.brand-mark { flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-weight: 650; font-size: 14.5px; color: #fff; letter-spacing: .1px; }
.brand-sub { font-size: 11.5px; color: #8ea6c8; }

.nav-primary {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: #b7c6de;
  font-size: 13.4px;
  font-weight: 500;
  transition: background .12s ease, color .12s ease;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .85; }
.nav-item:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav-item.active { background: rgba(125, 184, 255, 0.16); color: #fff; }
.nav-item.active svg { opacity: 1; color: #7db8ff; }

.sidebar-footer { margin-top: auto; padding-top: 14px; }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 8px; border-radius: var(--radius-sm); background: rgba(255,255,255,0.05); }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: #2a5aa3; color: #fff; font-size: 11.5px; font-weight: 650;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.25; overflow: hidden; }
.user-name { font-size: 12.6px; font-weight: 600; color: #fff; }
.user-role { font-size: 11px; color: #8ea6c8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 32px 18px 32px;
  background: var(--page-bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-title h1 { margin: 0; font-size: 21px; font-weight: 650; letter-spacing: -.2px; }
.topbar-title p { margin: 3px 0 0 0; font-size: 13px; color: var(--text-secondary); }
.env-pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-secondary);
  background: var(--surface); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px; white-space: nowrap;
}
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-good { background: #0ca30c; box-shadow: 0 0 0 3px rgba(12,163,12,0.15); }

.view { padding: 0 32px 40px 32px; flex: 1; }

/* =========================================================================
   Cards, sections, KPIs
   ========================================================================= */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px 22px; }
.section-title {
  font-size: 12.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted); margin: 0 0 12px 0;
}
.section-heading {
  display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px;
}
.section-heading h2 { font-size: 16px; margin: 0; font-weight: 650; }
.section-heading .hint { font-size: 12.5px; color: var(--text-muted); }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0,1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.kpi-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 15px 16px;
  display: flex; flex-direction: column; gap: 4px;
}
.kpi-value { font-size: 26px; font-weight: 650; letter-spacing: -.4px; color: var(--text-primary); }
.kpi-label { font-size: 12.3px; color: var(--text-secondary); }
.kpi-tile.flag .kpi-value { color: var(--serious); }

/* =========================================================================
   Badges
   ========================================================================= */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.6px; font-weight: 600;
  padding: 3px 9px 3px 7px; border-radius: 999px;
  white-space: nowrap;
}
.badge svg { width: 11px; height: 11px; }
.badge-good { background: var(--good-bg); color: var(--good); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-serious { background: var(--serious-bg); color: var(--serious); }
.badge-neutral { background: var(--neutral-badge-bg); color: var(--neutral-badge-text); }
.badge-accent { background: var(--accent-wash); color: var(--accent-strong); }

/* =========================================================================
   Buttons
   ========================================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid transparent; transition: filter .1s ease, background .1s ease;
  line-height: 1.2;
}
.btn svg { width: 14px; height: 14px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text-primary); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* =========================================================================
   Links to entities (traceable chips)
   ========================================================================= */
.xref {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--accent); font-weight: 600; cursor: pointer;
  border-bottom: 1px dashed rgba(29,77,140,0.4);
}
.xref:hover { color: var(--accent-strong); border-bottom-color: var(--accent-strong); }
.xref svg { width: 11px; height: 11px; }

/* =========================================================================
   Tables
   ========================================================================= */
.table-wrap { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--border); }
table.data-table { width: 100%; font-size: 13.2px; background: var(--surface); }
table.data-table th {
  text-align: left; font-size: 11.3px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--text-muted); font-weight: 650;
  background: var(--surface-2); padding: 10px 14px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover { background: var(--surface-2); }
table.data-table td.num, table.data-table th.num { font-variant-numeric: tabular-nums; }
.table-clickable tbody tr { cursor: pointer; }
.row-link { color: var(--accent); font-weight: 650; }

/* =========================================================================
   Assistant / Chat
   ========================================================================= */
.assistant-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
  align-items: start;
}
.chat-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex; flex-direction: column;
  height: calc(100vh - 200px);
  min-height: 560px;
  box-shadow: var(--shadow-sm);
}
.chat-scroll {
  flex: 1; overflow-y: auto; padding: 22px 24px;
  display: flex; flex-direction: column; gap: 18px;
}
.chat-msg { display: flex; gap: 11px; max-width: 100%; }
.chat-msg .avatar {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
}
.chat-msg.user { flex-direction: row-reverse; }
.chat-msg.user .avatar { background: #dbe6f5; color: var(--accent-strong); }
.chat-msg.bot .avatar { background: #12294a; color: #7db8ff; }
.chat-bubble {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 15px;
  max-width: 640px;
}
.chat-msg.user .chat-bubble { background: var(--accent-wash); border-color: var(--accent-wash-strong); }
.chat-bubble p { margin: 0 0 8px 0; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble h3 { font-size: 14.5px; margin: 0 0 2px 0; }
.chat-bubble .lede { color: var(--text-secondary); font-size: 12.8px; margin-bottom: 12px; }

.answer-card { display: flex; flex-direction: column; gap: 12px; }
.answer-summary { font-size: 13.6px; }
.answer-checkline {
  display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; color: var(--good);
  background: var(--good-bg); padding: 8px 12px; border-radius: var(--radius-sm);
}
.answer-checkline svg { width: 15px; height: 15px; flex-shrink: 0; }

.sources-box {
  border-top: 1px dashed var(--border-strong);
  margin-top: 4px; padding-top: 10px;
  font-size: 12px; color: var(--text-muted);
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
}
.sources-box .sources-label { font-weight: 650; text-transform: uppercase; font-size: 10.5px; letter-spacing: .4px; margin-right: 3px; }

.chat-suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
.chip {
  font-size: 12.4px; padding: 7px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border-strong);
  color: var(--text-primary); cursor: pointer; transition: background .1s;
}
.chip:hover { background: var(--accent-wash); border-color: var(--accent-wash-strong); color: var(--accent-strong); }

.chat-input-row {
  display: flex; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--border);
}
.chat-input-row input {
  flex: 1; border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  padding: 11px 14px; font-size: 13.6px; font-family: inherit; outline: none;
  background: var(--surface-2);
}
.chat-input-row input:focus { border-color: var(--accent); background: var(--surface); }
.send-btn {
  width: 42px; height: 42px; border-radius: var(--radius-md); flex-shrink: 0;
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:hover { background: var(--accent-strong); }
.send-btn svg { width: 17px; height: 17px; }

.typing-dots { display: inline-flex; gap: 3px; align-items: center; padding: 4px 0; }
.typing-dots span { width: 5px; height: 5px; border-radius: 50%; background: var(--text-muted); animation: blink 1.2s infinite ease-in-out; }
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.side-panel { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 90px; }
.faq-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.faq-item {
  text-align: left; font-size: 12.8px; padding: 9px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; color: var(--text-primary);
}
.faq-item:hover { background: var(--accent-wash); border-color: var(--accent-wash-strong); }

/* =========================================================================
   Detail views (Auftrag / Teil / Zeugnis)
   ========================================================================= */
.detail-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 20px;
  margin-bottom: 18px; flex-wrap: wrap;
}
.detail-header .eyebrow { font-size: 12px; color: var(--text-muted); font-weight: 600; margin-bottom: 4px; }
.detail-header h2 { font-size: 22px; margin: 0; font-weight: 650; }
.detail-header .subline { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

.kv-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0 28px; }
.kv-row { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13.2px; }
.kv-row:last-child, .kv-grid .kv-row:nth-last-child(2) { border-bottom: none; }
.kv-key { color: var(--text-muted); }
.kv-val { font-weight: 600; text-align: right; }

.grid-main-side { display: grid; grid-template-columns: minmax(0,1fr) 320px; gap: 18px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 18px; }

.path-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  background: var(--surface-sunken); padding: 8px 10px; border-radius: var(--radius-sm);
  overflow-x: auto; white-space: nowrap; color: var(--text-secondary); border: 1px solid var(--border);
}

.doc-list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 13px 15px; border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: 10px;
  background: var(--surface);
}
.doc-list-item:last-child { margin-bottom: 0; }
.doc-list-item .doc-main { display: flex; flex-direction: column; gap: 3px; }
.doc-list-item .doc-title { font-weight: 650; font-size: 13.6px; }
.doc-list-item .doc-sub { font-size: 12.2px; color: var(--text-muted); }

/* =========================================================================
   Filters / toolbars
   ========================================================================= */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type=search], .toolbar select {
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 8px 12px; font-size: 13px; font-family: inherit; background: var(--surface); color: var(--text-primary);
}
.toolbar input[type=search] { min-width: 240px; }
.toolbar .spacer { flex: 1; }
.result-count { font-size: 12.5px; color: var(--text-muted); }

/* =========================================================================
   Empty / misc
   ========================================================================= */
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.muted { color: var(--text-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

@media (max-width: 1180px) {
  .kpi-row { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .assistant-layout { grid-template-columns: 1fr; }
  .side-panel { position: static; }
  .grid-main-side { grid-template-columns: 1fr; }
}
