html, body { min-height: 100%; }
.chat-workspace {
  height: calc(100vh - 3.5rem);
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(360px, 2fr);
  background: var(--rs-bg);
}
.paper-pane, .assistant-pane { min-width: 0; min-height: 0; }
.paper-pane { display: flex; flex-direction: column; border-right: 1px solid var(--rs-border); }
.paper-toolbar, .assistant-toolbar {
  min-height: 3.35rem; padding: .45rem .75rem; background: var(--rs-surface);
  border-bottom: 1px solid var(--rs-border); display: flex; align-items: center; gap: .75rem;
}
.paper-mode {
  align-self: stretch; display: inline-flex; align-items: center; gap: .4rem; padding: 0 .35rem;
  color: var(--rs-primary); border-bottom: 2px solid var(--rs-primary); font-size: .77rem; font-weight: 750;
}
.paper-mode-icon { font-size: 1rem; }
.paper-heading { min-width: 0; flex: 1; }
.paper-heading h1 { font-size: .78rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.paper-heading p { font-size: .65rem; color: var(--rs-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.document-state { font-size: .72rem; padding: .25rem .55rem; border-radius: 999px; background: var(--rs-primary-50); color: var(--rs-primary); white-space: nowrap; }
.document-state.failed { background: #fee2e2; color: #b91c1c; }
[data-theme="dark"] .document-state.failed { background: #450a0a; color: #fca5a5; }
.pdf-toolbar {
  min-height: 2.55rem; padding: .35rem .65rem; display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center; gap: .65rem; border-bottom: 1px solid var(--rs-border); background: #11100f; color: #dedbd8;
}
.pdf-toolbar-group { display: flex; align-items: center; gap: .3rem; }
.pdf-toolbar-group:last-child { justify-content: flex-end; }
.pdf-toolbar-title {
  max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: #aaa4a0; font-size: .69rem; font-weight: 650; letter-spacing: .02em;
}
.pdf-tool-button, .pdf-fit-button {
  min-width: 1.9rem; height: 1.85rem; padding: 0 .42rem; display: inline-grid; place-items: center;
  border: 1px solid transparent; border-radius: .38rem; background: transparent; color: inherit; font-size: .9rem;
}
.pdf-tool-button:hover, .pdf-fit-button:hover { border-color: #4a4744; background: #211f1e; }
.pdf-tool-button:disabled, .pdf-fit-button:disabled { opacity: .35; cursor: default; }
.pdf-fit-button { width: auto; font-size: .66rem; font-weight: 650; }
.pdf-page-control { display: flex; align-items: center; gap: .3rem; color: #8f8b88; font-size: .68rem; }
#pdf-page-number {
  width: 2.4rem; height: 1.7rem; padding: 0 .3rem; border: 1px solid #3f3c39; border-radius: .3rem;
  background: #1f1d1c; color: #f5f2ef; text-align: center; font-size: .7rem; outline: none;
}
#pdf-page-number:focus { border-color: var(--rs-primary); }
#pdf-page-number::-webkit-inner-spin-button, #pdf-page-number::-webkit-outer-spin-button { appearance: none; margin: 0; }
.pdf-zoom-value { min-width: 2.55rem; color: #aaa4a0; text-align: center; font-size: .65rem; font-variant-numeric: tabular-nums; }
.paper-frame-wrap { flex: 1; min-height: 0; position: relative; background: #171615; }
.pdf-scroll { width: 100%; height: 100%; overflow: auto; scroll-behavior: smooth; scrollbar-color: #5c5854 #1b1a19; }
.pdf-scroll:focus-visible { outline: 2px solid var(--rs-primary); outline-offset: -2px; }
.pdf-pages { min-height: 100%; display: flex; flex-direction: column; align-items: center; gap: 1rem; padding: 1rem 1.5rem 3rem; }
.pdf-page {
  position: relative; flex: none; max-width: 100%; overflow: hidden; background: #242220;
  box-shadow: 0 0 0 1px rgba(255,255,255,.06), 0 9px 24px rgba(0,0,0,.24);
}
.pdf-page::before {
  content: attr(aria-label); position: absolute; inset: 0; display: grid; place-items: center;
  color: #746f6b; font-size: .7rem; font-weight: 650;
}
.pdf-page-canvas { position: relative; z-index: 1; display: block; max-width: none; }
[data-theme="dark"] .pdf-page-canvas { filter: invert(.9) hue-rotate(180deg) contrast(.94); }
#paper-frame { width: 100%; height: 100%; border: 0; display: none; }
.paper-placeholder { position: absolute; inset: 0; display: grid; place-items: center; padding: 2rem; text-align: center; color: #d1d5db; }
.paper-placeholder > div { max-width: 32rem; }
.pdf-loading-mark { margin-bottom: .55rem; color: var(--rs-primary); font-size: 1.6rem; }
.paper-loading-overlay {
  position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: 1.5rem;
  background: rgba(23, 22, 21, .96); color: #f5f2ef; transition: opacity .2s ease;
}
.paper-loading-overlay.hidden { display: none; }
.paper-loading-card { width: min(25rem, 88%); text-align: center; }
.paper-loading-spinner {
  width: 2rem; height: 2rem; margin: 0 auto .85rem; border: 3px solid #403d3a;
  border-top-color: var(--rs-primary); border-radius: 50%; animation: paper-loading-spin .8s linear infinite;
}
.paper-loading-card h2 { font-size: 1rem; font-weight: 750; }
#paper-loading-phase { margin-top: .3rem; color: #c4bfbb; font-size: .76rem; }
.paper-loading-progress-row { display: flex; align-items: center; gap: .7rem; margin-top: 1rem; }
.paper-loading-track { height: .42rem; flex: 1; overflow: hidden; border-radius: 999px; background: #403d3a; }
.paper-loading-track span {
  display: block; width: 0; height: 100%; border-radius: inherit; background: var(--rs-primary);
  transition: width .25s ease;
}
#paper-loading-percent { min-width: 2.8rem; color: #fff; text-align: right; font-size: .78rem; font-variant-numeric: tabular-nums; }
.paper-loading-detail { margin-top: .55rem; color: #8f8b88; font-size: .67rem; }
@keyframes paper-loading-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .paper-loading-spinner { animation-duration: 1.8s; }
  .paper-loading-track span { transition: none; }
}
.assistant-pane { display: flex; flex-direction: column; background: var(--rs-surface); }
.assistant-toolbar { justify-content: space-between; }
.assistant-tabs { display: flex; align-self: stretch; gap: 1rem; }
.assistant-tab { border: 0; background: transparent; color: var(--rs-muted); font-weight: 650; font-size: .82rem; border-bottom: 2px solid transparent; }
.assistant-tab.active { color: var(--rs-primary); border-color: var(--rs-primary); }
.chat-action { border: 1px solid var(--rs-border); border-radius: .55rem; background: var(--rs-surface); color: var(--rs-text); padding: .4rem .65rem; font-size: .75rem; font-weight: 600; }
.chat-action:hover { border-color: var(--rs-primary); color: var(--rs-primary); }
.assistant-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.hidden-view { display: none !important; }
.messages { flex: 1; overflow-y: auto; padding: 1.1rem; scroll-behavior: smooth; }
.chat-empty { min-height: 100%; display: grid; place-content: center; text-align: center; color: var(--rs-muted); }
.chat-empty h2 { color: var(--rs-text); font-size: 1.1rem; font-weight: 750; margin-bottom: .4rem; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; margin-top: 1rem; max-width: 34rem; }
.suggestion { text-align: left; padding: .75rem; border: 1px solid var(--rs-border); border-radius: .7rem; background: var(--rs-bg); color: var(--rs-text); font-size: .78rem; }
.suggestion:hover { border-color: var(--rs-primary); }
.message { margin-bottom: 1rem; display: flex; flex-direction: column; }
.message.user { align-items: flex-end; }
.message.assistant { align-items: flex-start; }
.message-bubble { max-width: 90%; border-radius: .85rem; padding: .75rem .9rem; line-height: 1.55; font-size: .86rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user .message-bubble { background: var(--rs-primary); color: #fff; }
.message.assistant .message-bubble { background: var(--rs-bg); color: var(--rs-text); border: 1px solid var(--rs-border); }
.message.failed .message-bubble { border-color: #ef4444; }
.citation-row { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin-top: .45rem; }
.citation-row-label { color: var(--rs-muted); font-size: .68rem; font-weight: 700; letter-spacing: .02em; }
.citation-chip { border: 1px solid var(--rs-border); background: var(--rs-surface); color: var(--rs-primary); border-radius: 999px; padding: .18rem .48rem; font-size: .68rem; font-weight: 650; }
.composer-wrap { padding: .75rem; border-top: 1px solid var(--rs-border); background: var(--rs-surface); }
.composer { border: 1.5px solid var(--rs-border); border-radius: .85rem; padding: .65rem; display: flex; gap: .6rem; align-items: flex-end; }
.composer:focus-within { border-color: var(--rs-primary); box-shadow: 0 0 0 3px var(--rs-primary-50); }
#chat-input { flex: 1; resize: none; max-height: 9rem; min-height: 2.5rem; background: transparent; border: 0; outline: 0; color: var(--rs-text); font-size: .86rem; }
.send-btn { width: 2.5rem; height: 2.5rem; border-radius: 50%; border: 0; background: var(--rs-primary); color: #fff; font-weight: 800; }
.send-btn:disabled { opacity: .45; cursor: not-allowed; }
.composer-note { min-height: 1rem; margin-top: .35rem; font-size: .67rem; color: var(--rs-muted); }
.history-list { flex: 1; overflow-y: auto; padding: .8rem; }
.history-item { border: 1px solid var(--rs-border); border-radius: .7rem; padding: .7rem; margin-bottom: .55rem; background: var(--rs-bg); }
.history-main { width: 100%; text-align: left; border: 0; background: transparent; color: var(--rs-text); }
.history-title { font-size: .82rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-meta { font-size: .68rem; color: var(--rs-muted); margin-top: .2rem; }
.history-actions { display: flex; gap: .4rem; margin-top: .5rem; }
.history-actions button { border: 0; background: transparent; color: var(--rs-muted); font-size: .68rem; }
.history-actions button:hover { color: var(--rs-primary); }
.history-actions button:disabled { opacity: .5; cursor: wait; }
.history-danger { color: #dc2626 !important; }
.history-footer { padding: .75rem; border-top: 1px solid var(--rs-border); }
.mobile-pane-tabs { display: none; }
@media (max-width: 960px) {
  html, body { overflow: auto; }
  .chat-workspace { height: calc(100vh - 3.5rem - 2.75rem); display: block; }
  .mobile-pane-tabs { height: 2.75rem; display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--rs-border); background: var(--rs-surface); }
  .mobile-pane-tab { border: 0; background: transparent; color: var(--rs-muted); font-weight: 700; }
  .mobile-pane-tab.active { color: var(--rs-primary); border-bottom: 2px solid var(--rs-primary); }
  .paper-pane, .assistant-pane { height: 100%; border-right: 0; }
  .mobile-hidden { display: none !important; }
}
@media (max-width: 720px) {
  .pdf-toolbar { grid-template-columns: 1fr auto; }
  .pdf-toolbar-title { display: none; }
  .pdf-pages { padding-inline: .75rem; }
}
@media (max-width: 560px) {
  .suggestions { grid-template-columns: 1fr; }
  .paper-toolbar, .assistant-toolbar { padding-inline: .7rem; }
  .paper-mode { display: none; }
  .document-state { display: none; }
  .pdf-fit-button { display: none; }
  .message-bubble { max-width: 96%; }
}
