* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #f4f6f8;
  color: #17202a;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  font-size: 15px;
}

.shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.shell.wide {
  width: min(1500px, calc(100% - 32px));
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

h1 {
  margin: 0 0 6px;
  font-size: 28px;
}

h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

p {
  margin: 0 0 10px;
  line-height: 1.7;
}

.panel {
  margin-bottom: 16px;
  padding: 18px;
  border: 1px solid #d9e0e7;
  border-radius: 8px;
  background: #ffffff;
}

.search-panel {
  margin-bottom: 12px;
}

.tabbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  padding: 8px;
  border: 1px solid #d9e0e7;
  border-radius: 8px;
  background: rgba(244, 246, 248, 0.96);
  backdrop-filter: blur(4px);
}

.tab-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid #b9c4cf;
  border-radius: 6px;
  border-color: #b9c4cf;
  background: #ffffff;
  color: #273746;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.tab-button.active {
  border-color: #255f99;
  background: #2c73b8;
  color: #ffffff;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.workspace-panel {
  display: block;
}

.cache-status {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid #c8d4df;
  border-radius: 6px;
  background: #eef4f8;
  color: #405261;
  white-space: nowrap;
}

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

.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.keyword-editor {
  flex: 1 0 100%;
  display: grid;
  gap: 8px;
}

.keyword-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

input[type="search"] {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #b9c4cf;
  border-radius: 6px;
  font-size: 16px;
}

.keyword-block-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 32px;
}

.keyword-block,
.keyword-inline-block {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 30px;
  padding: 3px 8px;
  border: 1px solid #bfd0df;
  border-radius: 6px;
  background: #eef6ff;
  color: #17202a;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.keyword-block button {
  min-height: 22px;
  margin-left: 6px;
  padding: 0 6px;
  border-color: #9fb6ca;
  background: #ffffff;
  color: #255f99;
}

.keyword-inline-block {
  margin: 0 4px 4px 0;
  font-weight: 700;
}

.directory-filter {
  flex: 1 0 100%;
  margin-top: 8px;
  padding: 12px;
  border: 1px solid #d8e0e8;
  border-radius: 8px;
  background: #f8fafc;
}

.filter-title {
  margin-bottom: 8px;
  color: #526170;
  font-size: 13px;
}

.filter-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.filter-toolbar .filter-title {
  margin-bottom: 0;
}

.folder-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 6px 12px;
  max-height: 180px;
  overflow: auto;
}

.folder-option {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding-left: calc(var(--depth, 0) * 16px);
  color: #17202a;
}

.folder-tree {
  max-height: 260px;
  overflow: auto;
  padding: 6px;
  border: 1px solid #e0e7ef;
  border-radius: 6px;
  background: #ffffff;
}

.compact-tree {
  max-height: 210px;
}

.ocr-tree {
  max-height: 320px;
}

.filter-tree-node {
  margin: 2px 0;
}

.filter-tree-node > summary {
  min-height: 42px;
  align-items: center;
  padding: 3px 0;
  cursor: pointer;
}

.filter-tree-node > summary::before {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  margin-right: 2px;
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
}

.filter-folder-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  min-height: 34px;
  color: #17202a;
}

.filter-file-label {
  display: flex;
  width: 100%;
  padding: 2px 0;
}

.filter-file-index {
  min-width: 28px;
  color: #6b7b88;
  text-align: right;
}

.filter-tree-children {
  margin-left: 20px;
  padding-left: 10px;
  border-left: 1px solid #e1e7ed;
}

.root-file-filter {
  min-height: 30px;
}

.ocr-status-tree {
  display: grid;
  gap: 8px;
}

.ocr-status-folder,
.ocr-status-file {
  margin: 4px 0;
}

.ocr-status-folder > summary,
.ocr-status-file > summary {
  min-height: 34px;
  padding: 4px 0;
}

.ocr-status-file {
  padding: 4px 0;
}

.ocr-status-pages {
  display: grid;
  gap: 8px;
  margin: 6px 0 8px 20px;
  padding-left: 12px;
  border-left: 1px solid #e1e7ed;
}

.ocr-status-page-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid #e6edf4;
  border-radius: 6px;
  background: #f8fafc;
}

