:root {
  color-scheme: light;
  --font-hei: "SimHei", "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", Arial, sans-serif;
  --font-kai: "KaiTi", "STKaiti", "Kaiti SC", "SimKai", "KaiTi_GB2312", serif;
  --font-ui: var(--font-hei);
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef3f0;
  --text: #1c2521;
  --muted: #66736d;
  --line: #d9e0dc;
  --primary: #2f6f5e;
  --primary-dark: #245548;
  --accent: #8f4a3d;
  --focus: #d19a38;
  --shadow: 0 16px 40px rgba(28, 37, 33, 0.08);
}

:root[data-font="hei"] {
  --font-ui: var(--font-hei);
}

:root[data-font="kai"] {
  --font-ui: var(--font-kai);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.service-ok {
  color: #bce2ce;
  font-weight: 700;
}

.service-warn {
  color: #f1d39a;
  font-weight: 700;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.compare-workspace {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 1fr);
  gap: 18px;
  align-items: start;
}

.reader-layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 14px;
  width: 100%;
  min-height: 0;
  overflow: hidden;
}

.reader-main {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  gap: 14px;
  width: 100%;
  min-width: 0;
  min-height: 0;
}

.reader-combined-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 14px;
  padding-bottom: 12px;
  min-height: 0;
  overflow: hidden;
}

.reader-compare {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  width: 100%;
  min-height: 0;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 20px;
}

.form-panel {
  display: grid;
  gap: 14px;
}

.file-picker-row {
  justify-items: stretch;
}

.file-picker-row input {
  width: 100%;
  text-align: center;
}

.info-field {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.info-field-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.info-field-heading span:last-child {
  font-weight: 400;
  white-space: nowrap;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.form-help {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}
.auth-bar { display:inline-flex; align-items:center; gap:0; }
.auth-bar .auth-actions { display:inline-flex; align-items:center; gap:0; }
.auth-bar .auth-user { margin-right:12px; color:var(--muted); font-size:13px; font-weight:700; white-space:nowrap; max-width:200px; overflow:hidden; text-overflow:ellipsis; }
.auth-bar .auth-user.hidden { display:none; }
.auth-modal { position:fixed; inset:0; background:rgba(15,23,42,.38); display:grid; place-items:center; z-index:20; }
.auth-modal.hidden { display:none; }
.auth-card { width:min(360px, calc(100vw - 32px)); background:#fff; padding:24px; border-radius:8px; box-shadow:0 16px 48px rgba(15,23,42,.2); display:grid; gap:12px; }
.auth-card input { padding:10px 12px; border:1px solid #cbd5e1; border-radius:4px; }
.auth-card p { color:#b42318; min-height:20px; margin:0; }

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

.workspace-grid > .document-detail {
  display: none;
}


.reader-sidebar-stack {
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(120px, 28%);
  gap: 14px;
  min-width: 0;
  min-height: 0;
}

.reader-sidebar {
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

.reader-sidebar-reserved {
  min-height: 0;
}

.refresh-stream-button.icon-button {
  display: inline-grid;
  width: 30px;
  height: 30px;
  padding: 5px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--primary);
  font-size: 0;
}

.refresh-stream-button:hover {
  background: #e3ebe7;
  color: var(--primary-dark);
}

.refresh-stream-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#reader-document-detail {
  margin: 0;
}

#reader-document-detail div {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
  font-size: 13px;
}

#reader-document-detail .metadata-pair-row {
  grid-template-columns: max-content minmax(0, 1fr) max-content minmax(0, 1fr);
  column-gap: 8px;
}

#reader-document-detail dt {
  color: var(--muted);
  font-weight: 700;
}

#reader-document-detail dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

#reader-document-detail .reader-visibility-row {
  align-items: center;
  padding: 10px 0 12px;
}

.reader-visibility-options {
  display: grid;
  grid-template-columns: max-content;
  gap: 8px;
  width: max-content;
  border: 0;
  padding: 0;
  background: transparent;
}

.reader-visibility-option {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.3;
  cursor: pointer;
}

.reader-visibility-option input {
  width: auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--primary);
}

.reader-visibility-option.is-disabled {
  cursor: default;
  opacity: 0.62;
}

.reader-stream-status {
  margin-top: 12px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdfc;
  color: var(--text);
  padding: 10px 11px;
  font-weight: 400;
}

textarea {
  resize: vertical;
  min-height: 360px;
  line-height: 1.7;
}

.layer-textarea {
  min-height: 160px;
}

.notes-textarea {
  min-height: 120px;
}

input:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(209, 154, 56, 0.28);
  outline-offset: 2px;
  border-color: var(--focus);
}

/* 首页底栏输入框本身无边框，聚焦时不再显示黄色焦点框。 */
.smart-input-box textarea:focus,
.smart-input-box textarea:focus-visible {
  outline: none;
  border-color: transparent;
}

.primary-button,
.secondary-button {
  min-height: 38px;
  border-radius: 6px;
  padding: 8px 14px;
  border: 1px solid transparent;
}

