/* View-specific layouts. Grows across tasks; starts with the login screen. */

/* Login */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--sp-8);
}

.login-card {
  width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-8);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  box-shadow: var(--shadow-menu);
}

.login-mark {
  width: 44px;
  height: 44px;
  margin-bottom: var(--sp-2);
}

.login-card h1 {
  font-size: var(--fs-28);
}

.login-google {
  justify-content: center;
  margin-top: var(--sp-3);
}

.login-footnote {
  color: var(--text-muted);
  font-size: var(--fs-13);
  margin-top: var(--sp-2);
}

.login-notice {
  color: var(--danger-hover);
  font-size: var(--fs-13);
  font-weight: var(--fw-medium);
  margin-top: var(--sp-1);
}

/* Not found */
.notfound-shell {
  min-height: 60vh;
  display: grid;
  place-items: center;
}

.notfound-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  align-items: flex-start;
  max-width: 420px;
}

/* App shell */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  padding: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  font-family: var(--font-display);
  font-weight: var(--fw-display);
  font-size: var(--fs-20);
  color: var(--text);
}

.brand:hover {
  text-decoration: none;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 16px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: var(--fw-medium);
}

.nav-item:hover {
  background: var(--bg-hover);
  text-decoration: none;
  color: var(--text);
}

.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.sidebar-bottom {
  margin-top: auto;
}

.jobs-widget-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: var(--fs-13);
  cursor: pointer;
}

.jobs-widget-btn:hover {
  background: var(--bg-hover);
}

.jobs-widget-btn.is-active {
  color: var(--status-processing-fg);
}

.jobs-pop {
  position: fixed;
  z-index: 70;
  width: 330px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-menu);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.jobs-pop-head {
  font-size: var(--fs-13);
}

.jobs-pop-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.jobs-pop-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.jobs-pop-title {
  font-weight: var(--fw-medium);
  font-size: var(--fs-13);
}

.jobs-pop-phase {
  color: var(--text-secondary);
  font-size: var(--fs-13);
}

.jobs-pop-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  background: var(--bg-app);
  border-bottom: 1px solid var(--border);
}

.crumb {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: var(--fs-13);
  min-width: 0;
}

.crumb a {
  color: var(--text-secondary);
}

.crumb .sep {
  color: var(--text-muted);
}

.topbar-end {
  display: flex;
  align-items: center;
  gap: 10px;
}

.content {
  padding: 24px;
  width: 100%;
}

/* The document view is an app shell: fixed height, static header/banner/tabs,
   and only the content column (plus the rail) scrolls. */
.content:has(> .doc-shell) {
  padding: 0;
  height: calc(100vh - var(--topbar-height));
  overflow: hidden;
}

.doc-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.boot-error {
  padding: 32px;
  color: var(--status-failed-fg);
}

/* Library */
.lib-searchrow {
  margin-bottom: 0;
}

.searchbox {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 0 12px;
  height: 40px;
  width: 100%;
  max-width: 560px;
  color: var(--text-muted);
}

.searchbox:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.searchbox input {
  border: 0;
  outline: 0;
  flex: 1;
  font: inherit;
  color: var(--text);
  background: transparent;
}

.filter-chips {
  display: flex;
  gap: 8px;
  margin: 12px 0;
  flex-wrap: wrap;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 11px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: var(--fs-13);
  cursor: pointer;
  color: var(--text-secondary);
}

.filter-chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.filter-chip.is-active {
  background: var(--accent-soft);
  border-color: var(--accent-soft-strong);
  color: var(--accent-hover);
  font-weight: var(--fw-medium);
}

.filter-chip .count {
  color: var(--text-muted);
}

.filter-chip.is-active .count {
  color: var(--accent-hover);
}

.bulk-bar {
  display: none;
  align-items: center;
  gap: 8px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft-strong);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  margin-bottom: 12px;
}

.bulk-count {
  font-weight: var(--fw-medium);
  color: var(--accent-hover);
  margin-right: auto;
}

.bulk-note {
  margin-left: 8px;
  font-size: var(--fs-12);
}

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

.fileicon {
  color: var(--text-muted);
  flex: none;
}

.doc-title-link {
  font-weight: var(--fw-medium);
  font-size: var(--fs-15);
  color: var(--text);
}

