/* ==========================================================================
   「选刊」Xuankan Dual-Theme Design System (Aligned with Topic & Quanjie)
   Light (Default): 「硬记」冷灰蓝磨砂玻璃 (#F3F5F8 / #FFFFFF / #283848 / #8A6520)
   Dark (Toggle):   「全解」深邃极客黑金   (#070708 / #111114 / #FCD34D / #F5F5F7)
   ========================================================================== */

:root,
:root[data-theme="light"] {
  --bg: #F3F5F8;
  --surface: #FFFFFF;
  --surface-elevated: rgba(255, 255, 255, 0.92);
  --surface-inset: #EAEFF4;
  --surface-hover: #E3E9F0;
  --header-bg: rgba(243, 245, 248, 0.84);
  --border: rgba(40, 56, 72, 0.10);
  --border-strong: rgba(40, 56, 72, 0.20);
  --ink: #283848;
  --ink-2: #56687A;
  --muted: #8896A6;
  --accent: #283848;
  --accent-ink: #FFFFFF;
  --accent-soft: rgba(40, 56, 72, 0.08);
  --gold: #8A6520;
  --gold-soft: rgba(138, 101, 32, 0.11);
  --ok: #2B624B;
  --ok-soft: rgba(43, 98, 75, 0.10);
  --danger: #7D4247;
  --danger-soft: rgba(125, 66, 71, 0.10);
  --scholar: #25506B;
  --scholar-soft: rgba(37, 80, 107, 0.10);
  --shadow-sm: 0 2px 10px rgba(40, 56, 72, 0.05);
  --shadow-md: 0 10px 30px rgba(40, 56, 72, 0.09);
}

:root[data-theme="dark"] {
  --bg: #070708;
  --surface: #111114;
  --surface-elevated: rgba(17, 17, 20, 0.92);
  --surface-inset: #0B0B0D;
  --surface-hover: #1B1B20;
  --header-bg: rgba(7, 7, 8, 0.84);
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.20);
  --ink: #F5F5F7;
  --ink-2: #A1A1AA;
  --muted: #71717A;
  --accent: #FCD34D;
  --accent-ink: #0B0B0D;
  --accent-soft: rgba(252, 211, 77, 0.12);
  --gold: #FCD34D;
  --gold-soft: rgba(252, 211, 77, 0.14);
  --ok: #86EFAC;
  --ok-soft: rgba(134, 239, 172, 0.12);
  --danger: #F97171;
  --danger-soft: rgba(249, 113, 113, 0.14);
  --scholar: #7FAECB;
  --scholar-soft: rgba(127, 174, 203, 0.14);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 14px 36px rgba(0, 0, 0, 0.55);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'IBM Plex Sans', 'PingFang SC', 'Noto Sans SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.serif-title {
  font-family: 'Songti SC', 'STSong', 'Noto Serif SC', Georgia, serif;
  letter-spacing: 0.01em;
}

.mono {
  font-family: 'SF Mono', 'JetBrains Mono', ui-monospace, Menlo, monospace;
}