.primary-button {
  background: var(--primary);
  color: #fff;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.secondary-button {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.secondary-button:hover {
  border-color: #bac7c0;
  background: #e3ebe7;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.compact-heading {
  margin-top: 20px;
  margin-bottom: 12px;
}

.section-heading h3,
.form-panel h3 {
  margin: 0;
  font-size: 18px;
}

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

.document-list,
.page-list,
.result-list {
  display: grid;
  gap: 10px;
}

.document-card,
.page-item,
.result-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdfc;
}

.page-item {
  align-items: center;
}

.page-item.active {
  border-color: var(--primary);
  background: #f1f7f4;
}

.document-card h4,
.result-item h4 {
  margin: 0 0 6px;
  font-size: 16px;
}

.meta-line,
.result-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
  font-size: 13px;
}

.document-detail dl,
#document-detail {
  margin: 0;
}

#document-detail div {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

#document-detail .metadata-pair-row {
  grid-template-columns: max-content minmax(0, 1fr) max-content minmax(0, 1fr);
  column-gap: 10px;
}

#document-detail dt {
  color: var(--muted);
  font-weight: 700;
}

#document-detail dd {
  margin: 0;
}

.transcription-panel {
  display: grid;
  gap: 14px;
}

.text-layer {
  gap: 8px;
}

.layer-tools {
  display: flex;
  justify-content: flex-end;
  margin-top: -6px;
}

.original-panel {
  display: grid;
  gap: 14px;
}

.page-image-picker {
  margin-bottom: 2px;
}

.original-viewer {
  display: grid;
  min-height: 460px;
  max-height: 70vh;
  place-items: center;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
  padding: 12px;
}

.original-viewer img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  background: #fff;
}

.reader-original-viewer {
  display: grid;
  min-height: 0;
  height: 100%;
  place-items: start center;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
  padding: 12px;
}

.reader-original-viewer img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--line);
  background: #fff;
}

.action-row,
.page-nav-row,
.reader-nav-row,
.page-add-row {
  display: flex;
  gap: 12px;
  align-items: end;
}

.page-nav-row,
.reader-nav-row {
  justify-content: flex-start;
  align-items: center;
  flex-wrap: wrap;
}

.reader-nav-row {
  justify-content: center;
  padding-top: 14px;
}

.reader-page-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.reader-page-jump {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: auto;
  min-width: 138px;
  min-height: 38px;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.reader-page-jump input {
  width: 48px;
  min-height: 30px;
  padding: 2px 6px;
  border-radius: 6px;
  text-align: center;
}

.reader-page-jump span {
  white-space: nowrap;
}

.page-add-row {
  margin-bottom: 12px;
}

.page-batch-row {
  margin-bottom: 12px;
}

.page-batch-row button {
  width: 100%;
}

.page-add-row label {
  flex: 1;
}

.empty-state {
  border: 1px dashed #bac7c0;
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.inline-status {
  color: var(--muted);
  font-size: 13px;
  line-height: 38px;
}

.stream-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 14px;
}

.progress-stack {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.progress-row {
  display: grid;
  grid-template-columns: 92px 1fr 86px;
  gap: 10px;
  align-items: center;
}

.progress-label {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: #e6ebe6;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #3e8f76);
  transition: width 0.3s ease;
}

.progress-fill-sub {
  background: linear-gradient(90deg, var(--gold), #d9a566);
}

.progress-value {
  color: var(--text);
  font-size: 12px;
  text-align: right;
  white-space: nowrap;
}

.reader-original-panel,
.reader-text-panel,
.reader-annotation-panel {
  min-height: 0;
  overflow: hidden;
}

.reader-original-panel,
.reader-text-panel,
.reader-annotation-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.reader-text-heading {
  min-height: 28px;
  justify-content: space-between;
  text-align: left;
}

.reader-annotation-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  min-height: 28px;
}

.reader-original-panel > .section-heading {
  min-height: 28px;
  justify-content: flex-start;
}

.reader-original-panel > .section-heading .reader-panel-toggle {
  order: -1;
}

.reader-annotation-heading h3 {
  text-align: right;
}

.reader-annotation-heading .reader-panel-toggle {
  justify-self: end;
}

.reader-annotation-status {
  min-height: 20px;
}

.reader-panel-toggle.icon-button {
  display: inline-grid;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  place-items: center;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--primary);
}

.reader-panel-toggle.icon-button:hover {
  background: #e3ebe7;
  color: var(--primary-dark);
}

.reader-panel-toggle svg {
  width: 16px;
  height: 16px;
  transition: transform 160ms ease;
}

.reader-panel-collapsed > :not(.section-heading) {
  display: none;
}

.reader-panel-collapsed .reader-panel-toggle svg {
  transform: rotate(180deg);
}

.reader-annotation {
  width: 100%;
  height: 100%;
  min-height: 0;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
  color: var(--text);
  padding: 18px;
  font: inherit;
  line-height: 1.85;
}

.reader-annotation:focus {
  border-color: var(--focus);
  outline: 2px solid color-mix(in srgb, var(--focus) 18%, transparent);
  outline-offset: 0;
}

.reader-annotation:disabled {
  background: #f8faf9;
  color: var(--muted);
}

.reader-text {
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
  padding: 18px;
  white-space: pre-wrap;
  line-height: 1.85;
}

.reader-original-viewer.is-empty,
.reader-text.is-empty {
  display: grid;
  place-items: center;
}

.reader-text.is-empty {
  white-space: normal;
}

.reader-text.is-editing {
  min-height: 220px;
  padding: 14px;
  border-color: var(--focus);
  background: #fffdf7;
  outline: none;
}

.reader-empty-state {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(251, 253, 252, 0.96);
  color: var(--muted);
  box-shadow: 0 10px 24px rgba(42, 48, 44, 0.06);
  line-height: 1.7;
}

.reader-notes {
  margin-top: 12px;
  border-left: 3px solid var(--accent);
  background: #f8f4ef;
  color: var(--muted);
  padding: 10px 12px;
  white-space: pre-wrap;
  line-height: 1.7;
}

.hidden {
  display: none !important;
}

mark {
  background: #f5d996;
  color: #1c2521;
  padding: 0 2px;
}

@media (max-width: 900px) {
  .app-shell,
  .workspace-grid,
  .compare-workspace,
  .reader-layout,
  .reader-compare {
    grid-template-columns: 1fr;
  }

  .page-item,
  .result-item,
  .action-row,
  .page-nav-row,
  .reader-nav-row,
  .stream-actions,
  .page-add-row {
    align-items: stretch;
    flex-direction: column;
  }
}

/* Bookshelf home redesign */
:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef1ec;
  --text: #20241f;
  --muted: #747b74;
  --line: #dde2dc;
  --primary: #2d6b5c;
  --primary-dark: #1f5145;
  --red: #d84233;
  --gold: #b78b55;
  --blue: #5477d8;
  --ink: #161916;
  --shadow: 0 18px 44px rgba(32, 36, 31, 0.1);
  --book-shadow: 0 16px 26px rgba(32, 36, 31, 0.18);
}