.ocr-status-page-main,
.ocr-status-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.ocr-status-page-main .snippet {
  min-width: 140px;
  max-width: 360px;
}

.ocr-status-actions {
  justify-content: flex-end;
}

.tag-tree,
.tag-list,
.tag-category-list {
  display: grid;
  gap: 10px;
}

.tag-category > summary,
.tag-card,
.tag-category-pill {
  align-items: center;
  gap: 10px;
}

.tag-color {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.18);
  flex: 0 0 auto;
}

.tag-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 10px 12px;
  border: 1px solid #e6edf4;
  border-radius: 6px;
  background: #f8fafc;
}

.tag-title {
  font-weight: 700;
  color: #175ea8;
  text-decoration: none;
}

.tag-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.tag-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 120px minmax(180px, 1.2fr);
  gap: 12px;
  align-items: end;
}

.tag-selected-text-field {
  grid-column: 1 / -1;
}

.tag-form textarea {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid #b9c4cf;
  border-radius: 6px;
  font: inherit;
  resize: vertical;
}

.tag-create-panel {
  margin-bottom: 10px;
  padding: 10px 14px;
}

.tag-create-panel > summary {
  min-height: 30px;
  cursor: pointer;
}

.tag-create-panel[open] > summary {
  margin-bottom: 10px;
}

.tag-box {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.18);
}

.draft-tag-box {
  border-style: dashed;
}

.tag-drawing {
  cursor: crosshair;
}

input[type="text"],
input[type="password"],
input[type="file"],
select {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid #b9c4cf;
  border-radius: 6px;
  font: inherit;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

label {
  display: block;
  margin-bottom: 12px;
  color: #334151;
  line-height: 1.5;
}

button,
.button,
.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid #255f99;
  border-radius: 6px;
  background: #2c73b8;
  color: #ffffff;
  text-decoration: none;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.link-button {
  background: #ffffff;
  color: #255f99;
}

.danger {
  border-color: #a63d3d;
  background: #c84d4d;
}

.small {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

.button.disabled {
  border-color: #c4ccd4;
  background: #e6ebef;
  color: #6d7882;
  cursor: default;
}

.path,
code {
  font-family: Consolas, "Courier New", monospace;
}

.notice {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid #d9c267;
  border-radius: 6px;
  background: #fff8d7;
}

.notice.error {
  border-color: #d27878;
  background: #ffe3e3;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid #e1e7ed;
  text-align: left;
  vertical-align: top;
}

th {
  background: #eef3f7;
}

.snippet {
  line-height: 1.6;
}

.snippet-block {
  margin: 10px 0 0;
  padding: 12px;
  overflow: auto;
  max-height: 260px;
  border: 1px solid #d8e0e8;
  border-radius: 6px;
  background: #fbfcfd;
  color: #14202c;
  font-family: Consolas, "Microsoft YaHei", monospace;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.empty {
  padding: 28px;
  text-align: center;
  color: #5d6873;
}

.upload-form,
.folder-form {
  display: grid;
  gap: 10px;
}

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

.upload-drop-zone {
  transition: border-color 0.18s ease, background 0.18s ease;
}

.upload-drop-zone.drag-over {
  border-color: #2c73b8;
  background: #eef6ff;
}

.folder-form {
  grid-template-columns: 1fr auto;
  align-items: end;
}

.folder-form input {
  height: 38px;
}

.tree-node,
.result-folder,
.result-file {
  margin: 8px 0;
}

summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  cursor: pointer;
}

summary::before {
  content: "▸";
  color: #5c6b78;
}

details[open] > summary::before {
  content: "▾";
}

.tree-name {
  font-weight: 700;
}

.muted {
  color: #667481;
  font-size: 13px;
}

.hidden {
  display: none !important;
}

.tree-children,
.page-results {
  margin-left: 20px;
  padding-left: 14px;
  border-left: 2px solid #e1e7ed;
}

.tree-file {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 3px 6px;
  border-radius: 6px;
}

.tree-folder-row {
  padding: 3px 6px;
  border-radius: 6px;
}

.tree-file:hover,
.tree-folder-row:hover,
.drop-hover {
  background: #eaf3fc;
}

.file-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: #17202a;
}

.inline-form {
  display: inline-flex;
  margin: 0;
}

.batch-toolbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid #d8e0e8;
  border-radius: 8px;
  background: #f8fafc;
}