#dot-grid {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.ico {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.custom-scroll::-webkit-scrollbar { width: 5px; height: 5px; }
.custom-scroll::-webkit-scrollbar-track { background: transparent; }
.custom-scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.custom-scroll::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ==================== Shell Layout ==================== */
.app-shell {
  position: relative;
  z-index: 1;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  flex-shrink: 0;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 16px;
  background: var(--header-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-seal {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.brand-seal .ico { width: 15px; height: 15px; stroke-width: 1.85; }

.brand-meta { display: flex; flex-direction: column; line-height: 1.18; min-width: 0; }
.brand-name { font-weight: 700; font-size: 14px; letter-spacing: 0.02em; white-space: nowrap; }
.brand-sub { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.seg-bar {
  display: inline-flex;
  align-items: center;
  background: var(--surface-inset);
  border: 1px solid var(--border);
  padding: 2.5px;
  border-radius: 10px;
  gap: 2px;
}

.seg-opt {
  border: none;
  background: transparent;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background 0.15s, color 0.15s;
}

.seg-opt:hover { color: var(--ink); }
.seg-opt.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* Four-stage Academic Workflow Stepper (adapted from Quanjie steps-dots) */
.pipeline-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 11px;
  color: var(--muted);
}

.pipe-step {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.pipe-step.cur { color: var(--ink); font-weight: 600; }
.pipe-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border-strong);
}
.pipe-step.cur .pipe-dot {
  background: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}
.pipe-sep { color: var(--border-strong); font-size: 10px; }

/* Buttons & Pills */
.pill-btn, .btn-primary, .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 31px;
  padding: 0 11px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.pill-btn {
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
}
.pill-btn:hover { background: var(--surface-inset); border-color: var(--border-strong); }

.btn-ghost {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
}
.btn-ghost:hover { background: var(--surface-inset); color: var(--ink); border-color: var(--border-strong); }

.btn-primary {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-primary:hover { opacity: 0.9; }

.btn-gold {
  border: 1px solid var(--gold);
  background: var(--gold-soft);
  color: var(--gold);
  font-weight: 600;
}
.btn-gold:hover { background: var(--gold); color: var(--accent-ink); }

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
}
.status-dot.warn { background: var(--gold); }

/* ==================== Three-Column Workstation ==================== */
.front-workspace {
  flex: 1;
  min-height: 0;
  max-width: 1720px;
  width: 100%;
  margin: 0 auto;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr) 368px;
  gap: 12px;
  overflow: hidden;
}

.front-workspace.left-collapsed {
  grid-template-columns: minmax(0, 1fr) 368px;
}

.col-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.col-scroll {
  overflow-y: auto;
  padding-right: 2px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

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

.card-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ==================== Left Column: Tile Map + History + Insights ==================== */
.tile-grid-map {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(7, minmax(0, 1fr));
  gap: 3px;
  height: 214px;
}

.tile-cell {
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-inset);
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 1px;
  line-height: 1.05;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

.tile-cell.has-hits {
  background: var(--scholar-soft);
  border-color: rgba(37, 80, 107, 0.25);
  color: var(--ink);
}

:root[data-theme="dark"] .tile-cell.has-hits {
  border-color: rgba(127, 174, 203, 0.30);
}

.tile-cell.selected {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--accent-ink);
  box-shadow: 0 0 0 2px var(--gold-soft);
}

.tile-cell:hover {
  transform: scale(1.06);
  z-index: 5;
  border-color: var(--gold);
}

.tile-name { font-size: 9px; font-weight: 600; }
.tile-cnt { font-size: 8.5px; font-weight: 700; opacity: 0.85; margin-top: 1px; }

.left-card-fixed { flex-shrink: 0; }
.insights-card {
  flex: 1 1 0;
  min-height: 220px;
  display: flex;
  flex-direction: column;
}
.insights-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 8px;
}

.rank-row {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  color: var(--ink);
  font-family: inherit;
}
.rank-row:hover { background: var(--surface-inset); }
.rank-row.active { background: var(--gold-soft); border-color: var(--gold); }
.rank-bar-track { height: 4px; border-radius: 99px; background: var(--surface-inset); overflow: hidden; margin-top: 3px; }
.rank-bar-fill { height: 100%; border-radius: 99px; background: var(--scholar); }
.rank-row.active .rank-bar-fill { background: var(--gold); }

/* ==================== Center Column: Results ==================== */
.intent-bar {
  flex-shrink: 0;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface-elevated);
  padding: 9px 12px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  box-shadow: var(--shadow-sm);
}