html {
  scroll-behavior: smooth;
}

body {
  background:
    radial-gradient(circle at 18% 8%, rgba(183, 139, 85, 0.12), transparent 26%),
    linear-gradient(180deg, #fafbf8 0%, var(--bg) 46%, #eef1ef 100%);
}

.app-shell {
  display: block;
  min-height: 100vh;
}

.main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 34px 24px 56px;
}

.reader-topbar,
.workspace-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.reader-topbar h2,
.workspace-topbar h2 {
  margin: 4px 0 0;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1;
  font-family: inherit;
  font-weight: 700;
}

.reader-topbar h2,
.workspace-topbar h2 {
  font-size: 34px;
  font-family: inherit;
}

.reader-title-block {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-width: 0;
}

.reader-title-block h2 {
  margin: 0;
  color: var(--text);
  font-size: 24px;
  line-height: 1.2;
}

.reader-title-block h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 28px;
  margin: -2px -4px 0 0;
}

.progress-title {
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.progress-header .refresh-stream-button {
  width: 26px;
  height: 26px;
  padding: 4px;
}

.progress-header .refresh-stream-button svg {
  width: 14px;
  height: 14px;
}

.progress-combined-track {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
}

.progress-track-combined {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: #edf2ef;
  overflow: hidden;
}

.progress-track-combined .progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  min-width: 0;
}

.progress-fill-ocr {
  z-index: 2;
  background: linear-gradient(90deg, var(--primary), #3e8f76);
}

.progress-fill-llm {
  z-index: 1;
  opacity: 0.78;
  background: linear-gradient(90deg, var(--accent), #c7775f);
}

.progress-ocr-pages,
.progress-llm-pages {
  min-width: 20px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.reader-progress-area {
  display: block;
}

.reader-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  align-items: center;
}

.reader-topbar .ghost-link {
  color: #7b817b;
}

.icon-text-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon-text-button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#edit-document:disabled {
  cursor: default;
  opacity: 0.55;
}

.eyebrow {
  margin: 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
  text-transform: none;
}

.icon-button,
.back-button,
.ghost-link,
.chip-button,
.round-send {
  border: 0;
  color: var(--text);
}

.icon-button {
  display: inline-grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 50%;
  background: transparent;
  font-size: 30px;
  line-height: 1;
}

.icon-button:hover,
.back-button:hover,
.ghost-link:hover {
  background: rgba(32, 36, 31, 0.06);
}

.icon-button.subtle {
  width: 36px;
  height: 36px;
  color: var(--muted);
  font-size: 24px;
}

.ghost-link {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 10px;
  border-radius: 6px;
  background: transparent;
  color: #7b817b;
  font-weight: 700;
}

.shelf-stage {
  position: relative;
  padding-bottom: 26px;
}

.document-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  column-gap: clamp(26px, 4vw, 54px);
  row-gap: 48px;
}

.book-card {
  position: relative;
  min-width: 0;
}

