:root {
  --blue: #3b99ee;
  --blue-dark: #267ad2;
  --nav-bg: #f3f5f9;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #dce5ef;
  --line-strong: #c8d6e6;
  --text: #1f2d3d;
  --muted: #718096;
  --soft: #94a3b8;
  --green: #19a974;
  --orange: #d97706;
  --red: #c2413c;
  --shadow: 0 12px 34px rgba(38, 88, 140, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: transparent;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.research-shell {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.research-shell[data-mode="popup"] {
  width: 100%;
  height: 100dvh;
  min-width: 0;
  margin: 0;
  border-radius: 0;
  box-shadow: none;
}

.research-shell[data-mode="minimized"] {
  display: none;
}

.research-titlebar {
  height: 56px;
  background: var(--blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  flex-shrink: 0;
}

.research-titlebar,
.assistant-menu,
.research-toolbar,
.research-statusbar {
  display: none;
}

.title-left {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.title-left strong {
  font-size: 20px;
  font-weight: 780;
}

.brand-orb {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  color: #fff;
}

.window-actions {
  display: inline-flex;
  gap: 8px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.14);
}

.icon-button:hover,
.icon-button.is-active {
  background: rgba(255, 255, 255, 0.22);
}

.research-frame {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  background: var(--bg);
}

.assistant-menu {
  min-height: 0;
  padding: 18px 0;
  background: var(--nav-bg);
  border-right: 1px solid #e4e9f1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.menu-item {
  height: 56px;
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  border: 0;
  background: transparent;
  color: #5c6470;
  text-decoration: none;
  text-align: left;
}

.menu-item span {
  font-size: 20px;
}

.menu-item b {
  font-size: 17px;
  font-weight: 680;
}

.menu-item:hover {
  color: #2b6cb0;
  background: #edf4fc;
}

.menu-item.is-active {
  color: #1f5d99;
  background: #e6f1fb;
  border-right: 3px solid var(--blue);
}

.menu-item.is-disabled {
  opacity: 0.62;
  cursor: default;
}

.research-workbench {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.research-toolbar {
  min-height: 88px;
  padding: 18px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.research-toolbar h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
  font-weight: 800;
}

.research-toolbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.toolbar-actions,
.box-head,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.primary-button,
.ghost-button,
.small-button,
.text-button {
  border: 0;
  border-radius: 7px;
  font-weight: 760;
  white-space: nowrap;
}

.primary-button {
  height: 42px;
  padding: 0 18px;
  background: #208b57;
  color: #fff;
}

.primary-button:hover {
  background: #167344;
}

.ghost-button {
  height: 42px;
  padding: 0 16px;
  background: #64748b;
  color: #fff;
}

.ghost-button:hover {
  background: #53647a;
}

.small-button {
  height: 38px;
  padding: 0 12px;
  background: var(--blue);
  color: #fff;
}

.text-button {
  padding: 0;
  background: transparent;
  color: #2b6cb0;
}

.research-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 0.88fr) minmax(0, 1.18fr) minmax(0, 0.94fr);
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}

.research-shell[data-mode="popup"] .research-grid {
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  gap: 10px;
  padding: 10px;
  overflow-y: auto;
}

.research-shell[data-mode="popup"] .result-panel {
  grid-column: 1 / -1;
  min-height: 300px;
}

.research-shell[data-mode="popup"] .panel-head {
  min-height: 44px;
  padding: 10px 12px;
}

.research-shell[data-mode="popup"] .panel-head h2 {
  font-size: 16px;
}

.research-shell[data-mode="popup"] label {
  padding: 0 12px;
  margin-top: 10px;
}

.research-shell[data-mode="popup"] input,
.research-shell[data-mode="popup"] select {
  height: 36px;
}

.research-shell[data-mode="popup"] textarea {
  min-height: 76px;
  padding: 9px 10px;
}

.research-shell[data-mode="popup"] .criterion-editor,
.research-shell[data-mode="popup"] .query-box,
.research-shell[data-mode="popup"] .risk-box,
.research-shell[data-mode="popup"] .protocol-box {
  margin-left: 12px;
  margin-right: 12px;
}

.research-shell[data-mode="popup"] .source-tabs {
  padding: 10px 12px 6px;
  gap: 6px;
}

.research-shell[data-mode="popup"] .source-tab {
  height: 34px;
}

.research-shell[data-mode="popup"] .mapping-table {
  padding: 0 12px 10px;
}

.research-shell[data-mode="popup"] .mapping-row {
  min-height: 44px;
  grid-template-columns: 0.9fr 1fr auto;
}

.research-shell[data-mode="popup"] pre {
  max-height: 142px;
}

.research-shell[data-mode="popup"] .metric-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 10px 12px;
}

.research-shell[data-mode="popup"] .metric-card {
  min-height: 76px;
  padding: 10px;
}

.research-shell[data-mode="popup"] .metric-card strong {
  font-size: 24px;
}

.research-shell[data-mode="popup"] .result-panel {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  grid-template-rows: auto auto minmax(0, 1fr);
  padding-bottom: 10px;
}

.research-shell[data-mode="popup"] .result-panel > .panel-head,
.research-shell[data-mode="popup"] .result-panel > .metric-grid {
  grid-column: 1 / -1;
}

.research-shell[data-mode="popup"] .risk-box {
  margin-top: 0;
}

.research-shell[data-mode="popup"] .protocol-box {
  margin-top: 0;
}

.research-shell[data-mode="popup"] .protocol-box textarea {
  min-height: 190px;
}

.research-shell[data-mode="popup"] .study-panel,
.research-shell[data-mode="popup"] .mapping-panel,
.research-shell[data-mode="popup"] .result-panel {
  min-width: 0;
}

.panel {
  min-width: 0;
  min-height: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-head {
  min-height: 54px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.panel-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.panel-head span {
  color: var(--muted);
  font-size: 13px;
}

.study-panel,
.mapping-panel,
.result-panel {
  padding-bottom: 14px;
}

label {
  display: grid;
  gap: 7px;
  padding: 0 16px;
  margin-top: 14px;
}

label span {
  color: #516173;
  font-size: 13px;
  font-weight: 720;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input,
select {
  height: 40px;
  padding: 0 12px;
}

textarea {
  min-height: 96px;
  padding: 11px 12px;
  resize: vertical;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #5ba5ee;
  box-shadow: 0 0 0 3px rgba(59, 153, 238, 0.14);
}

.date-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.criterion-editor {
  margin: 14px 16px 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.editor-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.criteria-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  overflow-y: auto;
  padding-right: 2px;
}

.criterion-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  max-width: 100%;
  padding: 5px 9px 5px 10px;
  border-radius: 999px;
  background: #eef6ff;
  color: #255f99;
  border: 1px solid #d3e8ff;
  font-size: 13px;
  font-weight: 680;
}

.criterion-chip button {
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: rgba(37, 95, 153, 0.1);
  color: #255f99;
}

.source-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 14px 16px 8px;
}

.source-tab {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fafc;
  color: #475569;
  font-weight: 760;
}

.source-tab.is-active {
  border-color: #88bff3;
  color: #1f5d99;
  background: #ecf6ff;
}

.mapping-table {
  min-height: 0;
  overflow-y: auto;
  padding: 0 16px 12px;
}

.mapping-row {
  display: grid;
  grid-template-columns: 1.1fr 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  border-bottom: 1px solid #edf2f7;
  font-size: 13px;
}

.mapping-row strong {
  font-size: 14px;
}

.mapping-row span {
  color: var(--muted);
}

.mapping-row mark {
  justify-self: end;
  padding: 4px 8px;
  border-radius: 999px;
  color: #1f6b48;
  background: #e7f7ef;
  font-weight: 760;
}

.query-box,
.risk-box,
.protocol-box {
  margin: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  overflow: hidden;
}

.query-box {
  flex-shrink: 0;
}

.box-head {
  min-height: 42px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.box-head h3,
.risk-box h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
}

pre {
  margin: 0;
  max-height: 210px;
  overflow: auto;
  padding: 12px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  color: #25415f;
  white-space: pre-wrap;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 14px 16px;
}

.metric-card {
  min-height: 96px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #f8fbff);
  padding: 12px;
}

.metric-card span,
.metric-card small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric-card strong {
  display: block;
  margin: 8px 0 5px;
  color: #1f5d99;
  font-size: 28px;
  line-height: 1;
  font-weight: 860;
}

.risk-box {
  padding: 12px 14px;
}

.risk-box ul {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.risk-box li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  color: #475569;
  font-size: 13px;
  line-height: 1.45;
}

.risk-box li::before {
  content: "";
  width: 8px;
  height: 8px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--orange);
}

.protocol-box {
  margin-top: 14px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.protocol-box textarea {
  flex: 1;
  min-height: 190px;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.research-statusbar {
  height: 38px;
  padding: 0 18px;
  background: #f5f7fb;
  border-top: 1px solid var(--line);
  color: #6b7280;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  font-size: 13px;
}

.research-statusbar span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #65c943;
}

.restore-button {
  position: fixed;
  right: 24px;
  bottom: 24px;
  height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 24px;
  background: var(--blue);
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 780;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 54px;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: #1f2937;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 14px;
  z-index: 20;
}

.research-shell .research-titlebar,
.research-shell .assistant-menu,
.research-shell .research-toolbar,
.research-shell .research-statusbar {
  display: none;
}

@media (max-width: 1180px) {
  .research-grid {
    grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
    overflow-y: auto;
  }

  .study-panel,
  .mapping-panel,
  .result-panel {
    min-width: 0;
  }

  .result-panel {
    grid-column: 1 / -1;
    min-height: 420px;
  }
}

@media (max-width: 820px) {
  .research-shell,
  .research-shell[data-mode="popup"] {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 100%;
    margin: 0;
    border-radius: 0;
  }

  .research-frame {
    grid-template-columns: minmax(0, 1fr);
  }

  .research-grid,
  .research-shell[data-mode="popup"] .research-grid {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }

  .research-shell[data-mode="popup"] .result-panel {
    display: flex;
    grid-column: auto;
    min-height: 0;
  }

  .metric-grid,
  .research-shell[data-mode="popup"] .metric-grid {
    grid-template-columns: 1fr;
  }
}
