:root {
  --sig: #2563eb;
  --date: #16a34a;
  --init: #ea580c;
  --title: #9333ea;
  --bg: #f6f6f7;
  --fg: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
  padding-top: max(12px, env(safe-area-inset-top));
}

h1 {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

select,
button {
  font: inherit;
  border: 1px solid var(--border);
  background: white;
  border-radius: 8px;
  padding: 8px 12px;
  min-height: 38px;
  color: var(--fg);
}

button {
  cursor: pointer;
}

button.primary {
  background: var(--fg);
  color: white;
  border-color: var(--fg);
  font-weight: 500;
}

button:disabled {
  opacity: 0.5;
  cursor: progress;
}

select {
  flex: 1;
  min-width: 0;
}

.client-link {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  color: var(--fg);
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  min-height: 38px;
}

.client-link:hover {
  background: var(--bg);
}

.status {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
  min-height: 18px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
}

.legend label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  cursor: pointer;
}

.legend input {
  margin: 0;
}

.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  color: white;
  font-weight: 500;
  font-size: 11px;
}

.chip.sig {
  background: var(--sig);
}

.chip.date {
  background: var(--date);
}

.chip.init {
  background: var(--init);
}

.chip.title {
  background: var(--title);
}

main {
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.page {
  position: relative;
  background: white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  border-radius: 2px;
  overflow: visible;
}

.page canvas {
  display: block;
  border-radius: 2px;
}

.page-label {
  position: absolute;
  bottom: -22px;
  left: 0;
  font-size: 11px;
  color: var(--muted);
}

.bbox {
  position: absolute;
  border: 2px solid;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 2px;
  pointer-events: auto;
}

.bbox-signature {
  border-color: var(--sig);
  background: color-mix(in srgb, var(--sig) 12%, transparent);
}

.bbox-date {
  border-color: var(--date);
  background: color-mix(in srgb, var(--date) 12%, transparent);
}

.bbox-initials {
  border-color: var(--init);
  background: color-mix(in srgb, var(--init) 12%, transparent);
}

.bbox-title {
  border-color: var(--title);
  background: color-mix(in srgb, var(--title) 12%, transparent);
}

.bbox-tag {
  position: absolute;
  top: -16px;
  left: -2px;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 5px;
  border-radius: 3px 3px 3px 0;
  color: white;
  white-space: nowrap;
  line-height: 1;
}

.bbox-signature .bbox-tag {
  background: var(--sig);
}

.bbox-date .bbox-tag {
  background: var(--date);
}

.bbox-initials .bbox-tag {
  background: var(--init);
}

.bbox-title .bbox-tag {
  background: var(--title);
}

#raw-panel {
  margin: 24px 12px 40px;
  padding: 8px 12px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
}

#raw-panel summary {
  cursor: pointer;
  user-select: none;
  font-weight: 500;
}

#raw-json {
  margin: 8px 0 0;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 50vh;
  overflow: auto;
  color: var(--fg);
}