.book-card[data-document-id] {
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.book-card.dragging {
  z-index: 3;
  cursor: grabbing;
  opacity: 0.28;
  transform: scale(0.98);
}

.book-drag-preview {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  margin: 0;
  pointer-events: none;
  opacity: 0.94;
  filter: drop-shadow(0 18px 28px rgba(32, 36, 31, 0.24));
}

.document-list.is-reordering .book-card {
  transition:
    opacity 120ms ease,
    transform 120ms ease;
}

.document-drag-active,
.document-drag-active * {
  cursor: grabbing !important;
}

.book-card::after {
  content: "";
  position: absolute;
  left: -8px;
  right: -8px;
  bottom: -8px;
  z-index: -1;
  height: 16px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(185, 180, 161, 0), rgba(185, 180, 161, 0.72), rgba(185, 180, 161, 0));
  filter: blur(6px);
}

.book-open {
  display: grid;
  width: 100%;
  gap: 12px;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.book-cover,
.add-document {
  aspect-ratio: 0.72;
  width: 100%;
  min-height: 210px;
  border-radius: 6px 4px 4px 6px;
}

.book-cover {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  padding: 18px 16px;
  box-shadow: var(--book-shadow);
  color: #fff;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.2) 0 9px, transparent 9px),
    linear-gradient(145deg, #314f64, #c24732);
}

.book-cover.image-cover {
  background-image:
    linear-gradient(90deg, rgba(0, 0, 0, 0.34) 0 9px, transparent 9px),
    linear-gradient(0deg, rgba(0, 0, 0, 0.58), rgba(0, 0, 0, 0.12) 48%, rgba(0, 0, 0, 0.34)),
    var(--cover-image);
  background-position: left top, center, center;
  background-repeat: no-repeat;
  background-size: auto, cover, cover;
  color: #fff;
}

.book-cover::before,
.book-cover::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.book-cover::before {
  inset: 0;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.22), transparent 35%),
    radial-gradient(circle at 80% 18%, rgba(255, 255, 255, 0.22), transparent 24%),
    linear-gradient(0deg, rgba(0, 0, 0, 0.3), transparent 42%);
}

.book-cover::after {
  left: 16px;
  right: 16px;
  bottom: 18px;
  height: 1px;
  background: rgba(255, 255, 255, 0.36);
}

.cover-1 .book-cover {
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.2) 0 9px, transparent 9px),
    linear-gradient(145deg, #e8e3d5, #7d9a72);
  color: #1f2b23;
}

.cover-2 .book-cover {
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.22) 0 9px, transparent 9px),
    linear-gradient(145deg, #141817, #bf2d22 62%, #f0d9b4);
}

.cover-3 .book-cover {
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.16) 0 9px, transparent 9px),
    linear-gradient(145deg, #f0c328, #e75d2a 58%, #25364b);
}

.cover-4 .book-cover {
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.2) 0 9px, transparent 9px),
    linear-gradient(145deg, #425d4e, #d6c4a4);
}

.cover-5 .book-cover {
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.22) 0 9px, transparent 9px),
    linear-gradient(145deg, #2c4772, #8e3d43 60%, #d8a84c);
}

.book-title {
  position: relative;
  z-index: 1;
  display: -webkit-box;
  overflow: hidden;
  font-size: clamp(20px, 2.2vw, 32px);
  font-family: inherit;
  font-weight: 700;
  line-height: 1.12;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
}

