:root {
  --bg: #ffffff;
  --panel: #fafafa;
  --border: #d9d9d9;
  --border-soft: #f0f0f0;
  --text: #1f2328;
  --text-soft: #333333;
  --muted: #888888;
  --accent: #1677ff;
  --accent-soft: #4096ff;
  --danger: #ff4d4f;
  --radius: 8px;
  --sider-width: 300px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--accent); }
code { background: var(--panel); padding: 1px 5px; border-radius: 4px; font-size: 13px; word-break: break-word; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

/* App layout */
.app { display: flex; min-height: 100dvh; }
.sider {
  width: var(--sider-width);
  flex-shrink: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-right: 1px solid var(--border);
  background: var(--panel);
}
.brand { font-size: 18px; font-weight: 700; }
.tagline { font-size: 12px; color: var(--muted); margin-top: -10px; }
.content { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 100dvh; }
.content-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 12px; color: var(--muted); }
.input-row { display: flex; gap: 4px; }
.input-row input { flex: 1; }
input[type='text'], input[type='password'], input[type='number'], select, textarea {
  padding: 5px 8px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 4px;
  outline: none;
  background: #fff;
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }
.btn {
  padding: 5px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-soft); color: #fff; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.row { display: flex; gap: 6px; align-items: center; }
.row-between { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

details.panel { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; background: #fff; }
details.panel > summary { cursor: pointer; font-size: 13px; font-weight: 600; }
details.panel[open] > summary { margin-bottom: 8px; }
.checkbox-row { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.checkbox-row input { width: auto; }

/* Tabs */
.tabs { display: flex; gap: 4px; align-items: center; padding: 10px 16px 0; border-bottom: 1px solid var(--border); }
.tab {
  padding: 7px 14px;
  font-size: 14px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: none;
  cursor: pointer;
  color: var(--text-soft);
}
.tab:hover { color: var(--accent); }
.tab[aria-selected='true'] { background: #fff; border-color: var(--border); color: var(--accent); font-weight: 600; margin-bottom: -1px; }
.tabs .spacer { flex: 1; }

.module-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: auto; }
.module-panel[hidden] { display: none; }

/* Chat */
.chat-area { flex: 1; overflow: auto; padding: 12px 16px 0; }
.chat-empty { text-align: center; margin-top: 96px; opacity: 0.55; color: var(--muted); font-size: 14px; }
.bubble {
  width: fit-content;
  max-width: 82%;
  padding: 8px 12px;
  border-radius: 12px;
  margin: 8px 0;
  word-break: break-word;
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.6;
}
.bubble-end { margin-left: auto; background: var(--accent); color: #fff; }
.bubble-start { margin-right: auto; background: #f5f5f5; color: var(--text-soft); }
.bubble-error { background: #fff1f0; color: var(--danger); }
.bubble img { max-width: 240px; max-height: 240px; border-radius: 8px; margin-top: 4px; object-fit: cover; display: block; }
.bubble-meta { font-size: 11px; color: var(--muted); margin: 2px 0 6px; }
.bubble-start .bubble-meta { margin-right: auto; }
.reasoning { margin-bottom: 8px; padding: 6px 8px; border-left: 2px solid var(--border); background: rgba(0,0,0,0.03); border-radius: 4px; font-size: 13px; color: #666; }
.reasoning summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.input-area { border-top: 1px solid var(--border); padding: 10px 16px 14px; }
.file-bar { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.file-tag { display: flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 4px; background: var(--panel); border: 1px solid var(--border-soft); font-size: 12px; }
.file-tag .remove { cursor: pointer; margin-left: 4px; opacity: 0.5; }
.file-tag .remove:hover { opacity: 1; }
.send-row { display: flex; gap: 8px; align-items: flex-end; }
.send-row textarea { flex: 1; padding: 8px 12px; font-size: 14px; border-radius: var(--radius); min-height: 40px; max-height: 140px; }
.send-actions { display: flex; align-items: center; gap: 4px; }
.attach-btn { font-size: 16px; cursor: pointer; opacity: 0.55; padding: 4px; background: none; border: none; }
.attach-btn:hover { opacity: 1; }
.send-btn { padding: 7px 16px; font-size: 14px; border-radius: var(--radius); }

/* Loading */
.loading-dots::after { content: '...'; animation: dots 1.2s steps(3) infinite; }
@keyframes dots { 0% { content: '.'; } 33% { content: '..'; } 66% { content: '...'; } }

/* Cards (compare + jev) */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; padding: 12px 16px; }
.card { border: 1px solid var(--border); border-radius: var(--radius); background: #fff; display: flex; flex-direction: column; min-width: 0; }
.card-head { padding: 8px 10px; border-bottom: 1px solid var(--border-soft); display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.card-title { font-size: 13px; font-weight: 600; word-break: break-all; }
.card-body { padding: 10px; font-size: 13px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; overflow: auto; max-height: 360px; }
.card-body.plain { white-space: normal; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 10px; background: var(--panel); border: 1px solid var(--border); color: var(--muted); }
.badge-ok { color: #389e0d; border-color: #b7eb8f; background: #f6ffed; }
.badge-err { color: var(--danger); border-color: #ffccc7; background: #fff1f0; }

.form-stack { display: flex; flex-direction: column; gap: 10px; padding: 12px 16px 16px; max-width: 980px; }
.question { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 8px; background: #fff; }
.question-head { display: flex; gap: 8px; align-items: center; }
.question-head input { flex: 1 1 auto; width: auto; min-width: 0; }
.question-head select { flex: 0 0 118px; width: 118px; }
.question-head .btn { flex: 0 0 auto; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.hint { font-size: 11px; color: var(--muted); }

/* Answer rendering */
.answer-head { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.answer-name { font-size: 13px; font-weight: 600; }
.answer-value { font-size: 13px; }
.bars { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(60px, 34%) 1fr auto; gap: 6px; align-items: center; font-size: 12px; }
.bar-track { background: var(--panel); border: 1px solid var(--border-soft); border-radius: 4px; height: 12px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); }

/* Inspector drawer */
.inspector {
  position: fixed;
  top: 0;
  right: 0;
  width: min(560px, 100%);
  height: 100dvh;
  background: #fff;
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  z-index: 60;
}
.inspector[hidden] { display: none; }
.inspector-head { padding: 10px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.inspector-body { flex: 1; overflow: auto; padding: 10px 14px 20px; }
.inspector section { margin-bottom: 14px; }
.inspector h4 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 6px; }
.inspector pre {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 8px;
  overflow: auto;
  max-height: 280px;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; font-size: 12px; }
.metric { background: var(--panel); border: 1px solid var(--border-soft); border-radius: 6px; padding: 6px 8px; }
.metric b { display: block; font-size: 13px; }

/* Dialog */
.dialog-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center; z-index: 100; }
.dialog-box { background: #fff; border-radius: var(--radius); padding: 20px; width: calc(100% - 32px); max-width: 440px; box-shadow: 0 8px 24px rgba(0,0,0,0.2); }
.dialog-title { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.dialog-body { font-size: 14px; line-height: 1.6; color: var(--text-soft); margin-bottom: 16px; white-space: pre-wrap; }
.dialog-actions { display: flex; justify-content: flex-end; }

/* Docs */
.skip-link { position: absolute; left: -9999px; top: 0; padding: 8px 14px; background: var(--accent); color: #fff; border-radius: 0 0 6px 0; font-size: 13px; z-index: 10; }
.skip-link:focus { left: 0; }
.sider-nav { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border-soft); }
.sider-nav a { display: block; font-size: 12px; color: var(--accent); text-decoration: none; margin-bottom: 4px; }
.docs { border-top: 1px solid var(--border); background: #fff; }
.docs-inner { max-width: 820px; margin: 0 auto; padding: 48px 20px 64px; }
.docs h1 { font-size: 30px; line-height: 1.25; margin: 0 0 12px; }
.docs h2 { font-size: 21px; line-height: 1.3; margin: 40px 0 12px; padding-top: 8px; border-top: 1px solid var(--border-soft); }
.docs h3 { font-size: 16px; line-height: 1.4; margin: 24px 0 6px; }
.docs p { font-size: 15px; line-height: 1.75; color: var(--text-soft); margin: 0 0 12px; }
.docs ul, .docs ol { margin: 0 0 14px; padding-left: 22px; }
.docs li { font-size: 15px; line-height: 1.75; color: var(--text-soft); margin-bottom: 6px; }
.docs .eyebrow { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); font-weight: 700; margin-bottom: 8px; }
.docs .lede { font-size: 17px; line-height: 1.7; }
.docs .meta-line { font-size: 13px; color: var(--muted); }
.docs .section-list { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 18px; margin-bottom: 4px; }
.docs .section-list a { font-size: 14px; text-decoration: none; }
.docs .faq-item { margin-bottom: 4px; }
.docs .answer { margin: 0 0 18px; }
.docs-footer { border-top: 1px solid var(--border); background: var(--panel); }
.docs-footer .docs-inner { padding: 28px 20px 40px; }
.docs-footer p { font-size: 13px; color: #666; margin: 0 0 6px; }

.docs figure { margin: 18px 0 22px; }
.docs figure img { display: block; width: 100%; height: auto; border: 1px solid var(--border); border-radius: 10px; }
.docs figcaption { font-size: 13px; line-height: 1.6; color: var(--muted); margin-top: 8px; }
.docs .table-wrap { overflow-x: auto; margin: 8px 0 18px; }
.docs table { width: 100%; min-width: 560px; border-collapse: collapse; font-size: 14px; }
.docs caption { caption-side: bottom; text-align: left; font-size: 12px; color: var(--muted); padding-top: 6px; }
.docs th, .docs td { border: 1px solid var(--border-soft); padding: 8px 10px; text-align: left; vertical-align: top; line-height: 1.55; color: var(--text-soft); }
.docs thead th { background: var(--panel); color: var(--text); font-weight: 600; }
.docs code { background: var(--panel); border: 1px solid var(--border-soft); border-radius: 4px; padding: 0 4px; font-size: 13px; }

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sider { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .docs h1 { font-size: 24px; }
  .docs-inner { padding: 32px 16px 48px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
