:root {
  --bs-blue: #0d6efd;
  --bs-blue-dark: #0a58ca;
  --bs-indigo: #6610f2;
  --bs-green: #198754;
  --bs-orange: #fd7e14;
  --bs-cyan: #0dcaf0;
  --bs-gray-100: #f8f9fa;
  --bs-gray-200: #e9ecef;
  --bs-gray-300: #dee2e6;
  --bs-gray-600: #6c757d;
  --bs-gray-800: #343a40;
  --bs-body: #f4f6f9;
  --bs-surface: #ffffff;
  --bs-text: #212529;
  --bs-border: #dee2e6;
  --bs-shadow: 0 0.5rem 1rem rgba(33, 37, 41, 0.08);
  --sidebar-width: 420px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bs-body);
  color: var(--bs-text);
  font-family: Arial, "Microsoft YaHei", sans-serif;
  font-size: 15px;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  min-height: 0;
}

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--bs-border);
  background: var(--bs-surface);
  box-shadow: 0 0.125rem 0.4rem rgba(33, 37, 41, 0.05);
}

.navbar-brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 0.75rem;
}

.brand-mark {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 0.5rem;
  background: var(--bs-blue);
  color: #fff;
  font-size: 1.35rem;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.2;
  font-weight: 700;
}

.metadata {
  margin-top: 0.2rem;
  color: var(--bs-gray-600);
  font-size: 0.875rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.75rem;
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  background: #d1e7dd;
  color: #0f5132;
  font-size: 0.8125rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge.muted {
  background: var(--bs-gray-200);
  color: var(--bs-gray-800);
}

.shell {
  display: grid;
  grid-template-columns: minmax(320px, var(--sidebar-width)) minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
  gap: 1rem;
  padding: 1rem;
}

.card {
  min-width: 0;
  border: 1px solid var(--bs-border);
  border-radius: 0.5rem;
  background: var(--bs-surface);
  box-shadow: var(--bs-shadow);
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 0;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--bs-border);
  background: var(--bs-gray-100);
  border-radius: 0.5rem 0.5rem 0 0;
}

.section-title {
  font-weight: 700;
}

.card-body {
  padding: 1rem;
}

.filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.45rem;
  border-bottom: 1px solid var(--bs-border);
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
}

.filter-toggle {
  min-height: 38px;
  border: 1px solid rgba(13, 110, 253, 0.35);
  border-radius: 0.375rem;
  padding: 0.45rem 0.7rem;
  background: #fff;
  color: var(--bs-blue);
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

.filter-toggle:hover {
  background: #eef5ff;
}

.active-filter-summary {
  overflow: hidden;
  color: var(--bs-gray-600);
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-modal[hidden] {
  display: none;
}

.filter-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.filter-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.38);
}

.filter-panel {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(520px, 100%);
  max-height: min(720px, calc(100vh - 2rem));
  border: 1px solid var(--bs-border);
  border-radius: 0.6rem;
  background: #fff;
  box-shadow: 0 1rem 2rem rgba(17, 24, 39, 0.2);
}

.filter-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--bs-border);
  padding: 1rem;
}

.filter-panel-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.filter-panel-header p {
  margin: 0.25rem 0 0;
  color: var(--bs-gray-600);
  font-size: 0.85rem;
}

.icon-button {
  display: grid;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--bs-border);
  border-radius: 0.375rem;
  background: #fff;
  color: var(--bs-gray-800);
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
}

.icon-button:hover {
  background: var(--bs-gray-100);
}

.filter-panel-body {
  display: grid;
  gap: 0.55rem;
  overflow: auto;
  padding: 1rem;
}

.filter-panel-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  border-top: 1px solid var(--bs-border);
  padding: 0.85rem 1rem;
}

.filter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.35rem;
}

.form-label {
  color: var(--bs-gray-600);
  font-size: 0.8125rem;
  font-weight: 700;
}

.form-control,
.form-select {
  display: block;
  width: 100%;
  min-height: 38px;
  border: 1px solid #ced4da;
  border-radius: 0.375rem;
  padding: 0.45rem 0.65rem;
  background: #fff;
  color: var(--bs-text);
}

.form-control:focus,
.form-select:focus {
  border-color: #86b7fe;
  outline: 0;
  box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.2);
}

.link-button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--bs-blue);
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 700;
}

.link-button:hover {
  text-decoration: underline;
}

.tag-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  max-height: 150px;
  overflow: auto;
  padding: 0.15rem 0 0.25rem;
}

