.scan-body {
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: #f5f0e6;
  color: var(--ink);
}

.scan-appbar {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  height: calc(58px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 10px 0;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 242, 232, 0.98);
}

.scan-back {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--ink-2);
  font-size: 14px;
  text-decoration: none;
}

.scan-brand {
  flex: none;
  line-height: 1;
}

.scan-brand b {
  display: block;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 500;
}

.scan-brand span {
  display: block;
  margin-top: 3px;
  color: var(--muted-2);
  font-family: var(--sans);
  font-size: 7px;
  letter-spacing: 0.16em;
}

.scan-heading {
  flex: 1;
  min-width: 0;
  padding-left: 3px;
}

.scan-title-input {
  width: 100%;
  height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 15px;
  line-height: 24px;
}

.scan-title-input:focus {
  outline: 0;
}

.scan-title-input[readonly] {
  color: var(--ink-2);
}

.scan-heading small {
  display: block;
  margin-top: 1px;
  overflow: hidden;
  color: var(--muted-2);
  font-family: var(--sans);
  font-size: 7px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scan-doc-btn {
  height: 28px;
  padding: 0 8px;
  flex: none;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: transparent;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 8px;
}

.scan-save {
  height: 30px;
  padding: 0 12px;
  flex: none;
  border: 1px solid var(--cinnabar);
  border-radius: 15px;
  background: var(--cinnabar);
  color: #fffaf0;
  font-family: var(--sans);
  font-size: 9px;
  letter-spacing: 0.06em;
}

.scan-save:disabled {
  opacity: 0.6;
}

.scan-screen {
  position: relative;
  height: calc(100dvh - 58px - env(safe-area-inset-top));
  overflow: hidden;
  background: #0b0a08;
}

.scan-camera-stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b0a08;
}

.scan-camera-stage video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-camera-stage video[hidden] {
  display: none;
}

.scan-camera-placeholder {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-content: center;
  gap: 6px;
  padding: 24px;
  color: #a89b86;
  text-align: center;
}

.scan-camera-placeholder b {
  color: #e3d6c2;
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 500;
}

.scan-camera-placeholder span {
  font-size: 10px;
}

.scan-camera-placeholder button {
  justify-self: center;
  margin-top: 9px;
  padding: 8px 20px;
  border: 1px solid rgba(244, 234, 215, 0.4);
  border-radius: 18px;
  background: transparent;
  color: #f1e3ca;
  font-size: 10px;
}

.scan-frame {
  position: absolute;
  top: 42%;
  left: 50%;
  z-index: 2;
  display: none;
  width: min(68%, 320px);
  aspect-ratio: 3 / 4;
  height: auto;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(238, 219, 181, 0.95);
  box-shadow:
    0 0 0 999px rgba(9, 8, 6, 0.42),
    0 0 0 1px rgba(40, 31, 20, 0.35) inset;
  pointer-events: none;
}

.scan-camera-stage.has-camera .scan-frame {
  display: block;
}

.scan-frame-inner {
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(238, 219, 181, 0.72);
}

.scan-frame-fish {
  position: absolute;
  top: -1px;
  left: 50%;
  width: 30px;
  height: 16px;
  transform: translateX(-50%);
}

.scan-frame-fish::before,
.scan-frame-fish::after {
  content: "";
  position: absolute;
  top: 0;
  width: 0;
  height: 0;
  border-top: 14px solid rgba(238, 219, 181, 0.9);
}

.scan-frame-fish::before {
  left: 0;
  border-right: 15px solid transparent;
}

.scan-frame-fish::after {
  right: 0;
  border-left: 15px solid transparent;
}

.scan-frame-seal {
  position: absolute;
  top: 14px;
  right: 9px;
  padding: 5px 3px;
  border: 1px solid rgba(181, 69, 50, 0.9);
  background: rgba(47, 29, 21, 0.42);
  color: #d98a70;
  font-family: var(--serif);
  font-size: 9px;
  line-height: 1.15;
  letter-spacing: 0.08em;
  writing-mode: vertical-rl;
}

