*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0d0d0d;
  --surface:  #161616;
  --surface2: #1e1e1e;
  --border:   #2a2a2a;
  --text:     #e0e0e0;
  --muted:    #777;
  --accent:   #2563eb;
  --green:    #16a34a;
  --orange:   #ea580c;
  --danger:   #dc2626;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  color-scheme: dark;
}

body {
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.app-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

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

.toolbar {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 11px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { background: #282828; }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: #1d4ed8;
}
.btn-primary:hover:not(:disabled) { background: #1d4ed8; }

.btn-danger {
  background: var(--danger);
  border-color: #b91c1c;
}
.btn-danger:hover:not(:disabled) { background: #b91c1c; }

.btn.active {
  background: var(--accent);
  border-color: #1d4ed8;
}

.btn-icon {
  padding: 5px 10px;
  font-size: 14px;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */

.app {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */

.sidebar {
  width: 240px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.field-count { font-size: 11px; color: var(--muted); }

.field-list {
  flex: 1;
  overflow-y: auto;
  padding: 2px 0;
}

.field-empty {
  padding: 16px 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.field-page-label {
  padding: 8px 12px 3px;
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field-item {
  padding: 6px 12px;
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background 0.1s;
}

.field-item:hover { background: #1a1a1a; }

.field-item.selected {
  background: rgba(37, 99, 235, 0.1);
  border-left-color: var(--accent);
}

.fi-name {
  display: block;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fi-key {
  display: block;
  font-size: 11px;
  color: var(--orange);
  font-family: "SF Mono", "Fira Mono", monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.field-item.mapped .fi-key { color: var(--green); }

/* ── Viewer ───────────────────────────────────────────────────────────────── */

.viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  padding: 6px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.page-info {
  font-size: 12px;
  color: var(--muted);
  min-width: 90px;
  text-align: center;
}

.canvas-container {
  flex: 1;
  overflow: auto;
  background: #0a0a0a;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
  position: relative;
}

.upload-prompt {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.upload-prompt p { font-size: 13px; }

/* Two canvases stacked */

.canvases {
  position: relative;
  display: none; /* shown after PDF loads */
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 8px 32px rgba(0, 0, 0, 0.6);
}

#pdf-canvas    { display: block; }
#overlay-canvas { position: absolute; top: 0; left: 0; cursor: default; }

/* ── Key panel ────────────────────────────────────────────────────────────── */

.key-panel {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.55);
  z-index: 200;
}

.key-panel.hidden { display: none; }

.key-panel-inner {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.key-panel-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.kp-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.kp-field-name {
  font-size: 12px;
  font-family: "SF Mono", "Fira Mono", monospace;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kp-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 500;
  flex-shrink: 0;
}

.kp-badge-acroform { background: rgba(37,99,235,0.2); color: #60a5fa; }
.kp-badge-manual   { background: rgba(234,88,12,0.2);  color: #fb923c; }

.kp-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kp-row.hidden { display: none; }

.kp-row label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.kp-input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 8px;
  border-radius: 4px;
  font-family: "SF Mono", "Fira Mono", monospace;
  font-size: 12px;
  width: 100%;
  transition: border-color 0.12s;
}

.kp-select {
  font-family: inherit;
}

.kp-textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.45;
}

.kp-input:focus {
  outline: none;
  border-color: var(--accent);
}

.kp-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.kp-actions .btn-danger { margin-left: auto; }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #444; }
