:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #f0f5f4;
  --ink: #18212f;
  --muted: #647184;
  --line: #d8dee8;
  --teal: #0f766e;
  --blue: #2563eb;
  --amber: #b45309;
  --red: #b91c1c;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "PingFang SC",
    "Microsoft YaHei",
    sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

body.packing-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
  padding: 18px 24px 16px;
}

.brand-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin: 0 auto 14px;
  max-width: 1500px;
}

h1 {
  margin: 0 0 5px;
  font-size: 24px;
  line-height: 1.2;
}

.build-summary {
  color: var(--muted);
  font-size: 13px;
}

.brand-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.top-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.top-links a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 13px;
  text-decoration: none;
}

.top-links a:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.result-total {
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 700;
  min-width: 92px;
  padding: 8px 11px;
  text-align: center;
}

.controls {
  display: grid;
  grid-template-columns: minmax(260px, 1.8fr) repeat(3, minmax(150px, 0.7fr));
  gap: 12px;
  margin: 0 auto;
  max-width: 1500px;
}

.controls > label,
.search-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.controls > label > span,
.search-field > label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.clear-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 14px;
}

.clear-button:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 18px;
  max-width: 1500px;
  margin: 18px auto 0;
  padding: 0 24px 24px;
}

.results-pane,
.detail-pane {
  min-width: 0;
}

.results-pane {
  align-self: start;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.link-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
  text-decoration: none;
}

.link-button:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.manual-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 186px);
  overflow: auto;
  padding-right: 4px;
}

.manual-card {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 132px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: inherit;
  padding: 10px;
  text-align: left;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
}

.manual-card:hover,
.manual-card:focus-within,
.manual-card.is-active {
  border-color: var(--teal);
  box-shadow: 0 8px 22px rgba(15, 118, 110, 0.12);
}

.manual-card-main {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
  width: 100%;
  min-height: 110px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
}

.manual-card-main:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.22);
  outline-offset: 3px;
}

.manual-card img {
  display: block;
  align-self: stretch;
  width: 80px;
  height: 100%;
  min-height: 110px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef2f7;
  object-fit: cover;
}

.manual-card-content {
  min-width: 0;
  padding-bottom: 36px;
}

.manual-card-actions {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.manual-card-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  padding: 0 10px;
  text-decoration: none;
}

.manual-card-action:hover {
  border-color: var(--teal);
  color: var(--teal);
}

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

.packing-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
}

.packing-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
}

.packing-dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(1080px, 100%);
  max-height: min(92vh, 920px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
  overflow: hidden;
}

.packing-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
}

.packing-head h2 {
  margin: 0 0 5px;
  font-size: 20px;
  line-height: 1.3;
}

.packing-subtitle {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.packing-close {
  flex: 0 0 auto;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 750;
  padding: 0 12px;
}

.packing-close:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.packing-body {
  display: grid;
  gap: 14px;
  overflow: auto;
  padding: 16px;
}

.packing-status,
.packing-note {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  line-height: 1.65;
  padding: 10px 12px;
}

.packing-status {
  display: inline-flex;
  justify-self: start;
  min-height: 30px;
  align-items: center;
  font-weight: 750;
}

.packing-status.found {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #047857;
}

.packing-status.text_only {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
}

.packing-status.not_found {
  border-color: #fed7aa;
  background: #fff7ed;
  color: var(--amber);
}

.packing-images {
  display: grid;
  gap: 12px;
}

.packing-image {
  display: block;
  width: 100%;
  max-height: 76vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  object-fit: contain;
}

.packing-section {
  display: grid;
  gap: 8px;
}

.packing-section h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
}

.packing-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  overflow-wrap: anywhere;
}

.packing-table th,
.packing-table td {
  border: 1px solid var(--line);
  padding: 9px 10px;
  line-height: 1.55;
  text-align: left;
  vertical-align: top;
}

.packing-table th {
  width: 54px;
  background: #f8fafc;
  color: var(--muted);
  font-weight: 750;
  text-align: center;
}

.packing-source {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: #334155;
  font-family: inherit;
  line-height: 1.65;
  overflow-wrap: anywhere;
  padding: 11px 12px;
  white-space: pre-wrap;
}