.tag-check {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--bs-border);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  background: #fff;
  color: var(--bs-gray-800);
  cursor: pointer;
  font-size: 0.78rem;
  user-select: none;
}

.tag-check:hover,
.tag-check.active {
  border-color: rgba(13, 110, 253, 0.45);
  background: #eef5ff;
  color: var(--bs-blue);
}

.tag-check input {
  width: 0;
  height: 0;
  margin: 0;
  opacity: 0;
}

.list-group {
  overflow: auto;
}

.results {
  min-height: 0;
  padding: 0.5rem;
}

.pagination-controls {
  display: grid;
  gap: 0.5rem;
  border-top: 1px solid var(--bs-border);
  padding: 0.65rem 0.75rem;
  background: var(--bs-gray-100);
  border-radius: 0 0 0.5rem 0.5rem;
}

.pagination-summary {
  color: var(--bs-gray-600);
  font-size: 0.8rem;
}

.pagination-buttons {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.25rem;
}

.page-button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 32px;
  border: 1px solid var(--bs-border);
  border-radius: 0.35rem;
  padding: 0.25rem 0.3rem;
  background: #fff;
  color: var(--bs-text);
  cursor: pointer;
  font-size: 0.78rem;
  white-space: nowrap;
}

.page-button:hover:not(:disabled),
.page-button.active {
  border-color: rgba(13, 110, 253, 0.45);
  background: #eef5ff;
  color: var(--bs-blue);
}

.page-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.pagination-jump {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--bs-gray-600);
  font-size: 0.8rem;
  min-width: 0;
}

.pagination-jump input {
  flex: 0 0 auto;
  width: 76px;
  min-height: 32px;
  border: 1px solid #ced4da;
  border-radius: 0.35rem;
  padding: 0.25rem 0.45rem;
  background: #fff;
  color: var(--bs-text);
}