.result-file {
  margin-left: 20px;
}

.result-card {
  position: relative;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  margin: 10px 0 14px;
  padding: 14px;
  border: 1px solid #d9e0e7;
  border-radius: 8px;
  background: #ffffff;
}

.result-card.visited-result {
  border-color: #9fc0df;
  background: #f5faff;
}

.result-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #e8f1fa;
  color: #255f99;
  font-weight: 700;
}

.result-body {
  min-width: 0;
}

.result-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.result-preview-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  margin-top: 12px;
}

.visual-preview {
  position: relative;
  display: block;
  width: 340px;
  max-width: 100%;
  overflow: hidden;
  border: 1px solid #cbd6e2;
  border-radius: 8px;
  background: #eef2f5;
  text-decoration: none;
}

.cached-preview-slot:empty {
  display: none;
}

.cached-from-browser {
  border-color: #33a474;
  box-shadow: 0 0 0 1px rgba(51, 164, 116, 0.18);
}

.cached-preview-viewport img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #ffffff;
}

.cached-preview-badge {
  position: absolute;
  right: 8px;
  top: 8px;
  z-index: 2;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(16, 124, 82, 0.92);
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
}

.preview-viewport {
  position: relative;
  overflow: hidden;
  width: 340px;
  max-width: 100%;
  height: 220px;
  background: #ffffff;
}

.preview-loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  color: #667481;
  font-size: 13px;
  text-align: center;
}

.lazy-search-preview .preview-loading-state::before {
  content: "";
  width: 18px;
  height: 18px;
  margin-right: 8px;
  border: 2px solid #b8c7d6;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: preview-loading-spin 0.9s linear infinite;
}

.preview-load-failed .preview-loading-state::before {
  display: none;
}

@keyframes preview-loading-spin {
  to { transform: rotate(360deg); }
}

.preview-canvas {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(var(--preview-scale, 1));
  transform-origin: center center;
  background: #ffffff;
}

.preview-canvas img {
  display: block;
  width: 100%;
  height: 100%;
}

.preview-highlight {
  position: absolute;
  border: 3px solid #e00000;
  background: rgba(255, 0, 0, 0.12);
  pointer-events: none;
}

.preview-note {
  margin: 8px 0 0;
  color: #667481;
  font-size: 13px;
}

.snippet-wrap {
  min-width: 0;
}

.snippet-wrap .snippet-block {
  margin-top: 6px;
}

.actions,
.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.top-actions {
  justify-content: flex-end;
}

.auth-body {
  min-height: 100vh;
  background: #eef3f7;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  padding: 26px;
  border: 1px solid #d4dde6;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 14px 36px rgba(31, 41, 55, 0.12);
}

.login-form {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.login-form button {
  width: 100%;
}

.login-help {
  margin-top: 16px;
  color: #526170;
  font-size: 13px;
}

.pager {
  position: sticky;
  top: 0;
  z-index: 6;
  margin-bottom: 10px;
  padding: 8px;
  border: 1px solid #d8e0e8;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
}

.viewer-toolbar {
  position: sticky;
  top: 58px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid #d8e0e8;
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.96);
  backdrop-filter: blur(4px);
}

.viewer-toolbar button {
  min-height: 34px;
  padding: 0 12px;
}

.viewer-status {
  min-width: 90px;
  color: #526170;
  font-family: Consolas, "Courier New", monospace;
  text-align: right;
}

.document-viewer-layout {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

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

.page-thumbnails {
  position: sticky;
  top: 126px;
  z-index: 4;
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 140px);
  overflow: auto;
  padding: 8px;
  border: 1px solid #d8e0e8;
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.96);
  backdrop-filter: blur(4px);
}

.page-thumbnail {
  display: grid;
  gap: 5px;
  padding: 7px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #ffffff;
  color: #273746;
  text-decoration: none;
}

.page-thumbnail:hover {
  border-color: #9fc0df;
  background: #f5faff;
}

