:root {
  color-scheme: dark;
  --bg: #0d0f12;
  --panel: #15181d;
  --panel-2: #1d2128;
  --line: #2c323b;
  --text: #f4f6f8;
  --muted: #9ba5b2;
  --accent: #d9ff62;
  --accent-text: #10130b;
  --paper: #fff;
  --field: #f6ffbf;
  --field-line: #98b72f;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 900px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(18px + var(--safe-top)) 14px calc(18px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}
.eyebrow {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .13em;
}
h1 {
  margin: 3px 0 0;
  font-size: clamp(29px, 8vw, 42px);
  letter-spacing: -.045em;
}
h2 { margin: 7px 0; letter-spacing: -.025em; }
.status {
  max-width: 44%;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
  line-height: 1.25;
}

.pocket-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  margin-bottom: 12px;
  background: #111318;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.pocket-switch-link {
  min-height: 34px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .05em;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.pocket-switch-link.active {
  background: var(--panel-2);
  color: var(--accent);
}

.toolbar {
  position: sticky;
  top: var(--safe-top);
  z-index: 50;
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 7px;
  margin: 0 -2px 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(21,24,29,.96);
  backdrop-filter: blur(14px);
  scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.tool-button,
.big-open {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 750;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.tool-button:active, .big-open:active { transform: scale(.98); }
.tool-button.active {
  background: #f5f5f5;
  border-color: #f5f5f5;
  color: #111;
}
.tool-button.accent,
.big-open {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.tool-button:disabled { opacity: .35; transform: none; }
.file-button { position: relative; overflow: hidden; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.empty-state {
  min-height: 62dvh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  padding: 28px;
  border: 1px dashed #39414c;
  border-radius: 18px;
  text-align: center;
  background: radial-gradient(circle at 50% 15%, #1a1f26, #111318 65%);
}
.empty-state p {
  max-width: 430px;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}
.empty-icon {
  width: 64px;
  height: 64px;
  border: 1px solid #3b4551;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: #20252d;
  color: var(--accent);
  font: 800 16px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.big-open { min-height: 46px; padding: 0 20px; }

.viewer {
  display: grid;
  gap: 16px;
  padding-bottom: 10px;
}
.page-shell {
  position: relative;
  width: 100%;
  margin: 0 auto;
  background: var(--paper);
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(0,0,0,.28);
  overflow: hidden;
  touch-action: manipulation;
}
.page-shell canvas.pdf-page {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
}
.field-layer,
.placed-layer {
  position: absolute;
  inset: 0;
}
.field-layer { z-index: 4; }
.placed-layer { z-index: 6; pointer-events: none; }
.form-field {
  position: absolute;
  border: 1px solid rgba(115,143,22,.7);
  background: rgba(246,255,191,.52);
  color: #10130b;
  border-radius: 3px;
  min-width: 18px;
  min-height: 18px;
}
.form-field.text-field {
  width: 100%;
  height: 100%;
  padding: 1px 3px;
  outline: none;
  font-size: max(12px, min(16px, 2.8vw));
}
.form-field.text-field:focus {
  border: 2px solid #7b9d0f;
  background: rgba(250,255,220,.92);
}
.checkbox-wrap {
  position: absolute;
  display: grid;
  place-items: center;
  background: rgba(246,255,191,.64);
  border: 1px solid rgba(115,143,22,.75);
  border-radius: 3px;
}
.checkbox-wrap input {
  width: 78%;
  height: 78%;
  margin: 0;
  accent-color: #111;
}
.signature-field {
  position: absolute;
  display: grid;
  place-items: center;
  border: 1.5px dashed #7b9d0f;
  border-radius: 4px;
  background: rgba(246,255,191,.58);
  color: #283300;
  font-size: 11px;
  font-weight: 800;
}
.placed-text {
  position: absolute;
  color: #111;
  font: 500 14px/1.15 Helvetica, Arial, sans-serif;
  white-space: nowrap;
  transform: translateY(-90%);
}
.placed-check {
  position: absolute;
  display: grid;
  place-items: center;
  color: #111;
  font: 800 24px/1 Arial, sans-serif;
}
.placed-signature {
  position: absolute;
  object-fit: contain;
  filter: contrast(1.15);
}

footer {
  padding: 16px 2px 2px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.modal {
  position: fixed;
  z-index: 100;
  inset: 0;
  padding: calc(20px + var(--safe-top)) 14px calc(20px + var(--safe-bottom));
  background: rgba(5,6,8,.78);
  backdrop-filter: blur(12px);
  display: grid;
  place-items: center;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(100%, 620px);
  padding: 14px;
  border: 1px solid #343b45;
  border-radius: 18px;
  background: #15181d;
  box-shadow: 0 25px 80px rgba(0,0,0,.55);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}
.modal-head h2 { margin-top: 3px; }
.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 24px;
}
.signature-canvas {
  display: block;
  width: 100%;
  height: 190px;
  margin: 10px 0;
  border-radius: 11px;
  background: #fff;
  touch-action: none;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-note { margin: 10px 2px 0; color: var(--muted); font-size: 11px; }

.toast {
  position: fixed;
  z-index: 200;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 28px);
  padding: 10px 14px;
  border: 1px solid #3b424c;
  border-radius: 999px;
  background: rgba(23,26,31,.97);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.toast[hidden] { display: none; }

@media (min-width: 700px) {
  .app-shell { padding-left: 22px; padding-right: 22px; }
  .viewer { gap: 22px; }
}