.doc-title-link:hover {
  text-decoration: none;
  color: var(--accent-hover);
}

.doc-title-sub {
  color: var(--text-muted);
  font-size: var(--fs-13);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 380px;
}

.cell-chips {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  max-width: 260px;
}

.muted-nowrap {
  color: var(--text-secondary);
  white-space: nowrap;
}

.lib-hits {
  display: none;
}

.hits-head {
  margin: 12px 0 8px;
  font-size: var(--fs-14);
  color: var(--text-secondary);
}

.hit-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

/* The hit rows can be <a> elements: keep the previous look (text colour,
   no underline on hover). */
.hit-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text);
}

.hit-row:hover {
  border-color: var(--border-strong);
  text-decoration: none;
}

.hit-title {
  font-family: var(--font-display);
  font-weight: var(--fw-display);
  font-size: var(--fs-17);
}

.hit-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--text-secondary);
  font-size: var(--fs-13);
}

.hit-snippet {
  color: var(--text-secondary);
  font-size: var(--fs-13);
}

.hit-snippet mark {
  background: var(--hl-soft);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* Document view */
.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
  flex: none;
  padding: 24px 24px 0;
}

.doc-header-text {
  min-width: 0;
}

.doc-header-text h1 {
  font-size: var(--fs-34);
  line-height: 1.1;
}

.doc-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: var(--fs-13);
}

/* The actions keep a single row; the title takes the line breaks instead. */
.doc-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex: none;
}

.doc-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  flex: none;
  margin: 0 24px;
}

.tabs {
  display: flex;
  gap: 2px;
}

.tab {
  padding: 8px 14px;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-weight: var(--fw-medium);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab:hover {
  color: var(--text);
}

.tab.is-active {
  color: var(--accent-hover);
  border-bottom-color: var(--accent);
}

.doc-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 0 24px;
  align-items: stretch;
  flex: 1;
  min-height: 0;
  margin-top: 16px;
  padding: 0 24px;
}

.doc-main {
  grid-column: 1;
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.doc-main-scroll {
  height: 100%;
  overflow-y: auto;
  min-height: 0;
  padding-bottom: 24px;
}

/* In Original mode the viewer fills the column; no scroll-end padding. */
.doc-main-scroll:has(> .doc-content-fill) {
  padding-bottom: 0;
}

.doc-rail {
  grid-column: 2;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.rail-scroll {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  min-height: 0;
  padding-right: 4px;
}

/* macOS renders scrollbars as overlays that are invisible at rest (and Chromium
   no longer lets custom ::-webkit-scrollbar styling reserve space), so scroll
   areas need their own affordance: a soft bottom shadow while there is more
   content below, toggled from document.js (.rail-has-more / .has-more). */
.rail-fade,
.doc-main-fade {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 40px;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(var(--shadow-tint), 0), rgba(var(--shadow-tint), 0.14));
  opacity: 0;
  transition: opacity 0.15s ease;
}

.doc-rail.rail-has-more .rail-fade {
  opacity: 1;
}

.doc-main.has-more .doc-main-fade {
  opacity: 1;
}

.rail-scroll::-webkit-scrollbar {
  width: 8px;
}

.rail-scroll::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.rail-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.rail-find {
  gap: 8px;
  flex: none;
}

.rail-find .find-count {
  min-height: 1em;
}

/* Rail card labels stay small caps even though the boxes are back (owner
   requested the boxed look again, 2026-10-10). */
.doc-rail .card h2 {
  font-family: var(--font-ui);
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.reading {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 40px 48px;
}

.reading .reading-heading {
  font-size: var(--fs-24);
}

.reading h2.reading-heading,
.reading h3.reading-heading {
  font-size: var(--fs-18);
}

.reading-heading {
  margin-top: 24px;
}

.reading-heading:first-child {
  margin-top: 0;
}

.reading-paragraph {
  margin-top: 12px;
  font-size: var(--fs-16);
  line-height: 1.7;
}

.reading-table {
  margin-top: 16px;
}

.page-sep {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 28px 0 8px;
  color: var(--text-muted);
  font-size: var(--fs-13);
}

.page-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.page-sep:first-child {
  margin-top: 0;
}

.page-sep.is-target {
  background: var(--hl-target);
  border-radius: 4px;
}

.find-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  height: 32px;
  width: 100%;
  color: var(--text-muted);
}

.find-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.find-bar input {
  border: 0;
  outline: 0;
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: var(--fs-13);
  background: transparent;
  color: var(--text);
}

.find-nav {
  width: 22px;
  height: 22px;
  flex: none;
}

mark.find-hit {
  background: var(--hl);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

mark.find-hit.is-active {
  background: var(--hl-strong);
  box-shadow: 0 0 0 1px var(--hl-ring);
}

.find-count {
  font-size: var(--fs-13);
  color: var(--text-muted);
  white-space: nowrap;
}

/* Library search: archived toggle */
.archive-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 3px 0;
  color: var(--text-secondary);
  font-size: var(--fs-13);
  cursor: pointer;
  white-space: nowrap;
}

/* Document: notes + clickable entities */
.archived-note {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--status-archived-bg);
  color: var(--status-archived-fg);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: var(--fs-13);
  margin: 0 24px 12px;
}