.page-thumbnail.active {
  border-color: #2d6fae;
  background: #eaf3fc;
  box-shadow: 0 0 0 2px rgba(45, 111, 174, 0.12);
}

.page-thumbnail img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: contain;
  border: 1px solid #d8e0e8;
  border-radius: 5px;
  background: #ffffff;
}

.page-thumbnail-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  color: #526170;
  font-size: 12px;
  font-weight: 700;
}

.page-frame {
  overflow: auto;
  height: calc(100vh - 220px);
  min-height: 620px;
  padding: 12px;
  border: 1px solid #d9e0e7;
  border-radius: 8px;
  background: #dfe5ea;
  cursor: grab;
  user-select: none;
}

.context-menu {
  position: fixed;
  z-index: 20;
  min-width: 150px;
  padding: 6px;
  border: 1px solid #c7d2de;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 8px 28px rgba(31, 41, 55, 0.2);
}

.context-menu button {
  display: flex;
  width: 100%;
  justify-content: flex-start;
  min-height: 32px;
  border: 0;
  background: transparent;
  color: #17202a;
}

.context-menu button:hover {
  background: #eaf3fc;
}

.context-menu button:disabled {
  color: #99a4af;
  cursor: not-allowed;
}

.page-frame.dragging {
  cursor: grabbing;
}

.page-stage {
  position: relative;
  min-width: 1px;
  min-height: 1px;
  margin: auto;
}

.page-canvas {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: center center;
  background: #ffffff;
  box-shadow: 0 2px 12px rgba(31, 41, 55, 0.2);
}

.page-canvas img {
  display: block;
  width: 100%;
  height: 100%;
}

.highlight {
  position: absolute;
  border: 3px solid #e00000;
  background: rgba(255, 0, 0, 0.12);
  pointer-events: none;
}

.ocr-box {
  border-color: #ff8a00 !important;
  background: rgba(255, 138, 0, 0.16) !important;
}

.source-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  color: #ffffff;
  font-size: 13px;
}

.source-native_pdf {
  background: #2c73b8;
}

.source-word {
  background: #3156a3;
}

.source-excel {
  background: #2d8a5f;
}

.source-text_file,
.source-file_text {
  background: #596675;
}

.source-image_text {
  background: #9a5a00;
}

.source-ocr {
  background: #d97800;
}

.source-mixed {
  background: #2d8a5f;
}

.ocr-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(320px, 1.2fr);
  gap: 16px;
  align-items: start;
}

.ocr-actions {
  display: grid;
  gap: 10px;
}

.progress-card {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid #d8e0e8;
  border-radius: 8px;
  background: #f8fafc;
}

.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.progress-bar {
  height: 14px;
  overflow: hidden;
  border: 1px solid #c5d1dc;
  border-radius: 999px;
  background: #e8eef4;
}

.progress-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #2d8a5f;
  transition: width 0.25s ease;
}

.folder-options.compact {
  max-height: 140px;
}

.ocr-match-list {
  display: grid;
  gap: 8px;
}

.ocr-match-item {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 10px;
  border: 1px solid #d8e0e8;
  border-radius: 6px;
  background: #fbfcfd;
}

.full-text-block {
  max-height: 72vh;
}

.text-match-summary {
  display: grid;
  gap: 8px;
  margin: 10px 0 12px;
  padding: 12px;
  border: 1px solid #d8e0e8;
  border-radius: 8px;
  background: #f8fafc;
}

.text-match-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.text-match-link {
  display: inline-flex;
  max-width: 100%;
  min-height: 30px;
  align-items: center;
  padding: 4px 8px;
  border: 1px solid #cbd6e2;
  border-radius: 6px;
  background: #ffffff;
  color: #255f99;
  font-size: 13px;
  text-decoration: none;
}

