:root {
  --paper: #f4f1e9;
  --surface: #fbfaf6;
  --surface-2: #ebe7dc;
  --ink: #20231f;
  --muted: #6c7068;
  --line: #d4cec0;
  --olive: #697a43;
  --cyan: #0a6971;
  --cyan-2: #e0f0ef;
  --warn: #9b5c24;
  --shadow: 0 18px 48px rgba(32, 35, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(32, 35, 31, 0.025) 1px, transparent 1px),
    linear-gradient(180deg, rgba(32, 35, 31, 0.025) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
a {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(251, 250, 246, 0.76);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

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

.mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--surface);
  font-weight: 800;
  border-radius: 8px;
}

h1,
h2,
p {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.1;
}

.brand p,
.label,
.source-card p,
.model-pill {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.nav {
  display: grid;
  gap: 7px;
}

.nav-item,
.chip,
.brief-actions button,
.primary,
.secondary {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.nav-item {
  text-align: left;
  padding: 11px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.nav-item span {
  color: var(--cyan);
  width: 26px;
  text-align: center;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .04em;
}

.nav-item.active,
.nav-item:hover,
.nav-item:focus-visible,
.chip.selected {
  background: var(--cyan-2);
  border-color: rgba(10, 105, 113, 0.38);
  color: var(--ink);
}

.quick-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.quick-links a,
.mini-action {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  color: var(--cyan);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  padding: 9px 10px;
  text-align: center;
  text-decoration: none;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.quick-links a:hover,
.mini-action:hover {
  background: var(--cyan-2);
  border-color: rgba(10, 105, 113, 0.38);
  transform: translateY(-1px);
}

.source-card {
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
}

.source-card strong {
  display: block;
  margin: 7px 0 4px;
  font-size: 18px;
}

.workspace {
  padding: 22px;
  min-width: 0;
}

.command-bar {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.query-wrap {
  display: grid;
  gap: 6px;
}

.query-wrap label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 14px 14px;
  outline: none;
}

input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(10, 105, 113, 0.12);
}

.primary,
.secondary {
  padding: 14px 16px;
  font-weight: 750;
}

.demo-link {
  text-decoration: none;
  display: inline-grid;
  place-items: center;
}

.primary {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}

button:disabled {
  cursor: wait;
  opacity: .6;
}

.secondary:hover,
.brief-actions button:hover,
.primary:hover,
.secondary:focus-visible,
.primary:focus-visible,
.brief-actions button:focus-visible,
.chip:focus-visible {
  transform: translateY(-1px);
  outline: none;
  box-shadow: 0 0 0 3px rgba(10, 105, 113, 0.12);
}

.signal-strip {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
  overflow-x: auto;
}

.chip {
  padding: 8px 11px;
  white-space: nowrap;
  font-size: 13px;
}

.chip.utility {
  color: var(--muted);
}

.model-pill {
  margin-left: auto;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 11px;
  white-space: nowrap;
}

.grid {
  display: grid;
  grid-template-columns: minmax(420px, 1.1fr) minmax(320px, 0.9fr);
  grid-template-rows: minmax(360px, 52vh) minmax(260px, 1fr);
  gap: 14px;
}

.panel {
  border: 1px solid var(--line);
  background: rgba(251, 250, 246, 0.92);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
  min-height: 0;
}

.results-panel {
  grid-row: 1 / span 2;
}

.ai-panel {
  grid-column: 2;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  align-items: center;
}

.preview-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.panel-head h2 {
  margin-top: 3px;
  font-size: 18px;
}

.count {
  min-width: 36px;
  text-align: center;
  padding: 6px 9px;
  background: var(--surface-2);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.results {
  height: calc(100% - 70px);
  overflow: auto;
}

.result-row {
  width: 100%;
  appearance: none;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 14px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 12px;
  transition: background 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.result-row:hover,
.result-row:focus-visible,
.result-row.selected {
  background: #f0ede3;
  outline: none;
}

.result-row:hover {
  transform: translateX(2px);
}

.result-row.selected {
  box-shadow: inset 4px 0 0 var(--cyan);
}

.rank {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  padding-top: 2px;
}

.row-main {
  display: grid;
  gap: 8px;
}

.row-main strong {
  font-size: 15px;
  line-height: 1.25;
}

.meta-line,
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.meta-line {
  color: var(--muted);
  font-size: 12px;
}

.tag {
  color: var(--cyan);
  background: var(--cyan-2);
  border: 1px solid rgba(10, 105, 113, 0.22);
  border-radius: 999px;
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 700;
}

.snippet,
.preview-body {
  color: #3b4038;
  font-size: 13px;
  line-height: 1.55;
}

.preview-empty,
.preview-content {
  padding: 16px;
}

.preview-empty {
  color: var(--muted);
  line-height: 1.55;
}

.source-link {
  display: inline-flex;
  margin-top: 14px;
  color: var(--cyan);
  font-weight: 800;
  text-decoration: none;
}

.brief-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.brief-actions button {
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 750;
}

.corner-agent {
  bottom: 22px;
  display: grid;
  gap: 12px;
  justify-items: end;
  position: fixed;
  right: 22px;
  z-index: 30;
}

.agent-launcher {
  align-items: center;
  background: var(--ink);
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 999px;
  box-shadow: 0 18px 48px rgba(32, 35, 31, .18);
  color: var(--surface);
  cursor: pointer;
  display: flex;
  gap: 10px;
  padding: 10px 14px 10px 10px;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.agent-launcher:hover,
.agent-launcher:focus-visible {
  box-shadow: 0 22px 56px rgba(32, 35, 31, .24);
  outline: none;
  transform: translateY(-2px);
}

.agent-launcher span {
  background: var(--cyan-2);
  border-radius: 999px;
  color: var(--cyan);
  display: grid;
  font-size: 12px;
  font-weight: 900;
  height: 34px;
  place-items: center;
  width: 34px;
}

.agent-launcher strong {
  font-size: 14px;
}

.agent-drawer {
  display: none;
  width: min(430px, calc(100vw - 28px));
}

.corner-agent.open .agent-drawer {
  display: block;
}

.assistant-box {
  background: rgba(251, 250, 246, .97);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(32, 35, 31, .18);
  display: grid;
  gap: 10px;
  max-height: min(690px, calc(100vh - 120px));
  overflow: hidden;
  padding: 14px;
}

.assistant-head {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.assistant-head h2 {
  font-size: 18px;
  margin-top: 3px;
}

.agent-head-actions {
  display: flex;
  gap: 6px;
}

.assistant-head button,
.assistant-suggestions button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  padding: 7px 9px;
}

.agent-context {
  background: #f0ede3;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  padding: 8px 9px;
}

.assistant-messages {
  display: grid;
  gap: 8px;
  max-height: 315px;
  overflow: auto;
  padding-right: 4px;
}

.chat-message {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f5ef;
  display: grid;
  gap: 5px;
  padding: 10px;
}

.chat-message.user {
  background: var(--cyan-2);
  border-color: rgba(10, 105, 113, 0.28);
}

.chat-message span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.chat-message p {
  color: #2f342d;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.chat-sources {
  display: grid;
  gap: 5px;
  margin-top: 2px;
}

.chat-sources a {
  color: var(--cyan);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.35;
  overflow: hidden;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-sources a:hover {
  text-decoration: underline;
}

.assistant-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.assistant-form input {
  padding: 11px 12px;
}

.assistant-form button {
  padding: 11px 13px;
}

.assistant-suggestions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.assistant-suggestions button:hover,
.assistant-head button:hover {
  background: var(--cyan-2);
  border-color: rgba(10, 105, 113, 0.38);
  color: var(--ink);
}

pre {
  margin: 0;
  padding: 16px;
  white-space: pre-wrap;
  overflow: auto;
  max-height: 360px;
  color: #2f342d;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  background: var(--ink);
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--surface);
  font-size: 13px;
  font-weight: 800;
  opacity: 0;
  padding: 11px 13px;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .quick-links {
    grid-template-columns: 1fr;
  }

  .source-card {
    margin-top: 0;
  }

  .command-bar,
  .grid {
    grid-template-columns: 1fr;
  }

  .results-panel,
  .ai-panel {
    grid-column: auto;
    grid-row: auto;
  }
}