.entity-chip.is-clickable {
  cursor: pointer;
}

.entity-chip.is-clickable:hover {
  background: var(--border);
}

/* Keep the occurrence count readable on the darkened hover surface (axe). */
.entity-chip.is-clickable:hover .entity-count {
  color: var(--text-secondary);
}

.entity-overview-sub {
  margin-bottom: 8px;
  font-size: var(--fs-13);
}

.entity-overview .hit-row {
  margin-bottom: 8px;
}

.phases {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 8px;
}

.phase {
  display: flex;
  gap: 10px;
  padding: 8px 0;
}

.phase-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  color: var(--text-muted);
  flex: none;
}

.phase-done .phase-icon {
  background: var(--status-ready-bg);
  border-color: transparent;
  color: var(--status-ready-fg);
}

.phase-active .phase-icon {
  background: var(--status-processing-bg);
  border-color: transparent;
  color: var(--status-processing-fg);
}

.phase-failed .phase-icon {
  background: var(--status-failed-bg);
  border-color: transparent;
  color: var(--status-failed-fg);
}

.phase-body {
  flex: 1;
  min-width: 0;
}

.phase-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.phase-label {
  font-weight: var(--fw-medium);
  font-size: var(--fs-14);
}

.phase-time {
  color: var(--text-muted);
  font-size: var(--fs-13);
}

.phase-explain {
  color: var(--text-secondary);
  font-size: var(--fs-13);
  margin: 2px 0 6px;
}

.phase-waiting .phase-label {
  color: var(--text-muted);
  font-weight: var(--fw-regular);
}

.error-banner {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  background: var(--status-failed-bg);
  color: var(--status-failed-fg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: var(--fs-13);
}

.error-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-start;
}

.processing-hero {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Document history: run timeline + the reused phase stepper */
.history {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.history-timeline {
  display: flex;
  flex-direction: column;
}

.history-row {
  display: flex;
  gap: 12px;
  padding: 6px 0 14px;
}

.history-row:last-child {
  padding-bottom: 2px;
}

.history-stem {
  flex: none;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 11px;
}

.history-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: var(--bg-surface);
  margin-top: 4px;
}

/* The connector reaches through the row padding so the dots read as one
   timeline; hidden on the last row (nothing follows). */
.history-stem::after {
  content: '';
  position: absolute;
  top: 17px;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  background: var(--border);
}

.history-row:last-child .history-stem::after {
  display: none;
}

.history-row.history-failed .history-dot {
  border-color: var(--status-failed-fg);
}

.history-row.history-active .history-dot {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.history-body {
  flex: 1;
  min-width: 0;
}

.history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.history-label {
  font-weight: var(--fw-medium);
}

.history-time {
  color: var(--text-muted);
  font-size: var(--fs-13);
  white-space: nowrap;
}

.history-message {
  margin: 4px 0 0;
  color: var(--text-secondary);
  font-size: var(--fs-13);
}

.kv {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-13);
}

.kv-key {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}

.kv-value {
  font-weight: var(--fw-medium);
}

.entity-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.entity-head {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: var(--fs-13);
  font-weight: var(--fw-medium);
}

.entity-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.entity-count {
  color: var(--text-muted);
  margin-left: 4px;
}

.keyword-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--fs-13);
}

