:root {
  color-scheme: light;
  --bg: #eef3f0;
  --panel: #ffffff;
  --ink: #18352d;
  --muted: #60756e;
  --line: #d8e2de;
  --accent: #14835c;
  --accent-dark: #0d6547;
  --amber: #f2b84b;
  --danger: #b44b40;
  --shadow: 0 16px 40px rgba(21, 51, 43, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

button,
input,
select {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: not-allowed;
  border-color: #b9c7c2;
  color: #6d7f79;
  background: #edf2f0;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 390px) 1fr;
  height: 100vh;
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #f9fbfa;
  overflow-y: auto;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-size: 14px;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.brand p,
.note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 14px;
  letter-spacing: 0;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 92px;
  padding: 14px;
  border: 1px dashed #9cb3aa;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: #f5faf7;
  cursor: pointer;
}

.drop-zone.dragging {
  border-color: var(--accent);
  color: var(--accent-dark);
  background: #e6f6ef;
}

.drop-zone input {
  display: none;
}

.file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.file-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  text-align: left;
  background: #fff;
  overflow: hidden;
}

.file-item:hover {
  color: var(--ink);
  background: #f5faf7;
}

.file-item.active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.file-select {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-width: 0;
  min-height: 38px;
  padding: 7px 9px 7px 12px;
  border: 0;
  border-radius: 0;
  color: var(--ink);
  text-align: left;
  background: transparent;
}

.file-select:hover {
  color: var(--ink);
  background: #f5faf7;
}

.file-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.file-item span {
  color: var(--muted);
  font-size: 12px;
}

.file-remove {
  display: grid;
  place-items: center;
  width: 30px;
  min-height: 30px;
  margin-right: 6px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 19px;
  line-height: 1;
}

.file-remove:hover {
  color: var(--danger);
  background: rgba(180, 75, 64, 0.1);
}

.library-search-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
}

.library-search-row button {
  padding: 0 12px;
}

.library-clear {
  border-color: #d9b6b1;
  color: var(--danger);
  background: #fff;
}

.library-clear:hover {
  color: #fff;
  background: var(--danger);
}

.library-list {
  display: grid;
  gap: 8px;
  max-height: 280px;
  margin-top: 10px;
  overflow: auto;
}