.list-group-item {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 0.65rem;
  width: 100%;
  min-height: 48px;
  margin-bottom: 0.35rem;
  border: 1px solid var(--bs-border);
  border-radius: 0.45rem;
  padding: 0.55rem 0.65rem;
  background: #fff;
  color: var(--bs-text);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.list-group-item:hover,
.list-group-item.active {
  border-color: rgba(13, 110, 253, 0.45);
  background: #eef5ff;
}

.list-group-item:hover {
  transform: translateY(-1px);
}

.result-index {
  color: var(--bs-blue);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
}

.result-main {
  display: grid;
  min-width: 0;
  gap: 0.2rem;
}

.result-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-marker {
  color: var(--bs-gray-600);
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail {
  min-height: 0;
  overflow: auto;
}

.detail-inner {
  max-width: 1080px;
  margin: 0 auto;
}

.detail h2 {
  margin: 0 0 1rem;
  font-size: 1.6rem;
  line-height: 1.3;
  font-weight: 700;
}

.fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.field {
  min-width: 0;
  border: 1px solid var(--bs-border);
  border-radius: 0.45rem;
  padding: 0.8rem;
  background: linear-gradient(180deg, #fff, var(--bs-gray-100));
}

.label {
  color: var(--bs-gray-600);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 1.6rem;
  margin-bottom: 0.25rem;
}

.value {
  overflow-wrap: anywhere;
}

.copy-button {
  min-height: 26px;
  border: 1px solid rgba(13, 110, 253, 0.3);
  border-radius: 0.35rem;
  padding: 0.15rem 0.45rem;
  background: #fff;
  color: var(--bs-blue);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
}

.copy-button:hover {
  background: #eef5ff;
}

.copy-button.copied {
  border-color: rgba(25, 135, 84, 0.45);
  background: #d1e7dd;
  color: #0f5132;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--bs-blue);
  border-radius: 0.375rem;
  padding: 0.45rem 0.8rem;
  background: var(--bs-blue);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  text-align: center;
}

.action:hover {
  background: #0b5ed7;
}

.action.secondary {
  background: #fff;
  color: var(--bs-blue);
}

.action.secondary:hover {
  background: #eef5ff;
}

.tag-editor,
.source-editor {
  display: grid;
  gap: 0.8rem;
  margin: 0.5rem 0 1rem;
  border: 1px solid var(--bs-border);
  border-radius: 0.5rem;
  padding: 1rem;
  background: #f8fafc;
}

.tag-editor .editor-title,
.source-editor .editor-title {
  margin-bottom: 0.1rem;
  color: #111827;
  font-size: 1rem;
  font-weight: 700;
}

.tag-editor .form-label,
.source-editor .form-label {
  margin: 0;
}

.tag-editor .form-control,
.source-editor .form-control,
.source-editor .form-select {
  min-height: 42px;
  background: #fff;
}

.source-editor textarea.form-control {
  min-height: 110px;
  resize: vertical;
}

.tag-editor .editor-actions,
.source-editor .editor-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding-top: 0.2rem;
}

.tag-editor .save-tags-button,
.source-editor .save-source-button {
  min-height: 40px;
}

.tag-editor .editor-status,
.source-editor .editor-status {
  color: var(--bs-gray-600);
  font-size: 0.9rem;
}

.book-source-links {
  margin: 0.5rem 0 1rem;
  border: 1px solid var(--bs-border);
  border-radius: 0.5rem;
  padding: 1rem;
  background: #fff;
}

.book-source-links h3 {
  margin: 0 0 0.7rem;
  font-size: 1rem;
  font-weight: 700;
}

.source-link-list {
  display: grid;
  gap: 0.5rem;
}

.source-link-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  border: 1px solid var(--bs-border);
  border-radius: 0.4rem;
  padding: 0.65rem 0.75rem;
  background: #f8fafc;
  color: var(--bs-blue);
  text-decoration: none;
  font-weight: 700;
}

.source-link-item:hover {
  background: #eef5ff;
}

.source-link-item span {
  color: var(--bs-gray-600);
  font-size: 0.82rem;
  font-weight: 400;
}

.book-description {
  margin: 0.5rem 0 1rem;
  border: 1px solid var(--bs-border);
  border-radius: 0.5rem;
  padding: 1rem;
  background: #fff;
}

.book-description h3 {
  margin: 0 0 0.55rem;
  font-size: 1rem;
  font-weight: 700;
}

.book-description p {
  margin: 0;
  color: var(--bs-gray-800);
  line-height: 1.7;
}

pre {
  margin: 0;
  border: 1px solid #1f2937;
  border-radius: 0.45rem;
  padding: 1rem;
  background: #18202b;
  color: #f8f9fa;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.detail-disclosure {
  margin: 0.5rem 0 1rem;
  border: 1px solid var(--bs-border);
  border-radius: 0.5rem;
  background: #fff;
}

.detail-disclosure summary {
  cursor: pointer;
  padding: 0.85rem 1rem;
  color: #111827;
  font-weight: 700;
  list-style-position: inside;
}

.detail-disclosure summary:hover {
  background: var(--bs-gray-100);
}

.detail-disclosure .fields,
.detail-disclosure pre {
  margin: 0 1rem 1rem;
}

.empty-state,
.message {
  padding: 1rem;
  color: var(--bs-gray-600);
}

.message.compact {
  padding: 0.25rem 0;
  font-size: 0.8125rem;
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
  }

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

  .shell {
    grid-template-columns: 1fr;
    padding: 0.75rem;
    overflow: auto;
  }

  .sidebar {
    min-height: calc(100vh - 1.5rem);
  }

  .results {
    height: 42vh;
  }

  .detail {
    overflow: visible;
  }

  .detail-inner {
    padding: 0.85rem;
  }

  .detail h2 {
    font-size: 1.25rem;
  }

  .fields {
    grid-template-columns: 1fr;
    gap: 0.55rem;
  }

  .field {
    padding: 0.7rem;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .action {
    width: 100%;
  }

  .tag-editor,
  .source-editor,
  .book-source-links,
  .book-description,
  .detail-disclosure summary {
    padding: 0.85rem;
  }

  .detail-disclosure .fields,
  .detail-disclosure pre {
    margin: 0 0.85rem 0.85rem;
  }

  .source-link-item {
    align-items: flex-start;
    flex-direction: column;
  }

  pre {
    max-height: 45vh;
  }
}

@media (max-width: 430px) {
  .navbar {
    padding: 0.75rem;
  }

  .brand-mark {
    flex-basis: 36px;
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }

  h1 {
    font-size: 1.15rem;
  }

  .shell {
    padding: 0.55rem;
  }

  .card-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .list-group-item {
    grid-template-columns: 68px minmax(0, 1fr);
    gap: 0.45rem;
    padding: 0.5rem;
  }

  .pagination-buttons {
    gap: 0.18rem;
  }

  .page-button {
    font-size: 0.72rem;
    padding: 0.2rem 0.16rem;
  }

  .pagination-jump {
    flex-wrap: wrap;
  }
}
