:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --surface-3: #eaf0f5;
  --line: #cbd6df;
  --line-soft: #e1e7ec;
  --text: #17212b;
  --muted: #5d6d7e;
  --muted-2: #7b8b9b;
  --teal: #087f70;
  --teal-strong: #0f9f8b;
  --amber: #a85d00;
  --amber-strong: #d47700;
  --red: #c94141;
  --paper: #ffffff;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow: 0 14px 36px rgba(34, 52, 68, .11);
  font-family: "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-width: 320px;
  background: #ffffff;
}

button, textarea, input, select { font: inherit; }

button { color: inherit; }

button:focus-visible,
textarea:focus-visible,
input:focus-visible,
select:focus-visible,
canvas:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

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

.app-shell {
  width: min(1900px, 100%);
  min-height: 100vh;
  margin: 0 auto;
}

.topbar {
  height: 68px;
  padding: 0 clamp(18px, 3vw, 46px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid rgba(93, 109, 126, .18);
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: var(--teal);
  background: rgba(15, 159, 139, .09);
  border: 1px solid rgba(15, 159, 139, .26);
}

.brand-mark svg {
  width: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.brand strong { display: block; font-size: 17px; letter-spacing: .01em; }
.brand small { display: block; margin-top: 1px; color: var(--muted); font-size: 11px; }

.global-nav {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--line-soft);
  border-radius: 11px;
  background: #f5f8fa;
}

.global-nav a {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  padding: 0 13px;
  color: var(--muted);
  border-radius: 8px;
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.global-nav a:hover { color: var(--text); background: #ffffff; }
.global-nav a.is-active {
  color: #ffffff;
  background: var(--teal);
  box-shadow: 0 4px 10px rgba(8, 127, 112, .18);
}

.document-facts { display: flex; align-items: center; gap: 9px; margin-left: auto; }

.fact,
.status-pill {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  color: var(--muted);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  font-size: 12px;
  background: rgba(247, 249, 251, .92);
}

.fact b { color: #263746; font-weight: 650; }
.status-pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted-2); }
.status-pill.is-ready i { background: var(--teal); box-shadow: 0 0 0 4px rgba(110, 231, 206, .09); }
.status-pill.is-error i { background: var(--red); }

.search-panel {
  padding: 10px 10px 8px;
  border-bottom: 1px solid rgba(93, 109, 126, .14);
}

.standard-picker {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 5px 10px;
  margin-bottom: 9px;
}

.standard-picker > label {
  color: #334657;
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
}

.select-shell {
  position: relative;
  min-width: 0;
}

.select-shell select {
  width: 100%;
  height: 40px;
  padding: 0 38px 0 12px;
  appearance: none;
  color: #17212b;
  -webkit-text-fill-color: #17212b;
  border: 1px solid #c5d2dc;
  border-radius: 11px;
  outline: 0;
  background: #ffffff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 5px 14px rgba(34, 52, 68, .06);
}

.select-shell select:hover { border-color: #9cb0bf; }

.select-shell select:focus {
  border-color: rgba(15, 159, 139, .72);
  box-shadow: 0 0 0 3px rgba(15, 159, 139, .1);
}

.select-shell svg {
  position: absolute;
  top: 50%;
  right: 12px;
  width: 18px;
  translate: 0 -50%;
  fill: none;
  stroke: var(--teal);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.standard-hint {
  grid-column: 2;
  color: var(--muted-2);
  font-size: 10px;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 5px;
  color: var(--teal);
  font-size: 10px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: .16em;
}

.search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 6px;
  padding: 5px;
  border: 1px solid #c5d2dc;
  border-radius: 15px;
  background: #ffffff;
  box-shadow: 0 8px 22px rgba(34, 52, 68, .08);
  transition: border-color .18s ease, box-shadow .18s ease;
}

.search-form:focus-within {
  border-color: rgba(15, 159, 139, .72);
  box-shadow: 0 0 0 3px rgba(15, 159, 139, .1);
}

.search-form textarea {
  width: 100%;
  min-height: 78px;
  max-height: 180px;
  padding: 10px 11px;
  resize: vertical;
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  caret-color: var(--teal-strong);
  border: 0;
  outline: 0;
  background: transparent;
  line-height: 1.55;
  font-size: 14px;
}

.search-button { min-width: 0; padding-inline: 8px; font-size: 13px; white-space: nowrap; }

.search-form textarea::placeholder { color: #8795a3; -webkit-text-fill-color: #8795a3; }

.primary-button,
.secondary-button,
.quiet-button,
.preset-button,
.icon-button,
.bundle-button {
  border: 0;
  cursor: pointer;
  transition: transform .14s ease, background .14s ease, border-color .14s ease, opacity .14s ease;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 17px;
  color: #ffffff;
  border-radius: 10px;
  background: var(--teal);
  font-weight: 750;
}

.primary-button:hover:not(:disabled) { background: #087f70; transform: translateY(-1px); }
.primary-button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

button:disabled { cursor: not-allowed; opacity: .38; transform: none !important; }

.search-feedback {
  min-height: 18px;
  display: flex;
  justify-content: space-between;
  padding: 5px 3px 0;
  color: var(--muted-2);
  font-size: 11px;
}
.search-feedback > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.search-feedback.is-error { color: var(--red); }
.shortcut { padding: 1px 6px; border: 1px solid var(--line); border-radius: 5px; }

.workspace {
  height: calc(100vh - 68px);
  min-height: 620px;
  display: grid;
  grid-template-columns: minmax(340px, 400px) minmax(0, 1fr);
  gap: 14px;
  padding: 14px clamp(18px, 3vw, 46px) 24px;
}

.results-panel,
.viewer-panel {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  background: #ffffff;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.results-panel { display: grid; grid-template-rows: auto auto minmax(0, 1fr); }

.panel-heading {
  min-height: 70px;
  padding: 15px 17px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line-soft);
}

.panel-heading h2 { margin: 0; font-size: 18px; letter-spacing: -.02em; }

.result-count {
  min-width: 31px;
  height: 27px;
  display: grid;
  place-items: center;
  color: var(--teal);
  border-radius: 8px;
  background: rgba(15, 159, 139, .1);
  font-size: 12px;
  font-weight: 750;
}

.results-list {
  padding: 9px;
  overflow-y: auto;
  scrollbar-color: #b8c5cf transparent;
  scrollbar-width: thin;
}

.empty-results {
  min-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 26px;
  text-align: center;
  color: var(--muted);
}

.empty-results strong { color: #263746; font-size: 14px; }
.empty-results p { max-width: 220px; margin: 7px 0 0; font-size: 12px; line-height: 1.6; }
.empty-icon { margin-bottom: 12px; color: var(--teal); font-size: 35px; }

.result-card {
  width: 100%;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 10px;
  padding: 12px 11px;
  color: inherit;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
}

.result-card + .result-card { margin-top: 4px; }
.result-card:hover { background: #f4f8fa; }
.result-card.is-active {
  border-color: rgba(15, 159, 139, .42);
  background: linear-gradient(135deg, rgba(15, 159, 139, .12), rgba(15, 159, 139, .04));
}

.result-rank {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
}

.result-card.is-active .result-rank { color: #ffffff; border-color: var(--teal); background: var(--teal); }
.result-topline { display: flex; align-items: center; gap: 7px; color: var(--teal); font-size: 12px; font-weight: 750; }
.result-topline span:last-child { color: var(--muted-2); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-title { margin: 5px 0 7px; color: #1e2b36; font-size: 14px; line-height: 1.35; font-weight: 650; }
.result-bottom { display: flex; gap: 8px; color: var(--muted); font-size: 11px; }
.result-bottom b { color: #334657; font-weight: 650; }

.result-skeleton {
  height: 98px;
  margin-bottom: 6px;
  border-radius: 12px;
  background: linear-gradient(90deg, #edf2f5 25%, #f7f9fb 45%, #edf2f5 65%);
  background-size: 220% 100%;
  animation: shimmer 1.35s infinite linear;
}

@keyframes shimmer { to { background-position: -220% 0; } }

.viewer-panel { position: relative; }

.viewer-empty {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 30px;
  background:
    linear-gradient(rgba(15, 159, 139, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 159, 139, .045) 1px, transparent 1px);
  background-size: 30px 30px;
}

.viewer-empty-card { max-width: 390px; text-align: center; color: var(--muted); }
.viewer-empty-card h2 { margin: 8px 0; color: var(--text); font-size: 23px; letter-spacing: -.03em; }
.viewer-empty-card > p:last-child { margin: 0; font-size: 13px; line-height: 1.6; }

.empty-page {
  width: 65px;
  height: 82px;
  display: block;
  margin: 0 auto 22px;
  border: 1px solid #c1ccd5;
  border-radius: 8px;
  background: linear-gradient(#aebbc6 0 0) 14px 20px/37px 3px no-repeat,
              linear-gradient(#c8d2da 0 0) 14px 31px/29px 3px no-repeat,
              linear-gradient(#c8d2da 0 0) 14px 42px/34px 3px no-repeat,
              #f8fafb;
  box-shadow: 9px 9px 0 rgba(15, 159, 139, .07);
}

.viewer-workspace {
  width: 100%;
  min-width: 0;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}
.viewer-workspace > * { min-width: 0; max-width: 100%; }

.viewer-header {
  min-height: 64px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line-soft);
}

.selected-heading { width: 100%; min-width: 0; }
.selected-meta { display: flex; align-items: center; gap: 8px; color: var(--muted-2); font-size: 11px; }
.section-badge { padding: 3px 7px; color: #ffffff; border-radius: 6px; background: var(--teal); font-weight: 800; }
.mapping-badge { padding-left: 8px; border-left: 1px solid var(--line); color: var(--amber); }
.selected-summary { min-width: 0; display: flex; align-items: baseline; gap: 10px; margin-top: 6px; }
.selected-summary h2 { max-width: 42%; flex: 0 1 auto; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; letter-spacing: -.02em; }
.selected-summary p { min-width: 0; flex: 1; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-family: Georgia, serif; font-size: 12px; }

.page-navigation { flex: 0 0 auto; display: flex; align-items: center; gap: 4px; }
.page-navigation label { display: flex; align-items: center; gap: 4px; padding: 0 6px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: #ffffff; }
.page-navigation label span { color: var(--muted-2); font-size: 8px; font-weight: 800; letter-spacing: .08em; }
.page-navigation input { width: 38px; padding: 0; color: var(--text); border: 0; outline: 0; background: transparent; font-size: 12px; font-weight: 750; }
.page-range { color: var(--muted-2); font-size: 10px; }
.page-navigation .icon-button { font-size: 17px; font-weight: 750; }

.icon-button {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  color: #405365;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fb;
}
.icon-button:hover:not(:disabled) { border-color: #94a7b7; background: #edf3f6; }

.capture-toolbar {
  width: 100%;
  min-width: 0;
  min-height: 60px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid var(--line-soft);
  background: #f8fafb;
}

.toolbar-group { display: flex; align-items: center; gap: 4px; }
.toolbar-label { margin-right: 3px; color: var(--muted); font-size: 10px; }
.preset-button,
.quiet-button,
.secondary-button {
  min-height: 31px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-size: 11px;
}
.preset-button:hover, .quiet-button:hover:not(:disabled), .secondary-button:hover:not(:disabled) { border-color: #94a7b7; background: #edf3f6; }
.preset-button.is-active { color: var(--teal); border-color: rgba(15, 159, 139, .45); background: rgba(15, 159, 139, .09); }
.secondary-button { color: var(--teal); border-color: rgba(15, 159, 139, .36); }

.range-controls { gap: 7px; }
.range-controls label { width: 78px; display: grid; grid-template-columns: 1fr auto; color: #506274; font-size: 11px; font-weight: 650; }
.range-controls output { color: #1e2f3f; font-size: 12px; font-weight: 800; }
.range-controls input { grid-column: 1 / -1; width: 100%; height: 10px; accent-color: var(--teal-strong); }

.lock-toggle { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 10px; cursor: pointer; }
.lock-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.lock-toggle span { width: 30px; height: 17px; position: relative; border-radius: 999px; background: #cad4dc; transition: background .15s ease; }
.lock-toggle span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 11px; height: 11px; border-radius: 50%; background: #ffffff; box-shadow: 0 1px 3px rgba(34, 52, 68, .25); transition: transform .15s ease, background .15s ease; }
.lock-toggle input:checked + span { background: rgba(47, 195, 168, .35); }
.lock-toggle input:checked + span::after { transform: translateX(13px); background: var(--teal); }
.toolbar-spacer { flex: 1; }
.zoom-controls { display: flex; align-items: center; gap: 4px; }
.zoom-controls output { min-width: 36px; color: var(--muted); text-align: center; font-size: 9px; }

.capture-area { width: 100%; min-width: 0; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 270px; overflow: hidden; }

.page-stage {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 20px;
  background:
    radial-gradient(circle at 50% 0, rgba(15, 159, 139, .06), transparent 24rem),
    #edf1f4;
  scrollbar-color: #b8c5cf transparent;
  scrollbar-width: thin;
}

.canvas-wrap {
  width: 100%;
  min-width: 0;
  min-height: 100%;
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

#pageCanvas {
  display: block;
  min-width: 0;
  width: 100%;
  height: auto;
  max-width: none;
  border-radius: 2px;
  background: var(--paper);
  box-shadow: 0 10px 28px rgba(34, 52, 68, .2);
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

.image-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  border-radius: 8px;
  background: rgba(255, 255, 255, .94);
  font-size: 11px;
}

.spinner {
  width: 25px;
  height: 25px;
  border: 2px solid #c3cfd8;
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

.export-rail {
  min-height: 0;
  overflow-y: auto;
  padding: 11px;
  border-left: 1px solid var(--line-soft);
  background: #f7f9fb;
  scrollbar-width: thin;
}

.rail-section { padding: 11px; border: 1px solid var(--line-soft); border-radius: 11px; background: #ffffff; }
.rail-section + .rail-section { margin-top: 8px; }
.rail-heading { display: flex; align-items: center; gap: 9px; }
.rail-heading > div { min-width: 0; }
.rail-heading strong { display: block; font-size: 11px; }
.rail-heading small { display: block; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted-2); font-size: 9px; }
.step-number { width: 22px; height: 22px; flex: 0 0 auto; display: grid; place-items: center; color: var(--teal); border: 1px solid rgba(15, 159, 139, .3); border-radius: 7px; background: rgba(15, 159, 139, .07); font-size: 9px; font-weight: 800; }
.selection-size { margin: 10px 0; padding: 8px 9px; color: var(--muted); border-radius: 7px; background: #f0f4f6; font-family: Consolas, monospace; font-size: 9px; }
.full-button { width: 100%; min-height: 34px; font-size: 11px; }

.preview-box {
  width: 100%;
  min-height: 70px;
  margin: 10px 0 8px;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: #70849a;
  border: 1px dashed #b6c3cd;
  border-radius: 8px;
  background: #f8f7f2;
  font-size: 9px;
}
.preview-box img { display: block; max-width: 100%; max-height: 115px; object-fit: contain; }
.capture-preview.has-image { border-style: solid; }
.capture-preview img { width: 100%; max-height: 130px; object-fit: contain; }
.title-preview { min-height: 58px; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.button-row button { padding-inline: 5px; }

.bundle-button {
  width: 100%;
  min-height: 36px;
  margin-top: 9px;
  color: var(--amber);
  border: 1px solid rgba(255, 191, 102, .28);
  border-radius: 9px;
  background: rgba(255, 191, 102, .065);
  font-size: 10px;
  font-weight: 700;
}
.bundle-button:hover:not(:disabled) { border-color: rgba(255, 191, 102, .52); background: rgba(255, 191, 102, .1); }
.clipboard-note { margin: 9px 0 1px; color: var(--muted-2); text-align: center; font-size: 8px; }
kbd { padding: 1px 4px; color: #46596a; border: 1px solid #c4cfd7; border-radius: 4px; background: #eef2f5; font-family: inherit; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  max-width: min(460px, calc(100vw - 32px));
  padding: 10px 15px;
  color: #ffffff;
  border-radius: 9px;
  background: var(--teal);
  box-shadow: 0 14px 34px rgba(34, 52, 68, .22);
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity .18s ease, transform .18s ease;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { color: #fff; background: #d95b5b; }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 340px minmax(0, 1fr); }
  .capture-area { grid-template-columns: minmax(0, 1fr) 240px; }
  .range-controls { display: none; }
  .fact { display: none; }
}

@media (max-width: 900px) {
  .topbar { height: auto; min-height: 64px; flex-wrap: wrap; padding-block: 10px; }
  .brand small, .document-facts .fact { display: none; }
  .global-nav { order: 3; width: 100%; }
  .global-nav a { flex: 1; justify-content: center; }
  .search-form { grid-template-columns: 1fr; }
  .search-button { min-height: 43px; }
  .workspace { height: auto; min-height: 0; grid-template-columns: 1fr; }
  .results-panel { max-height: 410px; }
  .viewer-panel { min-height: 760px; }
  .capture-area { grid-template-columns: 1fr; }
  .export-rail { border-top: 1px solid var(--line-soft); border-left: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .rail-section + .rail-section { margin-top: 0; }
  .bundle-button, .clipboard-note { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