.book-author {
  position: relative;
  z-index: 1;
  max-width: 100%;
  overflow: hidden;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-facts {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  margin-top: auto;
  font-size: 13px;
  line-height: 1.4;
  font-weight: 700;
}

.book-year,
.book-pages {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-pages {
  flex: 0 0 auto;
  text-align: right;
}

.book-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: #333832;
}

.book-meta strong {
  overflow: hidden;
  font-size: 16px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-meta small,
.add-document small {
  color: var(--muted);
  line-height: 1.5;
}

.add-document {
  place-items: center;
  padding: 22px;
  border: 1px solid #edf0ec;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--book-shadow);
  text-align: center;
}

.add-card.trash-card .add-document {
  border-color: #d9aaa4;
  background: #fff4f2;
  color: #a83228;
}

.add-card.trash-card .add-plus {
  color: #c94437;
  font-weight: 400;
}

.add-card.trash-card .book-meta strong {
  color: #a83228;
}

.add-card.trash-card.trash-hover .add-document {
  border-color: #c94437;
  background: #f8dedb;
  box-shadow: 0 18px 32px rgba(201, 68, 55, 0.2);
  transform: translateY(-2px);
}

.add-plus {
  display: grid;
  width: 84px;
  height: 84px;
  place-items: center;
  color: #c6cac4;
  font-size: 72px;
  font-weight: 200;
  line-height: 1;
}

.smart-dock {
  margin-top: 54px;
  padding-bottom: 10px;
}

.smart-input-box {
  display: grid;
  gap: 14px;
  min-height: 176px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 42px rgba(42, 48, 44, 0.09);
}

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

.reference-trigger {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7f9f7;
  color: #4f5b54;
  font-size: 13px;
  font-weight: 700;
}

.reference-trigger:hover {
  border-color: #b8c6be;
  background: #edf3ef;
}

.reference-trigger-count {
  display: inline-grid;
  min-width: 20px;
  height: 20px;
  place-items: center;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
}

.reference-chips {
  display: flex;
  min-width: 0;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.reference-chip {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  max-width: 240px;
  min-height: 30px;
  padding: 4px 5px 4px 10px;
  border: 1px solid #c8d8cf;
  border-radius: 999px;
  background: #edf5f0;
  color: #315d4f;
  font-size: 12px;
}

.reference-chip > span,
.reference-chip > a {
  overflow: hidden;
  color: inherit;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reference-chip > a:hover {
  text-decoration: underline;
}

.reference-chip button {
  display: grid;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  line-height: 1;
}

.reference-chip button:hover {
  background: rgba(47, 111, 94, 0.12);
}

.reference-chip-warning {
  border-color: #e2bd77;
  background: #fff7e7;
  color: #8c5c13;
}

.attachment-chip {
  border-color: #c8d2ea;
  background: #f0f3fb;
  color: #425c93;
}

.attachment-chip-pending {
  border-style: dashed;
  color: #6d6f78;
}

.reference-scope-status {
  margin: -6px 2px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.reference-scope-status.reference-scope-warning {
  color: #9a6217;
}

.smart-input-box textarea {
  min-height: 78px;
  padding: 6px 2px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  line-height: 1.6;
  resize: vertical;
}

.smart-input-box textarea::placeholder {
  color: #a1a8a3;
}

.smart-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Keep the conversation sources with the send control in the lower-right corner. */
#open-reference-documents {
  margin-left: auto;
}

.chip-button {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: #58615b;
  font-weight: 700;
}

.chip-button.active {
  border-color: #b9c9ff;
  background: #eef3ff;
  color: #3768f4;
}

.chip-button:not(.active):hover {
  background: #f1f4f1;
}

.chip-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.chip-button:disabled:hover {
  background: transparent;
}

.round-send {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border-radius: 50%;
  background: #aebdf7;
  color: #fff;
  font-size: 32px;
  line-height: 1;
}

.smart-results {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.form-sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(32, 36, 31, 0.28);
  backdrop-filter: blur(6px);
}

.confirm-dialog {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(32, 36, 31, 0.28);
  backdrop-filter: blur(6px);
}

.reference-dialog {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(32, 36, 31, 0.32);
  backdrop-filter: blur(6px);
}

.reference-dialog-card {
  display: grid;
  grid-template-rows: auto auto minmax(180px, 1fr) auto;
  gap: 14px;
  width: min(680px, 100%);
  max-height: min(720px, calc(100vh - 44px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.reference-dialog-header,
.reference-dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.reference-dialog-header {
  align-items: flex-start;
}

.reference-dialog-header h2,
.reference-dialog-header p {
  margin: 0;
}

.reference-dialog-header h2 {
  font-size: 21px;
}

.reference-dialog-header p {
  margin-top: 7px;
  color: var(--muted);
  line-height: 1.5;
}

.reference-dialog-close {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.reference-document-search {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--text);
}

.reference-document-list {
  display: grid;
  align-content: start;
  gap: 7px;
  min-height: 180px;
  padding: 2px;
  overflow-y: auto;
}

.reference-document-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfcfb;
  cursor: pointer;
}

.reference-document-option:hover {
  border-color: #afc3b8;
  background: #f2f7f4;
}

.reference-document-option input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.reference-document-option > span {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.reference-document-option strong,
.reference-document-option span span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reference-document-option span span,
.reference-dialog-footer,
.reference-document-empty {
  color: var(--muted);
  font-size: 13px;
}

.reference-document-empty {
  margin: 0;
  padding: 44px 12px;
  text-align: center;
}

.confirm-card {
  width: min(360px, 100%);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.confirm-card h2 {
  margin: 0;
  font-size: 20px;
}

.confirm-card p {
  margin: 12px 0 18px;
  color: var(--muted);
  line-height: 1.6;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.danger-button {
  min-height: 38px;
  border: 1px solid #c94437;
  border-radius: 6px;
  background: #c94437;
  color: #fff;
  padding: 8px 14px;
}

.danger-button:hover {
  background: #a83228;
}

.form-panel {
  width: min(680px, 100%);
  max-height: min(820px, calc(100vh - 44px));
  overflow: auto;
}

.back-button {
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 980px) {
  .document-list {
    grid-template-columns: repeat(3, minmax(130px, 1fr));
  }

  .workspace-grid,
  .compare-workspace,
  .reader-layout,
  .reader-compare {
    grid-template-columns: 1fr;
  }

  .reader-sidebar-stack {
    grid-template-rows: auto minmax(120px, 28%);
  }

  #reader-view.active {
    overflow: auto;
  }

  .reader-layout,
  .reader-main,
  .reader-combined-panel,
  .reader-compare {
    min-height: auto;
  }

  .reader-original-viewer,
  .reader-text,
  .reader-annotation {
    min-height: 320px;
  }
}

@media (max-width: 680px) {
  .main {
    padding: 22px 16px 40px;
  }

  .reader-topbar,
  .workspace-topbar,
  .page-item,
  .result-item,
  .action-row,
  .page-nav-row,
  .reader-nav-row,
  .stream-actions,
  .page-add-row {
    align-items: stretch;
    flex-direction: column;
  }

  .smart-actions {
    align-self: stretch;
  }

  .reference-context {
    align-items: flex-start;
    flex-direction: column;
  }

  .reference-chips {
    width: 100%;
  }

  .reference-dialog {
    padding: 10px;
  }

  .reference-dialog-card {
    max-height: calc(100vh - 20px);
    padding: 16px;
  }

  .reference-dialog-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .reference-dialog-footer .confirm-actions {
    justify-content: stretch;
  }

  .reference-dialog-footer .confirm-actions button {
    flex: 1 1 0;
  }

  .document-list {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
    column-gap: 22px;
    row-gap: 38px;
  }

  .book-cover,
  .add-document {
    min-height: 184px;
  }

  .smart-input-box {
    border-radius: 20px;
    padding: 18px;
  }

  .round-send {
    margin-left: 0;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }
}

/* Full-screen chat-library home */
html,
body {
  height: 100%;
  overflow: hidden;
}

.app-shell {
  height: 100vh;
  overflow: hidden;
}

.main {
  width: 100%;
  height: 100vh;
  padding: 0;
  overflow: hidden;
}

#library-view.active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  gap: 14px;
  padding: 14px;
  overflow: hidden;
}

.home-statusbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  min-height: 68px;
  padding: 10px 18px;
  border: 1px solid rgba(221, 226, 220, 0.86);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 12px 32px rgba(42, 48, 44, 0.08);
}

.service-strip {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  min-width: 0;
  color: #69716a;
  font-size: 14px;
  white-space: nowrap;
}

.service-item {
  display: inline-flex;
  flex: 0 0 112px;
  align-items: center;
  gap: 4px;
  min-width: 112px;
}

.service-item-version {
  flex-basis: 118px;
  min-width: 118px;
}

.service-item-llm {
  flex-basis: 136px;
  min-width: 136px;
}

.status-title {
  text-align: center;
}

.status-title .eyebrow {
  color: var(--text);
  font-size: 24px;
  font-family: inherit;
}

.home-topbar-actions {
  display: inline-flex;
  justify-self: end;
  align-items: center;
  gap: 4px;
  min-width: 0;
  white-space: nowrap;
}

.settings-button {
  color: #69716a;
}

.font-options {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border: 1px solid rgba(174, 184, 175, 0.78);
  border-radius: 8px;
  background: #f7faf6;
}

.font-option {
  min-width: 48px;
  min-height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #414842;
  padding: 3px 9px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
}

.font-option[data-font-option="hei"] {
  font-family: var(--font-hei);
}

.font-option[data-font-option="kai"] {
  font-family: var(--font-kai);
}

.font-option.active,
.font-option:hover {
  background: #2f6f5e;
  color: #ffffff;
}

.settings-dialog {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.38);
  z-index: 20;
}

.settings-card {
  width: min(360px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 16px 48px rgba(15, 23, 42, 0.2);
  padding: 18px;
}

.settings-header,
.settings-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.settings-header {
  margin-bottom: 18px;
}

.settings-header h2,
.settings-field-label {
  margin: 0;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
}

.accounts-dialog {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.38);
}

.accounts-dialog-card {
  display: grid;
  gap: 14px;
  width: 100%;
  max-width: 634px;
  min-width: 0;
  max-height: calc(100vh - 32px);
  overflow: hidden;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 16px 48px rgba(15, 23, 42, 0.2);
}

.accounts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.accounts-header h2 {
  margin: 0;
  color: var(--text);
  font-size: 18px;
}

.accounts-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
}

.accounts-toolbar-left {
  min-width: 0;
}

.accounts-search {
  width: min(260px, 100%);
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  color: var(--text);
  font: inherit;
}

.accounts-search:focus,
.accounts-pagination .pagination-input:focus {
  outline: 3px solid rgba(209, 154, 56, 0.28);
  border-color: var(--focus);
}

.accounts-count {
  justify-self: end;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.accounts-pagination {
  display: flex;
  align-items: center;
  justify-self: center;
  gap: 8px;
  min-height: 30px;
}

.accounts-pagination .pagination-info {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.accounts-pagination .pagination-input {
  width: 48px;
  min-height: 30px;
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  text-align: center;
}

.accounts-table-wrap {
  width: 100%;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.accounts-table {
  width: 100%;
  min-width: 592px;
  border-collapse: collapse;
  table-layout: fixed;
}

.accounts-table th,
.accounts-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #e6ebe7;
  text-align: center;
  white-space: nowrap;
}

.accounts-table thead th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.accounts-table tbody tr:last-child td {
  border-bottom: 0;
}

.accounts-table tbody tr:hover td {
  background: #f7faf8;
}

.accounts-table .col-id {
  width: 56px;
  color: var(--muted);
}

.accounts-table .col-username {
  width: 142px;
  overflow: hidden;
  font-weight: 700;
  text-align: left;
  text-overflow: ellipsis;
}

.accounts-table .col-role {
  width: 80px;
}

.accounts-table .col-created {
  width: 138px;
  color: var(--muted);
  font-size: 13px;
}

.accounts-table .col-actions {
  width: 176px;
  text-align: center;
}

.accounts-empty {
  padding: 42px 12px !important;
  color: var(--muted);
  text-align: center !important;
}

.account-tag {
  display: inline-block;
  min-width: 70px;
  padding: 2px 8px;
  border: 1px solid;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}

.account-tag-admin {
  border-color: #ecd9b6;
  background: #fdf3e5;
  color: #a06a18;
}

.account-tag-user {
  border-color: #d3e3da;
  background: #eef3f0;
  color: #2d6b5c;
}

.accounts-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.accounts-btn {
  min-height: 30px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
}

.accounts-btn:hover:not(:disabled) {
  border-color: #afc3b8;
  background: #f2f7f4;
}

/* 「设为普通用户 / 设为管理员」两种文案宽度对齐 */
.accounts-row .accounts-btn[data-act="role"] {
  min-width: calc(6em + 20px);
}

.accounts-btn:disabled {
  cursor: default;
  opacity: 0.45;
}

.accounts-btn-danger {
  border-color: #e3b7b2;
  color: #c0392b;
}

.accounts-btn-danger:hover:not(:disabled) {
  border-color: #c94437;
  background: #c94437;
  color: #fff;
}

.accounts-current {
  color: var(--muted);
  font-size: 13px;
}

.accounts-toast {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 60;
  max-width: min(560px, calc(100vw - 32px));
  padding: 10px 18px;
  transform: translateX(-50%);
  border-radius: 8px;
  background: #20241f;
  box-shadow: 0 12px 32px rgba(32, 36, 31, 0.24);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}

.accounts-toast.toast-error {
  background: #c0392b;
}

@media (max-width: 620px) {
  .accounts-dialog {
    padding: 10px;
  }

  .accounts-dialog-card {
    max-height: calc(100vh - 20px);
    padding: 14px;
  }

  .accounts-toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .accounts-toolbar-left {
    grid-column: 1 / -1;
    width: 100%;
  }

  .accounts-search {
    width: 100%;
  }

  .accounts-pagination {
    justify-self: start;
  }
}

.service-strip strong,
.service-strip b {
  display: inline-block;
  min-width: 48px;
  color: #414842;
}

.status-action {
  width: 52px;
  min-height: 26px;
  padding: 0 8px;
  border: 1px solid #aeb8af;
  border-radius: 6px;
  background: #f7faf6;
  color: #414842;
  font-size: 13px;
  font-weight: 700;
  line-height: 24px;
}

.status-action:disabled {
  cursor: wait;
  opacity: 0.72;
}

.home-board {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 330px;
  gap: 14px;
  min-height: 0;
  overflow: hidden;
}


.center-stack {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 14px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.home-sidebar,
.message-panel {
  min-height: 0;
  border: 1px solid rgba(221, 226, 220, 0.9);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 14px 34px rgba(42, 48, 44, 0.08);
}

.home-sidebar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-heading {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 58px;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(221, 226, 220, 0.74);
}

.sidebar-heading h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.sidebar-count {
  display: inline;
  margin-left: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.conversation-list {
  display: grid;
  flex: 1 1 auto;
  align-content: start;
  gap: 4px;
  min-height: 0;
  padding: 12px;
  overflow: auto;
}

.conversation-empty {
  display: grid;
  min-height: 100%;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
}

.conversation-date-heading {
  margin: 16px 8px 6px;
  color: #858d87;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
}

.conversation-date-heading:first-child {
  margin-top: 4px;
}

.conversation-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  align-items: center;
  gap: 4px;
  width: 100%;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
}

.conversation-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 42px;
  padding: 8px 0 8px 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.conversation-row:hover,
.conversation-row.active {
  border-color: #dfe5df;
  background: #f4f7f4;
}

.conversation-item strong {
  overflow: hidden;
  font-size: 14px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-head span {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 999px;
  background: #edf1ee;
  color: #646d66;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
}

.conversation-mode {
  justify-self: end;
  padding: 2px 6px;
  border-radius: 999px;
  background: #edf1ee;
  color: #747d76;
  font-size: 11px;
  line-height: 1.35;
  white-space: nowrap;
}

.conversation-delete {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #a0a8a2;
  font-size: 20px;
  line-height: 1;
}

.conversation-delete:hover {
  background: #f2e7e5;
  color: #c03d31;
}

.message-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 58px;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(221, 226, 220, 0.74);
}

.message-head h2 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 22px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-scroll {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
  padding: 18px;
  overflow-x: hidden;
  overflow-y: auto;
}

.message-panel .smart-results {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  height: 100%;
  margin-top: 0;
  min-height: 0;
}

.message-panel .result-list:empty:not(.empty-result-list) {
  display: none;
}

.message-panel .result-item {
  align-items: flex-start;
  background: rgba(251, 253, 252, 0.94);
}

.message-panel .result-list.empty-result-list {
  display: grid;
  height: 100%;
  min-height: 0;
  place-items: center;
}

.message-panel .result-empty {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(251, 253, 252, 0.96);
  color: var(--muted);
  box-shadow: 0 10px 24px rgba(42, 48, 44, 0.06);
  line-height: 1.7;
}

.chat-result p {
  white-space: pre-wrap;
}

.library-sidebar .shelf-stage {
  flex: 1 1 auto;
  min-height: 0;
  padding: 10px 14px 16px;
  overflow-x: hidden;
  overflow-y: auto;
}

.library-sidebar .document-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 14px;
  row-gap: 24px;
}

.library-sidebar .book-cover,
.library-sidebar .add-document {
  height: 160px;
  min-height: 0;
  aspect-ratio: auto;
}

.library-sidebar .book-title {
  font-size: 19px;
  -webkit-line-clamp: 4;
}

.library-sidebar .book-facts,
.library-sidebar .book-author,
.library-sidebar .book-meta small {
  font-size: 11px;
}

.library-sidebar .book-meta strong {
  font-size: 13px;
}

.library-sidebar .book-card::after {
  bottom: -8px;
}

.library-sidebar .add-plus {
  width: 52px;
  height: 52px;
  font-size: 46px;
}

#library-view .smart-dock {
  margin-top: 0;
  padding-bottom: 0;
}

#library-view .smart-input-box {
  min-height: 124px;
  padding: 16px 18px;
  border-radius: 24px;
}

#library-view .smart-input-box textarea {
  height: 82px;
  min-height: 82px;
  max-height: 82px;
  font-size: 17px;
  overflow-y: auto;
  resize: none;
}

#library-view .chip-button {
  min-height: 36px;
}

#library-view .round-send {
  width: 44px;
  height: 44px;
  font-size: 26px;
}

#documents-view.active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  gap: 14px;
  padding: 14px;
  overflow: hidden;
}