.keyword-row.is-clickable {
  border: 0;
  background: transparent;
  width: 100%;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
}

.keyword-row.is-clickable:hover {
  background: var(--bg-hover);
}

.keywords-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.keyword-toggle {
  align-self: flex-start;
  border: 0;
  background: transparent;
  padding: 2px 6px;
  font-size: var(--fs-13);
  color: var(--accent-hover);
  cursor: pointer;
}

.keyword-toggle:hover {
  text-decoration: underline;
}

.keyword-term {
  width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
}

.keyword-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-hover);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.keyword-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
}

.ai-box {
  border-top: 1px dashed var(--border);
  padding-top: 10px;
}

.ai-thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: var(--fs-13);
}

.ai-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft-strong);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.ai-card-head {
  display: flex;
  gap: 8px;
  align-items: center;
  font-weight: var(--fw-medium);
  font-size: var(--fs-13);
  color: var(--accent-hover);
}

.ai-confidence {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-13);
  color: var(--text-secondary);
}

.ai-bar {
  flex: 1;
  height: 6px;
  background: rgba(255, 253, 251, 0.75);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.ai-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.ai-reason {
  font-size: var(--fs-13);
  color: var(--text-secondary);
}

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

.org-collections {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.org-chip {
  padding-right: 4px;
}

.chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: inherit;
  cursor: pointer;
  opacity: 0.7;
}

.chip-remove:hover {
  opacity: 1;
  background: rgba(var(--shadow-tint), 0.08);
}

/* Original viewers */
.viewer-shell {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* In the doc shell the viewer fills the content column (which itself does not
   scroll in Original mode; the viewer body scrolls internally). */
.doc-content-fill {
  height: 100%;
}

.doc-content-fill .viewer-shell {
  height: 100%;
}

.doc-content-fill .viewer-body {
  flex: 1;
  min-height: 0;
  max-height: none;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  font-size: var(--fs-13);
  color: var(--text-secondary);
  flex-wrap: wrap;
}

.viewer-spacer {
  flex: 1;
}

.viewer-nav-start {
  margin-left: 10px;
}

.viewer-page-label {
  margin: 0 6px;
  white-space: nowrap;
}

.viewer-zoom-label {
  min-width: 96px;
  justify-content: center;
}

.viewer-note {
  font-size: var(--fs-13);
}

.viewer-body {
  background: var(--bg-app);
  overflow: auto;
  min-height: 200px;
}

.viewer-body-pdf,
.viewer-body-image {
  max-height: calc(100vh - 320px);
}

.pdf-pages {
  padding: 16px;
}

.pdf-page {
  position: relative;
  background: var(--paper);
  box-shadow: 0 1px 4px rgba(var(--shadow-tint), 0.18);
  margin: 0 auto 16px;
}

.pdf-page:last-child {
  margin-bottom: 0;
}

.pdf-canvas {
  display: block;
  background: var(--paper);
}

/* Text-layer rules mirror the upstream PDF.js viewer stylesheet
   (pdfjs-dist 6.4.299, web/pdf_viewer.css, Apache-2.0). The layer depends on these
   rules: PDF.js sets --font-height / --scale-x / --rotate inline on every span, and
   the rules below turn those variables into font-size and transform. Without them
   the browser text (find highlights, text selection) drifts from the canvas glyphs. */
.text-layer {
  position: absolute;
  inset: 0;
  overflow: clip;
  line-height: 1;
  letter-spacing: normal;
  word-spacing: normal;
  text-align: initial;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
  caret-color: CanvasText;
  --min-font-size: 1;
  --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size));
  --min-font-size-inv: calc(1 / var(--min-font-size));
}

.text-layer :is(span, br) {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
  user-select: text;
}

.text-layer > :not(.markedContent),
.text-layer .markedContent span:not(.markedContent) {
  z-index: 1;
  --font-height: 0;
  font-size: calc(var(--text-scale-factor) * var(--font-height));
  --scale-x: 1;
  --rotate: 0deg;
  transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv));
}

.text-layer .markedContent {
  display: contents;
}

.text-layer span[role='img'] {
  user-select: none;
  cursor: default;
}

.text-layer ::selection {
  background: rgba(var(--accent-rgb), 0.24);
  color: transparent;
}