.manual-title {
  display: -webkit-box;
  margin: 0 0 7px;
  overflow: hidden;
  font-weight: 750;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.manual-meta,
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  background: #eef2f7;
  color: #334155;
  padding: 2px 8px;
  white-space: nowrap;
}

.tag.category {
  background: #ecfdf5;
  color: #047857;
}

.tag.indexed {
  background: #eff6ff;
  color: var(--blue);
}

.tag.needs_ocr {
  background: #fff7ed;
  color: var(--amber);
}

.tag.extract_failed {
  background: #fef2f2;
  color: var(--red);
}

.detail-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.mobile-pdf-bar {
  display: none;
}

.detail-header {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

.detail-header img {
  width: 96px;
  height: 126px;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
}

.detail-header h2 {
  margin: 0 0 10px;
  font-size: 22px;
  line-height: 1.28;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--teal);
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-weight: 700;
  padding: 0 14px;
  text-decoration: none;
}

.primary-action:hover {
  background: #115e59;
}

.detail-body {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.snippet {
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  background: #eef2ff;
  color: #312e81;
  line-height: 1.65;
  padding: 12px;
}

.pdf-frame {
  width: 100%;
  height: min(72vh, 760px);
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f7;
}

.detail-empty,
.empty-list {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  padding: 28px;
  text-align: center;
}

mark {
  border-radius: 4px;
  background: #fde68a;
  color: inherit;
  padding: 0 2px;
}

@media (max-width: 980px) {
  .controls {
    grid-template-columns: 1fr;
  }

  .search-field {
    grid-column: 1 / -1;
  }

  .controls > label {
    display: none;
  }

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

  .manual-list {
    max-height: none;
  }

  .manual-card {
    min-height: 154px;
  }

  .manual-card-main {
    grid-template-columns: 108px minmax(0, 1fr);
    gap: 14px;
    min-height: 132px;
  }

  .manual-card img {
    width: 108px;
    min-height: 132px;
  }

  .manual-card-content {
    padding-bottom: 40px;
  }

  .detail-pane {
    display: none;
  }

  body.mobile-detail-open {
    overflow: hidden;
  }

  body.mobile-detail-open .detail-pane {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: block;
    overflow: auto;
    background: var(--surface);
  }

  body.mobile-detail-open .detail-card {
    min-height: 100dvh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
  }

  .mobile-pdf-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 48px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.98);
    padding: 7px 10px 7px 12px;
  }

  .mobile-pdf-title {
    display: -webkit-box;
    min-width: 0;
    overflow: hidden;
    font-weight: 750;
    line-height: 1.25;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .mobile-back {
    flex: 0 0 auto;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--teal);
    font-weight: 750;
    padding: 0 10px;
  }

  body.mobile-detail-open .detail-header,
  body.mobile-detail-open .detail-actions,
  body.mobile-detail-open .snippet {
    display: none;
  }

  body.mobile-detail-open .detail-body {
    flex: 1 1 auto;
    display: flex;
    min-height: 0;
    padding: 0;
  }

  body.mobile-detail-open .pdf-frame {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    border: 0;
    border-radius: 0;
  }

  .packing-modal {
    padding: 0;
  }

  .packing-dialog {
    width: 100%;
    height: 100dvh;
    max-height: none;
    border: 0;
    border-radius: 0;
  }

  .packing-head {
    align-items: center;
    padding: 10px 12px;
  }

  .packing-head h2 {
    display: -webkit-box;
    overflow: hidden;
    font-size: 17px;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .packing-body {
    padding: 12px;
  }

  .packing-image {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 14px;
  }

  .brand-row {
    align-items: stretch;
    flex-direction: column;
  }

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

  h1 {
    font-size: 21px;
  }

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

  .workspace {
    margin-top: 14px;
    padding: 0 14px 18px;
  }

  .detail-header {
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 12px;
    padding: 12px;
  }

  .detail-header img {
    width: 72px;
    height: 96px;
  }

  .detail-header h2 {
    font-size: 18px;
  }

  .pdf-frame {
    height: 64vh;
    min-height: 320px;
  }
}