.text-locator-block {
  overflow: auto;
  margin-top: 10px;
  padding: 8px 0;
  border: 1px solid #d8e0e8;
  border-radius: 6px;
  background: #fbfcfd;
  color: #14202c;
  font-family: Consolas, "Microsoft YaHei", monospace;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.text-line {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  min-width: max-content;
  scroll-margin-top: 90px;
}

.text-line.hit-line {
  background: #fff8d7;
}

.line-number {
  padding: 0 10px;
  border-right: 1px solid #e1e7ed;
  color: #7a8793;
  text-align: right;
  user-select: none;
}

.line-content {
  padding: 0 12px;
}

.line-content mark {
  padding: 1px 3px;
  border-radius: 3px;
  background: #ffe56b;
  color: #111827;
}

.theme-toggle {
  border-color: #53616f;
  background: #253341;
  color: #ffffff;
}

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

.browse-list {
  display: grid;
  gap: 10px;
}

.browse-tree {
  display: grid;
  gap: 8px;
}

.browse-tree-node {
  margin: 4px 0;
}

.browse-tree-node > summary {
  min-height: 34px;
  padding: 4px 0;
}

.browse-tree-children {
  display: grid;
  gap: 8px;
}

.browse-tree-file {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid #d9e0e7;
  border-radius: 6px;
  background: #ffffff;
}

.browse-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
  border: 1px solid #d9e0e7;
  border-radius: 8px;
  background: #ffffff;
}

.browse-main {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.browse-title {
  overflow-wrap: anywhere;
}

.doc-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 22px;
  margin-right: 8px;
  padding: 0 6px;
  border-radius: 999px;
  background: #e8f1fb;
  color: #175ea8;
  font-size: 12px;
  font-weight: 700;
  vertical-align: middle;
}

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

.page-jump-form {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 6px 8px;
  border: 1px solid #d8e0e8;
  border-radius: 8px;
  background: #f8fafc;
}

.page-jump-form input[type="number"] {
  width: 86px;
  min-height: 34px;
  padding: 4px 8px;
  border: 1px solid #b9c4cf;
  border-radius: 6px;
  font: inherit;
}

.cache-dashboard .section-heading,
.compact-heading {
  margin-bottom: 12px;
}

.cache-grid {
  align-items: start;
}

.cache-action-list,
.cache-inline-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.cache-inline-panel {
  margin-top: 12px;
}

.cache-inline-controls label {
  flex: 1 1 220px;
}

.cache-inline-controls input[type="text"] {
  width: 100%;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.cache-progress {
  margin: 10px 0;
}

.cache-list,
.cache-recent-list {
  display: grid;
  gap: 10px;
}

.cache-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid #d9e0e7;
  border-radius: 8px;
  background: #f8fafc;
}

.cache-item p {
  margin-bottom: 0;
  overflow-wrap: anywhere;
}

.cache-recent-link {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid #d9e0e7;
  border-radius: 8px;
  background: #f8fafc;
  color: inherit;
  text-decoration: none;
}

.cache-recent-link:hover {
  border-color: #8eb5d8;
}

.cache-toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid #8eb5d8;
  border-radius: 8px;
  background: #ffffff;
  color: #17202a;
  box-shadow: 0 12px 30px rgba(23, 32, 42, 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.cache-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.cache-toast[data-kind="error"] {
  border-color: #d17b7b;
}

.cache-toast[data-kind="ok"] {
  border-color: #71a97b;
}

button.cached-disabled,
button.cached-disabled:disabled {
  border-color: #9fb3a4;
  background: #e7f3ea;
  color: #356a43;
  cursor: default;
}

.cache-task-panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 24;
  display: none;
  width: min(420px, calc(100vw - 32px));
  padding: 12px;
  border: 1px solid #b9c4cf;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 12px 30px rgba(23, 32, 42, 0.18);
}

.cache-task-panel.active {
  display: block;
}

.cache-task-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.cache-task-actions {
  justify-content: flex-end;
}

.cache-doc-group {
  padding: 12px;
  border: 1px solid #d9e0e7;
  border-radius: 8px;
  background: #f8fafc;
}

.cache-doc-group + .cache-doc-group {
  margin-top: 10px;
}

.cache-doc-actions {
  margin: 10px 0;
}

.cache-item-details {
  display: grid;
  gap: 6px;
}