.text-layer br::selection {
  background: transparent;
}

.text-layer mark.find-hit {
  background: var(--hl-tl);
  color: transparent;
  border-radius: 2px;
  padding: 0;
}

.text-layer mark.find-hit.is-active {
  background: var(--hl-tl-strong);
  box-shadow: 0 0 0 1.5px var(--hl-tl-ring);
}

.viewer-image-wrap {
  display: flex;
  justify-content: center;
  padding: 16px;
}

.viewer-image {
  height: auto;
  box-shadow: 0 1px 4px rgba(var(--shadow-tint), 0.18);
}

.viewer-error {
  align-items: flex-start;
}

.viewer-error-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.sheet-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.sheet-tab {
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  padding: 3px 10px;
  font-size: var(--fs-13);
  cursor: pointer;
  color: var(--text-secondary);
}

.sheet-tab.is-active {
  background: var(--accent-soft);
  border-color: var(--accent-soft-strong);
  color: var(--accent-hover);
  font-weight: var(--fw-medium);
}

.sheet-host {
  padding: 12px;
}

.sheet-grid {
  background: var(--bg-surface);
}

.sheet-grid th,
.sheet-grid td {
  padding: 5px 8px;
  border: 1px solid var(--border);
  white-space: nowrap;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sheet-grid thead th {
  position: sticky;
  top: 0;
  background: var(--bg-subtle);
  z-index: 1;
}

.sheet-grid .sheet-corner,
.sheet-grid .sheet-row {
  position: sticky;
  left: 0;
  background: var(--bg-subtle);
  text-align: right;
  color: var(--text-muted);
  font-weight: var(--fw-regular);
  z-index: 2;
}

.sheet-grid .sheet-col {
  text-align: center;
  color: var(--text-muted);
  font-weight: var(--fw-regular);
}

.docx-body {
  background: var(--bg-surface);
  padding: 32px 40px;
  font-size: var(--fs-16);
  line-height: 1.7;
}

.docx-body h1,
.docx-body h2,
.docx-body h3,
.docx-body h4,
.docx-body h5,
.docx-body h6 {
  margin: 20px 0 8px;
}

.docx-body h1:first-child {
  margin-top: 0;
}

.docx-body p {
  margin: 10px 0;
}

.docx-body ul,
.docx-body ol {
  margin: 10px 0;
  padding-left: 24px;
}

.docx-body table {
  border-collapse: collapse;
  margin: 12px 0;
}

.docx-body td,
.docx-body th {
  border: 1px solid var(--border);
  padding: 6px 10px;
}

.original-html {
  width: 100%;
  height: calc(100vh - 300px);
  min-height: 480px;
  border: 0;
  background: var(--paper);
  display: block;
}

.simulated-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
}

.original-text {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  font-family: var(--font-mono);
  font-size: var(--fs-13);
  white-space: pre-wrap;
}

.original-generated {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.simulated-note {
  font-size: var(--fs-13);
}

.paper-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.paper {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(var(--shadow-tint), 0.06);
  padding: 32px 36px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.paper h3 {
  font-size: var(--fs-16);
  margin-top: 8px;
}

.paper p {
  font-size: var(--fs-13);
  color: var(--text-secondary);
}

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

.slide {
  aspect-ratio: 16 / 9;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 1px 2px rgba(var(--shadow-tint), 0.06);
}

.slide-title {
  font-weight: var(--fw-semibold);
  font-size: var(--fs-14);
}

.slide-text {
  font-size: var(--fs-13);
  color: var(--text-secondary);
  overflow: hidden;
}

/* Upload */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 40px 24px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent);
}

.dropzone-title {
  font-family: var(--font-display);
  font-weight: var(--fw-display);
  font-size: var(--fs-20);
}

.upload-section-title {
  margin: 24px 0 12px;
  font-size: var(--fs-16);
}

.upload-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.upload-context {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: var(--fs-13);
  margin-bottom: 12px;
}

.upload-context .btn {
  margin-left: auto;
}

.dup-list {
  margin: 0;
  padding-left: 18px;
  color: var(--text-secondary);
  font-size: var(--fs-13);
}

.upload-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.upload-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.upload-card-title {
  flex: 1;
  min-width: 0;
}