.scan-corner {
  position: absolute;
  width: 18px;
  height: 18px;
  border-color: rgba(238, 219, 181, 0.95);
  border-style: solid;
}

.scan-corner-tl {
  top: -1px;
  left: -1px;
  border-width: 2px 0 0 2px;
}

.scan-corner-tr {
  top: -1px;
  right: -1px;
  border-width: 2px 2px 0 0;
}

.scan-corner-bl {
  bottom: -1px;
  left: -1px;
  border-width: 0 0 2px 2px;
}

.scan-corner-br {
  right: -1px;
  bottom: -1px;
  border-width: 0 2px 2px 0;
}

.scan-camera-tools {
  position: absolute;
  top: 10px;
  right: 12px;
  left: 12px;
  z-index: 4;
  display: flex;
  justify-content: space-between;
}

.scan-camera-tools button {
  padding: 6px 10px;
  border: 1px solid rgba(255, 250, 240, 0.22);
  border-radius: 14px;
  background: rgba(14, 12, 9, 0.52);
  color: rgba(255, 250, 240, 0.82);
  font-size: 8px;
  backdrop-filter: blur(7px);
}

.scan-camera-tools button.is-on {
  border-color: rgba(244, 205, 116, 0.8);
  color: #f4cd74;
}

.scan-camera-hint {
  position: absolute;
  right: 0;
  bottom: calc(214px + env(safe-area-inset-bottom));
  left: 0;
  z-index: 4;
  margin: 0;
  color: rgba(255, 250, 240, 0.62);
  font-size: 8px;
  text-align: center;
}

.scan-bottom-ui {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
  padding: 26px 12px calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent 0%, rgba(8, 7, 5, 0.72) 24%, rgba(8, 7, 5, 0.94) 100%);
}

.scan-roll-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 2px 6px;
  color: rgba(241, 227, 202, 0.6);
  font-family: var(--sans);
  font-size: 7px;
}

.scan-roll-head b {
  color: #f1e3ca;
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 500;
}

.scan-roll-head span:last-child {
  margin-left: auto;
}

.scan-list {
  display: flex;
  gap: 6px;
  min-height: 0;
  max-height: 104px;
  overflow-x: auto;
  padding: 1px 1px 4px;
  scrollbar-width: none;
}

.scan-list::-webkit-scrollbar {
  display: none;
}

.scan-item {
  position: relative;
  flex: 0 0 68px;
  overflow: hidden;
  border: 1px solid rgba(244, 234, 215, 0.22);
  border-radius: 4px;
  background: rgba(255, 253, 247, 0.08);
}

.scan-item img {
  display: block;
  width: 100%;
  height: 84px;
  object-fit: cover;
  opacity: 0.78;
}

.scan-item.is-uploaded img {
  opacity: 1;
}

.scan-item.is-cached img {
  opacity: 0.82;
}

.scan-item-state {
  display: block;
  height: 18px;
  overflow: hidden;
  padding: 3px 2px;
  color: rgba(241, 227, 202, 0.58);
  font-family: var(--sans);
  font-size: 6px;
  line-height: 12px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scan-item.is-uploaded .scan-item-state {
  color: #a9c39e;
}

.scan-item.is-cached .scan-item-state {
  color: #d98a70;
}

.scan-item.is-error .scan-item-state {
  color: #e58a7a;
}

.scan-item-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  background: rgba(23, 20, 15, 0.7);
  color: #fffaf0;
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1;
}

.scan-item-tools {
  display: flex;
  border-top: 1px solid rgba(244, 234, 215, 0.14);
}

.scan-item-tools button {
  flex: 1;
  height: 19px;
  border: 0;
  border-right: 1px solid rgba(244, 234, 215, 0.14);
  background: rgba(255, 253, 247, 0.06);
  color: rgba(241, 227, 202, 0.8);
  font-size: 10px;
  line-height: 1;
}