.documents-topbar,
.reader-topbar,
.documents-bottombar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  min-height: 68px;
  padding: 10px 18px;
  border: 1px solid rgba(221, 226, 220, 0.86);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 12px 32px rgba(42, 48, 44, 0.08);
}

.reader-topbar {
  margin-bottom: 0;
}

.documents-bottombar {
  min-height: 58px;
}

.documents-hint {
  grid-column: 1 / -1;
  justify-self: center;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.5;
}

.documents-nav {
  min-width: 0;
}

#reader-back {
  justify-self: start;
}

.reader-title-block {
  justify-self: center;
}

.reader-actions {
  justify-self: end;
}

.documents-count {
  justify-self: end;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.documents-stage {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 6px 4px 40px;
}

.documents-stage .document-list {
  grid-template-columns: repeat(10, minmax(0, 142px));
  justify-content: space-between;
  column-gap: 14px;
  row-gap: 24px;
}

.documents-stage .book-cover,
.documents-stage .add-document {
  width: 100%;
  height: 160px;
  min-height: 0;
  aspect-ratio: auto;
}

.documents-stage .book-title {
  font-size: 19px;
  -webkit-line-clamp: 4;
}

.documents-stage .book-facts,
.documents-stage .book-author,
.documents-stage .book-meta small {
  font-size: 11px;
}

.documents-stage .book-meta strong {
  font-size: 13px;
}

.documents-stage .book-card::after {
  bottom: -8px;
}

.documents-stage .add-plus {
  width: 52px;
  height: 52px;
  font-size: 46px;
}

#reader-view.active,
#workspace-view.active {
  height: 100vh;
  padding: 28px;
  overflow: auto;
}

