:root {
  --ink: #0B0D10;
  --paper: #FFFFFF;
  --paper-soft: #F5F6F7;
  --carbon-blue: #1B4965;
  --carbon-blue-light: #4A7A96;
  --graphite: #3A3F44;
  --rule: #E4E4E4;
  --danger: #9D2D2D;
  --shadow-soft: 0 20px 60px rgba(11, 13, 16, 0.07);
  --shadow-card: 0 8px 30px rgba(11, 13, 16, 0.06);
  --radius-small: 10px;
  --radius-medium: 18px;
  --radius-large: 30px;
  --transition: 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  color: var(--ink);
  background: var(--paper);
  font-family: "Vazirmatn", sans-serif;
  font-size: 15px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

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

button {
  border: 0;
  background: none;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(27, 73, 101, 0.2);
  outline-offset: 2px;
}

.app {
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  background:
    linear-gradient(rgba(228, 228, 228, 0.35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(228, 228, 228, 0.24) 1px, transparent 1px),
    var(--paper);
  background-size: 56px 56px;
}

.app.auth-hidden {
  display: none;
}

.site-header {
  position: sticky;
  z-index: 80;
  top: 0;
  display: grid;
  grid-template-columns: 240px minmax(420px, 1fr) 300px;
  align-items: center;
  min-height: 76px;
  padding: 10px clamp(20px, 4vw, 64px);
  border-bottom: 1px solid var(--rule);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
}

.brand {
  direction: ltr;
  display: inline-flex;
  align-items: center;
  justify-self: end;
  gap: 11px;
  text-align: left;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 50%;
  color: var(--paper);
  background: var(--ink);
  font-family: "JetBrains Mono", monospace;
  font-size: 18px;
  font-weight: 600;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 17px;
  line-height: 1.1;
  letter-spacing: 0.03em;
}

.brand small {
  margin-top: 4px;
  color: var(--graphite);
  font-size: 10px;
}

.main-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.nav-btn {
  position: relative;
  padding: 9px 13px;
  border-radius: 999px;
  color: var(--graphite);
  font-size: 13px;
  white-space: nowrap;
  transition: color var(--transition), background var(--transition), transform var(--transition);
}

.nav-btn:hover {
  color: var(--ink);
  background: var(--paper-soft);
}

.nav-btn:active {
  transform: scale(0.97);
}

.nav-btn.active {
  color: var(--paper);
  background: var(--ink);
}

.header-actions {
  direction: ltr;
  display: flex;
  align-items: center;
  justify-self: start;
  gap: 10px;
}

.model-control {
  direction: rtl;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--graphite);
  font-size: 11px;
}

.model-selector {
  width: 142px;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  outline: 0;
  background: var(--paper);
  font-size: 11px;
}

.model-selector:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.account-container {
  position: relative;
  direction: rtl;
}

.account-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: 150px;
  padding: 6px 8px 6px 12px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--paper);
  font-size: 11px;
}

.account-btn > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-icon {
  display: grid;
  width: 29px;
  height: 29px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: var(--paper);
  background: var(--carbon-blue);
}

.account-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  display: none;
  min-width: 160px;
  padding: 6px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: var(--shadow-card);
}

.account-dropdown.open {
  display: block;
}

.account-logout-btn {
  width: 100%;
  padding: 9px 11px;
  border-radius: 8px;
  color: var(--danger);
  text-align: right;
}

.account-logout-btn:hover {
  background: rgba(157, 45, 45, 0.08);
}

.main {
  position: relative;
  min-height: calc(100vh - 76px);
}

.workspace-view {
  display: none;
  min-height: calc(100vh - 76px);
}

.workspace-view.active {
  display: block;
  animation: viewIn 400ms ease both;
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}