.risk-banner {
  flex-shrink: 0;
  border-radius: 11px;
  border: 1px solid var(--danger);
  background: var(--danger-soft);
  color: var(--ink);
  padding: 7px 12px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.results-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.results-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.journal-row {
  padding: 12px 15px;
  border-bottom: 1px dashed var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  transition: background 0.14s;
}
.journal-row:hover { background: var(--surface-inset); }

.journal-title {
  font-size: 15.5px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.35;
}

mark.hl {
  background: var(--gold-soft);
  color: var(--ink);
  padding: 0 2px;
  border-radius: 3px;
  border-bottom: 1.5px solid var(--gold);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-inset);
  color: var(--ink-2);
  white-space: nowrap;
}
.badge.cssci { background: var(--danger-soft); color: var(--danger); border-color: rgba(125, 66, 71, 0.28); }
.badge.pkucore { background: var(--scholar-soft); color: var(--scholar); border-color: rgba(37, 80, 107, 0.28); }
.badge.stic { background: var(--ok-soft); color: var(--ok); border-color: rgba(43, 98, 75, 0.28); }
.badge.ami, .badge.gold { background: var(--gold-soft); color: var(--gold); border-color: rgba(138, 101, 32, 0.30); }
.badge.depth-full { background: var(--gold-soft); color: var(--gold); border-color: var(--gold); }
.badge.depth-form { background: var(--scholar-soft); color: var(--scholar); border-color: var(--scholar); }
.badge.depth-none { background: transparent; color: var(--muted); border-color: var(--border); font-weight: 500; }

.chip-btn {
  padding: 4px 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.14s;
}
.chip-btn:hover { background: var(--surface-inset); color: var(--ink); }
.chip-btn.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}

.row-act-btn {
  padding: 4px 8px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.row-act-btn:hover { background: var(--surface-hover); color: var(--ink); border-color: var(--border-strong); }
.row-act-btn.starred { background: var(--gold-soft); color: var(--gold); border-color: var(--gold); }

/* ==================== Right Column: AI Chat & Manual Filters ==================== */
.right-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat-thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface-inset);
}

.msg-user {
  align-self: flex-end;
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 14px 14px 3px 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12.5px;
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
}

.msg-bot {
  align-self: flex-start;
  max-width: 96%;
  padding: 10px 12px;
  border-radius: 14px 14px 14px 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 12.5px;
  line-height: 1.6;
  box-shadow: var(--shadow-sm);
}

.msg-bot h3, .msg-bot h4 { margin: 4px 0 6px; font-size: 13px; font-weight: 700; color: var(--ink); }
.msg-bot p { margin: 4px 0; }
.msg-bot ul { margin: 4px 0; padding-left: 18px; }
.msg-bot li { margin: 2px 0; }

.tool-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 7px;
  background: var(--surface-inset);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--ink-2);
  margin: 0 4px 5px 0;
}

.thinking-box {
  margin-bottom: 6px;
  padding: 5px 8px;
  border-left: 2px solid var(--gold);
  background: var(--gold-soft);
  border-radius: 0 6px 6px 0;
  font-size: 11px;
  color: var(--ink-2);
}

.composer-wrap {
  flex-shrink: 0;
  padding: 10px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  position: relative;
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--surface-inset);
}

.composer-box:focus-within {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--gold-soft);
}

.composer-textarea {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--ink);
  resize: none;
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.45;
  outline: none;
  max-height: 92px;
}

.suggest-popover {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  z-index: 40;
  overflow: hidden;
}

/* ==================== Secondary Workspaces (Guide / Admin) ==================== */
.full-scroll-ws {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 18px 28px;
}

.ws-container {
  max-width: 1560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.input-ctrl, .select-ctrl, .textarea-ctrl {
  width: 100%;
  border: 1px solid var(--border-strong);
  background: var(--surface-inset);
  color: var(--ink);
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
}
.input-ctrl:focus, .select-ctrl:focus, .textarea-ctrl:focus {
  border-color: var(--gold);
}

/* ==================== Modals & Toast ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(7, 10, 16, 0.56);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  padding: 14px 18px;
  background: var(--accent);
  color: var(--accent-ink);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-foot {
  padding: 12px 18px;
  background: var(--surface-inset);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 120;
  padding: 9px 15px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* ==================== Responsive Mobile / Tablet ==================== */
@media (max-width: 1120px) {
  .pipeline-bar { display: none; }
  .app-shell { height: auto; min-height: 100vh; overflow: visible; }
  .front-workspace, .front-workspace.left-collapsed {
    grid-template-columns: 1fr;
    overflow: visible;
    height: auto;
  }
  .results-scroll { max-height: 60vh; }
  .chat-thread { min-height: 300px; max-height: 440px; }
  .insights-card { flex: none; min-height: 0; }
  .insights-body { max-height: 320px; }
}
