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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  min-height: 100vh;
}

/* ─── Toolbar ─── */
#toolbar {
  position: sticky;
  top: 0;
  background: #16213e;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 200;
  border-bottom: 1px solid #0f3460;
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-info {
  margin-left: auto;
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: #94a3b8;
}

.separator {
  width: 1px;
  height: 24px;
  background: #334155;
}

/* ─── Buttons ─── */
.btn {
  padding: 6px 14px;
  border: 1px solid #334155;
  border-radius: 6px;
  background: #1e293b;
  color: #e2e8f0;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.btn:hover { background: #334155; }
.btn-primary { background: #2563eb; border-color: #2563eb; color: white; }
.btn-primary:hover { background: #1d4ed8; }
.btn-danger { background: #dc2626; border-color: #dc2626; color: white; }
.btn-danger:hover { background: #b91c1c; }

.file-label { display: inline-block; cursor: pointer; }
.file-label input[type="file"] { display: none; }

select, input[type="text"], input[type="number"] {
  padding: 6px 10px;
  border: 1px solid #334155;
  border-radius: 6px;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 12px;
}
select:focus, input:focus {
  outline: none;
  border-color: #2563eb;
}

/* ─── Main layout ─── */
#main-layout {
  display: flex;
  position: relative;
}

/* ─── PDF Container ─── */
#pdf-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 24px;
  overflow-y: auto;
  min-height: calc(100vh - 50px);
}

.page-wrapper {
  position: relative;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  background: white;
}

.page-label {
  position: absolute;
  top: -22px;
  left: 0;
  font-size: 11px;
  color: #94a3b8;
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  cursor: crosshair;
  z-index: 10;
}

/* ─── Field boxes ─── */
.field-box {
  position: absolute;
  background: rgba(37, 99, 235, 0.12);
  border: 1.5px solid rgba(37, 99, 235, 0.6);
  cursor: pointer;
  z-index: 20;
  transition: background 0.1s, border-color 0.1s;
}
.field-box:hover {
  background: rgba(37, 99, 235, 0.25);
  border-color: rgba(37, 99, 235, 0.9);
}
.field-box.selected {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.15);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3);
}
.field-box.checkbox-field {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.6);
}
.field-box.checkbox-field:hover {
  background: rgba(16, 185, 129, 0.25);
}

.field-box span {
  font-size: 7px;
  color: #2563eb;
  padding: 0 2px;
  white-space: nowrap;
  overflow: hidden;
  display: block;
  pointer-events: none;
  line-height: 1;
  margin-top: 1px;
}
.field-box.checkbox-field span {
  color: #10b981;
}
.field-box.number-field {
  background: rgba(139, 92, 246, 0.12);
  border-color: rgba(139, 92, 246, 0.6);
}
.field-box.number-field:hover {
  background: rgba(139, 92, 246, 0.25);
}
.field-box.number-field span {
  color: #8b5cf6;
}
.field-box.calculated-field {
  background: rgba(249, 115, 22, 0.12);
  border-color: rgba(249, 115, 22, 0.6);
}
.field-box.calculated-field:hover {
  background: rgba(249, 115, 22, 0.25);
}
.field-box.calculated-field span {
  color: #f97316;
}
.field-box.dropdown-field {
  background: rgba(6, 182, 212, 0.12);
  border-color: rgba(6, 182, 212, 0.6);
}
.field-box.dropdown-field:hover {
  background: rgba(6, 182, 212, 0.25);
}
.field-box.dropdown-field span {
  color: #06b6d4;
}

/* ─── Drawing preview ─── */
#drawing-preview {
  position: fixed;
  border: 2px dashed #f59e0b;
  background: rgba(245, 158, 11, 0.1);
  pointer-events: none;
  z-index: 1000;
}
#drawing-preview.hidden { display: none; }

/* ─── Resize handles ─── */
.resize-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #2563eb;
  border: 1px solid white;
  border-radius: 2px;
  z-index: 30;
}
.resize-handle.se { bottom: -4px; right: -4px; cursor: se-resize; }
.resize-handle.sw { bottom: -4px; left: -4px; cursor: sw-resize; }
.resize-handle.ne { top: -4px; right: -4px; cursor: ne-resize; }
.resize-handle.nw { top: -4px; left: -4px; cursor: nw-resize; }

/* ─── Field panel ─── */
#field-panel {
  position: fixed;
  right: 20px;
  top: 70px;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 16px;
  width: 260px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  z-index: 300;
}
#field-panel.hidden { display: none; }
#field-panel h3 {
  font-size: 13px;
  margin-bottom: 12px;
  color: #f59e0b;
}
#field-panel label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  color: #94a3b8;
}
#field-panel label input,
#field-panel label select {
  display: block;
  width: 100%;
  margin-top: 3px;
}
#field-panel label input[type="checkbox"] {
  display: inline-block;
  width: auto;
}
#fp-options-row { display: none; }
#fp-maxlength-row { display: none; }
.fp-type-row { display: none; }
.fp-number-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.fp-formula-hint {
  font-size: 9px;
  color: #475569;
  margin-top: 3px;
  font-style: italic;
}
.fp-coords-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 8px 0;
}
.fp-coord-label {
  display: flex !important;
  align-items: center;
  gap: 4px;
  font-size: 10px !important;
  font-family: monospace;
  color: #64748b !important;
  margin-bottom: 0 !important;
}
.fp-coord-label input {
  width: 100% !important;
  padding: 3px 6px !important;
  font-size: 11px !important;
  font-family: monospace;
  margin-top: 0 !important;
}
.fp-page-display {
  grid-column: 1 / -1;
  font-size: 10px;
  font-family: monospace;
  color: #64748b;
}
.fp-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.fp-actions .btn { flex: 1; text-align: center; }
.fp-shortcuts {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #334155;
  font-size: 10px;
  color: #475569;
  line-height: 1.6;
  font-family: monospace;
}
.fp-shortcuts-title {
  color: #64748b;
  font-size: 10px;
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