.eyebrow {
  display: inline-block;
  color: var(--carbon-blue);
  font-family: "JetBrains Mono", "Vazirmatn", monospace;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

/* Landing */

.landing-view {
  display: none;
  min-height: calc(100vh - 76px);
  align-items: center;
  justify-content: flex-start;
  flex-direction: column;
  padding: 28px 24px 44px;
}

.landing-view.active {
  display: flex;
}

.landing-card {
  position: relative;
  isolation: isolate;
  width: min(980px, 100%);
  padding: 40px clamp(24px, 5vw, 64px) 44px;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: var(--radius-large);
  background: var(--paper-soft);
  box-shadow: var(--shadow-soft);
  transition: background-color 650ms ease, border-color 650ms ease, box-shadow 650ms ease;
}

.landing-card[data-service="assistant"] {
  border-color: rgba(27, 73, 101, 0.23);
  background: color-mix(in srgb, var(--carbon-blue) 17%, var(--paper));
}

.landing-card[data-service="search"] {
  border-color: rgba(74, 122, 150, 0.27);
  background: color-mix(in srgb, var(--carbon-blue-light) 16%, var(--paper));
}

.landing-card[data-service="book"] {
  border-color: rgba(58, 63, 68, 0.24);
  background: color-mix(in srgb, var(--graphite) 15%, var(--paper));
}
.landing-card[data-service="university"] {
  border-color: rgba(128, 84, 45, 0.28);
  background: color-mix(in srgb, #b47a45 14%, var(--paper));
}

.landing-card::before,
.landing-card::after {
  position: absolute;
  z-index: -1;
  content: "";
  border: 1px solid rgba(27, 73, 101, 0.1);
  border-radius: 50%;
}

.landing-card::before {
  top: -260px;
  right: -190px;
  width: 520px;
  height: 520px;
}

.landing-card::after {
  bottom: -210px;
  left: -120px;
  width: 390px;
  height: 390px;
}

.landing-orbit {
  position: absolute;
  z-index: -1;
  top: 32px;
  left: 38px;
  width: 105px;
  height: 1px;
  background: var(--rule);
  transform: rotate(-20deg);
}

.landing-orbit::before,
.landing-orbit::after {
  position: absolute;
  top: -3px;
  width: 7px;
  height: 7px;
  content: "";
  border-radius: 50%;
  background: var(--carbon-blue);
}

.landing-orbit::before { right: 0; }
.landing-orbit::after { left: 0; opacity: 0.35; }

.virgil-logo {
  color: var(--carbon-blue);
}

.virgil-logo svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.brand-logo-image { object-fit: cover; border-radius: 50%; }
.virgil-logo-large img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

.virgil-logo-large {
  width: 128px;
  height: 128px;
  margin: 0 auto 16px;
}

.logo-ring {
  fill: currentColor;
  transform-origin: center;
}

.logo-ring-outer {
  opacity: 0.38;
}

.logo-ring-mid {
  opacity: 0.75;
}

.logo-core-disc {
  fill: currentColor;
  opacity: 0.1;
}

.logo-traces {
  opacity: 0.22;
}

.logo-core {
  color: var(--ink);
}

.is-sending .virgil-logo-large .logo-ring-outer,
.message-pending .logo-ring-outer,
.message-status .logo-ring-outer {
  animation: orbitPulse 2.2s ease-in-out infinite;
}

.is-sending .virgil-logo-large .logo-ring-mid,
.message-pending .logo-ring-mid,
.message-status .logo-ring-mid {
  animation: reversePulse 2.2s 180ms ease-in-out infinite;
}

@keyframes orbitPulse {
  0%, 100% { opacity: 0.25; transform: scale(0.94) rotate(0); }
  50% { opacity: 0.85; transform: scale(1.08) rotate(12deg); }
}

@keyframes reversePulse {
  0%, 100% { opacity: 0.48; transform: scale(1.04) rotate(0); }
  50% { opacity: 1; transform: scale(0.92) rotate(-10deg); }
}

.welcome-copy {
  max-width: 690px;
  margin: 0 auto 28px;
  text-align: center;
}

.welcome-copy h1 {
  margin: 8px 0 7px;
  font-size: clamp(25px, 3.3vw, 40px);
  font-weight: 700;
  line-height: 1.45;
  letter-spacing: -0.035em;
}

.welcome-copy p {
  color: var(--graphite);
  font-size: 14px;
}

.landing-composer-slot {
  width: min(790px, 100%);
  margin: 0 auto;
}

.service-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

@media (max-width: 800px) {
  .service-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.service-btn {
  position: relative;
  display: flex;
  min-height: 92px;
  align-items: center;
  gap: 13px;
  padding: 17px;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 16px;
  color: var(--paper);
  text-align: right;
  transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
}

.service-btn:hover {
  z-index: 2;
  transform: translateY(-4px);
  box-shadow: 0 14px 28px rgba(11, 13, 16, 0.14);
  filter: saturate(1.08);
}

.service-btn:active {
  transform: translateY(-1px) scale(0.985);
}

.service-btn.active::after {
  position: absolute;
  inset: 6px;
  content: "";
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 12px;
  pointer-events: none;
}

.service-assistant { background: var(--carbon-blue); }
.service-search { background: var(--carbon-blue-light); }
.service-book { background: var(--graphite); }
.service-university { background: #a87545; }

.service-index {
  align-self: flex-start;
  padding-top: 2px;
  opacity: 0.55;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
}

.service-btn strong,
.service-btn small {
  display: block;
}

.service-btn strong {
  font-size: 14px;
  font-weight: 700;
}

.service-btn small {
  margin-top: 5px;
  opacity: 0.75;
  font-size: 10.5px;
  line-height: 1.6;
}

.landing-history-cue {
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 7px;
  min-width: 82px;
  margin-top: 15px;
  padding: 8px 16px 10px;
  border: 1px solid rgba(58, 63, 68, 0.12);
  border-radius: 999px;
  color: rgba(58, 63, 68, 0.56);
  background: rgba(255, 255, 255, 0.42);
  box-shadow: 0 5px 15px rgba(11, 13, 16, 0.045);
  font-family: "JetBrains Mono", "Vazirmatn", monospace;
  font-size: 10px;
  transition: color var(--transition), background var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.landing-history-cue:hover {
  border-color: rgba(27, 73, 101, 0.22);
  color: rgba(27, 73, 101, 0.82);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 8px 20px rgba(11, 13, 16, 0.07);
  transform: translateY(-2px);
}

.history-cue-chevron {
  width: 14px;
  height: 14px;
  border-right: 1.8px solid currentColor;
  border-bottom: 1.8px solid currentColor;
  transform: rotate(45deg);
  animation: cueBob 2.2s ease-in-out infinite;
}

@keyframes cueBob {
  0%, 100% { transform: rotate(45deg) translate(0, 0); }
  50% { transform: rotate(45deg) translate(3px, 3px); }
}

/* Composer */

.composer {
  display: flex;
  align-items: stretch;
  gap: 9px;
  width: 100%;
}

.input-wrapper {
  display: flex;
  min-width: 0;
  flex: 1;
  align-items: center;
  overflow: visible;
  border: 1px solid rgba(11, 13, 16, 0.18);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 8px 24px rgba(11, 13, 16, 0.07);
  transition: border var(--transition), box-shadow var(--transition), background var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--carbon-blue);
  box-shadow: 0 0 0 4px rgba(27, 73, 101, 0.1), 0 12px 30px rgba(11, 13, 16, 0.08);
}

.input-center {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
}

.input-textarea {
  width: 100%;
  min-height: 60px;
  max-height: 160px;
  resize: none;
  padding: 18px 6px;
  border: 0;
  outline: 0;
  background: transparent;
  line-height: 1.65;
}

.input-textarea::placeholder {
  color: rgba(58, 63, 68, 0.62);
}

.tool-btn {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  margin: 0 7px;
  border-radius: 50%;
  color: var(--graphite);
  transition: color var(--transition), background var(--transition), transform var(--transition);
}

.tool-btn:hover {
  color: var(--carbon-blue);
  background: var(--paper-soft);
}

.tool-btn:active {
  transform: scale(0.9);
}

.send-btn {
  color: var(--paper);
  background: var(--ink);
}

.send-btn:hover {
  color: var(--paper);
  background: var(--carbon-blue);
}

.send-btn:disabled {
  cursor: wait;
  opacity: 0.5;
}

.more-btn {
  display: flex;
  min-width: 58px;
  height: 42px;
  align-items: center;
  justify-content: center;
  flex-direction: row;
  gap: 4px;
  padding: 5px 8px;
  border: 1px solid var(--rule);
  border-radius: 16px;
  color: rgba(58, 63, 68, 0.75);
  background: #ECEDEF;
  box-shadow: 0 4px 12px rgba(11, 13, 16, 0.04);
  font-family: "JetBrains Mono", "Vazirmatn", monospace;
  font-size: 9px;
  font-weight: 600;
  transition: color var(--transition), background var(--transition), border var(--transition), transform var(--transition), box-shadow var(--transition);
}

.more-btn:hover {
  color: var(--ink);
  background: var(--paper-soft);
  transform: translateY(-2px);
  box-shadow: var(--shadow-card);
}

.more-btn:active {
  transform: scale(0.96);
}

.more-menu {
  position: relative;
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  margin-left: 2px;
  transform: translateX(-2px);
}

.clear-mode-btn {
  position: absolute;
  z-index: 3;
  top: -6px;
  left: -6px;
  display: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  color: var(--paper);
  background: var(--ink);
  font-size: 15px;
  line-height: 1;
}

.clear-mode-btn.visible {
  display: grid;
  place-items: center;
}

.more-dropdown {
  position: absolute;
  z-index: 60;
  bottom: calc(100% + 10px);
  right: 0;
  left: auto;
  display: none;
  width: min(190px, calc(100vw - 24px));
  padding: 6px;
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: var(--shadow-card);
}

.more-dropdown.open {
  display: block;
  animation: dropdownIn 160ms ease both;
}

@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(5px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.dropdown-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 9px;
  color: var(--graphite);
  text-align: right;
  font-size: 12px;
}

.dropdown-item:hover,
.dropdown-item.active {
  color: var(--carbon-blue);
  background: var(--paper-soft);
}

.dropdown-dot {
  width: 7px;
  height: 7px;
  border: 1px solid currentColor;
  border-radius: 50%;
}

.dropdown-item.active .dropdown-dot {
  background: currentColor;
}

.input-wrapper.mode-table,
.input-wrapper.mode-slide,
.input-wrapper.mode-markdown {
  border-color: var(--carbon-blue-light);
  background: color-mix(in srgb, var(--carbon-blue-light) 7%, var(--paper));
}

.input-wrapper.mode-semantic_review {
  border-color: #8b5cf6;
}

.input-wrapper.mode-systematic_review {
  border-color: #0ea5e9;
}

/* Conversation */

.conversation-view {
  display: none;
  height: calc(100vh - 76px);
  min-height: calc(100vh - 76px);
  max-width: 1120px;
  margin: 0 auto;
  padding: 30px clamp(20px, 4vw, 54px) 22px;
}

.conversation-view.active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0 11px;
  border-bottom: 1px solid var(--rule);
}

.chat-header > div {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.book-chat-scope {
  display: none;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.book-chat-scope.visible {
  display: flex;
}

.book-chat-chip {
  max-width: 220px;
  overflow: hidden;
  padding: 4px 8px;
  border: 1px solid rgba(38, 72, 105, 0.22);
  border-radius: 999px;
  background: rgba(38, 72, 105, 0.08);
  color: var(--carbon-blue);
  font-size: 10px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
}

.chat-meta {
  color: var(--graphite);
  font-family: "JetBrains Mono", "Vazirmatn", monospace;
  font-size: 10px;
}

.messages {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 30px;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: 30px 4px 40px 14px;
  scrollbar-color: var(--rule) transparent;
  scrollbar-width: thin;
}

.message {
  display: flex;
  width: min(850px, 94%);
  gap: 13px;
  animation: messageIn 240ms ease both;
}

@keyframes messageIn {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-user {
  align-self: flex-start;
}

.message-assistant {
  align-self: flex-end;
}

.message-avatar {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border-radius: 50%;
  font-family: "JetBrains Mono", "Vazirmatn", monospace;
  font-size: 9px;
  font-weight: 600;
}

.message-avatar.user {
  color: var(--paper);
  background: var(--graphite);
}

.message-avatar.ai {
  border: 1px solid rgba(27, 73, 101, 0.25);
  color: var(--carbon-blue);
  background: rgba(27, 73, 101, 0.08);
  font-size: 14px;
}

.message-content {
  min-width: 0;
  flex: 1;
}

.message-role {
  display: block;
  margin: 0 3px 6px;
  color: var(--graphite);
  font-size: 10px;
}

.message-text {
  padding: 14px 18px;
  border: 1px solid var(--rule);
  border-radius: 6px 18px 18px 18px;
  background: var(--paper);
  box-shadow: 0 6px 18px rgba(11, 13, 16, 0.035);
  line-height: 1.9;
  overflow-wrap: anywhere;
}

.message-user .message-text {
  border-color: transparent;
  color: var(--paper);
  background: var(--graphite);
  border-radius: 18px 6px 18px 18px;
}

.markdown-body {
  direction: rtl;
  text-align: right;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body > :last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin: 1.2em 0 0.55em;
  color: var(--ink);
  font-weight: 700;
  line-height: 1.55;
}

.markdown-body h1 { font-size: 1.45em; }
.markdown-body h2 { font-size: 1.28em; }
.markdown-body h3 { font-size: 1.12em; }

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-body table {
  margin: 0.75em 0;
}

.markdown-body ul,
.markdown-body ol {
  padding-right: 1.5em;
}

.markdown-body li + li {
  margin-top: 0.3em;
}

.markdown-body a {
  color: var(--carbon-blue);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.markdown-body blockquote {
  padding: 8px 14px;
  border-right: 3px solid var(--carbon-blue-light);
  color: var(--graphite);
  background: var(--paper-soft);
}

.markdown-body code,
.message-source-item code {
  direction: ltr;
  padding: 0.15em 0.38em;
  border-radius: 4px;
  color: var(--ink);
  background: var(--paper-soft);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.84em;
}

.markdown-body pre {
  direction: ltr;
  overflow-x: auto;
  padding: 14px;
  border-radius: 10px;
  color: #EDEFF1;
  background: var(--ink);
  text-align: left;
}

.markdown-body pre code {
  padding: 0;
  color: inherit;
  background: transparent;
}

.markdown-body table {
  display: block;
  width: max-content;
  min-width: 100%;
  max-width: 100%;
  overflow-x: auto;
  table-layout: auto;
  border-collapse: collapse;
  -webkit-overflow-scrolling: touch;
}

.markdown-body th,
.markdown-body td {
  padding: 7px 9px;
  border: 1px solid var(--rule);
  text-align: right;
  min-width: 120px;
  max-width: 360px;
  white-space: normal;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.markdown-body th {
  background: var(--paper-soft);
}

.message-copy-btn {
  position: relative;
  display: inline-grid;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  margin: 8px 2px 0;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 9px;
  color: var(--graphite);
  background: var(--paper);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.message-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.message-actions .message-copy-btn,
.message-actions .artifact-download-btn {
  margin-top: 8px;
}

.message-copy-btn:hover,
.message-copy-btn:focus-visible {
  border-color: var(--carbon-blue-light);
  color: var(--carbon-blue);
  background: var(--paper-soft);
}

.message-copy-btn.copied {
  border-color: #3a9b68;
  color: #26794e;
  background: rgba(58, 155, 104, 0.1);
}

.copy-icon {
  font-size: 17px;
  line-height: 1;
}

.copy-feedback {
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  padding: 4px 7px;
  border-radius: 6px;
  color: var(--paper);
  background: var(--ink);
  font-size: 10px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(3px);
  transition: opacity 160ms ease, transform 160ms ease;
  white-space: nowrap;
}

.message-copy-btn.copied .copy-feedback {
  opacity: 1;
  transform: translateY(0);
}

.artifact-download-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  padding: 8px 14px;
  border: 1px solid var(--carbon-blue);
  border-radius: 10px;
  color: var(--carbon-blue);
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.artifact-download-btn:hover {
  color: var(--paper);
  background: var(--carbon-blue);
}

.message-sources {
  margin-top: 10px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--paper-soft);
  color: var(--graphite);
  font-size: 11px;
  overflow: hidden;
}

.message-sources-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 13px;
  cursor: pointer;
  color: var(--carbon-blue);
  font-weight: 600;
  list-style: none;
  user-select: none;
}

.message-sources-title::-webkit-details-marker,
.message-source-item > summary::-webkit-details-marker {
  display: none;
}

.message-sources-title::before,
.message-source-item > summary::before {
  content: "‹";
  flex: 0 0 auto;
  font-size: 17px;
  line-height: 1;
  transform: rotate(0);
  transition: transform 160ms ease;
}

.message-sources[open] > .message-sources-title::before,
.message-source-item[open] > summary::before {
  transform: rotate(-90deg);
}

.message-sources[open] > .message-sources-title {
  border-bottom: 1px solid var(--rule);
}

.message-sources-list {
  padding: 0 13px 8px;
}

.message-source-item {
  border-top: 1px solid var(--rule);
}

.message-source-item:first-child {
  border-top: 0;
}

.message-source-item summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  cursor: pointer;
  color: var(--graphite);
  list-style: none;
  user-select: none;
}

.message-source-item summary span {
  min-width: 0;
  flex: 1;
  overflow-wrap: anywhere;
}

.message-source-item summary code {
  flex: 0 0 auto;
}

.message-source-details {
  padding: 0 25px 11px 0;
}

.message-source-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-bottom: 8px;
  color: var(--graphite);
}

.message-source-meta-item {
  overflow-wrap: anywhere;
}

.message-source-meta-item strong {
  color: var(--ink);
  font-weight: 600;
}

.message-source-content {
  max-height: 260px;
  padding: 9px 11px;
  overflow-y: auto;
  border: 1px solid var(--rule);
  border-radius: 8px;
  color: var(--graphite);
  background: var(--paper);
  line-height: 1.8;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.pending-response {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  color: var(--carbon-blue);
  font-size: 12px;
}

.virgil-logo-small {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
}

.message-status {
  display: grid;
  height: 100%;
  place-items: center;
  color: var(--graphite);
}

.error-status {
  color: var(--danger);
}

.chat-composer-slot {
  padding-top: 16px;
  border-top: 1px solid var(--rule);
}

/* Resource and library pages */

.resources-view,
.library-view {
  width: min(1160px, calc(100% - 40px));
  margin: 0 auto;
  padding: clamp(44px, 7vw, 86px) 0 90px;
}

.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 30px;
  margin-bottom: 34px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--rule);
}

.page-heading h1 {
  margin: 7px 0 6px;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.35;
}

.page-heading p {
  color: var(--graphite);
}

.page-actions {
  display: flex;
  gap: 9px;
}

.primary-action,
.secondary-action {
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  transition: transform var(--transition), background var(--transition);
}

.primary-action {
  color: var(--paper);
  background: var(--carbon-blue);
}

.secondary-action {
  border: 1px solid var(--rule);
  background: var(--paper);
}

.primary-action:hover,
.secondary-action:hover {
  transform: translateY(-2px);
}

.secondary-action:hover {
  background: var(--paper-soft);
}

.resource-search-form {
  display: flex;
  max-width: 790px;
  margin-bottom: 38px;
  border: 1px solid var(--ink);
  border-radius: 14px;
  background: var(--paper);
}

.resource-search-input {
  min-width: 0;
  flex: 1;
  padding: 14px 17px;
  border: 0;
  outline: 0;
  background: transparent;
}

.resource-search-form button {
  margin: 5px;
  padding: 8px 22px;
  border-radius: 9px;
  color: var(--paper);
  background: var(--ink);
}

.resource-results {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--rule);
}

.resource-card {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 24px;
  padding: 28px 4px;
  border-bottom: 1px solid var(--rule);
  transition: padding var(--transition), background var(--transition);
}

.resource-card:hover {
  padding-right: 18px;
  padding-left: 18px;
  background: var(--paper-soft);
}

.resource-number {
  color: var(--carbon-blue-light);
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
}

.resource-meta {
  display: flex;
  gap: 14px;
  color: var(--graphite);
  font-size: 11px;
}

.resource-meta span + span::before {
  margin-left: 14px;
  content: "—";
}

.resource-card h2 {
  margin: 6px 0 8px;
  font-size: clamp(18px, 2vw, 23px);
}

.resource-card p {
  max-width: 850px;
  color: var(--graphite);
  font-size: 13px;
  line-height: 1.9;
}

.relevance-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 6px;
  background: rgba(27, 73, 101, 0.08);
  color: var(--carbon-blue);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  font-weight: 600;
}

.resource-actions {
  margin-top: 14px;
}

.add-to-library-btn {
  padding: 8px 18px;
  border: 1px solid var(--carbon-blue);
  border-radius: var(--radius-small);
  background: var(--paper);
  color: var(--carbon-blue);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
}

.add-to-library-btn:hover:not(:disabled) {
  background: var(--carbon-blue);
  color: var(--paper);
}

.add-to-library-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.add-to-library-btn.added {
  border-color: rgba(45, 122, 74, 0.35);
  background: rgba(45, 122, 74, 0.09);
  color: #2D7A4A;
  opacity: 1;
  cursor: default;
}

.library-tabs {
  display: flex;
  gap: 8px;
  margin: 26px 0 18px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
}

.library-tab {
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--ink-soft);
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.library-tab:hover,
.library-tab.active {
  border-color: var(--carbon-blue);
  color: var(--paper);
  background: var(--carbon-blue);
}

.library-tab-count {
  display: inline-flex;
  min-width: 20px;
  height: 20px;
  align-items: center;
  justify-content: center;
  margin-right: 4px;
  padding: 0 5px;
  border-radius: 999px;
  color: var(--carbon-blue);
  background: var(--paper-soft);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
}

.library-tab.active .library-tab-count {
  color: var(--carbon-blue);
  background: var(--paper);
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.library-section {
  margin-top: 0;
}

.library-section[hidden] {
  display: none;
}

.library-section-head {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--rule);
}

.library-section-head h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.library-section-head p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.library-section--sources {
  padding: 20px;
  border-radius: 16px;
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 14%, transparent);
}

.library-section--sources .library-section-head {
  border-bottom-color: color-mix(in srgb, var(--accent) 22%, transparent);
}

.library-section--sources .library-section-head h2::before {
  content: "↳ ";
  color: var(--accent);
  opacity: 0.7;
}

.add-to-mylibrary-btn,
.pin-book-btn,
.delete-book-btn {
  padding: 8px 13px;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: transparent;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.add-to-mylibrary-btn {
  align-self: flex-start;
  margin-top: auto;
  color: var(--carbon-blue);
}

.add-to-mylibrary-btn:hover:not(:disabled) {
  border-color: var(--carbon-blue);
  background: var(--carbon-blue);
  color: var(--paper);
}

.add-to-mylibrary-btn.added,
.add-to-mylibrary-btn.added:hover:not(:disabled) {
  border-color: var(--danger);
  color: var(--danger);
  background: transparent;
  cursor: pointer;
  opacity: 1;
}

.library-card--source .add-to-mylibrary-btn.added,
.library-card--source .add-to-mylibrary-btn.added:hover:not(:disabled) {
  border-color: var(--danger);
  color: var(--danger);
  background: transparent;
}

.library-card--source .add-to-mylibrary-btn.added:hover:not(:disabled) {
  background: var(--danger);
  color: var(--paper);
}

.add-to-mylibrary-btn:disabled {
  border-color: var(--rule);
  color: var(--ink-soft);
  background: transparent;
  cursor: default;
  opacity: 0.75;
}

.library-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 235px;
  padding: 23px 25px 18px;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 4px 18px 18px 4px;
  background: var(--paper);
  box-shadow: 7px 9px 0 var(--paper-soft);
  transition: transform var(--transition), box-shadow var(--transition);
}

.library-card:hover {
  transform: translateY(-5px);
  box-shadow: 9px 13px 0 rgba(74, 122, 150, 0.12);
}

.library-card.pinned {
  border-color: rgba(27, 73, 101, 0.35);
}

.book-spine {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 7px;
  background: var(--graphite);
}

.library-card.pinned .book-spine {
  background: var(--carbon-blue);
}

.library-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.technical-label,
.pin-status {
  color: var(--carbon-blue);
  font-family: "JetBrains Mono", "Vazirmatn", monospace;
  font-size: 9px;
}

.pin-status {
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(27, 73, 101, 0.08);
}

.library-card h2 {
  margin: 30px 0 5px;
  overflow: hidden;
  font-size: 20px;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.library-card p {
  color: var(--graphite);
  font-size: 12px;
}

.library-card-actions {
  position: absolute;
  right: 25px;
  bottom: 18px;
  left: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
}

.pin-book-btn {
  color: var(--carbon-blue);
}

.pin-book-btn:hover:not(:disabled) {
  background: var(--carbon-blue);
  color: var(--paper);
}

.delete-book-btn {
  color: var(--danger);
}

.delete-book-btn:hover:not(:disabled) {
  background: var(--danger);
  color: var(--paper);
}

.pin-book-btn:disabled,
.delete-book-btn:disabled {
  opacity: 0.45;
  cursor: wait;
}

.page-empty {
  display: flex;
  min-height: 220px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  color: var(--graphite);
  text-align: center;
}

.page-empty span {
  font-size: 12px;
}

/* History graph */

.history-section {
  position: relative;
  min-height: 560px;
  padding: 72px clamp(20px, 5vw, 76px) 90px;
  overflow: hidden;
  color: var(--paper);
  background: var(--ink);
  scroll-margin-top: 75px;
}

.history-section::before {
  position: absolute;
  inset: 0;
  content: "";
  opacity: 0.22;
  background-image: radial-gradient(circle, rgba(255, 255, 255, 0.18) 1px, transparent 1px);
  background-size: 24px 24px;
}

.history-heading {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 38px;
}

.history-heading .eyebrow {
  color: var(--carbon-blue-light);
}

.history-heading h2 {
  margin-top: 7px;
  font-size: clamp(27px, 4vw, 44px);
}

.history-new-chat {
  padding: 10px 15px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  color: var(--paper);
}

.history-new-chat:hover {
  border-color: var(--paper);
}

.history-graph {
  position: relative;
  z-index: 2;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 15px;
  direction: ltr;
}

.chat-list {
  position: relative;
  width: 100%;
  min-width: 100%;
  min-height: 260px;
}

.graph-connections {
  position: absolute;
  z-index: 0;
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.graph-edge {
  fill: none;
  stroke: url(#historyEdgeGradient);
  stroke-width: 1.3;
  opacity: 0;
  vector-effect: non-scaling-stroke;
  transition: opacity 350ms ease, stroke-width 350ms ease;
}

.graph-edge.in-view {
  opacity: 0.28;
}

.graph-edge.in-view.dim {
  opacity: 0.06;
}

.graph-edge.in-view.lit {
  opacity: 0.9;
  stroke-width: 2;
}

.chat-item {
  position: absolute;
  z-index: 1;
  top: 0;
  left: 0;
  display: grid;
  grid-template-columns: 26px 1fr 9px;
  align-items: center;
  gap: 8px;
  width: 148px;
  min-height: 104px;
  padding: 14px 13px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 18px;
  color: rgba(255, 255, 255, 0.82);
  background: #0b0d10;
  direction: rtl;
  text-align: right;
  opacity: 0;
  will-change: transform;
  transition: color 300ms ease, border-color 300ms ease, background 300ms ease, box-shadow 300ms ease, filter 300ms ease, opacity 350ms ease;
}

.chat-item[data-virgil-mode]::before {
  position: absolute;
  top: -1px;
  right: 18px;
  left: 18px;
  height: 3px;
  border-radius: 0 0 999px 999px;
  content: "";
  background: var(--history-mode-color);
}

.chat-item[data-virgil-mode="research"] {
  --history-mode-color: var(--carbon-blue);
}

.chat-item[data-virgil-mode="book-search"] {
  --history-mode-color: var(--carbon-blue-light);
}

.chat-item[data-virgil-mode="book-chat"] {
  --history-mode-color: var(--graphite);
}

.chat-item[data-virgil-mode="university"] {
  --history-mode-color: #a87545;
}

.chat-item.in-view {
  opacity: 1;
}

.chat-item:hover,
.chat-item:focus-visible {
  z-index: 30;
  border-color: var(--carbon-blue-light);
  color: var(--paper);
  background: color-mix(in srgb, var(--carbon-blue) 42%, #0b0d10);
  box-shadow: 0 14px 34px -12px rgba(0, 0, 0, 0.7), inset 0 0 0 1px var(--carbon-blue-light);
  outline: none;
}

.chat-item.in-view.dim {
  opacity: 1;
  filter: brightness(0.45);
}

.chat-item.active {
  border-color: var(--carbon-blue-light);
  color: var(--paper);
  background: var(--carbon-blue);
}

.node-index {
  color: var(--carbon-blue-light);
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
}

.chat-item.active .node-index {
  color: rgba(255, 255, 255, 0.72);
}

.node-title {
  display: -webkit-box;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.65;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.node-dot {
  width: 7px;
  height: 7px;
  border: 1px solid currentColor;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(74, 122, 150, 0.12);
}

.history-empty {
  position: absolute;
  top: 20px;
  right: 0;
  display: grid;
  width: min(650px, calc(100vw - 40px));
  min-height: 210px;
  place-items: center;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.55);
}

/* Login */

.login-overlay {
  position: fixed;
  z-index: 200;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(circle at 80% 20%, rgba(74, 122, 150, 0.2), transparent 30%),
    var(--paper-soft);
}

.login-overlay.active {
  display: flex;
}

.login-card {
  width: min(410px, 100%);
  padding: 36px;
  border: 1px solid var(--rule);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: var(--shadow-soft);
}

.login-card h2 {
  margin: 5px 0 4px;
  font-size: 25px;
}

.login-sub {
  margin-bottom: 24px;
  color: var(--graphite);
  font-size: 12px;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.login-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  outline: 0;
  background: var(--paper-soft);
}

.login-input:focus {
  border-color: var(--carbon-blue);
  background: var(--paper);
}

.login-error {
  min-height: 4px;
  color: var(--danger);
  font-size: 11px;
}

.login-submit {
  padding: 12px;
  border-radius: 10px;
  color: var(--paper);
  background: var(--carbon-blue);
  font-weight: 600;
}

.login-submit:hover {
  background: var(--ink);
}

.login-submit:disabled {
  cursor: wait;
  opacity: 0.55;
}

@media (max-width: 980px) {
  .site-header {
    grid-template-columns: auto 1fr auto;
    padding-inline: 20px;
  }

  .brand {
    justify-self: start;
  }

  .brand small,
  .model-control > span,
  .account-btn > span:last-child {
    display: none;
  }

  .main-nav {
    justify-content: center;
  }

  .nav-btn {
    padding-inline: 10px;
    font-size: 11px;
  }

  .model-selector {
    width: 108px;
  }

  .service-picker {
    gap: 8px;
  }

  .service-btn {
    padding: 14px;
  }

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

@media (max-width: 720px) {
  .site-header {
    position: relative;
    grid-template-columns: 1fr auto;
    gap: 10px;
    min-height: 68px;
    padding: 9px 14px;
  }

  .brand {
    grid-column: 1;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .header-actions {
    position: relative;
    width: auto;
    gap: 0;
  }

  .model-control {
    position: absolute;
    z-index: 130;
    top: 48px;
    right: 0;
    display: none;
    width: 196px;
    padding: 10px;
    border: 1px solid var(--rule);
    border-radius: 12px;
    background: var(--paper);
    box-shadow: var(--shadow-card);
    font-size: 11px;
  }

  .header-actions:has(.account-dropdown.open) .model-control {
    display: flex;
    align-items: stretch;
    flex-direction: column;
    gap: 6px;
  }

  .model-selector {
    width: 100%;
    min-height: 44px;
  }

  .account-btn {
    width: 38px;
    height: 38px;
    padding: 3px;
    justify-content: center;
  }

  .account-btn > span:last-child {
    display: none;
  }

  .account-dropdown {
    top: calc(100% + 8px);
    right: 0;
    left: auto;
    width: 220px;
    padding: 12px;
    box-shadow: var(--shadow-card);
  }

  .account-dropdown::before {
    display: block;
    margin-bottom: 8px;
    color: var(--ink);
    content: attr(data-email);
    direction: ltr;
    font-size: 11px;
    text-align: left;
  }

  .account-logout-btn {
    min-height: 44px;
  }

  .main-nav {
    position: fixed;
    z-index: 120;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    justify-content: space-around;
    gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--rule);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 -8px 22px rgba(11, 13, 16, 0.08);
    backdrop-filter: blur(12px);
  }

  .nav-btn {
    display: flex;
    min-width: 0;
    flex: 1;
    padding: 7px 3px;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    font-size: 10px;
  }

  .nav-btn::before {
    display: block;
    color: currentColor;
    font-size: 14px;
    line-height: 1;
  }

  .new-chat-btn::before { content: "＋"; }
  .search-page-btn::before { content: "⌕"; }
  .library-page-btn::before { content: "▣"; }
  .history-scroll-btn::before { content: "◌"; }

  .main,
  .workspace-view,
  .landing-view {
    min-height: calc(100vh - 128px);
  }

  .landing-view {
    align-items: center;
    padding: 22px 12px 45px;
  }

  .landing-history-cue {
    align-self: center;
  }

  .landing-card {
    padding: 25px 14px 18px;
    border-radius: 22px;
  }

  .virgil-logo-large {
    width: 92px;
    height: 92px;
    margin-bottom: 8px;
  }

  .welcome-copy {
    margin-bottom: 20px;
  }

  .welcome-copy h1 {
    font-size: 23px;
  }

  .welcome-copy p {
    font-size: 12px;
  }

  .composer {
    display: flex;
    flex-direction: row;
    gap: 6px;
  }

  .input-wrapper {
    display: flex;
    flex: 1;
    border-radius: 17px;
  }

  .input-textarea {
    min-height: 54px;
    padding-block: 15px;
    font-size: 13px;
  }

  .more-btn {
    min-width: 54px;
    height: 38px;
    min-height: 38px;
    padding-inline: 6px;
    font-size: 8px;
  }

  .service-picker {
    grid-template-columns: 1fr;
    margin-top: 12px;
  }

  .service-btn {
    min-height: 70px;
  }

  .conversation-view {
    height: calc(100dvh - 68px);
    min-height: calc(100dvh - 68px);
    padding: 20px 12px 12px;
  }

  .chat-title {
    font-size: 15px;
  }

  .messages {
    gap: 22px;
    padding: 20px 0 28px;
  }

  .message {
    width: 100%;
    gap: 8px;
  }

  .message-avatar {
    width: 31px;
    height: 31px;
    flex-basis: 31px;
    font-size: 8px;
  }

  .message-text {
    padding: 12px 13px;
    font-size: 13px;
  }

  .page-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .resources-view,
  .library-view {
    width: min(100% - 28px, 1160px);
    padding-top: 38px;
  }

  .page-actions {
    width: 100%;
    flex-direction: column;
  }

  .resource-search-form {
    margin-bottom: 25px;
  }

  .resource-search-form button {
    padding-inline: 15px;
  }

  .resource-card {
    grid-template-columns: 38px 1fr;
    gap: 10px;
    padding-block: 22px;
  }

  .resource-card:hover {
    padding-inline: 4px;
  }

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

  .history-section {
    padding: 54px 18px 70px;
    overflow: visible;
  }

  .history-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 18px;
  }

  .history-graph {
    overflow: visible;
    padding: 4px 0 0;
  }

  .graph-connections {
    display: none;
  }

  .chat-list {
    display: flex;
    width: 100%;
    min-height: 0;
    padding: 8px 0 8px;
    flex-direction: column;
    gap: 16px;
  }

  .chat-list::before {
    position: absolute;
    z-index: 0;
    top: var(--history-line-top, 0px);
    height: var(--history-line-height, 0px);
    left: 24px;
    width: 1px;
    content: "";
    background: rgba(255, 255, 255, 0.22);
  }

  .chat-item {
    position: relative;
    top: auto;
    left: auto;
    display: grid;
    width: 100%;
    min-height: 72px;
    padding: 13px 18px;
    border-radius: 999px;
    color: var(--paper);
    background: var(--history-mode-color, #0b0d10);
    opacity: 1;
    transform: none !important;
    will-change: auto;
  }

  .chat-item[data-virgil-mode]::before {
    display: none;
  }

  .chat-item[data-virgil-mode="research"] {
    background: var(--carbon-blue);
  }

  .chat-item[data-virgil-mode="book-search"] {
    color: var(--ink);
    background: var(--carbon-blue-light);
  }

  .chat-item[data-virgil-mode="book-chat"] {
    background: var(--graphite);
  }

  .chat-item[data-virgil-mode="university"] {
    color: #fff8ed;
    background: #a87545;
  }

  .chat-item:hover,
  .chat-item:focus-visible,
  .chat-item.active {
    border-color: var(--paper);
    color: var(--paper);
    background: var(--history-mode-color, #0b0d10);
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.62);
  }

  .chat-item[data-virgil-mode="book-search"]:hover,
  .chat-item[data-virgil-mode="book-search"]:focus-visible,
  .chat-item[data-virgil-mode="book-search"].active {
    color: var(--ink);
    background: var(--carbon-blue-light);
  }

  .chat-item.in-view.dim {
    filter: none;
  }

  .node-index {
    color: currentColor;
    opacity: 0.72;
  }

  .node-title {
    font-size: 13px;
    -webkit-line-clamp: 1;
  }

  .node-dot {
    background: currentColor;
    box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.14);
  }

  .history-empty {
    position: relative;
    top: auto;
    width: 100%;
  }

  .login-card {
    padding: 28px 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Book Chat: selection checkboxes + confirm bar ── */
.book-select-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}

.book-select-checkbox input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--carbon-blue);
  cursor: pointer;
}

.resource-actions .book-select-checkbox {
  margin-top: 0;
  margin-inline-start: 12px;
}

.resource-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.book-chat-bar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 14px 20px;
  background: var(--ink);
  color: var(--paper);
  box-shadow: 0 -8px 24px rgba(11, 13, 16, 0.18);
}

.book-chat-bar.visible {
  display: flex;
}

.book-chat-bar-count {
  font-weight: 700;
}

.start-book-chat-btn {
  padding: 9px 20px;
  border: 1px solid var(--paper);
  border-radius: var(--radius-small);
  background: var(--paper);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  transition: all var(--transition);
}

.start-book-chat-btn:hover {
  background: var(--carbon-blue);
  color: var(--paper);
  border-color: var(--carbon-blue);
}

@media (max-width: 680px) {
  .book-chat-bar {
    flex-direction: column;
    gap: 10px;
    padding: 12px 16px;
  }
}