.cache-item-detail {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 92px auto auto;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-top: 1px solid #e1e7ed;
  overflow-wrap: anywhere;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

html[data-theme="dark"] body,
html[data-theme="dark"] .auth-body {
  background: #111820;
  color: #dbe5ee;
}

html[data-theme="dark"] .panel,
html[data-theme="dark"] .login-card,
html[data-theme="dark"] .browse-card,
html[data-theme="dark"] .browse-tree-file,
html[data-theme="dark"] .context-menu,
html[data-theme="dark"] .cache-item,
html[data-theme="dark"] .cache-recent-link,
html[data-theme="dark"] .cache-toast,
html[data-theme="dark"] .cache-task-panel,
html[data-theme="dark"] .cache-doc-group {
  border-color: #314151;
  background: #18222d;
}

html[data-theme="dark"] .tabbar,
html[data-theme="dark"] .viewer-toolbar,
html[data-theme="dark"] .pager {
  border-color: #314151;
  background: rgba(17, 24, 32, 0.94);
}

html[data-theme="dark"] .tab-button,
html[data-theme="dark"] .link-button,
html[data-theme="dark"] .text-match-link,
html[data-theme="dark"] .keyword-block button {
  border-color: #4a6884;
  background: #1f2d3a;
  color: #8fc7ff;
}

html[data-theme="dark"] .tab-button.active,
html[data-theme="dark"] button,
html[data-theme="dark"] .button {
  border-color: #4d94d8;
  background: #2d6fae;
  color: #ffffff;
}

html[data-theme="dark"] .theme-toggle {
  border-color: #d0a642;
  background: #2f2a1e;
  color: #f6d98b;
}

html[data-theme="dark"] input[type="search"],
html[data-theme="dark"] input[type="text"],
html[data-theme="dark"] input[type="password"],
html[data-theme="dark"] input[type="file"],
html[data-theme="dark"] input[type="number"],
html[data-theme="dark"] select {
  border-color: #425569;
  background: #0f1720;
  color: #e6eef6;
}

html[data-theme="dark"] input::placeholder {
  color: #8998a8;
}

html[data-theme="dark"] label,
html[data-theme="dark"] .filter-folder-label,
html[data-theme="dark"] .file-check {
  color: #dbe5ee;
}

html[data-theme="dark"] .muted,
html[data-theme="dark"] .filter-title,
html[data-theme="dark"] .preview-note,
html[data-theme="dark"] .viewer-status,
html[data-theme="dark"] .login-help {
  color: #a7b6c6;
}

html[data-theme="dark"] .directory-filter,
html[data-theme="dark"] .folder-tree,
html[data-theme="dark"] .batch-toolbar,
html[data-theme="dark"] .progress-card,
html[data-theme="dark"] .text-match-summary,
html[data-theme="dark"] .page-jump-form,
html[data-theme="dark"] .cache-status {
  border-color: #314151;
  background: #131d27;
}

html[data-theme="dark"] .tree-children,
html[data-theme="dark"] .page-results,
html[data-theme="dark"] .filter-tree-children,
html[data-theme="dark"] .ocr-status-pages,
html[data-theme="dark"] .line-number,
html[data-theme="dark"] .cache-item-detail {
  border-color: #30404f;
}

html[data-theme="dark"] .ocr-status-page-row {
  border-color: #30404f;
  background: #111827;
}

html[data-theme="dark"] .tag-card {
  border-color: #30404f;
  background: #111827;
}

html[data-theme="dark"] .tag-title {
  color: #93c5fd;
}

html[data-theme="dark"] .doc-index {
  background: #1e3a5f;
  color: #bfdbfe;
}

html[data-theme="dark"] .tree-file:hover,
html[data-theme="dark"] .tree-folder-row:hover,
html[data-theme="dark"] .drop-hover,
html[data-theme="dark"] .context-menu button:hover {
  background: #223445;
}

html[data-theme="dark"] .keyword-block,
html[data-theme="dark"] .keyword-inline-block,
html[data-theme="dark"] .result-number {
  border-color: #3f5f7d;
  background: #1f3448;
  color: #dbeeff;
}

html[data-theme="dark"] .snippet-block,
html[data-theme="dark"] .text-locator-block,
html[data-theme="dark"] .ocr-match-item {
  border-color: #314151;
  background: #0f1720;
  color: #e6eef6;
}

html[data-theme="dark"] .result-card {
  border-color: #314151;
  background: #17212b;
}

html[data-theme="dark"] .result-card.visited-result {
  border-color: #4d7fab;
  background: #1a2a38;
}

html[data-theme="dark"] .visual-preview,
html[data-theme="dark"] .preview-viewport {
  border-color: #314151;
  background: #101820;
}

html[data-theme="dark"] .cached-from-browser {
  border-color: #3db982;
  box-shadow: 0 0 0 1px rgba(61, 185, 130, 0.24);
}

html[data-theme="dark"] .page-frame {
  border-color: #314151;
  background: #0b1118;
}

html[data-theme="dark"] .page-thumbnails {
  border-color: #314151;
  background: rgba(19, 29, 39, 0.96);
}

html[data-theme="dark"] .page-thumbnail {
  background: #18222d;
  color: #dbe5ee;
}

html[data-theme="dark"] .page-thumbnail:hover {
  border-color: #4d7fab;
  background: #1a2a38;
}

html[data-theme="dark"] .page-thumbnail.active {
  border-color: #4d94d8;
  background: #1f2d3a;
}

html[data-theme="dark"] .page-thumbnail img {
  border-color: #314151;
  background: #ffffff;
}

html[data-theme="dark"] .page-thumbnail-number {
  color: #a7b6c6;
}

html[data-theme="dark"] .page-canvas,
html[data-theme="dark"] .preview-canvas {
  background: #ffffff;
}

html[data-theme="dark"] .notice {
  border-color: #7a6424;
  background: #2d2714;
  color: #f4df9d;
}

html[data-theme="dark"] .notice.error {
  border-color: #7e3e48;
  background: #35181e;
  color: #ffc6cb;
}

html[data-theme="dark"] th {
  background: #1f2d3a;
}

html[data-theme="dark"] th,
html[data-theme="dark"] td {
  border-color: #30404f;
}

html[data-theme="dark"] .button.disabled {
  border-color: #3a4652;
  background: #232d36;
  color: #8f9baa;
}

html[data-theme="dark"] .danger {
  border-color: #b65b60;
  background: #9b343f;
}

html[data-theme="dark"] button.cached-disabled,
html[data-theme="dark"] button.cached-disabled:disabled {
  border-color: #49745a;
  background: #173322;
  color: #9be0ad;
}

html[data-theme="dark"] .line-content mark {
  background: #f1c84b;
  color: #111827;
}

html[data-theme="dark"] .text-line.hit-line {
  background: #2d2714;
}

html[data-theme="dark"] .progress-bar {
  border-color: #425569;
  background: #0f1720;
}

@media (max-width: 760px) {
  body {
    font-size: 14px;
  }

  .shell,
  .shell.wide {
    width: 100%;
    padding: 12px;
  }

  .topbar,
  .search-form,
  .keyword-input-row,
  .grid,
  .ocr-grid,
  .upload-picker,
  .result-preview-row,
  .folder-form,
  .batch-toolbar {
    display: block;
  }

  .topbar {
    margin-bottom: 12px;
  }

  h1 {
    font-size: 22px;
  }

  h2 {
    font-size: 17px;
  }

  .panel {
    padding: 14px;
    border-radius: 8px;
  }

  .tabbar {
    position: sticky;
    top: 0;
    width: 100%;
    margin-left: 0;
    margin-right: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tab-button {
    flex: 0 0 auto;
    min-width: 96px;
  }

  .result-card {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .topbar .link-button,
  .topbar .theme-toggle,
  .search-form button,
  .folder-form button,
  .batch-toolbar button,
  .cache-action-list button,
  .cache-action-list .link-button,
  .cache-inline-controls button {
    margin-top: 10px;
  }

  .search-form input[type="search"],
  .search-form button,
  .keyword-input-row button,
  .folder-form input,
  .folder-form button,
  .batch-toolbar input,
  .batch-toolbar button,
  .upload-form button,
  .ocr-actions button,
  .ocr-actions .link-button,
  .cache-action-list button,
  .cache-action-list .link-button,
  .cache-inline-controls button {
    width: 100%;
  }

  .section-heading,
  .browse-card,
  .browse-tree-file,
  .tag-card,
  .cache-item {
    display: block;
  }

  .cache-inline-controls {
    align-items: stretch;
  }

  .cache-item .actions {
    margin-top: 10px;
  }

  .cache-task-panel {
    right: 10px;
    bottom: 10px;
    width: calc(100vw - 20px);
  }

  .cache-item-detail {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .cache-doc-actions,
  .cache-task-actions {
    justify-content: stretch;
  }

  .cache-doc-actions .link-button,
  .cache-doc-actions button,
  .cache-task-actions .link-button,
  .cache-task-actions button {
    width: 100%;
  }

  .filter-toolbar {
    display: grid;
    gap: 8px;
  }

  .filter-toolbar button {
    width: 100%;
  }

  .browse-actions {
    justify-content: stretch;
    margin-top: 12px;
  }

  .browse-actions .button,
  .browse-actions .link-button,
  .top-actions .theme-toggle {
    flex: 1 1 auto;
  }

  select {
    width: 100%;
  }

  .directory-filter {
    padding: 10px;
  }

  .filter-tree-node > summary {
    min-height: 50px;
  }

  .filter-tree-node > summary::before {
    flex-basis: 42px;
    width: 42px;
    height: 42px;
    font-size: 22px;
  }

  .filter-folder-label {
    min-height: 42px;
  }

  .folder-tree,
  .compact-tree,
  .ocr-tree {
    max-height: 300px;
  }

  .filter-tree-children,
  .tree-children,
  .page-results,
  .ocr-status-pages {
    margin-left: 8px;
    padding-left: 10px;
  }

  .tree-file {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .result-file {
    margin-left: 0;
  }

  .ocr-status-page-row {
    grid-template-columns: 1fr;
  }

  .ocr-status-actions {
    justify-content: stretch;
  }

  .ocr-status-actions,
  .ocr-status-actions .inline-form,
  .ocr-status-actions button,
  .ocr-status-actions .button {
    width: 100%;
  }

  .tag-form {
    grid-template-columns: 1fr;
  }

  .tag-card form {
    margin-top: 10px;
  }

  .result-meta {
    gap: 8px;
  }

  .visual-preview,
  .preview-viewport {
    width: 100%;
  }

  .preview-viewport {
    height: clamp(180px, 44vw, 260px);
  }

  .snippet-block {
    max-height: 190px;
    font-size: 13px;
  }

  .text-locator-block {
    max-height: 60vh;
    font-size: 13px;
  }

  .text-line {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .pager,
  .actions {
    gap: 8px;
  }

  .pager .button,
  .actions .link-button,
  .actions .theme-toggle {
    flex: 1 1 auto;
  }

  .page-jump-form {
    order: 3;
    flex: 1 0 100%;
    justify-content: center;
  }

  .page-jump-form input[type="number"] {
    flex: 0 1 96px;
  }

  .viewer-toolbar {
    top: 58px;
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    margin-left: 0;
    margin-right: 0;
  }

  .viewer-toolbar button {
    flex: 0 0 auto;
    min-height: 34px;
    padding: 0 10px;
  }

  .viewer-status {
    flex: 0 0 auto;
    min-width: 78px;
  }

  .document-viewer-layout {
    display: block;
  }

  .page-thumbnails {
    top: 112px;
    display: flex;
    gap: 8px;
    max-height: none;
    margin-bottom: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .page-thumbnail {
    flex: 0 0 86px;
    padding: 6px;
  }

  .page-thumbnail img {
    height: 112px;
  }

  .page-frame {
    min-height: 360px;
    height: calc(100vh - 190px);
    padding: 8px;
  }

  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 14px;
  }

  th,
  td {
    padding: 8px;
  }

  .login-shell {
    align-items: start;
    padding: 18px 12px;
  }

  .login-card {
    padding: 20px;
  }
}

@media (max-width: 480px) {
  .shell,
  .shell.wide {
    padding: 10px;
  }

  .panel {
    padding: 12px;
  }

  .result-number {
    width: 30px;
    height: 30px;
  }

  button,
  .button,
  .link-button {
    min-height: 40px;
    padding: 0 12px;
  }

  .source-badge {
    min-height: 24px;
  }

  .preview-viewport {
    height: 210px;
  }
}