.upload-name {
  font-weight: var(--fw-medium);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-sub {
  font-size: var(--fs-13);
}

.upload-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.upload-done {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--status-ready-fg);
  font-size: var(--fs-13);
}

.upload-duplicate {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: var(--fs-13);
}

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

.collection-card {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.collection-card:hover {
  border-color: var(--border-strong);
}

/* Whole-card click target via a stretched link, without nesting interactive
   elements (the menu button stays a separate control above it). */
.collection-card .card-link {
  color: inherit;
  text-decoration: none;
}

.collection-card .card-link::after {
  content: '';
  position: absolute;
  inset: 0;
}

.collection-card .card-link:hover {
  text-decoration: none;
}

.collection-card-head .icon-btn {
  position: relative;
  z-index: 1;
}

.collection-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.collection-card-head h2 {
  font-size: var(--fs-16);
}

.collection-meta {
  font-weight: var(--fw-medium);
  font-size: var(--fs-14);
}

.collection-updated {
  color: var(--text-muted);
  font-size: var(--fs-13);
}

.collection-ai {
  align-self: flex-start;
}

.collection-card.is-virtual {
  border-style: dashed;
}

.collection-card.is-virtual h2 {
  color: var(--text-secondary);
}

.form-error {
  color: var(--status-failed-fg);
  font-size: var(--fs-13);
  min-height: 1em;
}

.picker-list {
  max-height: 320px;
}

.picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 4px;
}

.picker-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* AI review */
.ai-review {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 50vh;
  overflow: auto;
}

.ai-review-analysis {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 0;
}

.review-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.review-row:last-child {
  border-bottom: 0;
}

.review-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.review-title {
  font-weight: var(--fw-medium);
}

.review-suggestion {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-13);
}

.review-confidence {
  color: var(--text-secondary);
}

.review-reason {
  font-size: var(--fs-13);
}

/* ---------- home: activity feed + attention rail (round 9) ---------- */

.home-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 0 24px;
  align-items: start;
  margin-top: 16px;
}

.home-main {
  min-width: 0;
}

.home-rail {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.home-day + .home-day {
  margin-top: 18px;
}

.home-day-label {
  margin: 0 0 6px;
  font-size: var(--fs-11);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.home-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.home-list li + li {
  border-top: 1px solid var(--border);
}

.home-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 8px;
  border-radius: var(--radius-md);
  color: inherit;
  text-decoration: none;
}

a.home-row:hover {
  background: var(--bg-app);
  text-decoration: none;
}

.home-row.is-plain {
  cursor: default;
}

.home-row-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: var(--fs-13);
  line-height: 1.45;
}

.home-row-body em {
  font-style: normal;
  font-weight: var(--fw-medium);
}

.home-quote {
  color: var(--text-secondary);
  font-size: var(--fs-12);
  font-style: italic;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.home-time {
  flex: none;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: var(--fs-11);
  white-space: nowrap;
}

.home-kind {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--bg-app);
  color: var(--text-secondary);
  flex: none;
}

.home-kind.kind-processing-failed {
  border-color: var(--accent);
  color: var(--accent);
}

.home-more {
  margin: 14px 0 0;
  font-size: var(--fs-12);
}

.attention-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
}

.attention-row + .attention-row {
  border-top: 1px solid var(--border);
}

.attention-icon {
  display: inline-flex;
  flex: none;
  color: var(--text-muted);
}

.attention-icon.is-failed {
  color: var(--accent);
}

.attention-icon.is-ok {
  color: var(--text-muted);
  margin-right: 6px;
}

.attention-text {
  flex: 1;
  min-width: 0;
  font-size: var(--fs-13);
  line-height: 1.4;
}

.attention-text strong {
  font-weight: var(--fw-semibold);
}

.attention-action {
  flex: none;
  font-size: var(--fs-12);
}

.attention-empty {
  display: flex;
  align-items: center;
  margin: 4px 0 0;
  font-size: var(--fs-13);
}

.home-recent {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.home-recent a {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: inherit;
  text-decoration: none;
}

.home-recent a:hover .home-recent-title {
  text-decoration: underline;
}

.home-recent-title {
  font-size: var(--fs-13);
  font-weight: var(--fw-medium);
}

.home-recent-meta {
  font-size: var(--fs-11);
}
