:root {
  --rd-panel-title-size: 13px;
  --rd-panel-title-spacing: 1.2px;
  --rd-input-min-h: 110px;
  --rd-input-max-h: 350px;
}

body.page-research-desk { overflow: hidden; height: 100vh; }
body.page-research-desk .main { overflow: hidden; height: 100%; min-height: 0; display: flex; flex-direction: column; }
body.page-research-desk .content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding-top: 18px;
  padding-bottom: 12px;
}
body.page-research-desk .page-head { flex: none; margin-bottom: 10px; }
body.page-research-desk .greeting h1 .mo-badge {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--ai);
  background: rgba(90, 160, 219, .12);
  padding: 3px 9px;
  border-radius: 99px;
  vertical-align: middle;
  margin-left: 8px;
}

.rd-matter-banner {
  flex: none;
  margin: 0 14px 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-muted, #9aa3ad);
  background: rgba(90, 160, 219, .08);
  border: 1px solid rgba(90, 160, 219, .18);
}
#rd-retrieval-errors {
  flex: none;
  margin: 0 14px 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
}

.rd-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 300px;
  gap: 12px;
}
@media (max-width: 1180px) {
  .rd-layout { grid-template-columns: 180px minmax(0, 1fr); }
  .rd-sources { display: none; }
}
@media (max-width: 860px) {
  .rd-layout { grid-template-columns: 1fr; }
  .rd-threads { display: none; }
}

.rd-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-1);
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.rd-panel.lp-accent { border-left: 3px solid var(--ai); }

.rd-ph {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: none;
}
.rd-ph h2 {
  margin: 0;
  font-size: var(--rd-panel-title-size);
  letter-spacing: var(--rd-panel-title-spacing);
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.rd-body { flex: 1; min-height: 0; overflow: auto; padding: 12px; }

.rd-thread {
  width: 100%;
  text-align: left;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 11px;
  margin-bottom: 8px;
  cursor: pointer;
  font-family: var(--serif);
  color: var(--text);
  transition: border-color .15s ease;
}
.rd-thread:hover, .rd-thread.active { border-color: var(--ai); }
.rd-thread .t { font-size: 15px; font-weight: 700; line-height: 1.3; }
.rd-thread .s { font-size: 13px; color: var(--muted); margin-top: 4px; }

.rd-chat { display: flex; flex-direction: column; min-height: 0; }
.rd-messages { flex: 1; min-height: 0; overflow: auto; padding: 14px 16px; }
.rd-empty { color: var(--muted); font-size: 17px; line-height: 1.5; padding: 24px 8px; }

.rd-msg { margin-bottom: 14px; max-width: 92%; }
.rd-msg.user { margin-left: auto; }
.rd-bubble {
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 17px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.rd-msg.user .rd-bubble { background: var(--surface3); border: 1px solid var(--border); }
.rd-msg.assistant .rd-bubble { background: var(--surface2); border: 1px solid var(--border); }

.rd-conf {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.rd-conf.cited { color: var(--ok); }
.rd-conf.partial { color: var(--warn); }
.rd-conf.inference { color: var(--muted); }

.rd-compose {
  flex: none;
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.rd-chips { display: flex; flex-wrap: wrap; gap: 10px; }
.rd-chip {
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 99px;
  padding: 8px 14px;
  min-height: 40px;
  font-size: var(--rd-panel-title-size);
  font-weight: 700;
  letter-spacing: var(--rd-panel-title-spacing);
  text-transform: uppercase;
  cursor: pointer;
  color: var(--text);
  font-family: var(--serif);
  transition: border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.rd-chip:hover,
.rd-chip:focus-visible {
  border-color: var(--ai);
  color: var(--ai);
  outline: none;
  box-shadow: 0 0 0 2px rgba(90, 160, 219, .22);
}
.rd-chip.active {
  border-color: var(--ai);
  color: var(--ai);
  background: rgba(90, 160, 219, .1);
}

.rd-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.rd-check { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.rd-check input { accent-color: var(--ai); }

.rd-input-row { display: flex; gap: 10px; align-items: flex-end; }
.rd-input {
  flex: 1;
  min-height: var(--rd-input-min-h);
  max-height: var(--rd-input-max-h);
  resize: vertical;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--serif);
  font-size: 17px;
  padding: 12px 14px;
  line-height: 1.45;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.rd-input:focus {
  outline: none;
  border-color: var(--ai);
  box-shadow: 0 0 0 2px rgba(90, 160, 219, .28);
}

[data-theme="dark"] .page-research-desk .rd-panel {
  border-color: #2E3A4F;
}
[data-theme="dark"] .page-research-desk .rd-ph {
  border-bottom-color: #2E3A4F;
}
[data-theme="dark"] .page-research-desk .rd-compose {
  border-top-color: #2E3A4F;
}
[data-theme="dark"] .page-research-desk .rd-chip {
  border-color: #3A4A62;
  background: var(--surface3);
}
[data-theme="dark"] .page-research-desk .rd-chip:hover,
[data-theme="dark"] .page-research-desk .rd-chip:focus-visible,
[data-theme="dark"] .page-research-desk .rd-chip.active {
  border-color: var(--ai);
  box-shadow: 0 0 0 2px rgba(90, 160, 219, .32);
}
[data-theme="dark"] .page-research-desk .rd-input {
  border-color: #3A4A62;
  background: var(--surface3);
}
[data-theme="dark"] .page-research-desk .rd-input:focus {
  border-color: var(--ai);
  box-shadow: 0 0 0 2px rgba(90, 160, 219, .35);
}
[data-theme="dark"] .page-research-desk .rd-thread {
  border-color: #3A4A62;
}
[data-theme="dark"] .page-research-desk .rd-check {
  color: var(--text);
}

.rd-source-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--ai);
  border-radius: 9px;
  padding: 10px 11px;
  margin-bottom: 8px;
}
.rd-source-card.matter { border-left-color: var(--gold); }
.rd-sc-title { font-size: 14px; font-weight: 700; color: var(--text); line-height: 1.35; }
.rd-sc-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.rd-sc-snip { font-size: 13px; color: var(--muted); margin-top: 6px; line-height: 1.4; }
.rd-sc-link { font-size: 12px; margin-top: 6px; }
.rd-sc-link a { color: var(--ai); text-decoration: none; }
.rd-sc-link a:hover { text-decoration: underline; }

.rd-status { font-size: 14px; color: var(--muted); min-height: 18px; }
.rd-status.error { color: var(--bad); }
.rd-status.ok { color: var(--ok); }

.rd-sel {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  font-family: var(--serif);
  font-size: 15px;
  padding: 8px 10px;
  min-width: 160px;
}