#reader-view.active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  overflow: hidden;
}

@media (max-width: 980px) {
  #library-view.active {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .home-statusbar {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .service-strip {
    grid-row: 2;
    justify-content: center;
    overflow-x: auto;
  }

  .status-title {
    grid-row: 1;
  }

  .home-topbar-actions {
    grid-row: 3;
    justify-self: center;
  }

  .home-board {
    grid-template-columns: 210px minmax(0, 1fr) 260px;
  }

  .library-sidebar .document-list {
    grid-template-columns: 1fr;
  }

  .documents-stage .document-list {
    grid-template-columns: repeat(auto-fill, 142px);
  }
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .app-shell,
  .main,
  #library-view.active,
  #documents-view.active,
  #reader-view.active {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  #library-view.active,
  #documents-view.active,
  #reader-view.active {
    display: grid;
    padding: 12px;
  }

  .home-statusbar,
  .documents-topbar,
  .reader-topbar,
  .documents-bottombar,
  .home-board {
    grid-template-columns: 1fr;
  }

  #documents-view.active {
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100vh;
    min-height: 0;
    overflow: hidden;
  }

  .documents-count,
  .documents-nav {
    justify-self: center;
  }

  .home-sidebar,
  .message-panel {
    max-height: none;
  }

  .conversation-list,
  .message-scroll,
  .library-sidebar .shelf-stage {
    max-height: 42vh;
  }
}