.scan-item-tools button:last-child {
  border-right: 0;
}

.scan-retry {
  position: absolute;
  right: 4px;
  bottom: 25px;
  left: 4px;
  height: 20px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(23, 20, 15, 0.8);
  color: #fffaf0;
  font-size: 7px;
}

.scan-empty {
  align-self: center;
  width: 100%;
  padding: 15px 10px;
  border: 1px dashed rgba(244, 234, 215, 0.18);
  border-radius: 5px;
  color: rgba(241, 227, 202, 0.48);
  font-size: 8px;
  line-height: 1.7;
  text-align: center;
}

.scan-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 30px 2px;
}

.scan-side-btn {
  width: 58px;
  border: 0;
  background: transparent;
  color: rgba(241, 227, 202, 0.72);
  font-family: var(--sans);
  font-size: 10px;
}

.scan-shutter {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  border: 2px solid rgba(255, 250, 240, 0.92);
  border-radius: 50%;
  background: transparent;
}

.scan-shutter span {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--cinnabar);
  transition: transform 100ms ease;
}

.scan-shutter:active span {
  transform: scale(0.9);
}

.scan-camera-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 1px 4px 0;
  color: rgba(241, 227, 202, 0.44);
  font-family: var(--sans);
  font-size: 7px;
}

.scan-camera-meta span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scan-sheet-scrim {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(16, 13, 9, 0.44);
  backdrop-filter: blur(2px);
}

.scan-sheet-scrim[hidden] {
  display: none;
}

.scan-doc-sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 90;
  padding: 16px 16px calc(18px + env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
  background: #fbf7ee;
  box-shadow: 0 -20px 50px rgba(23, 19, 14, 0.35);
  transform: translateY(105%);
  visibility: hidden;
  transition: transform 220ms ease, visibility 220ms ease;
}

.scan-doc-sheet.is-open {
  transform: translateY(0);
  visibility: visible;
}

.scan-sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.scan-sheet-head small {
  color: var(--muted-2);
  font-family: var(--sans);
  font-size: 7px;
  letter-spacing: 0.15em;
}

.scan-sheet-head h2 {
  margin: 2px 0 0;
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 500;
}

.scan-sheet-head button {
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 8px;
}

.scan-doc-fields {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 0;
}

.scan-category {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 9px;
}

.scan-category select {
  max-width: 150px;
  height: 32px;
  padding: 0 24px 0 9px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fffdf7;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 11px;
}

.scan-cache-mode {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 9px;
  white-space: nowrap;
}

.scan-cache-mode input {
  width: 15px;
  height: 15px;
  accent-color: var(--cinnabar);
}

.scan-sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 7px;
}

.scan-sheet-actions button {
  min-height: 38px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(255, 253, 247, 0.75);
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 9px;
}

.scan-sheet-actions button:first-child {
  border-color: rgba(164, 59, 43, 0.35);
  color: var(--cinnabar);
}

.scan-sheet-note {
  margin: 10px 0 0;
  color: var(--muted-2);
  font-size: 8px;
  line-height: 1.6;
}

.scan-body .modal-card {
  background: #fbf7ee;
}

@media (min-width: 720px) {
  .scan-body {
    width: 520px;
    margin: 0 auto;
    border-right: 1px solid var(--line);
    border-left: 1px solid var(--line);
  }
}

.scan-list {
  max-height: 112px;
}

.scan-item img {
  height: 72px;
}

.scan-item-state {
  height: 16px;
  line-height: 10px;
}

.scan-camera-hint {
  bottom: calc(252px + env(safe-area-inset-bottom));
}

.scan-personal {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 12px;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 10px;
}

.scan-personal input {
  width: 16px;
  height: 16px;
  accent-color: var(--cinnabar);
}
