:root {
  color-scheme: light;
  --ink: #171719;
  --muted: #6d6d73;
  --canvas: #f6f6f3;
  --surface: #ffffff;
  --surface-soft: #f0f0ed;
  --line: #e2e2de;
  --line-strong: #c9c9c4;
  --accent: #5654d8;
  --accent-dark: #4543bb;
  --accent-soft: #eeedff;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --shadow: 0 18px 60px rgb(23 23 25 / 8%);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgb(86 84 216 / 5%), transparent 30rem),
    var(--canvas);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }

button, a, input { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid rgb(86 84 216 / 22%);
  outline-offset: 2px;
}

h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { letter-spacing: -0.035em; line-height: 1.12; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 10px;
  left: 10px;
  padding: 10px 14px;
  color: white;
  background: var(--ink);
  border-radius: var(--radius-sm);
  transform: translateY(-150%);
}

.skip-link:focus { transform: translateY(0); }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 70px;
  padding: 0 max(24px, calc((100vw - 1280px) / 2));
  border-bottom: 1px solid rgb(226 226 222 / 85%);
  background: rgb(246 246 243 / 88%);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 720;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand-mark,
.auth-symbol {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: #fff;
  background: var(--ink);
  border-radius: 9px;
  font-size: 13px;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 12%);
}

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

#main-content {
  width: min(1280px, calc(100% - 48px));
  margin: 0 auto;
  padding: 58px 0 80px;
}

#main-content:focus { outline: 0; }

.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 36px;
  margin-bottom: 32px;
}

.page-heading h1 {
  margin: 5px 0 0;
  font-size: clamp(38px, 5vw, 58px);
  font-weight: 690;
}

.page-heading .lede { max-width: 370px; margin-bottom: 5px; }

.eyebrow {
  margin-bottom: 8px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.lede { color: var(--muted); font-size: 16px; line-height: 1.65; }

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

.main-panel,
.upload-panel,
.panel {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 1px rgb(23 23 25 / 2%);
}

.main-panel { min-width: 0; padding: 18px; }
.upload-panel { position: sticky; top: 94px; padding: 18px; }

.search-box {
  display: flex;
  align-items: end;
  gap: 10px;
  margin-bottom: 12px;
}

.search-field { position: relative; flex: 1; min-width: 0; }

.search-icon {
  position: absolute;
  left: 18px;
  width: 17px;
  height: 17px;
  border: 1.8px solid var(--muted);
  border-radius: 50%;
  pointer-events: none;
}

.search-icon::after {
  content: "";
  position: absolute;
  right: -5px;
  bottom: -3px;
  width: 7px;
  height: 1.8px;
  background: var(--muted);
  border-radius: 2px;
  transform: rotate(45deg);
}

.search-input {
  width: 100%;
  height: 56px;
  padding: 0 18px 0 50px;
  color: var(--ink);
  border: 1px solid transparent;
  background: var(--surface-soft);
  border-radius: 13px;
  font-size: 16px;
  transition: border-color 150ms ease, background 150ms ease, box-shadow 150ms ease;
}

.search-input::placeholder { color: #88888e; }

.search-input:focus {
  border-color: rgb(86 84 216 / 48%);
  background: white;
  box-shadow: 0 0 0 4px rgb(86 84 216 / 8%);
  outline: none;
}

.search-engine-field {
  display: grid;
  flex: 0 0 auto;
  gap: 5px;
}

.search-engine-field label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.search-engine-select {
  height: 56px;
  min-width: 150px;
  padding: 0 34px 0 13px;
  color: var(--ink);
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 13px;
  cursor: pointer;
}

.search-engine-select:focus {
  border-color: rgb(86 84 216 / 48%);
  box-shadow: 0 0 0 4px rgb(86 84 216 / 8%);
  outline: none;
}

@media (max-width: 620px) {
  .search-box { align-items: stretch; flex-direction: column; }
  .search-engine-select { width: 100%; height: 44px; }
}

.results-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 4px 12px;
}

.results-header h2 { margin: 0; font-size: 18px; font-weight: 680; letter-spacing: -0.02em; }
.muted { color: var(--muted); font-size: 13px; }

.document-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }

.document-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 112px;
  padding: 18px;
  border: 1px solid transparent;
  background: #fafaf8;
  border-radius: var(--radius-md);
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}

.document-item:hover {
  border-color: var(--line);
  background: white;
  transform: translateY(-1px);
}

.document-details { min-width: 0; flex: 1; }
.document-heading { display: flex; align-items: center; gap: 13px; min-width: 0; }
.document-heading > div { min-width: 0; }