.library-empty {
  padding: 12px;
  border: 1px dashed #afc0ba;
  border-radius: 7px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.library-item {
  display: grid;
  gap: 7px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.library-item strong {
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.library-code {
  overflow: hidden;
  color: var(--accent-dark);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 800;
}

.library-meta {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.library-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.library-actions button {
  min-height: 32px;
  padding: 0 10px;
}

.library-delete {
  border-color: #d9b6b1;
  color: var(--danger);
  background: #fff;
}

.library-delete:hover {
  color: #fff;
  background: var(--danger);
}

.quick-preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.quick-preset-grid button {
  min-height: 54px;
  padding: 8px;
  line-height: 1.15;
}

.quick-preset-grid span {
  color: rgba(255, 255, 255, 0.86);
  font-size: 12px;
}

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

.control-grid label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.control-grid label.full {
  grid-column: 1 / -1;
}

.checkbox-line {
  display: grid !important;
  grid-template-columns: 18px 1fr;
  align-items: center;
  min-height: 30px;
}

.checkbox-line input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.control-grid span {
  color: var(--muted);
  font-size: 12px;
}

input,
select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 9px;
  color: var(--ink);
  background: #fff;
}

input[type="color"] {
  padding: 3px;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.layout-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.layout-actions.full {
  grid-column: 1 / -1;
}

.workspace {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.toolbar {
  position: relative;
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.page-tools,
.zoom-tools,
.export-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-tools {
  flex: 0 0 auto;
}

.toolbar-status {
  flex: 1 1 160px;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.export-tools {
  flex: 0 0 auto;
}

.support-widget {
  position: relative;
  flex: 0 1 520px;
}

#supportButton {
  display: grid;
  gap: 2px;
  align-content: center;
  width: 100%;
  min-width: 340px;
  min-height: 58px;
  padding: 8px 16px;
  border-color: #d8a13d;
  color: #5d4314;
  text-align: left;
  background: #fff8e8;
  white-space: normal;
}

.support-button-main,
.support-button-sub {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.support-button-main {
  font-size: 15px;
  font-weight: 850;
}

.support-button-sub {
  font-size: 13px;
  font-weight: 650;
  line-height: 1.25;
}

#supportButton:hover,
.support-widget.pinned #supportButton {
  border-color: #d08a1d;
  color: #fff;
  background: #d08a1d;
}

.support-popover {
  position: absolute;
  top: calc(100% + 10px);
  left: 50%;
  z-index: 60;
  width: min(560px, calc(100vw - 430px));
  min-width: 460px;
  padding: 14px;
  border: 1px solid #ead6ab;
  border-radius: 8px;
  background: #fffdf7;
  box-shadow: 0 20px 48px rgba(21, 51, 43, 0.2);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.support-widget:hover .support-popover,
.support-widget:focus-within .support-popover,
.support-widget.pinned .support-popover {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

.support-popover::before {
  position: absolute;
  top: -7px;
  left: 50%;
  width: 12px;
  height: 12px;
  border-top: 1px solid #ead6ab;
  border-left: 1px solid #ead6ab;
  background: #fffdf7;
  content: "";
  transform: translateX(-50%) rotate(45deg);
}

.support-copy {
  display: grid;
  gap: 5px;
  margin: 0 0 12px;
  color: var(--ink);
  text-align: center;
  font-size: 13px;
  line-height: 1.45;
}

.support-copy p {
  margin: 0;
}

.support-copy-lead {
  font-size: 16px;
  font-weight: 850;
}

.support-copy strong {
  color: #b56f0d;
  font-weight: 850;
}

.support-codes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  justify-items: center;
}

.support-codes figure {
  display: grid;
  gap: 8px;
  margin: 0;
  justify-items: center;
}

.support-codes img {
  width: 100%;
  max-width: 210px;
  aspect-ratio: 1 / 1;
  height: auto;
  border: 1px solid #eadfca;
  border-radius: 7px;
  background: #fff;
  object-fit: contain;
  justify-self: center;
}

.support-codes figcaption {
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.export-tools button {
  min-height: 38px;
  padding: 0 12px;
  white-space: nowrap;
}

.page-tools button,
.zoom-tools button {
  width: 38px;
  padding: 0;
  font-size: 20px;
}

#pageIndicator,
#zoomIndicator {
  min-width: 86px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.preview-wrap {
  position: relative;
  display: grid;
  align-items: start;
  justify-items: center;
  min-height: 0;
  padding: 22px;
  overflow: auto;
}

.workspace.has-page-rail .preview-wrap {
  padding-right: 170px;
}

.preview-wrap.dragging {
  outline: 3px solid rgba(20, 131, 92, 0.26);
  outline-offset: -10px;
  background: #e6f6ef;
}

.page-rail {
  position: absolute;
  top: 70px;
  right: 14px;
  bottom: 14px;
  z-index: 12;
  display: grid;
  grid-template-rows: auto 1fr;
  width: 136px;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(249, 251, 250, 0.94);
  box-shadow: 0 10px 28px rgba(21, 51, 43, 0.12);
  backdrop-filter: blur(6px);
}

.page-rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 40px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

.page-rail-head strong {
  font-size: 13px;
}

.page-rail-head span {
  color: var(--muted);
  font-size: 12px;
}

.page-thumb-list {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 0;
  padding: 10px;
  overflow-y: auto;
}

.page-thumb {
  display: grid;
  gap: 6px;
  justify-items: center;
  min-height: 0;
  padding: 7px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
}

.page-thumb:hover {
  border-color: rgba(20, 131, 92, 0.36);
  color: var(--ink);
  background: #edf7f2;
}

.page-thumb.active {
  border-color: var(--accent);
  color: var(--accent-dark);
  background: #e7f5ef;
  box-shadow: inset 0 0 0 1px rgba(20, 131, 92, 0.18);
}

.page-thumb-sheet {
  position: relative;
  overflow: hidden;
  border: 1px solid #c9d5d0;
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(21, 51, 43, 0.16);
}

.page-thumb canvas {
  display: block;
  background: #fff;
}

.page-thumb-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.page-thumb-stamp {
  position: absolute;
  padding: 0 1px;
  border: 1px solid rgba(20, 131, 92, 0.9);
  border-radius: 2px;
  color: #111;
  background: rgba(242, 184, 75, 0.22);
  font-family: Arial, sans-serif;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  transform-origin: left top;
}

.page-thumb-number {
  font-size: 12px;
  font-weight: 700;
}

.workspace-drop-hint {
  position: absolute;
  inset: 22px;
  z-index: 30;
  display: none;
  place-items: center;
  align-content: center;
  gap: 8px;
  border: 2px dashed rgba(20, 131, 92, 0.56);
  border-radius: 10px;
  color: var(--accent-dark);
  text-align: center;
  background: rgba(245, 250, 247, 0.86);
  pointer-events: none;
}

.workspace-drop-hint strong {
  font-size: 20px;
}

.workspace-drop-hint span {
  color: var(--muted);
  font-size: 13px;
}

.preview-wrap.dragging .workspace-drop-hint {
  display: grid;
}

.browser-preview {
  position: absolute;
  inset: 18px;
  z-index: 20;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 260px;
  overflow: hidden;
  border: 1px solid #25332f;
  border-radius: 8px;
  background: #2c2f2d;
  box-shadow: var(--shadow);
}

.browser-preview iframe {
  display: none;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.browser-preview.has-preview iframe {
  display: block;
}

.browser-preview-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 8px 12px;
  color: #f8fbfa;
  background: #1f2422;
}

.browser-preview-bar strong {
  flex: 0 0 auto;
  font-size: 14px;
}

.browser-preview-bar span {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: #cad6d2;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.browser-preview-bar button {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 10px;
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.12);
}

.browser-preview-bar button:hover {
  background: rgba(255, 255, 255, 0.2);
}

.preview-empty {
  position: absolute;
  inset: 48px 0 0;
  display: grid;
  place-items: center;
  padding: 20px;
  color: #cad6d2;
  text-align: center;
  font-size: 13px;
}

.browser-preview.has-preview .preview-empty {
  display: none;
}

.empty-state {
  display: grid;
  gap: 8px;
  place-items: center;
  max-width: 360px;
  padding: 28px;
  border: 1px dashed #afc0ba;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: rgba(255, 255, 255, 0.72);
}

.empty-state strong {
  color: var(--ink);
  font-size: 18px;
}

.page-stage {
  position: relative;
  box-shadow: var(--shadow);
  background: #fff;
}

#pdfCanvas {
  display: block;
}

.guide-layer,
.redaction-layer,
.stamps-layer {
  position: absolute;
  inset: 0;
}

.guide-layer {
  pointer-events: none;
}

.cell-guide {
  position: absolute;
  border: 1px dashed rgba(20, 131, 92, 0.42);
  background: rgba(20, 131, 92, 0.035);
}

.redaction-layer {
  pointer-events: none;
}

.redaction-mask {
  position: absolute;
  display: grid;
  place-items: center;
  border: 1px solid rgba(180, 75, 64, 0.75);
  border-radius: 4px;
  color: #8b332c;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: inset 0 0 0 1px rgba(180, 75, 64, 0.18);
  cursor: move;
  font-size: 12px;
  font-weight: 700;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}

.redaction-mask.active {
  border-color: var(--danger);
  box-shadow:
    inset 0 0 0 1px rgba(180, 75, 64, 0.32),
    0 0 0 3px rgba(180, 75, 64, 0.14);
}

.redaction-label {
  display: block;
  pointer-events: none;
}

.redaction-resize-handle {
  position: absolute;
  z-index: 2;
  width: 10px;
  height: 10px;
  border: 1px solid #fff;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 1px 4px rgba(86, 36, 31, 0.28);
  pointer-events: auto;
}

.redaction-resize-handle.handle-nw {
  top: -6px;
  left: -6px;
  cursor: nwse-resize;
}

.redaction-resize-handle.handle-n {
  top: -6px;
  left: 50%;
  cursor: ns-resize;
  transform: translateX(-50%);
}

.redaction-resize-handle.handle-ne {
  top: -6px;
  right: -6px;
  cursor: nesw-resize;
}

.redaction-resize-handle.handle-e {
  top: 50%;
  right: -6px;
  cursor: ew-resize;
  transform: translateY(-50%);
}

.redaction-resize-handle.handle-se {
  right: -6px;
  bottom: -6px;
  cursor: nwse-resize;
}

.redaction-resize-handle.handle-s {
  bottom: -6px;
  left: 50%;
  cursor: ns-resize;
  transform: translateX(-50%);
}

.redaction-resize-handle.handle-sw {
  bottom: -6px;
  left: -6px;
  cursor: nesw-resize;
}

.redaction-resize-handle.handle-w {
  top: 50%;
  left: -6px;
  cursor: ew-resize;
  transform: translateY(-50%);
}

.stamps-layer {
  pointer-events: none;
}

.stamp-overlay {
  position: absolute;
  max-width: none;
  padding: 0 2px;
  border: 1px solid rgba(20, 131, 92, 0.75);
  border-radius: 4px;
  color: #111;
  background: rgba(242, 184, 75, 0.18);
  cursor: move;
  user-select: none;
  white-space: nowrap;
  touch-action: none;
  pointer-events: none;
  line-height: 1;
  transform-origin: left top;
  will-change: left, top, transform;
}

.stamp-overlay.primary {
  pointer-events: auto;
}

.stamp-overlay.primary:hover,
.stamp-overlay.primary:focus-visible {
  box-shadow: 0 0 0 3px rgba(20, 131, 92, 0.16);
}

.stamp-overlay.copy {
  border-color: rgba(20, 131, 92, 0.34);
  background: rgba(242, 184, 75, 0.11);
}

.stamp-overlay:focus-visible {
  outline: 3px solid rgba(20, 131, 92, 0.28);
}

.stamp-label {
  display: block;
  pointer-events: none;
}

.stamp-resize-handle {
  position: absolute;
  z-index: 2;
  width: 9px;
  height: 9px;
  border: 1px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(21, 51, 43, 0.28);
  pointer-events: auto;
}

.stamp-resize-handle.handle-nw {
  top: -6px;
  left: -6px;
  cursor: nwse-resize;
}

.stamp-resize-handle.handle-n {
  top: -6px;
  left: 50%;
  cursor: ns-resize;
  transform: translateX(-50%);
}

.stamp-resize-handle.handle-ne {
  top: -6px;
  right: -6px;
  cursor: nesw-resize;
}

.stamp-resize-handle.handle-e {
  top: 50%;
  right: -6px;
  cursor: ew-resize;
  transform: translateY(-50%);
}

.stamp-resize-handle.handle-se {
  right: -6px;
  bottom: -6px;
  cursor: nwse-resize;
}

.stamp-resize-handle.handle-s {
  bottom: -6px;
  left: 50%;
  cursor: ns-resize;
  transform: translateX(-50%);
}

.stamp-resize-handle.handle-sw {
  bottom: -6px;
  left: -6px;
  cursor: nesw-resize;
}

.stamp-resize-handle.handle-w {
  top: 50%;
  left: -6px;
  cursor: ew-resize;
  transform: translateY(-50%);
}

@media (max-width: 1680px) and (min-width: 981px) {
  .toolbar {
    flex-wrap: wrap;
  }

  .toolbar-status {
    flex: 1 1 120px;
  }

  .support-widget {
    flex: 1 1 340px;
    max-width: 520px;
  }
}

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

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    overflow: visible;
    min-height: 72vh;
  }

  .preview-wrap {
    align-items: center;
    padding-right: 22px;
  }

  .workspace.has-page-rail .preview-wrap {
    padding-right: 22px;
  }

  .page-rail {
    display: none;
  }

  .toolbar {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .toolbar-status {
    order: 4;
    flex-basis: 100%;
  }

  .export-tools {
    flex: 1 1 100%;
    justify-content: stretch;
  }

  .support-widget {
    flex: 1 1 360px;
    max-width: 100%;
  }

  .support-popover {
    right: auto;
    left: 0;
    width: min(520px, calc(100vw - 32px));
    min-width: 0;
    transform: translateY(-4px);
  }

  .support-widget:hover .support-popover,
  .support-widget:focus-within .support-popover,
  .support-widget.pinned .support-popover {
    transform: translateY(0);
  }

  .support-popover::before {
    right: auto;
    left: 28px;
    transform: rotate(45deg);
  }

  .export-tools button {
    flex: 1 1 0;
  }
}

@media (max-width: 560px) {
  .sidebar,
  .preview-wrap {
    padding: 12px;
  }

  .control-grid,
  .button-row,
  .layout-actions {
    grid-template-columns: 1fr;
  }

  .toolbar,
  .export-tools,
  .page-tools,
  .zoom-tools,
  .support-widget {
    align-items: stretch;
    flex-direction: column;
  }

  .page-tools,
  .zoom-tools {
    display: grid;
    grid-template-columns: 38px 1fr 38px;
  }

  .export-tools {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  #supportButton {
    width: 100%;
    min-width: 0;
    text-align: center;
  }

  .support-codes {
    grid-template-columns: 1fr;
  }

  .support-codes img {
    height: auto;
  }
}
