:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #64748b;
  --line: #dbe4f0;
  --primary: #2563eb;
  --primary-soft: #eaf2ff;
  --chip: #f1f5f9;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
}

.shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 12px;
}

.toolbar,
.info-bar,
.message,
.pane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.04);
}

.toolbar {
  min-height: 78px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 14px 18px;
  position: relative;
  z-index: 10;
}

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

.title-icon {
  width: 18px;
  height: 20px;
  border: 2px solid var(--primary);
  border-radius: 3px;
  position: relative;
}

.title-icon::after {
  content: "";
  position: absolute;
  top: -2px;
  bottom: -2px;
  left: 6px;
  width: 2px;
  background: var(--primary);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: 0;
}

.controls {
  min-width: 0;
  display: grid;
  grid-template-columns: 250px 152px minmax(420px, 1fr) 86px;
  align-items: end;
  gap: 16px;
}

.control {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.product-control {
  grid-template-columns: auto minmax(0, 1fr);
}

select,
input,
button {
  font: inherit;
}

select,
input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  outline: none;
}

select {
  padding: 0 14px;
}

input {
  padding: 0 12px 0 34px;
  color: var(--muted);
}

select:focus,
input:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgb(37 99 235 / 0.12);
}

.item-picker {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 36px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  height: 38px;
}

.item-search {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(210px, 0.7fr) minmax(250px, 1fr);
  position: relative;
  height: 36px;
}

.item-search input,
.item-search select {
  height: 36px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.item-search select {
  border-left: 1px solid var(--line);
}

.search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
  color: #94a3b8;
  font-size: 18px;
  line-height: 1;
}

button {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.nav-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 0;
  color: var(--primary);
  background: white;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-button:hover:not(:disabled) {
  background-color: var(--primary-soft);
}

#prevButton {
  border-right: 1px solid var(--line);
  border-top-left-radius: 6px;
  border-bottom-left-radius: 6px;
}

#nextButton {
  border-left: 1px solid var(--line);
  border-top-right-radius: 6px;
  border-bottom-right-radius: 6px;
}

.refresh-button {
  width: 100px;
  height: 38px;
  justify-self: end;
}

.count-badge {
  height: 38px;
  min-width: 86px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--chip);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Custom Select styling */
.custom-select {
  position: relative;
  width: 100%;
}

.custom-select-trigger {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  outline: none;
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.04);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  text-align: left;
}

.custom-select-trigger:focus,
.custom-select.is-open .custom-select-trigger {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgb(37 99 235 / 0.12);
}

.custom-select-value {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  margin-right: 8px;
}

.custom-select-arrow {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.2s ease;
  margin-right: 2px;
}

.custom-select.is-open .custom-select-arrow {
  transform: rotate(-135deg) translateY(2px);
}

.custom-select-options {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  max-height: 280px;
  overflow-y: auto;
  z-index: 1000;
  padding: 4px 0;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
}

.custom-select.is-open .custom-select-options {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.custom-select-option {
  padding: 8px 12px;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.custom-select-option:hover {
  background-color: var(--primary-soft);
  color: var(--primary);
}

.custom-select-option.is-selected {
  background-color: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

/* Custom select inside item search overrides */
.item-search .custom-select-trigger {
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
  height: 36px;
}

.item-search .custom-select-options {
  top: calc(100% + 2px);
  border-radius: 0 0 6px 6px;
}

.message {
  padding: 10px 12px;
  color: #8a4b00;
  background: #fff8e6;
  border-color: #f2d48d;
  font-size: 13px;
}

.info-bar {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  color: var(--muted);
  font-size: 16px;
  font-weight: 700;
}

.info-left,
.info-right {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.info-left strong,
.info-right strong {
  color: var(--ink);
}

.row-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  color: var(--primary);
  background: #dbeafe;
  font-size: 14px;
  font-weight: 850;
}

.english-name {
  padding-left: 16px;
  border-left: 1px solid var(--line);
}

.viewer-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 22px;
}

.pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.pane-head {
  min-height: 75px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
}

.pane-head h2 {
  font-size: 16px;
  font-weight: 850;
}

.pane-head p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

.pane-head p span {
  display: inline-flex;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--chip);
}

.page-viewer {
  flex: 1;
  width: 100%;
  min-height: 0;
  overflow: auto;
  background: #d9d9d9;
  padding: 18px 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.pdf-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #d9d9d9;
}

.pdf-loading,
.pdf-error {
  margin: 32px auto;
  width: min(92%, 920px);
  padding: 18px;
  border-radius: 6px;
  background: #ffffff;
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
  text-align: center;
  box-shadow: 0 1px 5px rgb(15 23 42 / 0.12);
}

.pdf-error {
  color: #b42318;
}

.pdf-page-wrap {
  margin: 0 auto 18px;
  max-width: calc(100% - 36px);
  background: white;
  box-shadow: 0 1px 5px rgb(15 23 42 / 0.18);
}

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

.pdf-page-wrap canvas {
  display: block;
  max-width: 100%;
  pointer-events: none;
}

.pdf-page-placeholder {
  display: flex;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.empty {
  position: absolute;
  inset: 75px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--muted);
  background: #f3f6fa;
  font-size: 13px;
  text-align: center;
}

.pane.has-pdf .empty {
  display: none;
}

@media (max-width: 1180px) {
  .toolbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

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

  .product-control {
    grid-column: 1 / -1;
  }

  .refresh-button {
    justify-self: start;
  }
}

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

  .item-search {
    grid-template-columns: 1fr;
  }

  .item-search select,
  .item-search .custom-select-trigger {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}