.file-icon {
  position: relative;
  flex: 0 0 auto;
  width: 36px;
  height: 42px;
  border: 1px solid var(--line-strong);
  background: white;
  border-radius: 7px;
  box-shadow: 0 2px 6px rgb(23 23 25 / 5%);
}

.file-icon::before,
.file-icon::after,
.file-icon span {
  content: "";
  position: absolute;
  left: 9px;
  width: 16px;
  height: 1px;
  background: #b1b1b6;
}

.file-icon::before { top: 14px; }
.file-icon span { top: 20px; }
.file-icon::after { top: 26px; width: 11px; }

.document-title {
  overflow: hidden;
  margin: 0;
  font-size: 15px;
  font-weight: 680;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-context {
  overflow: hidden;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-meta { display: flex; align-items: center; gap: 10px; margin: 10px 0 0 49px; color: var(--muted); font-size: 12px; }

.processing-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--accent-dark);
  font-weight: 650;
}

.processing-label::before {
  content: "";
  width: 6px;
  height: 6px;
  background: currentColor;
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.processing-label.status-failed { color: var(--danger); }
.processing-label.status-failed::before { box-shadow: 0 0 0 3px var(--danger-soft); }

.snippet { display: -webkit-box; overflow: hidden; margin: 11px 0 0 49px; color: #56565c; font-size: 13px; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.status-message { margin: 9px 0 0 49px; color: var(--muted); font-size: 13px; }

.document-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 4px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 39px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 680;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: 0.45; }
.button-primary { color: white; background: var(--accent); }
.button-primary:hover:not(:disabled) { background: var(--accent-dark); }
.button-secondary { color: var(--ink); border-color: var(--line); background: white; }
.button-secondary:hover:not(:disabled) { border-color: var(--line-strong); background: var(--surface-soft); }
.button-quiet { color: var(--muted); background: transparent; }
.button-quiet:hover:not(:disabled) { color: var(--ink); background: var(--surface-soft); }

.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 20px 0 2px; }
.pagination .button { min-height: 34px; padding: 0 12px; }

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 34px 22px 24px;
  text-align: center;
  border: 1px dashed var(--line-strong);
  background: #fafaf8;
  border-radius: 16px;
  transition: border-color 150ms ease, background 150ms ease;
}

.drop-zone[data-dragging="true"] { border-color: var(--accent); background: var(--accent-soft); }

.upload-icon {
  position: relative;
  width: 42px;
  height: 42px;
  margin-bottom: 16px;
  background: var(--accent-soft);
  border-radius: 13px;
}

.upload-icon::before {
  content: "+";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--accent-dark);
  font-size: 23px;
  font-weight: 350;
}

.field-label { font-size: 15px; font-weight: 700; }
.upload-copy { margin: 7px 0 16px; color: var(--muted); font-size: 13px; line-height: 1.55; }
#document-file { width: 100%; color: var(--muted); font-size: 12px; }
#document-file::file-selector-button { margin: 0 8px 14px 0; padding: 8px 11px; color: var(--ink); border: 1px solid var(--line); background: white; border-radius: 8px; cursor: pointer; font-weight: 650; }
.file-summary { width: 100%; min-height: 36px; margin-bottom: 13px; color: var(--muted); font-size: 12px; word-break: break-word; }
.drop-zone .button { width: 100%; }
.hint { margin: 14px 6px 2px; color: var(--muted); font-size: 12px; line-height: 1.55; }

.upload-progress { overflow: hidden; width: 100%; height: 3px; margin-top: 14px; background: var(--line); border-radius: 4px; }
.upload-progress[hidden] { display: none; }
.upload-progress span { display: block; width: 35%; height: 100%; background: var(--accent); border-radius: inherit; animation: progress 1s ease-in-out infinite alternate; }

.loading-state { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 150px; color: var(--muted); font-size: 14px; }
.spinner { width: 15px; height: 15px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 700ms linear infinite; }
.empty-state { margin: 8px 0; padding: 58px 24px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius-md); }
.empty-state strong { display: block; margin-bottom: 6px; font-size: 16px; }
.empty-state p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }

.alert { margin: 0 0 18px; padding: 13px 15px; color: #7a271a; border: 1px solid #f5c4bf; background: var(--danger-soft); border-radius: 10px; font-size: 13px; }

.auth-layout { display: grid; min-height: calc(100vh - 210px); place-items: center; }
.auth-card { width: min(430px, 100%); padding: 40px; box-shadow: var(--shadow); }
.auth-symbol { width: 44px; height: 44px; margin-bottom: 30px; border-radius: 13px; font-size: 16px; }
.auth-card h1 { margin-bottom: 12px; font-size: 36px; }
.auth-card .lede { margin-bottom: 28px; }
.stack { display: grid; gap: 17px; }
.field { display: grid; gap: 7px; }
.field label { font-size: 13px; font-weight: 680; }
.field input { width: 100%; height: 47px; padding: 0 13px; color: var(--ink); border: 1px solid var(--line-strong); background: white; border-radius: 10px; }
.field input:focus { border-color: var(--accent); outline: 3px solid rgb(86 84 216 / 10%); }
.stack > .button { width: 100%; min-height: 46px; margin-top: 4px; }

.preview-dialog {
  width: min(1050px, calc(100vw - 40px));
  height: min(820px, calc(100vh - 40px));
  max-width: none;
  max-height: none;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 30px 100px rgb(17 17 19 / 28%);
}

.preview-dialog::backdrop { background: rgb(17 17 19 / 52%); backdrop-filter: blur(4px); }
.preview-shell { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100%; }
.preview-header { display: flex; align-items: center; justify-content: space-between; gap: 24px; min-width: 0; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.preview-header > div:first-child { min-width: 0; }
.preview-header .eyebrow { margin-bottom: 4px; }
.preview-header h2 { overflow: hidden; margin: 0; font-size: 17px; text-overflow: ellipsis; white-space: nowrap; }
.preview-actions { display: flex; flex: 0 0 auto; gap: 6px; }
.document-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.document-chips .button { min-height: 28px; padding: 4px 8px; font-size: 12px; }
.organization-dialog { width: min(520px, calc(100vw - 32px)); padding: 24px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.organization-dialog::backdrop { background: rgb(17 17 19 / 52%); }
.organization-dialog h2 { margin: 0; }
.organization-note { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.preview-body { position: relative; min-height: 0; overflow: auto; background: #ececea; }
.preview-pdf { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100%; min-height: 100%; }
.pdf-toolbar { position: sticky; z-index: 2; top: 0; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: rgb(255 255 255 / 96%); backdrop-filter: blur(8px); }
.pdf-toolbar .button { min-height: 36px; padding: 7px 12px; }
.pdf-page-status { min-width: 96px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; text-align: center; }
.pdf-page-stage { position: relative; display: grid; min-width: 0; min-height: 100%; padding: 24px; place-items: start center; }
.pdf-page-surface { position: relative; max-width: 100%; overflow: hidden; background: white; box-shadow: 0 8px 30px rgb(23 23 25 / 16%); }
.pdf-canvas { display: block; max-width: 100%; height: auto; background: white; box-shadow: 0 8px 30px rgb(23 23 25 / 16%); }
.pdf-page-surface .pdf-canvas { box-shadow: none; }
.pdf-text-layer {
  position: absolute;
  z-index: 1;
  inset: 0;
  overflow: clip;
  color-scheme: only light;
  font-size: 1px;
  line-height: 1;
  text-align: initial;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
}
.pdf-text-layer :is(span, br) { position: absolute; color: transparent; white-space: pre; cursor: text; user-select: text; transform-origin: 0 0; }
.pdf-text-layer > :not(.markedContent),
.pdf-text-layer .markedContent span:not(.markedContent) {
  --font-height: 0;
  --scale-x: 1;
  --rotate: 0deg;
  z-index: 1;
  font-size: calc(var(--total-scale-factor) * var(--font-height));
  transform: rotate(var(--rotate)) scaleX(var(--scale-x));
}
.pdf-text-layer .markedContent { display: contents; }
.pdf-text-layer ::selection { color: transparent; background: rgb(86 84 216 / 24%); }
.pdf-page-surface > .xfaLayer { --xfa-focus-outline: 2px solid CanvasText; --xfa-unfocused-field-background: transparent; position: absolute; z-index: 1; inset: 0; overflow: hidden; color-scheme: only light; background: transparent; line-height: 1.2; text-align: initial; transform-origin: 0 0; }
.pdf-page-surface > .xfaLayer * { box-sizing: border-box; margin: 0; padding: 0; color: inherit; background-color: transparent; font: inherit; font-style: inherit; font-weight: inherit; font-kerning: inherit; letter-spacing: -0.01px; line-height: inherit; text-align: inherit; text-decoration: inherit; }
.pdf-page-surface > .xfaLayer div,
.pdf-page-surface > .xfaLayer svg,
.pdf-page-surface > .xfaLayer svg * { pointer-events: none; }
.pdf-page-surface > .xfaLayer :is(a, button, input, select, textarea) { pointer-events: auto; }
.pdf-page-surface > .xfaLayer a { color: var(--accent); }
.pdf-page-surface > .xfaLayer.xfaFont { color: #000; font-size: 10px; font-style: normal; font-weight: normal; font-kerning: none; letter-spacing: 0; text-decoration: none; }
.pdf-page-surface > .xfaLayer .xfaPage { position: relative; overflow: hidden; }
.pdf-page-surface > .xfaLayer .xfaContentarea,
.pdf-page-surface > .xfaLayer .xfaBorder,
.pdf-page-surface > .xfaLayer .xfaLink { position: absolute; }
.pdf-page-surface > .xfaLayer .xfaPrintOnly { display: none; }
.pdf-page-surface > .xfaLayer :is(.xfaCaption, .xfaCaptionForCheckButton) { overflow: hidden; flex: 0 0 auto; }
.pdf-page-surface > .xfaLayer .xfaCaptionForCheckButton { flex: 1 1 auto; }
.pdf-page-surface > .xfaLayer .xfaLabel,
.pdf-page-surface > .xfaLayer .xfaWrapped,
.pdf-page-surface > .xfaLayer :is(.xfaButton, .xfaLink, .xfaCheckbox, .xfaRadio, .xfaRich, .xfaImage) { width: 100%; height: 100%; }
.pdf-page-surface > .xfaLayer :is(.xfaLeft, .xfaRight, .xfaTop, .xfaBottom, .xfaLrTb, .xfaRlTb, .xfaTb, .xfaLr, .xfaRl, .xfaTable, .xfaRow, .xfaRlRow) { display: flex; align-items: stretch; }
.pdf-page-surface > .xfaLayer :is(.xfaLeft, .xfaLr, .xfaRow) { flex-direction: row; }
.pdf-page-surface > .xfaLayer :is(.xfaRight, .xfaRl, .xfaRlRow) { flex-direction: row-reverse; }
.pdf-page-surface > .xfaLayer :is(.xfaTop, .xfaLrTb, .xfaRlTb, .xfaTb, .xfaTable) { flex-direction: column; }
.pdf-page-surface > .xfaLayer .xfaBottom { flex-direction: column-reverse; }
.pdf-page-surface > .xfaLayer :is(.xfaLeft, .xfaRight) { align-items: center; }
.pdf-page-surface > .xfaLayer :is(.xfaTop, .xfaBottom) { align-items: flex-start; }
.pdf-page-surface > .xfaLayer :is(.xfaTextfield, .xfaSelect) { width: 100%; height: 100%; flex: 1 1 auto; border: 0; resize: none; background-image: var(--xfa-unfocused-field-background); }
.pdf-page-surface > .xfaLayer :is(.xfaTextfield, .xfaSelect):focus { outline: var(--xfa-focus-outline); outline-offset: -1px; background: transparent; }
.pdf-page-surface > .xfaLayer :is(.xfaCheckbox, .xfaRadio):focus { outline: var(--xfa-focus-outline); }
.pdf-page-surface > .xfaLayer .xfaButton { border: 0; text-align: center; cursor: pointer; }
.pdf-page-surface > .xfaLayer .xfaCheckbox,
.pdf-page-surface > .xfaLayer .xfaRadio { flex: 0 0 auto; border: 0; }
.pdf-page-surface > .xfaLayer .xfaRich { white-space: pre-wrap; }
.pdf-page-surface > .xfaLayer .xfaImage { object-fit: contain; object-position: left top; }
.pdf-page-surface > .xfaLayer :is(.xfaPosition, .xfaArea) { position: relative; }
.pdf-page-surface > .xfaLayer .xfaValignMiddle { display: flex; align-items: center; }
.pdf-page-surface > .xfaLayer .xfaRlRow { flex: 1; }
.pdf-page-surface > .xfaLayer .xfaRlRow > div { flex: 1; }
.preview-loading {
  position: absolute;
  z-index: 1;
  right: 16px;
  bottom: 16px;
  left: 16px;
  width: fit-content;
  max-width: calc(100% - 32px);
  margin: 0 auto;
  padding: 9px 13px;
  color: var(--muted);
  background: rgb(255 255 255 / 94%);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 6px 20px rgb(23 23 25 / 10%);
  font-size: 12px;
  pointer-events: none;
}
.pdf-password-form { align-self: center; width: min(420px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: 0 12px 36px rgb(23 23 25 / 12%); }
.pdf-password-form h3 { margin: 0; font-size: 18px; }
.pdf-password-form > p { margin: 8px 0 20px; }
.pdf-password-form .preview-actions { margin-top: 18px; }
.pdf-password-error { color: #a42b2b; }
.preview-image { display: block; max-width: calc(100% - 48px); max-height: calc(100% - 48px); margin: 24px auto; object-fit: contain; box-shadow: 0 8px 30px rgb(23 23 25 / 16%); }
.preview-text { min-height: calc(100% - 48px); margin: 24px; padding: 32px; overflow: auto; color: #27272a; border: 1px solid var(--line); background: white; border-radius: 10px; box-shadow: 0 8px 30px rgb(23 23 25 / 8%); font: 14px/1.7 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.preview-note { position: sticky; bottom: 12px; width: fit-content; margin: -60px auto 20px; padding: 9px 13px; color: var(--muted); background: rgb(255 255 255 / 92%); border-radius: 8px; font-size: 12px; }
.preview-unavailable { display: grid; min-height: 100%; padding: 40px; text-align: center; place-content: center; }
.preview-unavailable strong { font-size: 17px; }
.preview-unavailable p { max-width: 390px; margin: 8px 0 0; color: var(--muted); }

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

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes progress { from { transform: translateX(-20%); } to { transform: translateX(205%); } }

@media (max-width: 900px) {
  #main-content { width: min(100% - 32px, 720px); padding-top: 38px; }
  .workspace-grid { grid-template-columns: 1fr; }
  .upload-panel { position: static; grid-row: 1; }
  .drop-zone { padding: 25px 20px 20px; }
  .page-heading { align-items: start; flex-direction: column; gap: 12px; }
  .page-heading .lede { max-width: 520px; }
}

@media (max-width: 600px) {
  .topbar { min-height: 62px; padding: 0 16px; }
  .brand { gap: 7px; font-size: 14px; }
  .brand-mark { width: 28px; height: 28px; }
  .nav-actions { gap: 2px; }
  .nav-actions .button { min-height: 34px; padding: 0 8px; font-size: 12px; }
  #main-content { width: calc(100% - 24px); padding: 28px 0 50px; }
  .page-heading { margin: 0 4px 24px; }
  .page-heading h1 { font-size: 40px; }
  .main-panel, .upload-panel { padding: 12px; border-radius: 17px; }
  .document-item { align-items: stretch; flex-direction: column; min-height: 0; padding: 16px; }
  .document-actions { justify-content: flex-end; }
  .document-actions .button { flex: 1; }
  .results-header { padding: 16px 4px 10px; }
  .auth-card { padding: 28px 22px; }
  .preview-dialog { width: 100vw; height: 100vh; border: 0; border-radius: 0; }
  .preview-header { align-items: stretch; flex-direction: column; gap: 12px; padding: 14px; }
  .preview-actions .button { flex: 1; }
  .pdf-page-stage { padding: 12px; }
  .pdf-toolbar { padding: 8px; }
  .pdf-toolbar .button { flex: 1; }
  .pdf-password-form { padding: 22px; }
  .preview-text { margin: 12px; padding: 18px; }
}

@media (max-width: 340px) {
  html { min-width: 0; }
  .brand { gap: 5px; font-size: 12px; }
  .brand-mark { width: 26px; height: 26px; font-size: 12px; }
  .nav-actions { gap: 1px; }
  .nav-actions .button { min-height: 32px; padding: 0 5px; font-size: 11px; }
}

@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; }
}

/* Quiet Library production surface -------------------------------------- */
:root {
  --quiet-canvas: #f4f6f2;
  --quiet-surface: #fffefa;
  --quiet-soft: #edf1ed;
  --quiet-line: #dce3de;
  --quiet-line-strong: #c2cec6;
  --quiet-ink: #1d2521;
  --quiet-muted: #68736d;
  --quiet-accent: #4c5fc0;
  --quiet-accent-dark: #3c4b9f;
  --quiet-accent-soft: #eef0ff;
  --quiet-danger: #a63a33;
  --quiet-danger-soft: #fff1ef;
}

body {
  color: var(--quiet-ink);
  background:
    radial-gradient(circle at 20% -8%, rgb(76 95 192 / 8%), transparent 28rem),
    var(--quiet-canvas);
}

.topbar {
  min-height: 64px;
  padding-inline: max(20px, calc((100vw - 1120px) / 2));
  border-bottom-color: rgb(220 227 222 / 90%);
  background: rgb(244 246 242 / 88%);
}

.brand { color: var(--quiet-ink); font-size: 15px; font-weight: 720; }
.brand-mark { background: var(--quiet-ink); }
.nav-actions .button { min-height: 38px; }
.nav-current { color: var(--quiet-ink); font-weight: 720; }
.nav-secondary { color: var(--quiet-muted); }

#main-content {
  width: min(1120px, calc(100% - 40px));
  padding: 46px 0 72px;
}

.documents-heading {
  align-items: end;
  gap: 28px;
  margin: 0 0 26px;
}

.page-heading-copy { min-width: 0; }
.documents-heading h1 { margin: 4px 0 8px; font-size: clamp(34px, 4vw, 48px); font-weight: 690; }
.documents-heading .lede { max-width: 460px; margin: 0; color: var(--quiet-muted); font-size: 15px; }
.documents-heading .eyebrow { color: var(--quiet-accent-dark); }
.upload-trigger { flex: 0 0 auto; min-height: 44px; padding-inline: 17px; }

.documents-layout { display: block; }
.library-panel {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--quiet-line);
  background: var(--quiet-surface);
  border-radius: 18px;
  box-shadow: 0 1px 1px rgb(29 37 33 / 3%);
}

.search-box { display: grid; gap: 8px; margin: 0; }
.search-field { position: relative; display: flex; align-items: center; min-width: 0; }
.search-input {
  height: 54px;
  padding: 0 92px 0 48px;
  color: var(--quiet-ink);
  border: 1px solid var(--quiet-line);
  background: var(--quiet-soft);
  border-radius: 12px;
  font-size: 16px;
  transition: border-color 150ms ease, background 150ms ease, box-shadow 150ms ease;
}
.search-input::placeholder { color: #7b8580; }
.search-input:focus { border-color: rgb(76 95 192 / 60%); background: var(--quiet-surface); box-shadow: 0 0 0 4px rgb(76 95 192 / 10%); }
.search-icon { left: 17px; border-color: var(--quiet-muted); }
.search-icon::after { background: var(--quiet-muted); }
.search-clear {
  position: absolute;
  right: 7px;
  min-height: 36px;
  padding-inline: 10px;
  color: var(--quiet-muted);
  border-radius: 8px;
}
.search-clear:hover:not(:disabled) { color: var(--quiet-ink); background: rgb(255 255 255 / 70%); }
.search-options { color: var(--quiet-muted); }
.search-options summary { width: fit-content; padding: 3px 4px; cursor: pointer; font-size: 12px; }
.search-options summary:focus-visible { outline: 3px solid rgb(76 95 192 / 22%); outline-offset: 2px; border-radius: 4px; }
.search-engine-field { display: flex; align-items: center; gap: 9px; width: fit-content; margin: 8px 4px 2px; font-size: 12px; }
.search-engine-field label { font-weight: 680; }
.search-engine-select { min-height: 34px; padding: 4px 28px 4px 9px; color: var(--quiet-ink); border: 1px solid var(--quiet-line-strong); background: var(--quiet-surface); border-radius: 8px; font-size: 12px; }
.search-engine-select:focus-visible { outline: 3px solid rgb(76 95 192 / 22%); outline-offset: 2px; }

.results-header { padding: 22px 4px 12px; }
.results-header h2 { color: var(--quiet-ink); font-size: 18px; font-weight: 690; }
.results-header .muted { color: var(--quiet-muted); font-size: 13px; }
.document-list { gap: 0; border-top: 1px solid var(--quiet-line); }
.document-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 16px;
  align-items: center;
  min-height: 86px;
  padding: 14px 8px 14px 10px;
  border: 0;
  border-bottom: 1px solid var(--quiet-line);
  background: transparent;
  border-radius: 0;
  transition: background 150ms ease;
}
.document-item:hover { border-color: var(--quiet-line); background: #f8faf7; transform: none; }
.document-details { min-width: 0; }
.document-heading { gap: 12px; }
.file-icon { width: 32px; height: 38px; border-color: var(--quiet-line-strong); border-radius: 6px; box-shadow: none; }
.file-icon::before { top: 12px; left: 8px; width: 14px; background: #9da8a1; }
.file-icon span { top: 18px; left: 8px; width: 14px; background: #9da8a1; }
.file-icon::after { top: 24px; left: 8px; width: 9px; background: #9da8a1; }
.document-title { color: var(--quiet-ink); font-size: 15px; font-weight: 700; line-height: 1.3; }
.document-context { color: var(--quiet-muted); font-size: 13px; line-height: 1.35; }
.document-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin: 7px 0 0 44px; color: var(--quiet-muted); font-size: 12px; }
.document-type { color: #4f5d56; }
.document-type::before { content: "·"; margin-right: 7px; color: #a1aaa4; }
.processing-label { color: var(--quiet-accent-dark); font-weight: 680; }
.processing-label::before { width: 6px; height: 6px; background: currentColor; box-shadow: 0 0 0 3px var(--quiet-accent-soft); }
.processing-label.status-failed { color: var(--quiet-danger); }
.processing-label.status-failed::before { box-shadow: 0 0 0 3px var(--quiet-danger-soft); }
.snippet, .status-message { margin-left: 44px; color: var(--quiet-muted); font-size: 12px; }
.snippet { margin-top: 8px; }
.status-message { margin-top: 6px; }
.document-chips { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; margin: 0; }
.document-chips .button { min-height: 30px; padding: 4px 8px; color: var(--quiet-muted); font-size: 11px; }
.document-chips .button:hover:not(:disabled) { color: var(--quiet-ink); background: var(--quiet-soft); }
.document-actions { display: flex; align-items: center; gap: 4px; }
.document-actions .button { min-height: 40px; padding-inline: 12px; }
.document-actions .button-secondary { color: var(--quiet-accent-dark); border-color: rgb(76 95 192 / 28%); background: var(--quiet-accent-soft); }
.document-actions .button-secondary:hover:not(:disabled) { border-color: rgb(76 95 192 / 50%); background: #e4e7ff; }
.document-actions .button-quiet { color: var(--quiet-muted); }

.pagination { gap: 12px; margin-top: 12px; padding: 17px 0 2px; }
.pagination .button { min-height: 38px; }
.pagination .muted { min-width: 56px; text-align: center; }

.empty-state {
  display: grid;
  min-height: 220px;
  margin: 0;
  padding: 30px 24px;
  border: 1px dashed var(--quiet-line-strong);
  border-radius: 12px;
  background: #fbfcfa;
  place-content: center;
  text-align: center;
}
.empty-state .state-icon { display: grid; width: 38px; height: 38px; margin: 0 auto 13px; color: var(--quiet-accent-dark); border: 1px solid rgb(76 95 192 / 20%); background: var(--quiet-accent-soft); border-radius: 50%; place-items: center; font-size: 18px; }
.empty-state .state-icon-error { color: var(--quiet-danger); border-color: rgb(166 58 51 / 18%); background: var(--quiet-danger-soft); }
.empty-state strong { margin-bottom: 7px; font-size: 16px; }
.empty-state p { max-width: 350px; margin: 0 auto 17px; color: var(--quiet-muted); font-size: 14px; }
.empty-state .button { margin-inline: auto; }
.state-error { border-style: solid; border-color: #f0c4bd; background: var(--quiet-danger-soft); }
.state-error strong { color: #7f302b; }
.state-empty { min-height: 250px; }

.loading-list { display: grid; min-height: 248px; align-content: center; gap: 16px; }
.loading-status { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--quiet-muted); font-size: 13px; }
.loading-list .spinner { width: 18px; height: 18px; }
.skeleton-list { display: grid; gap: 8px; }
.skeleton-row { height: 58px; border-radius: 9px; background: linear-gradient(90deg, #f0f3f0 25%, #e4eae5 45%, #f0f3f0 65%); background-size: 220% 100%; animation: quiet-skeleton 1.25s ease-in-out infinite; }
@keyframes quiet-skeleton { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.upload-dialog {
  width: min(560px, calc(100vw - 32px));
  max-width: none;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--quiet-line);
  background: var(--quiet-surface);
  border-radius: 18px;
  box-shadow: 0 24px 80px rgb(29 37 33 / 22%);
}
.upload-dialog::backdrop { background: rgb(29 37 33 / 44%); backdrop-filter: blur(4px); }
.upload-dialog-shell { display: grid; gap: 0; }
.upload-dialog-header { display: flex; align-items: start; justify-content: space-between; gap: 24px; padding: 20px 22px 16px; border-bottom: 1px solid var(--quiet-line); }
.upload-dialog-header h2 { margin: 4px 0 0; font-size: 21px; }
.upload-dialog-header .button { min-height: 38px; }
.upload-form { padding: 20px 22px 24px; }
.drop-zone { display: grid; gap: 10px; padding: 28px 22px 22px; border: 1px dashed var(--quiet-line-strong); background: #f8faf7; border-radius: 13px; text-align: center; }
.drop-zone[data-dragging="true"] { border-color: var(--quiet-accent); background: var(--quiet-accent-soft); }
.upload-icon { width: 44px; height: 44px; margin: 0 auto 3px; background: var(--quiet-accent-soft); border-radius: 13px; }
.upload-icon::before { color: var(--quiet-accent-dark); }
.drop-zone-title { margin: 0; font-size: 18px; }
.upload-copy { margin: 0; color: var(--quiet-muted); font-size: 13px; }
.file-picker { position: relative; display: inline-flex; justify-content: center; margin: 5px auto 0; cursor: pointer; }
.file-picker input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.file-picker .button { min-height: 44px; }
.file-summary { min-height: 20px; margin: 0; color: var(--quiet-muted); font-size: 12px; word-break: break-word; }
.upload-error { margin: 0; color: var(--quiet-danger); font-size: 13px; }
.drop-zone > button { min-height: 44px; margin-top: 1px; }
.upload-progress { height: 3px; margin-top: 1px; background: var(--quiet-line); }
.upload-progress span { background: var(--quiet-accent); }

.preview-dialog { width: min(1080px, calc(100vw - 36px)); height: min(840px, calc(100vh - 36px)); border-radius: 18px; }
.preview-header { padding: 16px 18px; }
.preview-header h2 { font-size: 17px; }
.preview-actions { gap: 6px; }
.preview-actions .button { min-height: 40px; }
.preview-download-button { min-width: 92px; }
.preview-close-button { min-width: 68px; }
.preview-more { position: relative; }
.preview-more summary { display: inline-flex; align-items: center; min-height: 40px; padding: 0 11px; color: var(--quiet-muted); border: 1px solid transparent; border-radius: 9px; cursor: pointer; font-size: 13px; font-weight: 680; list-style: none; }
.preview-more summary::-webkit-details-marker { display: none; }
.preview-more summary::after { content: "⌄"; margin-left: 6px; font-size: 14px; }
.preview-more summary:focus-visible { outline: 3px solid rgb(76 95 192 / 22%); outline-offset: 2px; }
.preview-more[open] summary { border-color: var(--quiet-line); background: var(--quiet-soft); }
.preview-more-actions { position: absolute; z-index: 5; top: calc(100% + 6px); right: 0; display: grid; min-width: 170px; padding: 5px; border: 1px solid var(--quiet-line); background: var(--quiet-surface); border-radius: 10px; box-shadow: 0 10px 28px rgb(29 37 33 / 15%); }
.preview-more-actions .button { justify-content: flex-start; min-height: 38px; }
.preview-more-actions .button[hidden] { display: none; }
.preview-body { background: #e9ede9; }
.pdf-toolbar { gap: 8px; padding: 9px 12px; }
.pdf-toolbar .button { min-height: 38px; }
.pdf-page-stage { padding: 22px; }
.preview-unavailable { padding: 32px; }

@media (max-width: 760px) {
  #main-content { width: min(100% - 28px, 640px); padding-top: 30px; }
  .documents-heading { align-items: start; margin-bottom: 20px; }
  .documents-heading .upload-trigger { align-self: start; }
  .library-panel { padding: 12px; }
  .document-item { grid-template-columns: minmax(0, 1fr) auto; gap: 9px 12px; padding: 14px 5px; }
  .document-chips { grid-column: 1 / -1; justify-content: flex-start; margin-left: 44px; }
  .document-actions { grid-column: 2; grid-row: 1; }
  .document-actions .button { min-height: 40px; }
  .document-actions .button-secondary { padding-inline: 10px; }
  .document-actions .button-quiet { width: 38px; padding: 0; overflow: hidden; font-size: 0; }
  .document-actions .button-quiet::after { content: "↓"; font-size: 18px; }
  .document-meta { margin-left: 44px; }
  .preview-dialog { width: 100vw; height: 100vh; border: 0; border-radius: 0; }
  .preview-header { align-items: center; flex-direction: row; gap: 10px; padding: 12px 14px; }
  .preview-header > div:first-child { min-width: 0; }
  .preview-header .eyebrow { margin-bottom: 3px; }
  .preview-actions { flex: 0 0 auto; }
  .preview-actions .button { min-height: 42px; }
  .preview-download-button { min-width: 0; padding-inline: 10px !important; font-size: 0 !important; }
  .preview-download-button::before { content: "↓"; font-size: 19px; }
  .preview-close-button { min-width: 42px; width: 42px; padding: 0 !important; overflow: hidden; font-size: 0 !important; }
  .preview-close-button::before { content: "×"; font-size: 23px; font-weight: 400; }
  .preview-more summary { width: 42px; min-height: 42px; justify-content: center; padding: 0; font-size: 0; }
  .preview-more summary::before { content: "⋯"; font-size: 21px; }
  .preview-more summary::after { display: none; }
  .preview-more-actions { right: -42px; }
  .pdf-toolbar { flex-wrap: wrap; }
  .pdf-toolbar .button { min-height: 40px; }
}

@media (max-width: 480px) {
  .topbar { min-height: 60px; padding-inline: 14px; }
  .brand { font-size: 14px; }
  .nav-actions .nav-secondary { display: none; }
  #main-content { width: calc(100% - 24px); padding-top: 24px; }
  .documents-heading { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; }
  .documents-heading h1 { font-size: 34px; }
  .documents-heading .lede { grid-column: 1 / -1; font-size: 14px; }
  .upload-trigger { min-height: 44px; padding-inline: 14px; }
  .search-input { height: 52px; padding-right: 78px; }
  .search-engine-field { flex-wrap: wrap; }
  .document-item { min-height: 82px; }
  .document-title { font-size: 14px; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .document-context { white-space: normal; }
  .document-actions .button-secondary { font-size: 12px; }
  .document-chips { margin-left: 44px; }
  .upload-dialog { width: calc(100vw - 24px); }
  .upload-dialog-header { padding: 16px; }
  .upload-form { padding: 16px; }
  .drop-zone { padding-inline: 14px; }
  .preview-header h2 { font-size: 15px; }
  .pdf-page-stage { padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton-row { animation: none; }
}
