/* ScanDocument.app — scanner app styles (mobile-first) */

.app-body { background: var(--paper); min-height: 100vh; display: flex; flex-direction: column; }

[hidden] { display: none !important; }

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: rgba(247, 246, 242, .92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.page-count {
  font-family: var(--mono); font-size: 11px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-soft); font-weight: 600;
}

.app-main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 16px; }

.view { display: none; }
.view.active { display: block; }
.view-title { font-size: 17px; font-weight: 700; text-align: center; margin-bottom: 12px; }

/* ---------- empty state ---------- */
.empty-state { text-align: center; padding: 12vh 8px 0; }
.empty-art { display: flex; justify-content: center; margin-bottom: 18px; }
.empty-state h1 { font-size: 26px; letter-spacing: -.02em; }
.empty-state p { color: var(--ink-soft); margin-top: 8px; }
.big-actions { display: flex; flex-direction: column; gap: 12px; max-width: 320px; margin: 26px auto 0; }
.hint { font-size: 13px; color: var(--ink-soft); margin-top: 18px; }

/* ---------- pages grid ---------- */
.pages-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px; padding-bottom: 90px;
}
.page-card {
  background: var(--white); border: 1px solid var(--line-strong);
  border-radius: 6px; overflow: hidden;
  box-shadow: 0 8px 20px rgba(20, 22, 28, .06);
}
.page-card img { width: 100%; aspect-ratio: 3/4; object-fit: contain; background: var(--paper-deep); cursor: pointer; }
.page-card-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px; border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--ink-soft);
}
.mini {
  width: 30px; height: 30px; border-radius: 5px; font-size: 18px; line-height: 1;
  color: var(--ink); border: 1px solid var(--line-strong); background: var(--paper);
}

/* ---------- bottom bar ---------- */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; gap: 10px; justify-content: center; align-items: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(247, 246, 242, .94); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line-strong);
}
.bottom-bar .btn {
  flex: 1 1 0; max-width: 220px; min-height: 48px;
  white-space: nowrap; padding: 12px 10px; font-size: 14.5px;
}

/* ---------- crop view ---------- */
.crop-stage {
  position: relative; display: flex; justify-content: center;
  touch-action: none; margin-bottom: 90px;
}
.crop-inner { position: relative; }
#crop-canvas { border-radius: 8px; box-shadow: 0 4px 18px rgba(16, 40, 88, .15); }
#crop-svg { position: absolute; top: 0; left: 0; pointer-events: none; }
#crop-poly {
  fill: rgba(29, 78, 216, .12);
  stroke: var(--blue); stroke-width: 2; vector-effect: non-scaling-stroke;
}
.crop-handle {
  position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px;
  touch-action: none; cursor: grab; z-index: 5;
}
.crop-handle::after {
  content: ''; position: absolute; inset: 11px;
  background: #fff; border: 4px solid var(--blue); border-radius: 50%;
  box-shadow: 0 2px 8px rgba(16, 40, 88, .35);
}
.crop-handle:active { cursor: grabbing; }

/* ---------- edit view ---------- */
.edit-stage { position: relative; display: flex; justify-content: center; }
#edit-canvas { border-radius: 8px; box-shadow: 0 4px 18px rgba(16, 40, 88, .15); background: #fff; }

.filter-row { display: flex; gap: 8px; justify-content: center; margin: 16px 0 10px; flex-wrap: wrap; }
.chip {
  padding: 8px 16px; border-radius: 5px;
  font-family: var(--mono); font-size: 12.5px; letter-spacing: .04em; font-weight: 600;
  background: var(--white); color: var(--ink-soft); border: 1px solid var(--line-strong);
}
.chip.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.tool-row { display: flex; gap: 6px; justify-content: center; margin-bottom: 90px; flex-wrap: wrap; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-width: 62px; padding: 10px 8px; border-radius: 6px;
  font-size: 20px; color: var(--ink); background: var(--white); border: 1px solid var(--line-strong);
}
.tool span {
  font-family: var(--mono); font-size: 10px; letter-spacing: .06em;
  text-transform: uppercase; font-weight: 600; color: var(--ink-soft);
}
.tool:active { background: var(--paper-deep); }
.tool.danger { color: #a03024; }

/* ---------- signature overlay ---------- */
.sig-overlay {
  position: absolute; z-index: 20; touch-action: none; cursor: move;
  border: 2px dashed var(--blue); border-radius: 6px; padding: 4px;
  background: rgba(255, 255, 255, .25);
}
.sig-overlay img { width: 100%; pointer-events: none; }
.sig-resize {
  position: absolute; right: -14px; bottom: -14px; width: 28px; height: 28px;
  background: var(--blue); border: 3px solid #fff; border-radius: 50%;
  box-shadow: 0 2px 8px rgba(16, 40, 88, .4); cursor: nwse-resize; touch-action: none;
}

/* ---------- signature pad modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(16, 24, 40, .55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
  background: var(--white); border: 1px solid var(--line-strong);
  border-radius: 10px; padding: 20px;
  width: 100%; max-width: 600px;
  box-shadow: 0 24px 60px rgba(20, 22, 28, .25);
}
.modal-card h3 { margin-bottom: 12px; font-size: 18px; letter-spacing: -.01em; }
.sig-pad {
  width: 100%; border: 1.5px dashed var(--line-strong); border-radius: 8px;
  background: repeating-linear-gradient(var(--white), var(--white) 54px, var(--paper-deep) 55px);
  touch-action: none;
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.modal-card .hint { margin-top: 12px; text-align: center; }

/* ---------- live camera scanner ---------- */
.no-scroll { overflow: hidden; }
.scan-screen {
  position: fixed; inset: 0; z-index: 300; background: #000;
}
#scan-video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover;
}
#scan-overlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
}
.scan-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(rgba(0, 0, 0, .55), transparent);
}
.scan-hint {
  color: #fff; font-size: 14px; font-weight: 600; text-align: center; flex: 1;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .6);
}
.scan-icon-btn {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  background: rgba(255, 255, 255, .18); color: #fff; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(6px);
}
.scan-icon-btn.on { background: #ffd60a; color: #000; }
.scan-bottom {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 2;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 18px 24px calc(24px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, .6));
}
.scan-thumb-wrap { position: relative; justify-self: start; width: 52px; height: 52px; }
#scan-thumb {
  width: 52px; height: 52px; object-fit: cover; border-radius: 8px;
  border: 2px solid #fff; cursor: pointer; background: #222;
}
.scan-count {
  position: absolute; top: -8px; right: -8px;
  min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px;
  background: var(--blue); color: #fff; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #000;
}
.scan-shutter {
  width: 72px; height: 72px; border-radius: 50%; justify-self: center;
  background: #fff; border: 5px solid rgba(255, 255, 255, .35);
  background-clip: padding-box;
  box-shadow: 0 0 0 3px #fff;
  transition: transform .1s ease;
}
.scan-shutter:active { transform: scale(.9); }
.scan-done { justify-self: end; padding: 10px 16px; font-size: 14px; }
.scan-flash {
  position: absolute; inset: 0; z-index: 3; background: #fff;
  opacity: 0; pointer-events: none; transition: opacity .12s ease;
}
.scan-flash.go { opacity: .85; }

/* ---------- busy spinner ---------- */
.busy {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(255, 255, 255, .5);
  display: flex; align-items: center; justify-content: center;
}
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--blue);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
